/* ===================================================================
   Bear Media Lab — UI kit
   -------------------------------------------------------------------
   The single source of truth for colour, type, spacing and the shared
   primitives (buttons, fields, panels, badges). Every page links this
   first; page- or tool-specific stylesheets layer on top and should
   only ever reach for the tokens below — never raw hex values, or the
   light theme breaks.

   Theme: light by default, dark when the OS asks for it, and either
   one pinned by `data-theme="light|dark"` on <html> (set by the
   toggle in the top bar). The `:root:not([data-theme="light"])` guard
   is what lets the toggle win over the OS preference.
   =================================================================== */

/* --- Tokens: light -------------------------------------------------- */
:root {
  color-scheme: light;

  /* Surfaces, back to front. The -2 names are the legacy aliases the
     tool stylesheets already use; keep both in step. */
  --bg:        #faf9f7;
  --bg-2:      #f1eeea;
  --panel:     #ffffff;
  --panel-2:   #f5f2ee;
  --line:      #e2dcd4;
  --line-soft: #eee9e2;

  /* Text */
  --text:  #1b1a17;
  --muted: #6a655d;
  --faint: #99938a;

  /* Primary action — plain ink, not a colour. Restraint reads as design. */
  --ink:    #1b1a17;
  --on-ink: #faf9f7;

  /* Accent, used sparingly: links, focus, active state, progress. */
  --accent:      #b45f13;
  --accent-ink:  #ffffff;
  --accent-soft: rgba(180, 95, 19, .10);

  --ok:   #2f7d5d;
  --warn: #a8620d;
  --err:  #b3322f;

  /* Scrim for chips floating over imagery, and the preview checkerboard. */
  --scrim:  rgba(27, 26, 23, .72);
  --check-a: #eeeae4;
  --check-b: #f8f6f3;

  /* Illustration palette — the hero art is inline SVG so it inherits these. */
  --art-line:   #1b1a17;
  --art-1:      #ddd6cc;
  --art-2:      #efeae3;
  --art-3:      #ffffff;
  --art-accent: #d8862f;

  /* Shape & depth */
  --radius:    10px;
  --radius-sm: 6px;
  --radius-lg: 16px;
  --shadow:    0 1px 2px rgba(27, 26, 23, .05), 0 8px 24px rgba(27, 26, 23, .07);
  --shadow-sm: 0 1px 2px rgba(27, 26, 23, .06);

  /* Type */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  /* Motion — one duration, one curve, everywhere. */
  --ease: cubic-bezier(.2, .7, .3, 1);
  --dur:  .18s;
}

/* --- Tokens: dark --------------------------------------------------- */
/* Declared twice on purpose: once for the OS preference (which the explicit
   `light` pin must be able to override) and once for the explicit `dark` pin. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;

    --bg:        #131210;
    --bg-2:      #1a1917;
    --panel:     #1c1b18;
    --panel-2:   #24221f;
    --line:      #302d29;
    --line-soft: #262421;

    --text:  #ece8e2;
    --muted: #a09a91;
    --faint: #7b756c;

    --ink:    #ece8e2;
    --on-ink: #171614;

    --accent:      #e09a4e;
    --accent-ink:  #171614;
    --accent-soft: rgba(224, 154, 78, .14);

    --ok:   #63c39a;
    --warn: #e0a55e;
    --err:  #e88b83;

    --scrim:   rgba(8, 8, 7, .78);
    --check-a: #201e1c;
    --check-b: #191816;

    --art-line:   #ece8e2;
    --art-1:      #3a3733;
    --art-2:      #2a2825;
    --art-3:      #201e1c;
    --art-accent: #e09a4e;

    --shadow:    0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px rgba(0, 0, 0, .45);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --bg:        #131210;
  --bg-2:      #1a1917;
  --panel:     #1c1b18;
  --panel-2:   #24221f;
  --line:      #302d29;
  --line-soft: #262421;

  --text:  #ece8e2;
  --muted: #a09a91;
  --faint: #7b756c;

  --ink:    #ece8e2;
  --on-ink: #171614;

  --accent:      #e09a4e;
  --accent-ink:  #171614;
  --accent-soft: rgba(224, 154, 78, .14);

  --ok:   #63c39a;
  --warn: #e0a55e;
  --err:  #e88b83;

  --scrim:   rgba(8, 8, 7, .78);
  --check-a: #201e1c;
  --check-b: #191816;

  --art-line:   #ece8e2;
  --art-1:      #3a3733;
  --art-2:      #2a2825;
  --art-3:      #201e1c;
  --art-accent: #e09a4e;

  --shadow:    0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px rgba(0, 0, 0, .45);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 var(--font);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

img, svg { max-width: 100%; }

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

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

/* --- Type ----------------------------------------------------------- */
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -.021em; line-height: 1.2; }
h1 { font-size: clamp(30px, 4.4vw, 42px); }
h2 { font-size: 19px; }
h3 { font-size: 16px; }
p  { margin: 0; }

a { color: var(--accent); text-underline-offset: 2px; }
a:hover { color: var(--text); }

/* Small mono label — section eyebrows, counters, meta. */
.eyebrow {
  font: 500 11px/1 var(--mono);
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--faint);
}

.lead  { color: var(--muted); font-size: 16px; }
.hint  { color: var(--faint); font-size: 13px; }
.meta  { color: var(--faint); font-size: 12.5px; }

/* --- Top bar -------------------------------------------------------- */
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 0 22px; height: 58px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  position: sticky; top: 0; z-index: 50;
}
.topbar .spacer { flex: 1; }

.brand {
  display: inline-flex; align-items: baseline; gap: 7px;
  font-size: 15px; font-weight: 600; letter-spacing: -.015em;
  text-decoration: none; color: var(--text);
}
.brand { align-items: center; }
.brand .mark { display: inline-flex; }
.brand .mark img { height: 20px; width: auto; }

/* Two copies of the logo; the theme decides which one shows, the same way
   the theme toggle picks its glyph. */
.brand .logo-light { display: block; }
.brand .logo-dark  { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .brand .logo-light { display: none; }
  :root:not([data-theme="light"]) .brand .logo-dark  { display: block; }
}
:root[data-theme="dark"] .brand .logo-light { display: none; }
:root[data-theme="dark"] .brand .logo-dark  { display: block; }
.brand .sub  { color: var(--faint); font-weight: 400; }

.crumb { color: var(--faint); font-size: 13.5px; }
.crumb a { color: var(--muted); text-decoration: none; }
.crumb a:hover { color: var(--text); }

.user-box { display: flex; align-items: center; gap: 10px; font-size: 13.5px; color: var(--muted); }
.balance-chip {
  display: inline-flex; align-items: baseline; gap: 6px;
  padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--panel); color: var(--text); text-decoration: none; font-size: 13px;
}
.balance-chip:hover { border-color: var(--faint); color: var(--text); }
.balance-chip b { font-weight: 600; font-variant-numeric: tabular-nums; }

/* Plain data table — admin lists, billing history. */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th, table.data td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--line-soft); white-space: nowrap; }
table.data th { font: 500 11px/1 var(--mono); letter-spacing: .09em; text-transform: uppercase; color: var(--faint); background: var(--panel-2); }
table.data tr:last-child td { border-bottom: 0; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data td.wrap { white-space: normal; }

.avatar { width: 26px; height: 26px; border-radius: 50%; background: var(--panel-2); object-fit: cover; }

/* --- Buttons -------------------------------------------------------- */
.btn {
  appearance: none; display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  padding: 8px 15px; border-radius: var(--radius-sm);
  font: inherit; font-size: 14px; font-weight: 500; line-height: 1.4;
  text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease), opacity var(--dur) var(--ease);
}
.btn:hover:not(:disabled):not([aria-disabled="true"]) { background: var(--panel-2); border-color: var(--faint); color: var(--text); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; }

.btn.primary { background: var(--ink); border-color: var(--ink); color: var(--on-ink); }
.btn.primary:hover:not(:disabled):not([aria-disabled="true"]) { background: var(--ink); border-color: var(--ink); color: var(--on-ink); opacity: .86; }

.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover:not(:disabled) { background: var(--panel-2); color: var(--text); }

.btn.danger { color: var(--err); border-color: var(--line); }
.btn.danger:hover:not(:disabled) { border-color: var(--err); }

.btn.sm  { padding: 5px 10px; font-size: 13px; }
.btn.lg  { padding: 11px 20px; font-size: 15px; }

.link-btn {
  background: none; border: 0; padding: 0; color: var(--muted);
  font: inherit; font-size: 13.5px; cursor: pointer; text-decoration: underline;
  text-underline-offset: 2px;
}
.link-btn:hover { color: var(--text); }

/* Square icon button — theme toggle, arrows, close. */
.icon-btn {
  appearance: none; display: grid; place-items: center;
  width: 34px; height: 34px; padding: 0;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--panel); color: var(--muted); cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.icon-btn:hover:not(:disabled) { background: var(--panel-2); color: var(--text); }
.icon-btn:disabled { opacity: .35; cursor: not-allowed; }
.icon-btn svg { width: 16px; height: 16px; display: block; }

/* The toggle swaps which glyph is visible purely from the theme token. */
.theme-toggle .sun  { display: none; }
.theme-toggle .moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .sun  { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .moon { display: none; }
}
:root[data-theme="dark"] .theme-toggle .sun  { display: block; }
:root[data-theme="dark"] .theme-toggle .moon { display: none; }
:root[data-theme="light"] .theme-toggle .sun  { display: none; }
:root[data-theme="light"] .theme-toggle .moon { display: block; }

/* --- Panels --------------------------------------------------------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}
.panel h2 { margin: 0 0 4px; font-size: 15px; }
.panel .hint { margin: 0 0 14px; }

/* --- Badges --------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font: 500 11px/1 var(--mono); letter-spacing: .09em; text-transform: uppercase;
  padding: 5px 9px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--muted);
}
.badge::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.badge.live     { color: var(--ok);     border-color: color-mix(in srgb, var(--ok) 35%, var(--line)); }
.badge.progress { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); }
.badge.plain::before { display: none; }

/* Legacy inline tag used beside headings. */
.tag {
  display: inline-block; font: 500 11px/1 var(--mono); letter-spacing: .09em; text-transform: uppercase;
  padding: 4px 8px; border-radius: 999px; margin-left: 8px; vertical-align: middle;
  background: var(--panel-2); color: var(--faint); border: 1px solid var(--line);
}
.tag.soon { color: var(--accent); }

/* --- Fields --------------------------------------------------------- */
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }

input[type=text], input[type=number], input[type=email], input[type=search], select, textarea {
  width: 100%; padding: 8px 10px; font: inherit; font-size: 14px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
  color: var(--text);
  transition: border-color var(--dur) var(--ease);
}
input::placeholder, textarea::placeholder { color: var(--faint); }
input[type=text]:focus, input[type=number]:focus, input[type=email]:focus,
input[type=search]:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
}
input[type=color] {
  width: 100%; height: 34px; padding: 2px; cursor: pointer;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
}
input[type=range]    { width: 100%; accent-color: var(--accent); }
input[type=checkbox] { accent-color: var(--accent); width: 15px; height: 15px; vertical-align: -2px; }

.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text); margin: 0; cursor: pointer; }

/* --- Status text ---------------------------------------------------- */
.status { font-size: 13px; color: var(--muted); min-height: 18px; }
.status.ok  { color: var(--ok); }
.status.err { color: var(--err); }

.center-note { text-align: center; color: var(--muted); padding: 60px 20px; }

/* --- Ad slot -------------------------------------------------------- */
/* Placeholder box that holds the space for an AdSense unit. A banner by
   default; .tall is the 300x250 rectangle used in side rails. */
.ad-slot {
  display: grid; place-items: center; text-align: center;
  min-height: 120px;
  border: 1px dashed var(--line); border-radius: var(--radius-lg);
  background: var(--bg-2); color: var(--faint);
  position: relative; overflow: hidden;
}
.ad-slot .eyebrow { position: absolute; top: 10px; left: 12px; }
.ad-slot.tall { min-height: 250px; }

/* --- Utilities ------------------------------------------------------ */
.stack    { display: flex; flex-direction: column; gap: 12px; }
.cluster  { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer   { flex: 1; }
.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;
}

/* --- Narrow screens: keep the top bar on one line ------------------- */
@media (max-width: 640px) {
  .topbar { padding: 0 16px; gap: 10px; }
  /* Logo only: the wordmark text would push the account controls off-screen. */
  .brand { white-space: nowrap; flex-shrink: 0; font-size: 0; gap: 0; }
  .brand .mark { flex-shrink: 0; }
  .topbar .crumb { display: none; }
  .user-box > span, .user-box .avatar, .balance-chip .eyebrow { display: none; }
}
