/* ============================================================
   rewind.css — shared design system
   AGPL-3.0
   ------------------------------------------------------------
   Dark-first by design. Catppuccin Mocha is the canonical palette;
   the full semantic accent set is exposed because dense data
   (logs table, replay timeline, event strip) genuinely benefits
   from categorical color encoding. A Latte light variant is a
   future follow-up — only the surface and text tokens would
   change; semantic accents keep their names so component classes
   continue to work.

   Loaded by:
     web/admin-prototype/*.html       — dashboard SPA pages
     web/replay-prototype/*.html      — iframe + WASM replay shells
     web/apex-prototype/*.html        — marketing site

   Page-specific extensions (replay scrubber, logs filter chips,
   apex hero composition) live in sibling stylesheets that load
   AFTER this file.
   ============================================================ */

/* ---------- 1. Fonts ---------- */

/* Self-host in production; Google Fonts in prototype. Geist Sans
   is the body face — geometric, technical, neutral enough to recede
   so the monospace (where most of the *information* lives) carries
   the personality. JetBrains Mono is the load-bearing typeface. */

@import url('https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600&family=JetBrains+Mono:wght@400;500;600&display=swap');

/* ---------- 2. Tokens ---------- */

:root {
  color-scheme: dark;

  /* Catppuccin Mocha surfaces.
     Five levels of depth, ordered low→high; --base is the page,
     --crust is the deepest recess (sidebar, panel headers), --mantle
     sits between, and --surface-0/1/2 stack upward into hover/active.
     Use --base for the page background, --crust for chrome rails,
     --surface-0 for cards, --surface-1 for row hover, --surface-2 for
     pressed/selected. */
  --crust:     #11111b;
  --mantle:    #181825;
  --base:      #1e1e2e;
  --surface-0: #313244;
  --surface-1: #45475a;
  --surface-2: #585b70;

  /* Text. Mocha names them subtext / overlay / text. We rename to
     a numeric scale because that maps more cleanly to typography
     intentions: --text-0 is the body, --text-1 is secondary (eyebrow
     labels, metadata), --text-2 is tertiary (timestamps, hints),
     --text-3 is the dimmest legible (placeholders, disabled). */
  --text-0:    #cdd6f4;  /* text          */
  --text-1:    #bac2de;  /* subtext1      */
  --text-2:    #a6adc8;  /* subtext0      */
  --text-3:    #7f849c;  /* overlay1      */
  --text-4:    #585b70;  /* surface2      — borders, dividers */

  /* Semantic event accents.
     These map Catppuccin's eight accent hues to the categorical
     event types the dashboard and replay surface visualize. The
     names are the *meaning*, not the hue, so a future palette swap
     keeps the component classes valid.

     Hue → meaning mapping is intentional, not arbitrary:
       green     = KV read       (familiar "data in" cue)
       peach     = KV write      (warm-but-warning, mutation)
       teal      = fetch / http  (signals "going elsewhere")
       blue      = info / log    (the most neutral accent)
       rosewater = side effect   (queued post-response work — webhook/email/emit;
                                  the quieter accent suits work that runs after
                                  the main flow finishes)
       pink      = error         (Mocha's red-pink reads as failure)
       yellow    = warning       (timeout, slow, edge case)
       lavender  = control flow  (function entry/exit, branch taken)
       mauve     = brand         (current selection, playhead, primary action —
                                  the most distinct + memorable accent owns the
                                  thing the user is actively looking at) */
  --c-read:     #a6e3a1;  /* green     */
  --c-write:    #fab387;  /* peach     */
  --c-fetch:    #94e2d5;  /* teal      */
  --c-info:     #89b4fa;  /* blue      */
  --c-effect:   #f5e0dc;  /* rosewater */
  --c-error:    #f38ba8;  /* pink      */
  --c-warn:     #f9e2af;  /* yellow    */
  --c-control:  #b4befe;  /* lavender  */
  --c-brand:    #cba6f7;  /* mauve     */

  /* Outcome colors — the stable status set the brief asks for.
     These are aliases over the accents above so "success" looks
     identical on the instance list, log rows, and replay headers. */
  --outcome-ok:      var(--c-read);
  --outcome-warn:    var(--c-warn);
  --outcome-error:   var(--c-error);
  --outcome-pending: var(--text-3);

  /* Typography. One sans, one mono, three sizes per axis. */
  --font-sans: 'Geist', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', 'Cascadia Code', Consolas, monospace;

  --fs-display: 28px;   /* page H1, hero number */
  --fs-h2:      18px;   /* section header */
  --fs-h3:      14px;   /* card header, table column */
  --fs-body:    13px;   /* body, table cell */
  --fs-meta:    12px;   /* eyebrow, metadata */
  --fs-mono-lg: 13px;   /* file paths, ids in headers */
  --fs-mono:    12.5px; /* table cells, breadcrumbs */
  --fs-mono-sm: 11.5px; /* line numbers, hint chips */

  --lh-tight:   1.2;
  --lh-snug:    1.4;
  --lh-body:    1.55;

  /* Spacing. 4px base. Use these tokens; don't reach for arbitrary
     pixel values. The constraints make composed layouts read as
     one piece. */
  --sp-1:  4px;
  --sp-2:  8px;
  --sp-3:  12px;
  --sp-4:  16px;
  --sp-5:  20px;
  --sp-6:  24px;
  --sp-8:  32px;
  --sp-10: 40px;
  --sp-12: 48px;
  --sp-16: 64px;

  /* Radii. Mostly small — this is a tool, not a marketing site.
     The pill radius shows up for the scrubber playhead chip and
     filter chips. */
  --r-sm:   3px;
  --r-md:   5px;
  --r-lg:   8px;
  --r-pill: 999px;

  /* Borders. Hairlines for table dividers, slightly heavier for
     panel separators. */
  --border-1: 1px solid var(--surface-0);
  --border-2: 1px solid var(--surface-1);

  /* Shadows. Used sparingly — most depth in this UI comes from
     surface layering, not drop shadow. */
  --shadow-drawer:  0 12px 32px rgba(0,0,0,0.4), 0 0 0 1px var(--surface-0);
  --shadow-popover: 0 6px 18px rgba(0,0,0,0.3), 0 0 0 1px var(--surface-0);

  /* Motion. One scale, fast — this is a tool, not a presentation. */
  --motion-fast:   80ms;
  --motion-base:   140ms;
  --motion-slow:   220ms;
  --ease-out:      cubic-bezier(0.2, 0.7, 0.3, 1);

  /* Z-index scale. */
  --z-drawer:   100;
  --z-popover:  200;
  --z-modal:    300;
  --z-toast:    400;
}

/* ---------- 3. Resets + base ---------- */

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--base);
  color: var(--text-0);
  font: 400 var(--fs-body)/var(--lh-body) var(--font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-feature-settings: 'cv11' 1, 'ss01' 1;  /* Geist stylistic alts */
}

::selection { background: var(--c-brand); color: var(--crust); }

a {
  color: var(--c-info);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color var(--motion-fast) var(--ease-out);
}
a:hover { border-bottom-color: currentColor; }

button {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}

input, textarea, select {
  font-family: inherit;
  font-size: inherit;
  color: var(--text-0);
  background: var(--mantle);
  border: var(--border-1);
  border-radius: var(--r-md);
  padding: var(--sp-2) var(--sp-3);
  outline: none;
  transition: border-color var(--motion-fast) var(--ease-out);
}
input:focus, textarea:focus, select:focus {
  border-color: var(--c-brand);
}

::placeholder { color: var(--text-3); }

code, kbd, pre, samp { font-family: var(--font-mono); }

hr {
  border: none;
  border-top: var(--border-1);
  margin: var(--sp-6) 0;
}

/* ---------- 4. Typography utilities ---------- */

.t-display {
  font-size: var(--fs-display);
  font-weight: 500;
  line-height: var(--lh-tight);
  letter-spacing: -0.01em;
}
.t-h2     { font-size: var(--fs-h2);   font-weight: 500; line-height: var(--lh-snug); }
.t-h3     { font-size: var(--fs-h3);   font-weight: 500; line-height: var(--lh-snug); }
.t-body   { font-size: var(--fs-body); font-weight: 400; line-height: var(--lh-body); }
.t-meta   { font-size: var(--fs-meta); font-weight: 400; line-height: var(--lh-snug); color: var(--text-2); }
.t-eyebrow {
  font-size: var(--fs-meta);
  font-weight: 500;
  line-height: var(--lh-snug);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-2);
}

.t-mono     { font-family: var(--font-mono); font-size: var(--fs-mono);    }
.t-mono-lg  { font-family: var(--font-mono); font-size: var(--fs-mono-lg); }
.t-mono-sm  { font-family: var(--font-mono); font-size: var(--fs-mono-sm); }

.t-dim    { color: var(--text-2); }
.t-dimmer { color: var(--text-3); }
.t-mute   { color: var(--text-4); }

/* Color utilities — semantic, not by-hue. The names tell the reader
   what the color *means* in this product. */
.c-read    { color: var(--c-read);    }
.c-write   { color: var(--c-write);   }
.c-fetch   { color: var(--c-fetch);   }
.c-info    { color: var(--c-info);    }
.c-effect  { color: var(--c-effect);  }
.c-error   { color: var(--c-error);   }
.c-warn    { color: var(--c-warn);    }
.c-control { color: var(--c-control); }
.c-brand   { color: var(--c-brand);   }

/* ---------- 5. Layout primitives ---------- */

.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.row    { display: flex; }
.row-c  { display: flex; align-items: center; }
.row-sb { display: flex; align-items: center; justify-content: space-between; }

.col    { display: flex; flex-direction: column; }
.gap-1  { gap: var(--sp-1); }
.gap-2  { gap: var(--sp-2); }
.gap-3  { gap: var(--sp-3); }
.gap-4  { gap: var(--sp-4); }
.gap-6  { gap: var(--sp-6); }
.gap-8  { gap: var(--sp-8); }

.grow   { flex: 1 1 auto; min-width: 0; min-height: 0; }
.shrink { flex: 0 0 auto; }

.pad-3  { padding: var(--sp-3); }
.pad-4  { padding: var(--sp-4); }
.pad-6  { padding: var(--sp-6); }
.pad-8  { padding: var(--sp-8); }

/* ---------- 6. App chrome ---------- */

/* The top bar that sits across dashboard pages.
   Logo lockup left, instance switcher center-ish, account right. */
.appbar {
  display: flex;
  align-items: center;
  gap: var(--sp-6);
  height: 48px;
  padding: 0 var(--sp-6);
  background: var(--crust);
  border-bottom: var(--border-1);
  flex-shrink: 0;
}

.appbar__brand {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: 14px;
  letter-spacing: -0.01em;
  color: var(--text-0);
}

/* Inline rewind-triangle mark. Two left-pointing triangles inside
   a rosewater pill — the logo's signature gesture, miniaturized.
   The motif recurs at larger scale on the scrubber's playhead. */
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  width: 28px;
  height: 16px;
  border-radius: var(--r-pill);
  background: var(--c-brand);
  color: var(--crust);
}
.brand-mark__tri {
  width: 0; height: 0;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-right: 7px solid currentColor;
}

/* The instance breadcrumb / switcher chip. */
.crumb {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  height: 28px;
  padding: 0 var(--sp-3);
  border: var(--border-1);
  border-radius: var(--r-md);
  font-family: var(--font-mono);
  font-size: var(--fs-mono);
  color: var(--text-1);
  background: var(--mantle);
  transition: border-color var(--motion-fast) var(--ease-out),
              background var(--motion-fast) var(--ease-out);
}
.crumb:hover { background: var(--surface-0); border-color: var(--surface-1); }
.crumb__sep  { color: var(--text-4); }

/* ---------- 7. Tab strip ---------- */

.tabs {
  display: flex;
  gap: var(--sp-1);
  border-bottom: var(--border-1);
  padding: 0 var(--sp-6);
  background: var(--crust);
  flex-shrink: 0;
}
.tab {
  position: relative;
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--fs-body);
  color: var(--text-2);
  transition: color var(--motion-fast) var(--ease-out);
}
.tab:hover { color: var(--text-0); }
.tab[aria-current="page"],
.tab.is-active {
  color: var(--text-0);
}
.tab[aria-current="page"]::after,
.tab.is-active::after {
  content: '';
  position: absolute;
  left: var(--sp-4);
  right: var(--sp-4);
  bottom: -1px;
  height: 2px;
  background: var(--c-brand);
  border-radius: 1px 1px 0 0;
}

/* ---------- 8. Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  height: 28px;
  padding: 0 var(--sp-3);
  border-radius: var(--r-md);
  border: var(--border-1);
  background: var(--surface-0);
  color: var(--text-0);
  font-size: var(--fs-body);
  font-weight: 500;
  cursor: pointer;
  transition: background var(--motion-fast) var(--ease-out),
              border-color var(--motion-fast) var(--ease-out);
  white-space: nowrap;
}
.btn:hover    { background: var(--surface-1); border-color: var(--surface-2); }
.btn:active   { background: var(--surface-2); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn--primary {
  background: var(--c-brand);
  color: var(--crust);
  border-color: var(--c-brand);
}
.btn--primary:hover  { background: #d5abfb; border-color: #d5abfb; }
.btn--primary:active { background: var(--c-brand); }

.btn--ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-1);
}
.btn--ghost:hover { background: var(--surface-0); color: var(--text-0); }

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

.btn--sm { height: 24px; font-size: var(--fs-meta); padding: 0 var(--sp-2); }
.btn--lg { height: 36px; padding: 0 var(--sp-4); }

/* ---------- 9. Chips ---------- */

/* Filter chip — pill-shaped, two states (off/on), used in the logs
   filter row and the replay event-type toggles. */
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  height: 22px;
  padding: 0 var(--sp-2) 0 var(--sp-2);
  border-radius: var(--r-pill);
  border: var(--border-1);
  background: var(--mantle);
  color: var(--text-2);
  font-size: var(--fs-meta);
  font-weight: 500;
  cursor: pointer;
  transition: background var(--motion-fast) var(--ease-out),
              color var(--motion-fast) var(--ease-out);
  white-space: nowrap;
}
.chip:hover { color: var(--text-0); background: var(--surface-0); }
.chip.is-on { color: var(--text-0); background: var(--surface-1); border-color: var(--surface-2); }

.chip__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

/* Outcome badge — used in log rows, replay headers, instance list. */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  height: 18px;
  padding: 0 var(--sp-2);
  border-radius: var(--r-sm);
  font-size: var(--fs-mono-sm);
  font-family: var(--font-mono);
  font-weight: 500;
  background: var(--surface-0);
  color: var(--text-1);
}
.badge--ok    { background: rgba(166,227,161,0.12); color: var(--c-read);  }
.badge--warn  { background: rgba(249,226,175,0.12); color: var(--c-warn);  }
.badge--error { background: rgba(243,139,168,0.12); color: var(--c-error); }
.badge--info  { background: rgba(137,180,250,0.12); color: var(--c-info);  }

/* ---------- 10. Panels + cards ---------- */

.panel {
  background: var(--mantle);
  border: var(--border-1);
  border-radius: var(--r-lg);
  overflow: hidden;
}
.panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: var(--border-1);
  background: var(--crust);
}
.panel__title {
  font-size: var(--fs-h3);
  font-weight: 500;
  letter-spacing: -0.005em;
}
.panel__body  { padding: var(--sp-4); }

/* Card — the generic raised surface used by the marketing site and
   any page that wants a bordered container without the panel's
   header/overflow chrome. Padding + shadow are set by the caller
   (inline or a page overlay) so one class serves both the dense
   dashboard card and the chunky marketing card. */
.card {
  background: var(--mantle);
  border: var(--border-1);
  border-radius: var(--r-lg);
}

/* Rail — the dense, scrollable sidebar pattern. Used for the
   modules list in the replay shell, the prefix tree in KV, etc.
   Distinct from panel because it has no internal padding — children
   fill the rail edge to edge for that "file tree" feel. */
.rail {
  background: var(--crust);
  border-right: var(--border-1);
  overflow-y: auto;
}
.rail__head {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: var(--sp-3) var(--sp-4);
  background: var(--crust);
  border-bottom: var(--border-1);
}

/* ---------- 11. Tables ---------- */

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-body);
}
.table th {
  position: sticky;
  top: 0;
  background: var(--crust);
  text-align: left;
  font-weight: 500;
  font-size: var(--fs-meta);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-2);
  padding: var(--sp-2) var(--sp-3);
  border-bottom: var(--border-1);
  z-index: 1;
}
.table td {
  padding: var(--sp-3);
  border-bottom: var(--border-1);
  vertical-align: top;
  color: var(--text-0);
}
.table tr:last-child td { border-bottom: none; }
.table tr:hover td      { background: var(--mantle); cursor: pointer; }
.table tr.is-selected td { background: var(--surface-0); }
.table td.col-mono,
.table th.col-mono { font-family: var(--font-mono); font-size: var(--fs-mono); }
.table td.col-num  { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- 12. KV-style key/value pairs ---------- */

/* Used in the variable inspector, the drawer detail view, the
   instance metadata strip. Two columns, label dim, value mono. */
.kv {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: var(--sp-2) var(--sp-4);
  font-size: var(--fs-body);
}
.kv__k {
  color: var(--text-2);
  font-family: var(--font-mono);
  font-size: var(--fs-mono-sm);
}
.kv__v {
  color: var(--text-0);
  font-family: var(--font-mono);
  font-size: var(--fs-mono);
  word-break: break-word;
}

/* ---------- 13. Code surface ---------- */

/* The code panel is a load-bearing surface — replay source view,
   inline code samples, the KV editor's right pane. It uses --crust
   (deeper than --base) so it reads as recessed; the line-number
   gutter is dimmer still. */
.code {
  display: flex;
  background: var(--crust);
  font-family: var(--font-mono);
  font-size: var(--fs-mono);
  line-height: 1.65;
  overflow: auto;
}
.code__gutter {
  flex-shrink: 0;
  padding: var(--sp-3) var(--sp-3) var(--sp-3) var(--sp-4);
  text-align: right;
  color: var(--text-4);
  user-select: none;
  background: var(--crust);
  border-right: var(--border-1);
}
.code__gutter .ln {
  display: block;
  font-size: var(--fs-mono-sm);
}
.code__body {
  flex: 1;
  padding: var(--sp-3) var(--sp-4);
  white-space: pre;
  overflow-x: auto;
}
.code__body .line {
  display: block;
  position: relative;
  padding: 0 var(--sp-2);
  margin: 0 calc(var(--sp-2) * -1);
  border-radius: var(--r-sm);
}
.code__body .line.is-current {
  background: rgba(203,166,247,0.08);
  box-shadow: inset 2px 0 0 var(--c-brand);
}
.code__body .line.has-breakpoint::before {
  content: '';
  position: absolute;
  left: calc(var(--sp-2) * -1 - 4px);
  top: 50%;
  transform: translateY(-50%);
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--c-error);
}

/* Syntax tokens — restrained, just three colors over the body
   so the source stays readable rather than rainbow-noisy. */
.tok-kw    { color: var(--c-effect); }   /* keyword: const, function, return */
.tok-str   { color: var(--c-read);   }   /* string  */
.tok-num   { color: var(--c-write);  }   /* number  */
.tok-fn    { color: var(--c-info);   }   /* function name */
.tok-comm  { color: var(--text-3);   font-style: italic; }
.tok-punc  { color: var(--text-2);   }

/* ---------- 14. Icons ---------- */

/* SVG icons inherit currentColor; this just standardizes sizing. */
.icon    { width: 16px; height: 16px; flex-shrink: 0; }
.icon-sm { width: 12px; height: 12px; flex-shrink: 0; }
.icon-lg { width: 20px; height: 20px; flex-shrink: 0; }

/* ---------- 15. Empty state ---------- */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  padding: var(--sp-12);
  color: var(--text-3);
  text-align: center;
}
.empty__title { font-size: var(--fs-h3); color: var(--text-1); }
.empty__hint  { font-size: var(--fs-meta); max-width: 320px; }

/* ---------- 16. Scrollbars ---------- */

* {
  scrollbar-width: thin;
  scrollbar-color: var(--surface-1) transparent;
}
::-webkit-scrollbar           { width: 10px; height: 10px; }
::-webkit-scrollbar-track     { background: transparent; }
::-webkit-scrollbar-thumb     { background: var(--surface-0); border-radius: 5px; border: 2px solid var(--base); }
::-webkit-scrollbar-thumb:hover { background: var(--surface-1); }

/* ---------- 17. Focus ring ---------- */

:focus-visible {
  outline: 2px solid var(--c-brand);
  outline-offset: 1px;
  border-radius: var(--r-sm);
}
