/*
 * MobilePhotoFaceTagging — per-photo face tagger (mobile + desktop).
 * Distinct from mobile-face-training (which trains recognition for one person).
 *
 * Mobile-first base styles apply at all breakpoints. The `.mpft-desktop`
 * modifier (set by JS when opts.desktopMode is true) re-layouts the overlay
 * into a centered card with a side-by-side photo + actions split at wider
 * viewports. No hard kill-switch at any breakpoint — convergence means the
 * same UX at mobile, tablet, and desktop.
 */

.mpft-overlay {
  position: fixed;
  inset: 0;
  /* Reserve room for tab-bar (z 11000 sits above this z 10200).
     See mobile-tab-bar.css → "UNIVERSAL MOBILE-MODAL BOTTOM RESERVATION". */
  padding-bottom: var(--mobile-control-panel-height, 56px);
  z-index: 10200;              /* above UMI scaffold + story safety-exit */
  background: #0b0d12;
  color: #f5f6f8;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Header ──────────────────────────────────────────────────────────── */

.mpft-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 14px 10px;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.mpft-back {
  width: 40px;
  height: 40px;
  border-radius: 20px;
  border: none;
  background: rgba(255, 255, 255, 0.08);
  color: #f5f6f8;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex: 0 0 auto;
}

.mpft-back:active { background: rgba(255, 255, 255, 0.16); }
.mpft-back:hover { background: rgba(255, 255, 255, 0.14); }

.mpft-title {
  flex: 1 1 auto;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.01em;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mpft-badge {
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  color: #cfd3d8;
  letter-spacing: 0.02em;
}

/* ── Photo panel ─────────────────────────────────────────────────────── *
 * Layout: large face stage on top (zoomed to current face via background-
 * image) + small thumbnail rail below (whole photo with clickable bboxes).
 */

.mpft-photo-panel {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  background: #050608;
  padding: 8px;
  gap: 8px;
  /* S2 D2.4: surrender horizontal gestures to JS so iOS Safari stops eating
     them as edge-swipe / scroll. Vertical pans still flow through normally. */
  touch-action: pan-y;
}

.mpft-face-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  background-color: #0b0d12;
  background-repeat: no-repeat;
  border-radius: 10px;
  overflow: hidden;
  transition: background-position 180ms ease, background-size 180ms ease;
  /* S2 D2.4: same rationale — explicit pan-y on the stage itself; some iOS
     versions probe the topmost element rather than the parent. */
  touch-action: pan-y;
}

.mpft-thumb-rail {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding-top: 4px;
}

.mpft-thumb-frame {
  position: relative;
  height: 72px;
  max-width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.mpft-thumb {
  max-width: 100%;
  max-height: 72px;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
  border-radius: 6px;
  opacity: 0.85;
  user-select: none;
  -webkit-user-drag: none;
}

.mpft-thumb-hint {
  font-size: 11px;
  color: #6b7078;
  letter-spacing: 0.02em;
}

.mpft-overlay-layer {
  position: absolute;
  pointer-events: none;   /* container ignores; children (.mpft-bbox) receive */
}

.mpft-bbox {
  position: absolute;
  border: 1.5px solid rgba(255, 255, 255, 0.55);
  border-radius: 3px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
  pointer-events: auto;
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}

.mpft-bbox.is-current {
  border-color: #f7b500;            /* amber highlight */
  border-width: 2.5px;
  box-shadow:
    0 0 0 2px rgba(0, 0, 0, 0.4),
    0 0 18px rgba(247, 181, 0, 0.55);
}

.mpft-bbox.is-confirmed:not(.is-current) {
  border-color: rgba(16, 185, 129, 0.85);
}

.mpft-bbox.is-rejected:not(.is-current) {
  border-color: rgba(239, 68, 68, 0.7);
  border-style: dashed;
}

.mpft-photo-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.mpft-spinner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.15);
  border-top-color: #f5f6f8;
  animation: mpft-spin 0.9s linear infinite;
}

@keyframes mpft-spin {
  to { transform: rotate(360deg); }
}

/* ── Action panel ────────────────────────────────────────────────────── */

.mpft-action-panel {
  flex: 0 0 auto;
  background: rgba(18, 21, 28, 0.98);
  padding: 10px 14px calc(env(safe-area-inset-bottom, 0px) + 10px);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  max-height: 42vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.mpft-status {
  text-align: center;
  font-size: 14px;
  color: #9aa0a8;
  padding: 16px 0;
}

.mpft-q {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0 0 2px;
}

.mpft-confidence {
  font-size: 12px;
  color: #9aa0a8;
  margin-bottom: 8px;
}

.mpft-predicted {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  margin-bottom: 8px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  font-size: 13px;
}

.mpft-predicted.is-confirmed {
  background: rgba(16, 185, 129, 0.10);
  border-color: rgba(16, 185, 129, 0.35);
}

.mpft-predicted.is-rejected {
  background: rgba(239, 68, 68, 0.10);
  border-color: rgba(239, 68, 68, 0.35);
}

.mpft-predicted-name {
  flex: 1;
  font-weight: 600;
}

.mpft-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #10b981;
  flex: 0 0 auto;
}

.mpft-tag {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #10b981;
}

/* S2 D2.2 layout:
 *   .mpft-actions stays a vertical stack but only contains 2 children:
 *     1. Optional .mpft-btn-confirm (full-width "Yes, that's <Name>")
 *     2. .mpft-actions-pair  — two-column row with [Not family][Someone else]
 *   This gives the dominant action breathing room above the disambiguation
 *   pair, while making it impossible to render those two side-by-side rows in
 *   a single column (the prior bug). */
.mpft-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 6px;
}

.mpft-actions-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.mpft-actions-pair > .mpft-btn {
  /* Equalize line-height so a 2-line "Not a family member" sits flush with the
     1-line "Someone else…" instead of jumping the row's vertical alignment. */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  line-height: 1.2;
  min-height: 44px;
}

.mpft-btn {
  appearance: none;
  border: none;
  min-height: 42px;
  padding: 9px 14px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 10px;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: transform 100ms ease, background 120ms ease;
}

.mpft-btn:active {
  transform: scale(0.98);
}

.mpft-btn-primary {
  background: linear-gradient(135deg, #6d6cff 0%, #9a69ff 100%);
  color: #ffffff;
  box-shadow: 0 6px 18px rgba(109, 108, 255, 0.35);
}

.mpft-btn-secondary {
  background: rgba(255, 255, 255, 0.10);
  color: #f5f6f8;
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.mpft-btn-secondary:active,
.mpft-btn-secondary:hover {
  background: rgba(255, 255, 255, 0.18);
}

.mpft-btn-ghost {
  background: transparent;
  color: #cfd3d8;
  border: 1px solid rgba(255, 255, 255, 0.10);
}

.mpft-btn-ghost:active,
.mpft-btn-ghost:hover {
  background: rgba(255, 255, 255, 0.06);
}

.mpft-btn-skip {
  font-weight: 500;
  color: #9aa0a8;
}

/* Photo-level bulk disposition — deliberately quieter than the per-face
   decisions above it (it acts on the whole photo, so it must not be the button
   a thumb reaches for first), and tinted destructive so its nature is visible. */

.mpft-btn-link {
  background: transparent;
  border: none;
  color: #e08a8a;
  font-weight: 500;
  font-size: 13px;
  text-decoration: underline;
  text-underline-offset: 3px;
  margin-top: 2px;
  min-height: 38px;
}

.mpft-btn-link:active,
.mpft-btn-link:hover {
  color: #f0a6a6;
}

/* S2 D2.1: .mpft-nav and .mpft-nav-btn retired. Previous/Next now live in the
   Mobile Control Panel slots (see mobile-control-panel.js + mobile-tab-bar.css). */

/* ── lbc S3: unified comment field ───────────────────────────────────
 * Single textarea footer below the action panel. Persists across face
 * navigation (lives in the modal shell, never re-rendered). Target is
 * inferred at flush time: current face when focused, photo when
 * end-of-sequence. Replaces the hkh S4 dual-field design.
 * Shares .mpft-comment-field layout for textarea + inline mic.
 */

.mpft-comment-unified {
  flex: 0 0 auto;
  padding: 10px 14px calc(env(safe-area-inset-bottom, 0px) + 10px);
  background: rgba(12, 14, 19, 0.98);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.mpft-comment-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #9aa0a8;
  margin-bottom: 6px;
  text-transform: uppercase;
}

.mpft-comment-field {
  position: relative;
  display: block;
}

.mpft-comment-input {
  width: 100%;
  min-height: 44px;
  resize: vertical;
  padding: 10px 52px 10px 12px;  /* right padding reserves room for mic */
  font-family: inherit;
  font-size: 14px;
  line-height: 1.35;
  color: #f5f6f8;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  outline: none;
  transition: border-color 120ms ease, background 120ms ease;
  box-sizing: border-box;
}

.mpft-comment-input::placeholder {
  color: rgba(154, 160, 168, 0.7);
}

.mpft-comment-input:focus {
  border-color: rgba(109, 108, 255, 0.55);
  background: rgba(255, 255, 255, 0.09);
}

/* VoiceDictation mic button — positioned inside the textarea's padding gutter.
 * The .vd-mic-btn global baseline (css/voice-dictation.css) supplies the
 * amber gradient + pulsing .vd-mic-active halo. We position-override it here
 * so it sits top-right of the textarea. */
.mpft-comment-field .vd-mic-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  margin: 0;
}

/* ── Completion / empty states ───────────────────────────────────────── */

.mpft-complete,
.mpft-empty {
  text-align: center;
  padding: 22px 8px 8px;
}

.mpft-complete-icon {
  width: 56px;
  height: 56px;
  line-height: 56px;
  border-radius: 28px;
  margin: 0 auto 12px;
  font-size: 28px;
  background: rgba(16, 185, 129, 0.18);
  color: #10b981;
  font-weight: 700;
}

.mpft-complete-title {
  margin: 0 0 6px;
  font-size: 20px;
  font-weight: 700;
}

.mpft-complete-stats {
  margin: 0 0 12px;
  color: #9aa0a8;
  font-size: 14px;
}

/* S2 D2.1: hint copy that points users at the bookend Done + slot Previous
   in the Mobile Control Panel (no in-card buttons here anymore). */
.mpft-complete-hint {
  margin: 0;
  color: #cfd3d8;
  font-size: 13px;
  line-height: 1.4;
  max-width: 320px;
  margin-left: auto;
  margin-right: auto;
}

.mpft-complete-hint strong {
  color: #f5f6f8;
  font-weight: 700;
}

.mpft-empty p {
  color: #9aa0a8;
  margin: 0 0 14px;
  font-size: 14px;
}

/* ── Fallback toast ──────────────────────────────────────────────────── */

.mpft-toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 24px);
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  z-index: 10300;
  background: rgba(20, 22, 28, 0.95);
  color: #f5f6f8;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
}

.mpft-toast-success { background: rgba(16, 185, 129, 0.95); color: #fff; }
.mpft-toast-error   { background: rgba(239, 68, 68, 0.95);  color: #fff; }

/* ── Desktop mode ────────────────────────────────────────────────────── *
 * Opt-in via `.mpft-desktop` modifier class (JS sets this from opts.desktopMode).
 * Preserves the vertical header/photo/actions layout but re-centers the overlay
 * as a card with max-width and border-radius. No hard kill-switch — mobile base
 * styles still apply below 768px even if desktopMode was requested in error.
 */

@media (min-width: 768px) {
  .mpft-overlay.mpft-desktop {
    /* Scrim behind the card */
    padding: 0;
    background: rgba(5, 6, 8, 0.82);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    align-items: center;
    justify-content: center;
  }

  /* The three panels share a max-width and form a vertical card. We can't
     wrap them in a single <div> without an HTML change, so instead apply
     constraints to each sibling. */
  .mpft-overlay.mpft-desktop .mpft-header,
  .mpft-overlay.mpft-desktop .mpft-photo-panel,
  .mpft-overlay.mpft-desktop .mpft-action-panel {
    width: min(92vw, 920px);
    margin-left: auto;
    margin-right: auto;
    flex: 0 0 auto;
  }

  .mpft-overlay.mpft-desktop .mpft-header {
    padding: 14px 18px;
    border-radius: 16px 16px 0 0;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    background: #0b0d12;
  }

  .mpft-overlay.mpft-desktop .mpft-photo-panel {
    height: min(60vh, 540px);
    padding: 14px;
    background: #050608;
    border-left: 1px solid rgba(255, 255, 255, 0.08);
    border-right: 1px solid rgba(255, 255, 255, 0.08);
  }

  .mpft-overlay.mpft-desktop .mpft-action-panel {
    padding: 18px 22px;
    max-height: 38vh;
    border-radius: 0 0 16px 16px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(18, 21, 28, 0.98);
  }

  .mpft-overlay.mpft-desktop .mpft-btn {
    min-height: 42px;
    padding: 10px 16px;
    font-size: 14px;
  }

  .mpft-overlay.mpft-desktop .mpft-actions {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 10px;
  }

  .mpft-overlay.mpft-desktop .mpft-actions > .mpft-btn {
    flex: 1 1 220px;
  }
}
