/* ── Focus Stack — shared card-stack styles ─────────────────────────────────
 * One source of truth for the calm "one card at a time" surface, used by BOTH:
 *   - the SPA home view (inbox.html, injected into #content)
 *   - the standalone /focus-stack page (focus-stack.html)
 * via window.FocusStack (js/focus-stack.js). B1, 2026-05-29.
 *
 * EVERY selector is scoped under `.fstack` so it cannot clash with the SPA's
 * global CSS. The only genuine clashes were `.btn` (dashboard.css:205) and
 * `.toast` (dashboard.css:1655); `.fstack .btn` / `.fstack .toast` win on
 * specificity. CSS custom properties are declared ON `.fstack` so the card
 * styles are self-consistent regardless of the surrounding SPA theme vars.
 * Keyframes are prefixed `fs*` so they don't collide with the SPA's `pulse`/
 * `toastIn`/`toastOut`.
 * ───────────────────────────────────────────────────────────────────────── */

.fstack {
  --bg: #f6f7f9;
  --ink: #1a1f2e;
  --ink-mute: #6b7280;
  --ink-dim: #9ca3af;
  --border: #e5e7eb;
  --gold: #e2bd23;
  --gold-ink: #92400e;
  --primary: #1a1f2e;
  --danger: #dc2626;
  --warn: #f59e0b;
  --calm: #4a6fa5;
  --good: #059669;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: var(--ink);
  line-height: 1.4;
}
.fstack *, .fstack *::before, .fstack *::after {
  box-sizing: border-box; -webkit-tap-highlight-color: transparent;
}

.fstack .wrap { max-width: 720px; margin: 0 auto; padding: 16px; }
.fstack .nav-back {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--ink-mute); text-decoration: none;
  padding: 6px 10px; border-radius: 6px;
}
.fstack .nav-back:hover { color: var(--ink); background: rgba(0,0,0,0.04); }

/* Header — counter + day */
.fstack header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; padding: 8px 0; }
.fstack .day { font-size: 14px; color: var(--ink-mute); }
.fstack .counter {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 14px; background: #fff; border: 1px solid var(--border);
  border-radius: 999px; font-size: 13px; font-weight: 600; color: var(--ink);
}
.fstack .counter__dot { color: var(--good); font-size: 14px; }
.fstack .counter.pulse { animation: fsPulse 0.6s ease-out; }
@keyframes fsPulse {
  0% { transform: scale(1); }
  35% { transform: scale(1.08); box-shadow: 0 0 0 6px rgba(5,150,105,0.18); }
  100% { transform: scale(1); }
}

/* The stack */
.fstack .stack { display: flex; flex-direction: column; gap: 12px; perspective: 1000px; }

/* Primary card — the one big "do this now" */
.fstack .card-primary {
  background: #fff; border: 1px solid var(--border); border-radius: 16px;
  padding: 24px 22px; box-shadow: 0 4px 14px rgba(0,0,0,0.04);
  position: relative; overflow: hidden;
  transition: transform 0.35s cubic-bezier(.34,.7,.4,1), opacity 0.35s, height 0.35s;
}
.fstack .card-primary.urgent { border-color: var(--danger); border-width: 2px; box-shadow: 0 4px 18px rgba(220,38,38,0.08); }
.fstack .card-primary .meta-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.fstack .urgency-pill {
  font-size: 10px; padding: 3px 8px; border-radius: 999px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.4px;
  background: #f3f4f6; color: var(--ink-mute);
}
.fstack .urgency-pill.critical { background: #fee2e2; color: var(--danger); }
.fstack .urgency-pill.high { background: #fef3c7; color: var(--gold-ink); }
.fstack .urgency-pill.normal { background: #dbeafe; color: var(--calm); }
.fstack .kind-label { font-size: 11px; color: var(--ink-mute); text-transform: uppercase; letter-spacing: 0.4px; }
.fstack .owner-icon { font-size: 18px; }
.fstack .contact-pill { font-size: 12px; color: var(--ink-mute); display: inline-flex; align-items: center; gap: 4px; }

.fstack .card-primary h2 {
  font-size: 22px; font-weight: 700; line-height: 1.25; margin: 0 0 8px;
  color: var(--ink); letter-spacing: -0.01em;
}
.fstack .card-primary .ctx { font-size: 14px; color: var(--ink-mute); margin: 0 0 10px; line-height: 1.5; }
.fstack .card-primary .suggestion {
  font-size: 14px; color: #4b5563; font-style: italic;
  background: #f9fafb; border-left: 3px solid var(--gold);
  padding: 10px 14px; margin: 12px 0 16px; border-radius: 0 8px 8px 0;
  line-height: 1.55;
}

.fstack .actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.fstack .btn {
  padding: 12px 18px; border-radius: 10px; font-size: 14px; font-weight: 600;
  border: 1px solid var(--border); background: #fff; color: var(--ink);
  cursor: pointer; transition: transform 0.1s, background 0.1s, border-color 0.1s;
  font-family: inherit; white-space: nowrap; line-height: 1.2;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  text-decoration: none;
}
.fstack .btn:hover { background: #f9fafb; border-color: var(--ink-mute); }
.fstack .btn:active { transform: scale(0.97); }
.fstack .btn--primary {
  background: var(--primary); color: #fff; border-color: var(--primary);
  flex: 1 1 auto; min-width: 0; font-size: 15px; padding: 14px 22px;
}
.fstack .btn--primary:hover { background: #111827; border-color: #111827; }
.fstack .btn--ghost { color: var(--ink-mute); background: #fff; }
.fstack .btn--ghost:hover { color: var(--ink); }

/* Secondary cards — smaller previews of #2 and #3 */
.fstack .card-secondary {
  background: #fff; border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 16px; box-shadow: 0 1px 3px rgba(0,0,0,0.03);
  display: flex; align-items: center; gap: 12px;
  transition: transform 0.3s cubic-bezier(.34,.7,.4,1), opacity 0.3s;
  cursor: default;
}
.fstack .card-secondary .next-tag {
  font-size: 10px; padding: 2px 6px; border-radius: 4px;
  background: #f3f4f6; color: var(--ink-mute); font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.4px; flex-shrink: 0;
}
.fstack .card-secondary .body { flex: 1; min-width: 0; }
.fstack .card-secondary .body strong { font-size: 14px; font-weight: 600; color: var(--ink); display: block; line-height: 1.3; }
.fstack .card-secondary .body small { font-size: 12px; color: var(--ink-mute); }

/* In-window conversation context — messages + window state + inline composer
   (G1 fix, 2026-05-30). Lives inside .card-primary, below the suggestion, so the
   operator triages + replies without leaving Focus. */
.fstack .fs-context { margin: 14px 0 2px; border-top: 1px solid var(--border); padding-top: 14px; }
.fstack .fs-ctx-loading, .fstack .fs-ctx-err, .fstack .fs-ctx-empty {
  font-size: 13px; color: var(--ink-mute); padding: 8px 2px;
}
.fstack .fs-linklike {
  background: none; border: none; padding: 0; color: var(--calm);
  font: inherit; cursor: pointer; text-decoration: underline;
}
.fstack .fs-ctx-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.fstack .fs-ctx-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px; color: var(--ink-dim); }
.fstack .fs-win { font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.fstack .fs-win.open { background: #d1fae5; color: var(--good); }
.fstack .fs-win.closed { background: #fef3c7; color: var(--gold-ink); }

.fstack .fs-ctx-msgs { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; max-height: 230px; overflow-y: auto; }
.fstack .fs-bub { max-width: 82%; padding: 8px 11px; border-radius: 12px; font-size: 13px; line-height: 1.4; }
.fstack .fs-bub.in { align-self: flex-start; background: #f3f4f6; color: var(--ink); border-bottom-left-radius: 4px; }
.fstack .fs-bub.out { align-self: flex-end; background: #e8eef7; color: var(--ink); border-bottom-right-radius: 4px; }
.fstack .fs-bub-txt { white-space: pre-wrap; word-wrap: break-word; }
.fstack .fs-bub-meta { font-size: 10px; color: var(--ink-dim); margin-top: 3px; }

.fstack .fs-composer { display: flex; gap: 8px; align-items: flex-end; }
.fstack .fs-composer-input {
  flex: 1; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  font-size: 14px; font-family: inherit; resize: vertical; min-height: 44px; line-height: 1.4;
}
.fstack .fs-composer-input:focus { outline: none; border-color: var(--calm); }
.fstack .fs-composer.is-closed .fs-composer-input { background: #fffbeb; border-color: #fde68a; }
.fstack .fs-composer-send { flex: 0 0 auto; }

/* Secondary cards are now clickable — promote to top to act on now */
.fstack .card-secondary[data-fs-promote] { cursor: pointer; }
.fstack .card-secondary[data-fs-promote]:hover { border-color: var(--ink-mute); box-shadow: 0 2px 8px rgba(0,0,0,0.06); }
.fstack .fs-bringup { font-size: 11px; color: var(--ink-dim); font-weight: 600; flex-shrink: 0; opacity: 0; transition: opacity 0.15s; }
.fstack .card-secondary[data-fs-promote]:hover .fs-bringup { opacity: 1; }

/* Animations: card #1 slides off, #2 promotes */
.fstack .card-primary.is-resolving { animation: fsSlideOff 0.4s cubic-bezier(.4,.1,.4,1) forwards; }
@keyframes fsSlideOff { to { transform: translateX(120%) rotate(2deg); opacity: 0; } }
.fstack .card-secondary.is-promoting { animation: fsPromote 0.45s cubic-bezier(.34,.7,.4,1) forwards; }
@keyframes fsPromote { 0% { transform: translateY(8px); } 100% { transform: translateY(0); } }
.fstack .card-secondary.is-entering { animation: fsEnter 0.4s cubic-bezier(.34,.7,.4,1) backwards; }
@keyframes fsEnter { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* Empty + states */
.fstack .empty { text-align: center; padding: 60px 20px; color: var(--ink-mute); }
.fstack .empty h2 { font-size: 20px; color: var(--ink); margin: 0 0 8px; }
.fstack .empty p { font-size: 14px; margin: 0; }
.fstack .empty .emoji { font-size: 48px; margin-bottom: 16px; }

/* Footer link */
.fstack .footer-link { text-align: center; margin-top: 32px; font-size: 13px; }
.fstack .footer-link a, .fstack .footer-link button {
  color: var(--ink-mute); text-decoration: none; padding: 8px 12px; border-radius: 6px;
  background: none; border: none; font-size: 13px; font-family: inherit; cursor: pointer;
}
.fstack .footer-link a:hover, .fstack .footer-link button:hover { color: var(--ink); background: rgba(0,0,0,0.04); }

/* Toast */
.fstack .toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 10px;
  font-size: 13px; font-weight: 500; box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  z-index: 9999; opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.fstack .toast.show { opacity: 1; pointer-events: auto; }
.fstack .toast--error { background: var(--danger); }
.fstack .toast--good { background: var(--good); }

/* Loading state */
.fstack .loading { display: flex; justify-content: center; padding: 80px 20px; color: var(--ink-dim); }

/* Override modal — "doesn't fit?" affordance */
.fstack .fs-modal { position: fixed; inset: 0; z-index: 9000; display: none; align-items: center; justify-content: center; padding: 16px; }
.fstack .fs-modal.show { display: flex; }
.fstack .fs-modal__backdrop { position: absolute; inset: 0; background: rgba(15,23,42,0.55); }
.fstack .fs-modal__panel { position: relative; background: #fff; border-radius: 12px; padding: 24px 26px; max-width: 480px; width: 100%; box-shadow: 0 24px 60px rgba(0,0,0,0.35); }
.fstack .fs-modal__panel h3 { margin: 0 0 4px; font-size: 16px; font-weight: 700; }
.fstack .fs-modal__panel p { margin: 0 0 16px; font-size: 13px; color: var(--ink-mute); }
.fstack .fs-modal__panel select,
.fstack .fs-modal__panel textarea { width: 100%; padding: 11px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; font-family: inherit; }
.fstack .fs-modal__panel textarea { font-size: 13px; resize: vertical; min-height: 54px; }
.fstack .fs-modal__panel label { display: block; font-size: 12px; font-weight: 600; color: var(--ink); margin: 12px 0 6px; }
.fstack .fs-modal__panel .fs-modal__row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }
.fstack .btn[disabled] { opacity: 0.5; cursor: default; }

/* Snooze modal — preset durations + AI/Me resume picker (G6, 2026-05-30) */
.fstack .fs-snooze-presets { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 10px; }
.fstack .fs-snooze-when { padding: 8px 14px; font-size: 13px; }
.fstack .fs-snooze-when.is-sel { background: var(--good); color: #fff; border-color: var(--good); }
.fstack .fs-snooze-when.is-sel:hover { background: var(--good); border-color: var(--good); }
.fstack .fs-snooze-reason { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; font-family: inherit; resize: vertical; min-height: 48px; }
.fstack .fs-snooze-resume { display: flex; flex-direction: column; gap: 6px; margin: 4px 0; }
.fstack .fs-snooze-resume label { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 500; color: var(--ink); margin: 0; }
.fstack .fs-snooze-resume input { margin: 0; flex-shrink: 0; }

/* Undo snackbar (P1 phone surface, 2026-07-04) — UI-RUBRIC "undo within reach
   on every commit". Sits above the thumb-zone action bar; ≥44pt Undo target. */
.fstack .fs-undobar {
  position: fixed; bottom: 84px; left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: var(--ink, #1f2937); color: #fff;
  padding: 10px 10px 10px 16px; border-radius: 12px;
  display: flex; align-items: center; gap: 12px;
  font-size: 14px; white-space: nowrap;
  opacity: 0; pointer-events: none; transition: opacity .22s, transform .22s;
  z-index: 8500; box-shadow: 0 10px 28px rgba(0,0,0,0.3);
}
.fstack .fs-undobar.show { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto; }
.fstack .fs-undo-btn {
  background: none; border: none; cursor: pointer;
  color: #fbbf24; font-weight: 800; font-size: 14px; letter-spacing: .3px;
  padding: 10px 12px; min-height: 44px; border-radius: 8px;
}
.fstack .fs-undo-btn:hover { background: rgba(255,255,255,0.08); }

/* Armed send (two-tap confirm on the one irreversible act) */
.fstack .btn.is-armed { background: #b45309; border-color: #b45309; color: #fff; }

/* Phone tightening. Breakpoint 600px (not 480): Chrome's minimum WINDOW width
   is ~500px so a 480 cut can never be reached by resizing a desktop window,
   and any ≤600px surface is thumb/narrow territory where these rules help. */
@media (max-width: 600px) {
  .fstack .wrap { padding: 12px; }
  .fstack .card-primary { padding: 18px 16px; }
  .fstack .card-primary h2 { font-size: 19px; }
  .fstack .btn--primary { flex: 1 1 100%; }
  .fstack .actions { gap: 6px; }
  .fstack .fs-composer { flex-direction: column; align-items: stretch; }
  .fstack .fs-composer-send { width: 100%; }
  /* Thumb-zone floor (UI-RUBRIC §3): the primary card's action row rides the
     bottom of the viewport while its card is on screen — decisions live in the
     thumb's green zone, not wherever the card happens to end. ≥48px targets. */
  .fstack .btn { min-height: 48px; }
  .fstack .card-primary .actions {
    position: sticky; bottom: 0; z-index: 5;
    background: linear-gradient(to top, #fff 78%, rgba(255,255,255,0));
    padding: 12px 0 8px; margin-top: 10px;
  }
}

/* Reduce motion */
@media (prefers-reduced-motion: reduce) {
  .fstack *, .fstack *::before, .fstack *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
