/* Shared shell for every page: tokens, the sidebar, and the few components all tools use.
   Pages keep their own layout CSS, but alias their old token names onto these (e.g. buzz
   `--plane: var(--bg)`), so there is one palette in one place. Loaded before each page's
   inline <style>, so a page rule of equal specificity still wins. */

:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --text: #0f172a;
  --text-2: #334155;
  --muted: #5b6472;          /* 5.9:1 on --surface — the floor for small text */
  --border: #dfe3ea;
  --border-strong: #c5ccd6;
  --accent: #c2410c;         /* Every Media orange, darkened: white on it is 5.2:1 */
  --accent-hover: #9a3412;
  --accent-text: #c2410c;
  --accent-soft: #fff1e8;
  --on-accent: #ffffff;
  --ring: #c2410c;
  --ok: #15803d;   --ok-soft: #ecfdf3;
  --warn: #a16207; --warn-soft: #fefce8;
  --err: #b91c1c;  --err-soft: #fef2f2;
  --pos: #2563eb;  --neu: #cbd5e1; --neg: #dc2626;   /* sentiment, matches the decks */

  --font: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
  --fs-xs: 12px; --fs-sm: 13px; --fs: 15px; --fs-lg: 18px; --fs-xl: 24px; --fs-2xl: 32px;
  --r-sm: 6px; --r: 10px; --r-lg: 14px;
  --sh-1: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .08);
  --sh-2: 0 12px 32px rgba(15, 23, 42, .14);
  --ease: cubic-bezier(.2, .7, .2, 1);
  --side-w: 236px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --surface: #161a21;
    --surface-2: #1e232c;
    --text: #e6e9ef;
    --text-2: #b4bcc8;
    --muted: #9aa3af;
    --border: #2a303a;
    --border-strong: #3a414d;
    --accent: #fb923c;
    --accent-hover: #fdba74;
    --accent-text: #fdba74;
    --accent-soft: #3a2210;
    --on-accent: #1a0f06;    /* dark text on light orange — white would be ~2.2:1 */
    --ring: #fdba74;
    --ok: #4ade80;   --ok-soft: #0f2a1a;
    --warn: #facc15; --warn-soft: #2a2408;
    --err: #f87171;  --err-soft: #2d1414;
    --pos: #4c8df6;  --neu: #475569; --neg: #ef6b6b;
    --sh-1: 0 1px 2px rgba(0, 0, 0, .4);
    --sh-2: 0 16px 40px rgba(0, 0, 0, .5);
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body.app { margin: 0; min-height: 100dvh; background: var(--bg); color: var(--text);
  font: 400 var(--fs)/1.55 var(--font); -webkit-font-smoothing: antialiased; }
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--ring); outline-offset: 2px; }

/* ---- sidebar ------------------------------------------------------------------------- */
.side { display: flex; flex-direction: column; gap: 4px; background: var(--surface);
  border-right: 1px solid var(--border); padding: 18px 12px 14px; z-index: 40; }
.side .em-logo { display: block; padding: 4px 10px 14px; }
.side .em-logo img { display: block; width: 136px; height: auto; } /* 480px source: sharp at 3x */
.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-label { margin: 14px 10px 4px; color: var(--muted); font: 600 var(--fs-xs)/1 var(--font);
  letter-spacing: .08em; text-transform: uppercase; }
.side .nav-item, .side .update-button {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 40px; padding: 8px 10px;
  border: 0; border-radius: var(--r-sm); background: none; color: var(--text-2);
  font: 500 14px/1.25 var(--font); text-align: left; text-decoration: none; cursor: pointer;
  transition: background-color .15s var(--ease), color .15s var(--ease); }
.side .nav-item:hover:not(:disabled), .side .update-button:hover:not(:disabled) {
  background: var(--surface-2); color: var(--text); }
.side .nav-item[aria-current="page"] { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
/* A page of the tool above it (Saved reports under Buzz Dashboard): indented, slightly smaller. */
.side .nav-item.sub { padding-left: 38px; min-height: 34px; font-size: 13px; }
.side .nav-item.sub svg { width: 15px; height: 15px; }
.side .nav-item svg { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.side .nav-item.busy { cursor: progress; opacity: 1; }
.side .nav-item.busy svg { display: none; } /* the spinner takes the icon's place */
.side-foot { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 2px; }
.side-foot [data-desktop] { display: flex; flex-direction: column; gap: 2px; }
.side-foot:not(:has(> :not([hidden]))) { display: none; } /* web: nothing desktop-only to show */
.side-user { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 0 6px 10px; }
.side-user span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; font-size: 14px; }
.side-user .nav-item { width: auto; flex: none; color: var(--text-2); }

/* A page this account may not see (app-shell.js blockPage) */
main.blocked { max-width: 36rem; margin: 0 auto; padding: clamp(4rem, 14vh, 9rem) 32px 64px; }
main.blocked h1 { margin: 0 0 8px; font-size: var(--fs-xl); }
main.blocked p { margin: 0; color: var(--text-2); font-size: var(--fs-lg); line-height: 1.5; }
.side .update-button { border: 1px solid var(--border); justify-content: center; margin-top: 6px;
  color: var(--text); font-weight: 600; }
.side .update-button:disabled { cursor: progress; opacity: .7; }
.orm-status { display: flex; align-items: center; gap: 8px; min-height: 32px; padding: 4px 10px;
  color: var(--text-2); font-size: var(--fs-sm); }
.orm-status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; flex: none;
  background: var(--muted); }
.orm-status[data-state="ok"]::before { background: var(--ok); }
.orm-status[data-state="wait"]::before { background: var(--warn); }
.orm-status[data-state="down"]::before { background: var(--err); }
.orm-status[data-state="down"] { color: var(--err); font-weight: 600; }
html.electron-app .brand-agent { display: none; }

@media screen and (min-width: 1024px) {
  body.app { padding-left: var(--side-w); }
  .side { position: fixed; inset: 0 auto 0 0; width: var(--side-w); overflow-y: auto; }
}
@media screen and (max-width: 1023.98px) {
  /* Narrow window: the sidebar becomes a top bar — logo and actions on one row,
     the tool links scrolling on the next. */
  .side { position: sticky; top: 0; flex-direction: row; flex-wrap: wrap; align-items: center;
    gap: 6px 8px; padding: 10px 14px; border-right: 0; border-bottom: 1px solid var(--border); }
  .side .em-logo { padding: 4px 6px; }
  .side-label { display: none; }
  .side-nav { order: 3; flex: 1 0 100%; flex-direction: row; overflow-x: auto; }
  .side .side-nav .nav-item { width: auto; white-space: nowrap; }
  .side-foot { margin: 0 0 0 auto; padding: 0; border: 0; flex-direction: row; flex-wrap: wrap;
    align-items: center; gap: 4px; }
  .side-foot [data-desktop] { flex-direction: row; flex-wrap: wrap; gap: 4px; }
  .side .side-foot .nav-item, .side .side-foot .update-button { width: auto; margin: 0; min-height: 36px; }
}
body.share .side { display: none; }
body.app.share { padding-left: 0; }
@media print { .side { display: none !important; } } /* the sidebar offset is screen-only */

/* ---- buttons ------------------------------------------------------------------------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px;
  padding: 0 16px; border: 1px solid transparent; border-radius: var(--r-sm); font: 600 14px/1 var(--font);
  text-decoration: none; cursor: pointer; transition: background-color .15s var(--ease),
  border-color .15s var(--ease), color .15s var(--ease); }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); }
.btn-ghost { background: none; color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.busy::before, .spinner { content: ""; display: inline-block; width: 14px; height: 14px; flex: none;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  animation: em-spin .8s linear infinite; vertical-align: -2px; }
.btn.busy:disabled { opacity: .85; cursor: progress; }
.busy::before { margin-right: .5em; }
.btn.busy::before, .side .busy::before { margin-right: 0; } /* flex gap already spaces these */
@keyframes em-spin { to { transform: rotate(360deg); } }

/* ---- alerts ------------------------------------------------------------------------- */
.alert { display: grid; grid-template-columns: 20px 1fr; gap: 2px 10px; align-items: start;
  margin: 12px 0; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--r);
  background: var(--surface-2); color: var(--text); font-size: 14px; line-height: 1.5; }
.alert svg { width: 20px; height: 20px; grid-row: span 3; fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round; }
.alert > b { grid-column: 2; font-weight: 600; }
.alert .detail, .alert .fix { grid-column: 2; color: var(--text-2); overflow-wrap: anywhere; }
.alert .fix { font-weight: 500; }
.alert-err { background: var(--err-soft); border-color: color-mix(in srgb, var(--err) 35%, transparent); }
.alert-err svg { color: var(--err); }
.alert-warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.alert-warn svg { color: var(--warn); }
.alert-ok { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
.alert-ok svg { color: var(--ok); }

/* ---- progress card ------------------------------------------------------------------ */
.progress-card { margin: 16px 0; padding: 16px 18px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--sh-1); }
.progress-card .ph { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.progress-card .ph b { font-size: var(--fs); font-weight: 600; }
.progress-card .elapsed { font: 500 var(--fs-sm) var(--mono); color: var(--muted);
  font-variant-numeric: tabular-nums; }
.steps { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 12px 0; padding: 0; list-style: none;
  font-size: var(--fs-sm); color: var(--muted); }
.steps li { display: flex; align-items: center; gap: 6px; }
.steps li::before { content: ""; width: 10px; height: 10px; border-radius: 50%; border: 2px solid currentColor; }
.steps li[data-state="active"] { color: var(--accent-text); font-weight: 600; }
.steps li[data-state="active"]::before { background: currentColor; }
.steps li[data-state="done"] { color: var(--ok); }
.steps li[data-state="done"]::before { background: currentColor; }
.progress-card progress { width: 100%; height: 8px; appearance: none; border: 0; border-radius: 99px;
  overflow: hidden; background: var(--surface-2); }
.progress-card progress::-webkit-progress-bar { background: var(--surface-2); }
.progress-card progress::-webkit-progress-value { background: var(--accent); border-radius: 99px;
  transition: width .3s var(--ease); }
.progress-card progress:not([value]) { background: linear-gradient(90deg, var(--surface-2) 0 35%,
  var(--accent) 50%, var(--surface-2) 65% 100%) 0 0 / 300% 100%; animation: em-slide 1.4s linear infinite; }
.progress-card progress:not([value])::-webkit-progress-bar { background: transparent; }
@keyframes em-slide { from { background-position: 100% 0; } to { background-position: 0 0; } }
.progress-card .pnote { margin: 10px 0 0; color: var(--text-2); font-size: var(--fs-sm); }

/* ---- toasts ------------------------------------------------------------------------- */
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 1000; display: flex; flex-direction: column;
  gap: 8px; pointer-events: none; }
.toast { max-width: 420px; padding: 12px 16px; border: 1px solid var(--border);
  border-left: 4px solid var(--accent); border-radius: var(--r); background: var(--surface); color: var(--text);
  box-shadow: var(--sh-2); font-size: 14px; pointer-events: auto; animation: em-in .2s var(--ease); }
.toast-ok { border-left-color: var(--ok); }
.toast-err { border-left-color: var(--err); }
@keyframes em-in { from { opacity: 0; transform: translateY(8px); } }

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