/* ==========================================================================
   Preview — the app shell.

   The visual world is inherited from the incumbent home-server dashboards
   (guide page, homepage, QA reporter): the same ground, surfaces, hairlines,
   accent pair, radii, and system-sans stack. This file extends that system; it
   does not introduce a second one.

   Two rules the design commits to:
     - accent is spent only on the primary action, the active segment, focus
       rings, and the eye button. Never decoration.
     - every control ships default / hover / focus-visible / active / disabled.
   ========================================================================== */

:root {
  --bg:        #0b1020;
  --card:      #141b2e;
  --card-2:    #1a2340;
  --sunken:    #0f172a;
  --text:      #e2e8f0;
  --muted:     #94a3b8;
  /* Lifted from the incumbent stack's #64748b, which measures 3.60:1 on a card
     — below the 4.5:1 body-text floor. This keeps the same slate hue and the
     same visual step below --muted while clearing AA. */
  --faint:     #8496ad;
  --line:      #243050;
  --line-2:    #2c3a5e;
  --accent:    #7dd3fc;
  --accent-2:  #a78bfa;
  --good:      #34d399;
  --warn:      #fbbf24;
  --bad:       #f87171;
  --glow:      radial-gradient(1200px 620px at 18% -12%, #1e293b 0%, var(--bg) 58%);

  --r-card: 14px;
  --r-ctl:  10px;
  --r-sm:   8px;
  --bar-h:  60px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .38);
  --fast:   150ms cubic-bezier(.16, 1, .3, 1);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

*, *::before, *::after { box-sizing: border-box; }

/* The `hidden` attribute must win. A component rule like `.drag-veil{display:grid}`
   has the same specificity as the UA's `[hidden]{display:none}` and, being later,
   would otherwise override it — which is exactly how a drag overlay ends up
   covering the whole app on load. This one rule makes `hidden` authoritative. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  overflow: hidden; /* panes scroll, the shell does not */
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.muted { color: var(--muted); font-size: .82rem; }

/* ── toolbar ─────────────────────────────────────────────────────────────── */

.bar {
  flex: 0 0 auto;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  z-index: 30;
}

.bar-in {
  height: var(--bar-h);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 14px;
}

.mark {
  display: inline-flex; align-items: center; gap: 8px;
  text-decoration: none; color: var(--text);
  font-weight: 750; font-size: .74rem; letter-spacing: .16em;
  padding: 6px 4px; flex: 0 0 auto;
}
.mark-eye { width: 21px; height: 21px; flex: 0 0 auto; }
.mark-eye path, .mark-eye circle {
  fill: none; stroke: var(--accent); stroke-width: 1.9; stroke-linejoin: round;
}
.mark-eye circle { fill: var(--accent-2); stroke: var(--accent-2); }
.mark:hover span { color: var(--accent); }

/* intake ------------------------------------------------------------------ */

.intake {
  position: relative;
  flex: 1 1 auto;
  min-width: 180px;
  max-width: 720px;
  display: flex; align-items: center;
}

.intake-ico {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; pointer-events: none; color: var(--faint);
}
.intake-ico svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }

.intake input {
  width: 100%;
  height: 38px;
  padding: 0 74px 0 35px;
  background: var(--sunken);
  color: var(--text);
  border: 1px solid var(--line-2);
  border-radius: var(--r-ctl);
  font: inherit; font-size: .92rem;
  transition: border-color var(--fast), box-shadow var(--fast);
}
.intake input::placeholder { color: var(--faint); }
.intake input:hover { border-color: #3a4a72; }
.intake input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}
.intake input:disabled { opacity: .5; cursor: not-allowed; }

.intake .btn-primary {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  height: 30px; padding: 0 14px; font-size: .86rem; border-radius: 7px;
}
.intake .btn-primary[aria-busy="true"] { opacity: .7; }

.intake-side { display: flex; gap: 6px; flex: 0 0 auto; }

/* buttons ----------------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  height: 36px; padding: 0 12px;
  background: var(--card-2);
  color: var(--text);
  border: 1px solid var(--line-2);
  border-radius: var(--r-ctl);
  font: inherit; font-size: .87rem; font-weight: 500;
  cursor: pointer; white-space: nowrap;
  transition: background var(--fast), border-color var(--fast),
              color var(--fast), transform var(--fast), opacity var(--fast);
}
.btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.btn:hover:not(:disabled) { background: #223055; border-color: #3a4a72; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .42; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  color: #0b1020; border-color: transparent; font-weight: 700;
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
.btn-primary:active:not(:disabled) { filter: brightness(.96); }

.btn-ghost { background: transparent; border-color: var(--line-2); color: var(--muted); }
.btn-ghost:hover:not(:disabled) { background: var(--card-2); color: var(--text); }
.caret { font-size: .7em; opacity: .7; }

.btn-icon { width: 38px; padding: 0; justify-content: center; }

/* the eyeball — the signature control, and the only accent-filled button */
.btn-eye { color: var(--muted); position: relative; }
.btn-eye .eye-slash { opacity: 1; transition: opacity var(--fast); }
.btn-eye[aria-pressed="true"] {
  background: color-mix(in srgb, var(--accent) 20%, transparent);
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
  color: var(--accent);
}
.btn-eye[aria-pressed="true"] .eye-slash { opacity: 0; }

/* view controls ----------------------------------------------------------- */

.views { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; margin-left: auto; }

.seg {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--sunken);
  border: 1px solid var(--line-2);
  border-radius: var(--r-ctl);
}
.seg button {
  height: 28px; padding: 0 11px;
  background: transparent; color: var(--muted);
  border: 0; border-radius: 7px;
  font: inherit; font-size: .83rem; font-weight: 500;
  cursor: pointer; transition: background var(--fast), color var(--fast);
}
.seg button:hover { color: var(--text); background: color-mix(in srgb, var(--card-2) 80%, transparent); }
.seg button[aria-pressed="true"] {
  background: var(--card-2); color: var(--accent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 26%, transparent);
}

/* menu -------------------------------------------------------------------- */

.dl-wrap { position: relative; }

.menu {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 40;
  min-width: 260px; padding: 6px;
  background: var(--card); border: 1px solid var(--line-2);
  border-radius: var(--r-card); box-shadow: var(--shadow);
  animation: pop 140ms cubic-bezier(.16, 1, .3, 1);
}
.menu-up { top: auto; bottom: calc(100% + 8px); right: auto; left: 0; min-width: 320px; }
@keyframes pop { from { opacity: 0; transform: translateY(-5px) scale(.985); } }

.menu-h {
  margin: 6px 10px 4px; font-size: .68rem; font-weight: 700;
  letter-spacing: .12em; text-transform: uppercase; color: var(--faint);
}
.menu button {
  display: flex; align-items: baseline; gap: 10px; width: 100%;
  padding: 8px 10px; background: transparent; color: var(--text);
  border: 0; border-radius: var(--r-sm);
  font: inherit; font-size: .89rem; text-align: left; cursor: pointer;
  transition: background var(--fast), color var(--fast);
}
.menu button:hover:not(:disabled) { background: var(--card-2); }
.menu button:disabled { opacity: .42; cursor: not-allowed; }
.mi-name { flex: 1 1 auto; }
.mi-note { color: var(--faint); font-size: .78rem; }
.menu-sep { height: 1px; margin: 5px 6px; background: var(--line); }

/* ── PDF page setup ──────────────────────────────────────────────────────── */

#dl-pdf { padding-bottom: 4px; }

.menu-back {
  display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; margin-right: 6px; padding: 0;
  background: var(--card-2); color: var(--text);
  border: 1px solid var(--line-2); border-radius: 6px;
  font-size: .9rem; line-height: 1; cursor: pointer;
  transition: background var(--fast), border-color var(--fast);
  vertical-align: middle;
}
.menu-back:hover { background: #223055; border-color: #3a4a72; }

.opt {
  display: flex; align-items: center; gap: 10px;
  padding: 5px 10px; font-size: .86rem; color: var(--muted);
}
.opt > span:first-child { flex: 0 0 92px; }
.opt select {
  flex: 1 1 auto; height: 30px; padding: 0 8px;
  background: var(--sunken); color: var(--text);
  border: 1px solid var(--line-2); border-radius: 7px;
  font: inherit; font-size: .85rem; cursor: pointer;
  transition: border-color var(--fast);
}
.opt select:hover { border-color: #3a4a72; }
.opt select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent); }

.opt-check { gap: 8px; cursor: pointer; }
.opt-check > span:first-child { flex: 1 1 auto; }
.opt-check input[type="checkbox"] {
  order: -1; width: 15px; height: 15px; margin: 0;
  accent-color: var(--accent); cursor: pointer;
}
/* when the checkbox leads, the label must not reserve the select column */
.opt-check > span { flex: 0 0 auto; color: var(--text); }

.menu-go {
  width: calc(100% - 20px); margin: 8px 10px 2px; justify-content: center;
  height: 34px; font-size: .88rem;
}
.menu-go[aria-busy="true"] { opacity: .75; cursor: progress; }

.menu-foot {
  margin: 6px 10px 8px; font-size: .74rem; color: var(--faint);
  text-align: center; letter-spacing: .02em;
}

/* a busy download button pulses rather than spinning: state, not decoration */
.menu-go[aria-busy="true"]::after {
  content: ""; width: 12px; height: 12px; margin-left: 8px;
  border: 2px solid rgba(11, 16, 32, .35); border-top-color: #0b1020;
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── landing ─────────────────────────────────────────────────────────────── */

.welcome {
  flex: 1 1 auto;
  display: grid; place-items: center;
  padding: 24px 20px 72px;
  background: var(--glow);
  overflow: auto;
}
.welcome[hidden] { display: none; }

.welcome-in { width: 100%; max-width: 660px; text-align: center; }

.lede {
  margin: 0 0 22px;
  font-size: clamp(1.42rem, 3.1vw, 1.95rem);
  line-height: 1.24; font-weight: 700; letter-spacing: -.015em;
}
/* Two-tone rather than gradient-clipped: the second line carries the accent
   as ink, which reads the same at any font size or zoom and keeps the text
   contrast measurable. */
.lede span { color: var(--accent); }

.drop {
  position: relative;
  padding: 34px 26px 30px;
  background: color-mix(in srgb, var(--card) 82%, transparent);
  border: 1.5px dashed var(--line-2);
  border-radius: var(--r-card);
  transition: border-color var(--fast), background var(--fast), transform var(--fast);
}
.drop:hover, .drop:focus-visible { border-color: color-mix(in srgb, var(--accent) 50%, var(--line-2)); }
.drop.is-over {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 9%, var(--card));
  transform: scale(1.008);
}

.drop-ico { width: 30px; height: 30px; margin-bottom: 12px; color: var(--accent); opacity: .85; }
.drop-ico path { fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.drop-lead { margin: 0 0 4px; font-size: 1.02rem; font-weight: 600; }
.drop-sub { margin: 0 0 18px; color: var(--muted); font-size: .87rem; }

.drop-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; align-items: center; }
.try { position: relative; }

.cap {
  margin: 22px 0 0;
  font-size: .74rem; font-weight: 600; letter-spacing: .14em;
  text-transform: uppercase; color: var(--faint);
}
.cap .arrow { color: var(--accent); margin: 0 6px; }

/* ── workbench ───────────────────────────────────────────────────────────── */

.work {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
  background: var(--bg);
}
.work[hidden] { display: none; }

.pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.pane-source { flex: 1 1 50%; background: var(--sunken); }
.pane-preview { flex: 1 1 50%; }

.pane-h {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 8px;
  height: 34px; padding: 0 12px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  font-size: .78rem; color: var(--muted);
}
.pane-h .spacer { flex: 1 1 auto; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--line-2); flex: 0 0 auto; }
.dot-accent { background: var(--accent); }

#editor {
  flex: 1 1 auto;
  width: 100%; min-height: 0;
  padding: 18px 20px 40px;
  background: transparent; color: var(--text);
  border: 0; resize: none;
  font-family: var(--mono); font-size: .875rem; line-height: 1.65;
  tab-size: 2;
}
#editor:focus { outline: none; }
#editor::placeholder { color: var(--faint); }

.frame-wrap { flex: 1 1 auto; min-height: 0; background: #fff; position: relative; }
#frame { display: block; width: 100%; height: 100%; border: 0; background: #fff; }

.gutter {
  flex: 0 0 7px;
  background: var(--card);
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  cursor: col-resize;
  transition: background var(--fast);
}
.gutter:hover, .gutter.is-drag { background: color-mix(in srgb, var(--accent) 30%, var(--card)); }

/* mode switching ---------------------------------------------------------- */

.work[data-mode="source"] .pane-preview,
.work[data-mode="source"] .gutter { display: none; }
.work[data-mode="source"] .pane-source { flex: 1 1 100%; }

.work[data-mode="preview"] .pane-source,
.work[data-mode="preview"] .gutter { display: none; }
.work[data-mode="preview"] .pane-preview { flex: 1 1 100%; }

/* busy indicator on the preview pane header ------------------------------- */

.pane-preview.is-busy .dot-accent { background: var(--warn); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }

/* ── drag veil ───────────────────────────────────────────────────────────── */

.drag-veil {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(3px);
  border: 3px dashed var(--accent);
  pointer-events: none;
}
.drag-veil span {
  padding: 14px 26px; border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  color: #0b1020; font-weight: 750; font-size: 1.02rem;
  box-shadow: var(--shadow);
}

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

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  z-index: 70; max-width: min(92vw, 560px);
  display: flex; align-items: center; gap: 10px;
  padding: 11px 18px 11px 15px;
  background: var(--card); color: var(--text);
  border: 1px solid var(--line-2);
  border-radius: var(--r-ctl); box-shadow: var(--shadow);
  font-size: .89rem;
  animation: rise 180ms cubic-bezier(.16, 1, .3, 1);
}
/* Status is carried by a small solid marker plus a slightly lifted surface,
   not by a thick coloured stripe down one edge. */
.toast::before {
  content: ""; flex: 0 0 auto;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
}
.toast.is-bad { border-color: color-mix(in srgb, var(--bad) 45%, var(--line-2)); }
.toast.is-bad::before { background: var(--bad); }
.toast.is-good { border-color: color-mix(in srgb, var(--good) 45%, var(--line-2)); }
.toast.is-good::before { background: var(--good); }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 10px); } }

/* ── responsive: structural collapse, not fluid type ─────────────────────── */

@media (max-width: 1100px) {
  .bar-in { height: auto; min-height: var(--bar-h); flex-wrap: wrap; padding: 10px 12px; gap: 10px; }
  .intake { order: 3; flex: 1 1 100%; max-width: none; }
  .views { margin-left: 0; }
  .mark { order: 1; }
  .intake-side { order: 2; margin-left: auto; }
  .views { order: 4; flex: 1 1 100%; justify-content: flex-end; }
  .menu { right: 0; }

  /* split becomes stacked: source above, preview below */
  .work[data-mode="split"] { flex-direction: column; }
  .work[data-mode="split"] .pane-source { flex: 0 0 38%; }
  .work[data-mode="split"] .pane-preview { flex: 1 1 auto; }
  .work[data-mode="split"] .gutter {
    flex: 0 0 7px; cursor: row-resize;
    border-left: 0; border-right: 0;
    border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
  }
}

@media (max-width: 720px) {
  .mark span { display: none; }
  .intake-side .btn span { display: none; }
  .intake-side .btn { width: 38px; justify-content: center; padding: 0; }
  .seg button { padding: 0 9px; font-size: .79rem; }
  .drop { padding: 26px 18px 22px; }
  .lede { margin-bottom: 20px; }
  .menu { min-width: min(88vw, 260px); }
}

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

/* ── print: the shell itself never prints, only the document does ────────── */
@media print {
  .bar, .welcome, .drag-veil, .toast, .pane-source, .gutter, .pane-h { display: none !important; }
  body { overflow: visible; background: #fff; }
  .work { display: block; }
  .frame-wrap { background: #fff; }
}
