/* =====================================================================
   tuestio — design system (marca v2, interfaz)
   Geist for UI and figures (tabular), Geist Mono only for codes, axes and
   the live instrument. Inside the app the interface accent is ink: black
   buttons, neutral selection. Naranja internacional is a *signal* (--signal):
   the logo, the live roaster, the bean-temperature curve, the next batch.
   Brand pieces (login poster, trace page hero) use it as a full field.
   ===================================================================== */

:root {
  color-scheme: light;

  --font-ui: 'Geist', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'Geist Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  --font-display: var(--font-ui);

  --bg: #eeebe6;            /* behind the canvas (sidebar sits here) */
  --canvas: #f7f5f2;        /* main content plane */
  --surface: #ffffff;
  --surface-2: #faf9f7;
  --surface-3: #f1eee9;
  --hover: rgba(20, 17, 15, 0.04);
  --hover-strong: rgba(20, 17, 15, 0.07);
  --border: rgba(20, 17, 15, 0.09);
  --border-strong: rgba(20, 17, 15, 0.16);
  --control-border: rgba(20, 17, 15, 0.46);   /* field outlines: ≥ 3:1 on white (WCAG 1.4.11) */
  --placeholder: rgba(20, 17, 15, 0.40);
  --text: #14110f;
  --text2: #4a4540;
  --text3: #6e6862;         /* ≥ 4.5:1 on white and canvas */

  /* Interface accent: ink. Buttons, selection, focus. */
  --accent: #14110f;
  --accent2: #2b2622;
  --accent-text: #14110f;
  --on-accent: #f6efe6;
  --accent-soft: rgba(20, 17, 15, 0.05);
  --accent-soft-2: rgba(20, 17, 15, 0.10);
  --ring: 0 0 0 3px rgba(20, 17, 15, 0.12);

  /* Brand signal: naranja internacional, used sparingly. */
  --signal: #ff4f00;
  --signal-text: #c23b00;   /* orange text on light grounds (4.7:1) */
  --signal-soft: rgba(255, 79, 0, 0.07);

  --green: #1f7a4d;
  --green-soft: rgba(31, 122, 77, 0.09);
  --red: #b3261e;
  --red-soft: rgba(179, 38, 30, 0.08);
  --amber: #8a5a00;
  --amber-soft: rgba(138, 90, 0, 0.10);
  --blue: #2e5e9e;
  --blue-soft: rgba(46, 94, 158, 0.09);

  --shadow-xs: 0 1px 1px rgba(20, 17, 15, 0.03);
  --shadow-sm: 0 1px 2px rgba(20, 17, 15, 0.04);
  --shadow-md: 0 1px 2px rgba(20, 17, 15, 0.04), 0 6px 20px -8px rgba(20, 17, 15, 0.10);
  --shadow-lg: 0 2px 6px rgba(20, 17, 15, 0.05), 0 24px 60px -18px rgba(20, 17, 15, 0.24);
  --shadow-primary: 0 1px 2px rgba(20, 17, 15, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.08);

  --r-sm: 6px;
  --r-md: 9px;
  --r-lg: 12px;
  --r-xl: 16px;

  /* Instrument (live roast) — always dark */
  --ink: #0b0908;
  --ink-2: #16120f;
  --ink-3: #221c18;
  --ink-line: rgba(246, 239, 230, 0.08);
  --ink-line-2: rgba(246, 239, 230, 0.15);
  --ink-text: #f6efe6;
  --ink-text2: rgba(246, 239, 230, 0.64);
  --ink-text3: rgba(246, 239, 230, 0.56);   /* ≥ 4.5:1 on the instrument */
  --bt: #ff4f00;
  --et: #e2cda8;
  --ror: #4fd1a5;

  --ease: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-spring: cubic-bezier(0.34, 1.4, 0.64, 1);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #070605;
  --canvas: #0e0c0b;
  --surface: #171412;
  --surface-2: #131110;
  --surface-3: #1f1b18;
  --hover: rgba(246, 239, 230, 0.05);
  --hover-strong: rgba(246, 239, 230, 0.08);
  --border: rgba(246, 239, 230, 0.09);
  --border-strong: rgba(246, 239, 230, 0.16);
  --control-border: rgba(246, 239, 230, 0.40);
  --placeholder: rgba(246, 239, 230, 0.38);
  --text: #f3eee8;
  --text2: #bdb5ab;
  --text3: #8f877d;
  --accent: #f3eee8;
  --accent2: #e3dcd2;
  --accent-text: #f3eee8;
  --on-accent: #0b0908;
  --accent-soft: rgba(246, 239, 230, 0.06);
  --accent-soft-2: rgba(246, 239, 230, 0.12);
  --ring: 0 0 0 3px rgba(246, 239, 230, 0.16);
  --signal: #ff5a14;
  --signal-text: #ff7a3d;
  --signal-soft: rgba(255, 90, 20, 0.10);
  --green: #4fb877;
  --green-soft: rgba(79, 184, 119, 0.12);
  --red: #f0675a;
  --red-soft: rgba(240, 103, 90, 0.12);
  --amber: #e0a24a;
  --amber-soft: rgba(224, 162, 74, 0.13);
  --blue: #7fa9e6;
  --blue-soft: rgba(127, 169, 230, 0.13);
  --shadow-xs: 0 0 0 1px rgba(255, 255, 255, 0.0);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px -8px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 2px 6px rgba(0, 0, 0, 0.3), 0 30px 80px -20px rgba(0, 0, 0, 0.7);
  --shadow-primary: none;
  --ink: #121010;
  --ink-2: #1b1714;
}

/* ---------- Base ---------- */
[hidden] { display: none !important; }
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; overscroll-behavior: none; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'ss01';
}
button, input, select, textarea { font: inherit; color: inherit; }
::selection { background: var(--accent-soft-2); }
a { color: var(--accent-text); text-decoration: none; }
a:hover { color: var(--text2); }
code, .mono { font-family: var(--font-mono); font-size: 0.92em; }
code { background: var(--surface-3); padding: 1px 6px; border-radius: 5px; color: var(--text); }
.tnum { font-variant-numeric: tabular-nums; }
.muted { color: var(--text3); }
svg { flex-shrink: 0; }
:where(svg.ico) { width: 16px; height: 16px; }
.ico, button svg, .navitem svg { stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

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

kbd, .kbd {
  font-family: var(--font-mono); font-size: 10.5px; font-weight: 500;
  min-width: 18px; height: 18px; padding: 0 5px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 5px; border: 1px solid var(--border-strong); border-bottom-width: 2px;
  background: var(--surface); color: var(--text2); line-height: 1;
}

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; border: 3px solid transparent; background-clip: content-box; }

/* ---------- App shell ---------- */
.app {
  display: grid;
  grid-template-columns: 252px minmax(0, 1fr);
  height: 100vh;
  padding: 8px 8px 8px 0;
}

.sidebar {
  display: flex; flex-direction: column;
  padding: 10px 10px 8px 12px;
  min-height: 0; overflow-y: auto; overscroll-behavior: none;
}
.workspace { display: flex; align-items: center; gap: 10px; padding: 4px 8px 4px 6px; border-radius: 10px; cursor: pointer; transition: background .12s; }
.workspace:hover { background: var(--hover); }
.ws-logo { width: 30px; height: 30px; border-radius: 8px; flex-shrink: 0; box-shadow: 0 0 0 1px rgba(20, 17, 15, .08); }
.ws-text { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.25; }
.ws-name { font-size: 13.5px; font-weight: 600; letter-spacing: -0.01em; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ws-name.has-brand { display: flex; align-items: center; height: 17px; }
.ws-brand { display: block; max-height: 15px; max-width: 100%; width: auto; object-fit: contain; object-position: left center; }
:root[data-theme="dark"] .ws-brand { filter: invert(1) hue-rotate(180deg); }
.ws-plan { font-size: 12px; color: var(--text3); white-space: nowrap; }
.ws-chev { width: 14px; height: 14px; color: var(--text3); }

.side-search {
  margin: 8px 0 2px; width: 100%; height: 32px; padding: 0 6px 0 10px;
  display: flex; align-items: center; gap: 8px;
  background: var(--hover); border: 1px solid transparent; border-radius: 8px;
  color: var(--text3); font-size: 13px; font-weight: 400; cursor: pointer; box-shadow: none;
  transition: background .12s, color .12s, border-color .12s;
}
.side-search:hover { background: var(--surface); border-color: var(--border); color: var(--text2); }
.side-search svg { width: 14px; height: 14px; }
.side-search span { flex: 1; text-align: left; }
.side-search kbd { background: transparent; border-color: var(--border); border-bottom-width: 1px; color: var(--text3); }

.navsection { font-size: 11.5px; font-weight: 500; color: var(--text3); padding: 14px 8px 4px 10px; line-height: 1.3;
  display: flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; border-radius: 6px; transition: color .15s; }
.navsection:hover, .navsection:focus-visible { color: var(--text); }
/* Chevron: points down when open, right when folded; quiet until hovered. */
.navsection::after { content: ''; order: 3; width: 5px; height: 5px; margin-left: 2px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor;
  transform: translateY(-1px) rotate(45deg); opacity: 0; transition: transform .22s var(--ease), opacity .15s; }
.navsection:hover::after, .navsection:focus-visible::after, .navsection.folded::after { opacity: .7; }
.navsection.folded::after { transform: rotate(-45deg); }
/* Folded: how many entries it hides, at the right. */
.navsection::before { content: attr(data-label); order: 2; margin-left: auto; min-width: 18px; height: 16px; padding: 0 5px; border-radius: 999px;
  font-size: 10.5px; line-height: 16px; text-align: center; font-variant-numeric: tabular-nums; color: var(--text3); background: var(--hover-strong);
  opacity: 0; transform: scale(.85); transition: opacity .18s, transform .22s var(--ease); }
.navsection.folded::before { opacity: 1; transform: none; color: var(--text2); }
.navsection.folded { color: var(--text2); margin-top: 2px; background: var(--hover); }
.navsection.folded:hover { background: var(--hover-strong); }
/* Items collapse in height (no display:none) so opening and closing animate. */
.navitem.nav-folded { height: 0 !important; min-height: 0 !important; opacity: 0; padding-top: 0; padding-bottom: 0; margin-top: 0; margin-bottom: 0;
  border-width: 0; pointer-events: none; visibility: hidden; transform: translateY(-3px);
  transition: height .2s var(--ease), opacity .12s, transform .2s var(--ease), padding .2s var(--ease), visibility 0s .2s; }
.sidebar .navitem { overflow: hidden; }
.sidebar .navitem:not(.nav-folded) { transition: background .12s, color .12s, height .24s var(--ease) var(--d, 0ms), opacity .2s var(--d, 0ms),
  transform .24s var(--ease) var(--d, 0ms), padding .24s var(--ease) var(--d, 0ms), visibility 0s; }
.sidebar.nav-measure .navitem { transition: none !important; }
@media (prefers-reduced-motion: reduce) { .sidebar .navitem, .navsection::after, .navsection::before { transition: none !important; } }

/* Compact rail toggle at the foot of the sidebar. */
.rail-toggle { display: flex; align-items: center; gap: 10px; height: 30px; padding: 0 10px; margin: 0 0 6px; border: 0; background: transparent;
  box-shadow: none; color: var(--text3); font-size: 12.5px; font-weight: 450; border-radius: 7px; justify-content: flex-start; }
.rail-toggle:hover { background: var(--hover); color: var(--text); }
.rail-toggle svg { width: 16px; height: 16px; }
.rail-toggle .rail-chev { transition: transform .25s var(--ease); transform-origin: 14.5px 12px; }
.app.rail .rail-toggle .rail-chev { transform: rotate(180deg); }

/* Icon rail */
.app { transition: grid-template-columns .28s var(--ease); }
.app.rail { grid-template-columns: 64px minmax(0, 1fr); }
.app.rail .sidebar { padding: 10px 8px 8px; overflow-x: hidden; }
.app.rail .ws-text, .app.rail .ws-chev, .app.rail .side-search span, .app.rail .side-search kbd, .app.rail .rail-toggle span,
.app.rail #sideLiveState, .app.rail .side-live-run, .app.rail .side-live-idle, .app.rail .side-live-arrow, .app.rail .side-live .spark { display: none; }
.app.rail .workspace { justify-content: center; padding: 4px 0; }
.app.rail .side-search { justify-content: center; padding: 0; }
.app.rail .navsection { font-size: 0; height: 1px; padding: 0; margin: 10px 10px; background: var(--border); cursor: default; }
.app.rail .navsection::before, .app.rail .navsection::after { display: none; }
.app.rail .navitem { justify-content: center; padding: 0; gap: 0; font-size: 0; }
.app.rail .navitem .icon { width: 18px; height: 18px; }
.app.rail .navitem .icon svg { width: 18px; height: 18px; }
.app.rail .navitem .dot { position: absolute; top: 5px; right: 9px; margin: 0; }
.app.rail .rail-toggle { justify-content: center; padding: 0; }
.app.rail .side-live { padding: 0; height: 36px; display: flex; align-items: center; justify-content: center; }
.app.rail .side-live-dot { width: 8px; height: 8px; }
.app.rail .side-live-top { justify-content: center; }
@media (max-width: 760px) { .rail-toggle { display: none; } }

.navitem {
  display: flex; align-items: center; gap: 10px;
  height: 28px; padding: 0 10px; border-radius: 7px;
  color: var(--text2); font-weight: 450; font-size: 13.5px; letter-spacing: -0.005em;
  cursor: pointer; user-select: none; position: relative;
  border: 1px solid transparent;
  transition: background .12s, color .12s;
}
.navitem:hover { background: var(--hover); color: var(--text); }
.navitem.active { background: var(--surface); color: var(--text); font-weight: 500; border-color: transparent; box-shadow: 0 0 0 1px var(--border), 0 1px 2px rgba(20, 17, 15, .05); }
.navitem .icon { width: 16px; height: 16px; display: inline-flex; color: var(--text3); transition: color .12s; }
.navitem .icon svg { width: 16px; height: 16px; }
.navitem:hover .icon { color: var(--text2); }
.navitem.active .icon { color: var(--text); }
.navitem .dot { margin-left: auto; width: 7px; height: 7px; border-radius: 50%; background: var(--signal); box-shadow: 0 0 0 3px var(--signal-soft); animation: pulse 1.6s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

.sidebar > * { flex-shrink: 0; }  /* never squash nav items; the sidebar scrolls instead */
.sidebar-spacer { flex: 1 1 auto; min-height: 10px; }

/* Sidebar live widget — a miniature of the instrument */
.side-live {
  position: relative; overflow: hidden; cursor: pointer; flex-shrink: 0;
  background: var(--ink);
  border-radius: 9px; padding: 9px 11px;
  color: var(--ink-text);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.06), var(--shadow-sm);
  transition: transform .18s var(--ease), box-shadow .18s;
}
.side-live:hover { box-shadow: inset 0 0 0 1px rgba(255,255,255,0.12), var(--shadow-md); }
.side-live-top { display: flex; align-items: center; gap: 7px; font-size: 11.5px; color: var(--ink-text2); font-weight: 500; }
.side-live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-text3); }
.side-live.connected .side-live-dot { background: var(--ror); box-shadow: 0 0 0 3px rgba(79, 209, 165, 0.18); }
.side-live.running .side-live-dot { background: var(--signal); box-shadow: 0 0 0 3px rgba(255, 79, 0, 0.22); animation: pulse 1.4s infinite; }
.side-live-arrow { margin-left: auto; width: 14px; height: 14px; color: var(--ink-text3); transition: transform .18s, color .18s; }
.side-live:hover .side-live-arrow { transform: translateX(2px); color: var(--ink-text); }
.side-live-idle { display: none; }  /* idle: one line is enough; the card grows while roasting */
.side-live-idle small { display: block; font-size: 11.5px; color: var(--ink-text3); font-weight: 400; margin-top: 2px; }
.side-live-run { display: none; margin-top: 6px; align-items: baseline; justify-content: space-between; gap: 8px; }
.side-live.running .side-live-idle { display: none; }
.side-live.running .side-live-run { display: flex; }
.side-live-time { font-family: var(--font-mono); font-size: 22px; font-weight: 500; letter-spacing: -0.02em; }
.side-live-bt { font-family: var(--font-mono); font-size: 13px; color: var(--bt); }
.side-live svg.spark { display: block; width: 100%; height: 26px; margin-top: 6px; }

/* Canvas (topbar + main) */
.canvas {
  display: flex; flex-direction: column; min-width: 0; min-height: 0;
  background: var(--canvas);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 1px 2px rgba(20, 17, 15, .03);
  overflow: hidden;
}

.topbar {
  display: flex; align-items: center; gap: 14px;
  height: 52px; padding: 0 12px 0 24px; flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--canvas) 85%, transparent);
  backdrop-filter: saturate(160%) blur(12px);
  position: relative; z-index: 50;
}
.topbar-crumb { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text3); min-width: 0; white-space: nowrap; }
.topbar-crumb .crumb-sep { width: 12px; height: 12px; opacity: .6; }
.topbar-crumb strong { color: var(--text); font-weight: 500; }
.topbar-spacer { flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 6px; }
.topbar-divider { width: 1px; height: 20px; background: var(--border); margin: 0 6px; }

.topbar-icon {
  width: 34px; height: 34px; padding: 0; border-radius: 9px; position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: 1px solid transparent; color: var(--text2); cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}
.topbar-icon:hover { background: var(--hover); color: var(--text); }
.topbar-icon svg { width: 17px; height: 17px; }
.topbar-status { height: 28px; padding: 0 10px; gap: 7px; border-radius: 999px; background: transparent; border: 1px solid var(--border); box-shadow: none; font-size: 12.5px; font-weight: 450; color: var(--text2); }
.topbar-status:hover { background: var(--hover); border-color: var(--border-strong); }
.topbar-icon-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text3); flex-shrink: 0; }
.topbar-icon-dot.live { background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.topbar-icon-dot.error { background: var(--red); }

.topbar-quick, .topbar-user { position: relative; }
.topbar-cta { height: 30px; padding: 0 12px 0 10px; font-size: 13px; gap: 6px; }
.topbar-cta-chev { width: 13px; height: 13px; opacity: .75; margin-left: 2px; transition: transform .18s; }
.topbar-quick.open .topbar-cta-chev { transform: rotate(180deg); }

.topbar-user-btn {
  display: flex; align-items: center; justify-content: center; height: 34px; width: 34px; padding: 0;
  background: transparent; border: 1px solid transparent; border-radius: 50%; cursor: pointer; box-shadow: none;
  transition: background .12s, border-color .12s;
}
.topbar-user-btn:hover, .topbar-user.open .topbar-user-btn { background: var(--hover); }
.avatar {
  width: 28px; height: 28px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent); color: var(--on-accent);
  font-weight: 600; font-size: 12px;
  box-shadow: none;
}
.topbar-user-info { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.15; }
.topbar-user-name { font-size: 12.5px; font-weight: 600; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-user-tenant { font-size: 11px; color: var(--text3); max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-user-chev { width: 12px; height: 12px; color: var(--text3); }

/* Popover menus */
.topbar-menu {
  display: none; position: absolute; top: calc(100% + 8px); right: 0; min-width: 260px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 13px;
  box-shadow: var(--shadow-lg); padding: 6px; z-index: 200;
  transform-origin: top right;
}
.topbar-quick.open .topbar-menu, .topbar-user.open .topbar-menu { display: block; animation: popIn .18s var(--ease); }
@keyframes popIn { from { opacity: 0; transform: translateY(-4px) scale(.97); } to { opacity: 1; transform: none; } }
.topbar-menu-item {
  display: flex; align-items: center; gap: 11px; padding: 8px 10px; border-radius: 8px;
  cursor: pointer; font-size: 13px; font-weight: 500; transition: background .1s;
}
.topbar-menu-item:hover { background: var(--hover); }
.topbar-menu-item > svg { width: 16px; height: 16px; color: var(--text3); }
.topbar-menu-item .mi-icon { width: 30px; height: 30px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; background: var(--surface-3); color: var(--text2); flex-shrink: 0; }
.topbar-menu-item .mi-icon svg { width: 15px; height: 15px; }
.topbar-menu-item:hover .mi-icon { background: var(--surface); color: var(--text); box-shadow: 0 0 0 1px var(--border); }
.topbar-menu-item div { display: flex; flex-direction: column; gap: 1px; }
.topbar-menu-item strong { font-weight: 550; font-size: 13px; }
.topbar-menu-item span { font-size: 11.5px; color: var(--text3); font-weight: 400; }
.topbar-menu-item kbd { margin-left: auto; }
.topbar-menu-item.danger { color: var(--red); }
.topbar-menu-item.danger > svg { color: var(--red); }
.topbar-menu-item.danger:hover { background: var(--red-soft); }
.topbar-menu-sep { height: 1px; background: var(--border); margin: 5px 4px; }
.topbar-menu-user { min-width: 280px; }
.topbar-user-card { display: flex; gap: 12px; align-items: center; padding: 10px 8px 12px; }
.topbar-user-card .avatar { width: 40px; height: 40px; border-radius: 50%; font-size: 15px; }
.topbar-user-card-name { font-size: 14px; font-weight: 600; letter-spacing: -0.01em; }
.topbar-user-card-email { font-size: 12px; color: var(--text2); }
.topbar-user-card-role { display: inline-block; margin-top: 5px; padding: 1px 8px; font-size: 11.5px; font-weight: 500; letter-spacing: 0; background: var(--accent-soft); color: var(--accent-text); border-radius: 999px; }

/* Main */
.main { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: none; padding: 32px 40px 72px; scroll-behavior: smooth; }
section.view { display: none; max-width: 1320px; margin: 0 auto; }
section.view.active { display: block; animation: viewIn .4s var(--ease); }
@keyframes viewIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Page header ---------- */
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin: 0 0 26px; }
.page-header .eyebrow { display: none; }
.eyebrow { font-size: 12px; font-weight: 500; color: var(--text3); letter-spacing: 0.01em; margin-bottom: 6px; display: flex; align-items: center; gap: 6px; }
.page-header .title {
  font-family: var(--font-display); font-weight: 600; font-size: 28px; line-height: 1.15;
  letter-spacing: -0.03em; margin: 0; text-wrap: balance;
}
.page-header .title em { font-style: normal; color: inherit; }
.page-header .subtitle { font-size: 14px; color: var(--text3); margin-top: 6px; max-width: 620px; text-wrap: pretty; }
.page-header .actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.page-subheader { display: flex; align-items: flex-end; justify-content: space-between; margin: 0 0 14px; }
.subtitle-h { font-family: var(--font-display); font-weight: 600; font-size: 21px; letter-spacing: -0.018em; margin: 0; }
.page-subheader .subtitle { font-size: 13px; color: var(--text2); margin-top: 4px; }

.section-label { font-size: 13px; font-weight: 600; letter-spacing: -0.005em; margin: 34px 0 14px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.section-label .link { font-size: 12.5px; font-weight: 500; color: var(--text2); cursor: pointer; display: inline-flex; align-items: center; gap: 4px; }
.section-label .link:hover { color: var(--accent-text); }
.section-label .link svg { width: 13px; height: 13px; }

/* ---------- Buttons ---------- */
button {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 14px; border-radius: 9px;
  font-size: 13.5px; font-weight: 500; line-height: 1; white-space: nowrap;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-xs);
  cursor: pointer;
  transition: background .14s, border-color .14s, box-shadow .14s, transform .08s, filter .14s, color .14s;
}
button:hover { background: var(--surface-2); border-color: color-mix(in srgb, var(--border-strong) 70%, var(--text3)); }
button:active { transform: translateY(1px); }
button svg { width: 15px; height: 15px; }
button:disabled { opacity: .45; cursor: not-allowed; transform: none; }

button.primary, button.amber {
  background: var(--accent);
  border-color: var(--accent); color: var(--on-accent); font-weight: 500;
  box-shadow: var(--shadow-primary);
}
button.primary:hover:not(:disabled), button.amber:hover:not(:disabled) { background: var(--accent2); border-color: var(--accent2); }
button.primary:active:not(:disabled), button.amber:active:not(:disabled) { background: var(--accent2); }
button.danger { background: var(--red); border-color: var(--red); color: #fff; box-shadow: var(--shadow-xs); }
button.danger:disabled { background: var(--surface-3); border-color: var(--border); color: var(--text3); opacity: 1; }
button.danger:hover:not(:disabled) { filter: brightness(1.06); }
button.ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--text2); }
button.ghost:hover { background: var(--hover); color: var(--text); }
button.sm { height: 30px; padding: 0 11px; font-size: 12.5px; border-radius: 8px; gap: 5px; }
button.sm svg { width: 13px; height: 13px; }
button.lg { height: 42px; padding: 0 18px; font-size: 14px; border-radius: 11px; }
button.icon-btn { width: 30px; height: 30px; padding: 0; color: var(--text2); }
button.icon-btn:hover { color: var(--text); }
button.icon-btn svg { width: 14px; height: 14px; }
button.advance, button.accent-soft { background: transparent; border-color: var(--border); color: var(--text2); box-shadow: none; font-weight: 500; }
tr:hover button.advance { border-color: var(--border-strong); color: var(--text); }
button.advance:hover, button.accent-soft:hover { background: var(--accent-soft-2); color: var(--text); border-color: transparent; }
button.block { width: 100%; }

/* ---------- Inputs ---------- */
input[type=text], input[type=password], input[type=email], input[type=number], input.num-input, input[type=date], input[type=search], select, textarea {
  width: 100%; height: 38px; padding: 0 12px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--control-border); border-radius: 9px;
  font-size: 13.5px; outline: none; box-shadow: var(--shadow-xs);
  transition: border-color .15s, box-shadow .15s, background .15s;
}
textarea { height: auto; min-height: 72px; padding: 10px 12px; resize: vertical; line-height: 1.5; }
input:hover:not(:focus):not(:disabled), select:hover:not(:focus), textarea:hover:not(:focus) { border-color: var(--text3); }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: var(--ring); }
input::placeholder, textarea::placeholder { color: var(--placeholder); }
input:disabled, select:disabled { opacity: .55; cursor: not-allowed; }
input[type=number], input.num-input { font-family: var(--font-ui); font-variant-numeric: tabular-nums; font-size: 13px; -moz-appearance: textfield; }
input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: 12.5px; font-weight: 500; color: var(--text2); }
.field > span small { color: var(--text3); font-weight: 400; }

.input-icon { position: relative; display: block; }
.input-icon > svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--text3); pointer-events: none; }
.input-icon > input { padding-left: 34px; }

/* Custom select */
.cs-wrap { position: relative; display: block; width: 100%; }
.cs-native { position: absolute; opacity: 0; pointer-events: none; width: 0; height: 0; }
.cs-button {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  width: 100%; height: 38px; padding: 0 10px 0 12px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--control-border); border-radius: 9px;
  font-size: 13.5px; font-weight: 400; text-align: left; box-shadow: var(--shadow-xs);
}
.cs-button:hover { background: var(--surface); }
.cs-wrap.open .cs-button, .cs-button:focus-visible { border-color: var(--accent); box-shadow: var(--ring); outline: none; }
.cs-button .cs-value { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.cs-button.placeholder .cs-value { color: var(--text3); }
.cs-chev { width: 14px; height: 14px; color: var(--text3); transition: transform .2s var(--ease); }
.cs-wrap.open .cs-chev { transform: rotate(180deg); color: var(--accent); }
.cs-panel {
  display: none; position: absolute; top: calc(100% + 6px); left: 0; min-width: 100%;
  background: var(--surface); border: 1px solid var(--border); border-radius: 11px;
  box-shadow: var(--shadow-lg); z-index: 300; padding: 5px; max-height: 300px; overflow-y: auto;
}
.cs-wrap.open .cs-panel { display: block; animation: popIn .16s var(--ease); }
.cs-option { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 7px; cursor: pointer; font-size: 13.5px; }
.cs-option:hover, .cs-option:focus { background: var(--hover); outline: none; }
.cs-option.selected { background: var(--accent-soft); color: var(--accent-text); font-weight: 500; }
.cs-option.selected::after { content: ''; margin-left: auto; width: 14px; height: 14px; background: currentColor; -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'><polyline points='20 6 9 17 4 12'/></svg>") center/contain no-repeat; mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'><polyline points='20 6 9 17 4 12'/></svg>") center/contain no-repeat; }
.cs-empty { padding: 14px 12px; text-align: center; color: var(--text3); font-size: 12.5px; }

/* Custom date picker */
.cdp-wrap { position: relative; display: block; width: 100%; }
.cdp-native { position: absolute; opacity: 0; pointer-events: none; width: 0; height: 0; }
.cdp-button {
  display: flex; align-items: center; justify-content: flex-start; gap: 9px;
  width: 100%; height: 38px; padding: 0 12px;
  background: var(--surface); border: 1px solid var(--control-border); border-radius: 9px;
  font-size: 13.5px; font-weight: 400; box-shadow: var(--shadow-xs);
}
.cdp-button:hover { background: var(--surface); }
.cdp-wrap.open .cdp-button { border-color: var(--accent); box-shadow: var(--ring); }
.cdp-icon { width: 15px; height: 15px; color: var(--text3); }
.cdp-button .cdp-value { flex: 1; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cdp-button.placeholder .cdp-value { color: var(--text3); }
.cdp-panel { display: none; position: absolute; top: calc(100% + 6px); left: 0; width: 280px; background: var(--surface); border: 1px solid var(--border); border-radius: 13px; box-shadow: var(--shadow-lg); z-index: 300; padding: 14px; }
.cdp-wrap.open .cdp-panel { display: block; animation: popIn .16s var(--ease); }
.cdp-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.cdp-nav { width: 28px; height: 28px; padding: 0; border-radius: 7px; background: transparent; border-color: transparent; box-shadow: none; color: var(--text2); }
.cdp-nav:hover { background: var(--hover); }
.cdp-title { font-size: 13.5px; font-weight: 600; cursor: pointer; padding: 4px 10px; border-radius: 6px; }
.cdp-title:hover { background: var(--hover); }
.cdp-dow, .cdp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cdp-dow > div { text-align: center; font-size: 10.5px; font-weight: 600; color: var(--text3); padding: 4px 0; }
.cdp-day { aspect-ratio: 1; display: flex; align-items: center; justify-content: center; font-size: 12.5px; border-radius: 8px; cursor: pointer; font-variant-numeric: tabular-nums; transition: background .12s; position: relative; }
.cdp-day:hover { background: var(--hover); }
.cdp-day.muted { color: var(--text3); }
.cdp-day.today { color: var(--text); font-weight: 600; box-shadow: inset 0 0 0 1px var(--border-strong); }
.cdp-day.today::after { content: ''; position: absolute; bottom: 4px; width: 3px; height: 3px; border-radius: 50%; background: currentColor; }
.cdp-day.selected { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.cdp-footer { display: flex; justify-content: space-between; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); }
.cdp-footer button { height: 28px; font-size: 12px; padding: 0 10px; }
.cdp-yearpicker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.cdp-yearitem { padding: 9px 6px; border-radius: 8px; text-align: center; cursor: pointer; font-size: 13px; }
.cdp-yearitem:hover { background: var(--hover); }
.cdp-yearitem.selected { background: var(--accent); color: var(--on-accent); font-weight: 600; }

/* Range slider (cupping) */
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 22px; background: transparent; cursor: pointer; --pct: 50%; }
input[type=range]::-webkit-slider-runnable-track { height: 6px; border-radius: 999px; background: linear-gradient(90deg, var(--accent) 0 var(--pct), var(--surface-3) var(--pct) 100%); }
input[type=range]::-moz-range-track { height: 6px; border-radius: 999px; background: var(--surface-3); }
input[type=range]::-moz-range-progress { height: 6px; border-radius: 999px; background: var(--accent); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; margin-top: -6px; border-radius: 50%; background: #fff; border: 1px solid var(--border-strong); box-shadow: 0 1px 3px rgba(26,23,20,.25), 0 0 0 0 var(--accent-soft-2); transition: box-shadow .15s, transform .15s; }
input[type=range]::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: #fff; border: 1px solid var(--border-strong); box-shadow: 0 1px 3px rgba(26,23,20,.25); }
input[type=range]:hover::-webkit-slider-thumb { box-shadow: 0 1px 3px rgba(26,23,20,.25), 0 0 0 6px var(--accent-soft); }
input[type=range]:active::-webkit-slider-thumb { transform: scale(1.1); }
input[type=range]:focus { outline: none; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 22px 24px; box-shadow: var(--shadow-sm); }
.card.flush { padding: 0; overflow: hidden; }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 18px; }
.card.flush .card-h { margin: 0; padding: 18px 22px 14px; }
.card-h h3 { margin: 0; font-size: 14px; font-weight: 600; letter-spacing: -0.01em; }
.card-h .card-h-meta { font-size: 12.5px; color: var(--text3); }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
hr.sep { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }

/* Composer — inline "add" bar */
.composer {
  display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap;
  padding: 16px 18px; margin-bottom: 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm); position: relative;
}
.composer-tag { position: absolute; top: -9px; left: 16px; font-size: 11px; font-weight: 500; color: var(--text3); background: var(--canvas); padding: 0 6px; letter-spacing: 0.01em; }
.composer .field { flex: 1 1 140px; }
.composer .composer-cta { height: 38px; }

/* ---------- Tables ---------- */
.table-toolbar { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.table-toolbar .input-icon { width: 260px; max-width: 100%; }
.table-toolbar input[type=search] { height: 34px; background: var(--surface-2); box-shadow: none; }
.table-toolbar .count { margin-left: auto; font-size: 12.5px; color: var(--text3); font-variant-numeric: tabular-nums; }

.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: separate; border-spacing: 0; }
th, td { text-align: left; padding: 13px 18px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th {
  font-size: 12px; font-weight: 500; color: var(--text3);
  padding-top: 10px; padding-bottom: 10px; background: var(--surface-2);
  white-space: nowrap; position: sticky; top: 0; z-index: 1;
}
tbody td { font-size: 13.5px; }
tbody tr { transition: background .1s; }
tbody tr:hover td { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tr.selected td { background: var(--accent-soft) !important; }
tr.selected td:first-child { box-shadow: none; }
td.num, th.num { text-align: right; }
td.num { font-family: var(--font-ui); font-variant-numeric: tabular-nums; font-size: 13px; font-variant-numeric: tabular-nums; }
td.num strong { font-weight: 600; }
td.id, td.num-muted { font-family: var(--font-ui); font-variant-numeric: tabular-nums; font-size: 12px; color: var(--text3); width: 1%; white-space: nowrap; }
.cell-strong { font-weight: 550; }
.cell-sub { font-size: 12px; color: var(--text3); margin-top: 2px; }
.cell-muted { color: var(--text3); }
.list-more { display: block; margin: 10px auto 14px; }
.cell-with-avatar { display: flex; align-items: center; gap: 11px; }
.row-avatar { width: 32px; height: 32px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 11.5px; font-weight: 600; background: var(--surface-3); color: var(--text2); border: 1px solid var(--border); flex-shrink: 0; }
.row-actions { display: inline-flex; gap: 6px; align-items: center; justify-content: flex-end; width: 100%; }
.row-actions a { display: inline-flex; }
.unit { color: var(--text3); font-size: .9em; margin-left: 2px; }

/* Stock meter */
.meter { display: flex; align-items: center; gap: 10px; justify-content: flex-end; }
.meter-track { width: 64px; height: 5px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.meter-fill { height: 100%; border-radius: inherit; background: var(--accent); }
.meter.low .meter-fill { background: var(--amber); }
.meter.neg .meter-fill { background: var(--red); }

/* Empty state */
.empty, .empty-state { text-align: center; padding: 56px 24px; color: var(--text3); font-size: 13.5px; }
.empty-state .es-icon { width: 52px; height: 52px; margin: 0 auto 14px; border-radius: 15px; display: flex; align-items: center; justify-content: center; background: var(--accent-soft); color: var(--accent-text); }
.empty-state .es-icon svg { width: 24px; height: 24px; }
.empty-state h4 { font-family: var(--font-display); font-weight: 600; font-size: 18px; letter-spacing: -0.015em; color: var(--text); margin: 0 0 6px; }
.empty-state p { margin: 0 auto; max-width: 360px; color: var(--text2); line-height: 1.55; }
.empty-state button { margin-top: 18px; }
td.empty-cell { padding: 0; }
td.empty-cell:hover, tr:hover td.empty-cell { background: transparent !important; }

/* ---------- Chips, badges ---------- */
.chip { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 9px; border-radius: 999px; font-size: 12px; font-weight: 500; white-space: nowrap; background: var(--surface-3); color: var(--text2); }
.chip::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
.chip.no-dot::before { display: none; }
.chip-draft, .chip-paused { background: var(--surface-3); color: var(--text2); }
.chip-confirmed { background: var(--blue-soft); color: var(--blue); }
.chip-prepared, .chip-cadence, .chip-live, .chip-ref { background: var(--accent-soft); color: var(--accent-text); }
.chip-shipped { background: var(--amber-soft); color: var(--amber); }
.chip-delivered, .chip-active, .chip-specialty { background: var(--green-soft); color: var(--green); }
.chip-cancelled { background: var(--red-soft); color: var(--red); }
.chip-import { background: var(--surface-3); color: var(--text2); }
.pill { display: inline-flex; align-items: center; height: 22px; padding: 0 9px; margin: 2px 3px 2px 0; border-radius: 999px; font-size: 12px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text2); }
.shrink-badge { font-family: var(--font-ui); font-variant-numeric: tabular-nums; }

.score-badge { display: inline-flex; align-items: center; justify-content: center; min-width: 54px; height: 26px; padding: 0 9px; border-radius: 8px; font-family: var(--font-ui); font-variant-numeric: tabular-nums; font-weight: 600; font-size: 13px; }
.score-badge.top { background: var(--green-soft); color: var(--green); }
.score-badge.specialty { background: var(--surface-3); color: var(--text); }
.score-badge.commercial { background: transparent; color: var(--text3); box-shadow: inset 0 0 0 1px var(--border); }

.user-role { height: 30px; font-size: 12.5px; font-weight: 550; padding: 0 10px; border-radius: 8px; width: auto !important; }
.user-role.role-admin { background: var(--accent-soft); color: var(--accent-text); border-color: transparent; }
.user-role.role-operator { background: var(--blue-soft); color: var(--blue); border-color: transparent; }
.user-role.role-viewer { background: var(--surface-3); color: var(--text2); border-color: transparent; }

/* Segmented control */
.segmented { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-3); border-radius: 10px; border: 1px solid var(--border); }
.segmented button { height: 28px; padding: 0 11px; font-size: 12.5px; border: 0; background: transparent; box-shadow: none; color: var(--text2); border-radius: 7px; gap: 6px; }
.segmented button:hover { color: var(--text); background: transparent; }
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm), 0 0 0 1px var(--border); }
.segmented .seg-count { font-family: var(--font-ui); font-variant-numeric: tabular-nums; font-size: 11px; color: var(--text3); }

.period-pill { display: inline-flex; align-items: center; gap: 7px; height: 32px; padding: 0 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); font-size: 12.5px; color: var(--text2); font-weight: 500; box-shadow: var(--shadow-xs); }

/* ---------- Dashboard ---------- */
.hero { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 28px; }
.hero-date { font-size: 13px; color: var(--text3); margin-bottom: 8px; font-weight: 500; }
.hero h1 { font-family: var(--font-display); font-size: 38px; font-weight: 600; letter-spacing: -0.025em; line-height: 1.08; margin: 0; }
.hero h1 em { font-style: normal; color: inherit; }
.hero p { margin: 10px 0 0; color: var(--text2); font-size: 14.5px; }
.hero .actions { display: flex; gap: 8px; align-items: center; }

.stats-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.stat-card {
  position: relative; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 18px 20px 18px; box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; min-height: 148px;
  transition: transform .2s var(--ease), box-shadow .2s, border-color .2s;
  animation: rise .5s var(--ease) both;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-card.has-spark { padding-bottom: 0; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.stat-top { display: flex; align-items: center; gap: 8px; }
.stat-icon { width: 26px; height: 26px; border-radius: 7px; display: inline-flex; align-items: center; justify-content: center; background: var(--surface-3); color: var(--text2); }
.stat-icon svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.stat-card.featured .stat-icon { background: var(--accent-soft); color: var(--accent-text); }
.stat-label { font-size: 13px; font-weight: 500; color: var(--text2); }
.stat-value-row { display: flex; align-items: baseline; gap: 10px; margin-top: 14px; }
.stat-value { font-family: var(--font-display); font-size: 30px; font-weight: 600; letter-spacing: -0.025em; line-height: 1; font-variant-numeric: tabular-nums; }
.stat-value small { font-size: 15px; font-weight: 500; color: var(--text3); letter-spacing: -0.01em; margin-left: 2px; }
.stat-trend { font-size: 11.5px; font-weight: 600; height: 20px; padding: 0 7px; border-radius: 999px; display: inline-flex; align-items: center; gap: 3px; font-variant-numeric: tabular-nums; }
.stat-trend.up { background: var(--green-soft); color: var(--green); }
.stat-trend.down { background: var(--red-soft); color: var(--red); }
.stat-sub { font-size: 12.5px; color: var(--text3); margin-top: 8px; }
.stat-card .spark { margin: auto -20px 0; padding-top: 10px; line-height: 0; }

/* Ranked bar list */
.rank-list { display: flex; flex-direction: column; gap: 4px; }
.rank-row { display: grid; grid-template-columns: 22px minmax(0, 1fr) auto; grid-template-rows: auto auto; column-gap: 10px; row-gap: 7px; align-items: center; padding: 9px 8px; border-radius: 9px; transition: background .12s; }
.rank-row:hover { background: var(--surface-2); }
.rank-n { font-family: var(--font-ui); font-variant-numeric: tabular-nums; font-size: 11.5px; color: var(--text3); }
.rank-label { font-size: 13.5px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-value { font-family: var(--font-ui); font-variant-numeric: tabular-nums; font-size: 12.5px; color: var(--text2); text-align: right; }
.rank-track { grid-column: 2 / 4; height: 5px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.rank-fill { height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, color-mix(in srgb, var(--bar, var(--accent)) 55%, transparent), var(--bar, var(--accent))); animation: barGrow .9s var(--ease) forwards; }
@keyframes barGrow { to { width: var(--pct); } }

/* Recent roast cards */
.roast-strip { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.roast-mini {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 14px 14px 12px; cursor: pointer; box-shadow: var(--shadow-sm);
  transition: transform .2s var(--ease), box-shadow .2s, border-color .2s;
  animation: rise .5s var(--ease) both; min-width: 0;
}
.roast-mini:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--border-strong); }
.roast-mini svg { width: 100%; height: 64px; display: block; margin: 2px 0 10px; overflow: visible; }
.roast-mini .rm-name { font-weight: 550; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.roast-mini .rm-meta { display: flex; justify-content: space-between; gap: 8px; margin-top: 4px; font-size: 12px; color: var(--text3); }
.roast-mini .rm-meta span:last-child { font-family: var(--font-ui); font-variant-numeric: tabular-nums; }
.roast-mini .rm-top { display: flex; justify-content: space-between; align-items: center; font-size: 11.5px; color: var(--text3); }
.roast-mini .rm-top .mono { font-size: 11px; }

/* ---------- Live roast: setup + instrument ---------- */
.live-setup { padding: 18px 20px; }
.live-form { display: grid; grid-template-columns: minmax(170px, 1.2fr) minmax(170px, 1.4fr) minmax(190px, 1.6fr) 110px auto; gap: 12px; align-items: end; }
.machine-field { display: flex; gap: 6px; }
.machine-field .cs-wrap { flex: 1; min-width: 0; }
.machine-field > button { width: 38px; height: 38px; padding: 0; flex-shrink: 0; }
.live-form-actions { display: flex; gap: 8px; }
.live-form-actions button { height: 38px; }
#startBtn { padding: 0 18px; }

.instrument {
  position: relative; margin-top: 16px; overflow: clip;
  border-radius: var(--r-xl);
  background:
    radial-gradient(900px 380px at 0% -10%, rgba(255, 79, 0, 0.13), transparent 60%),
    radial-gradient(700px 320px at 100% 110%, rgba(255, 159, 90, 0.08), transparent 60%),
    linear-gradient(180deg, var(--ink-2), var(--ink));
  color: var(--ink-text);
  border: 1px solid rgba(0, 0, 0, 0.4);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), var(--shadow-lg);
}
.instrument::before { /* fine grain */
  content: ''; position: absolute; inset: 0; pointer-events: none; opacity: .5;
  background-image: radial-gradient(rgba(255,255,255,0.035) 1px, transparent 1px);
  background-size: 3px 3px;
}
.instrument > * { position: relative; }
.inst-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 22px 0; }
.inst-title { display: flex; align-items: center; gap: 10px; font-size: 13px; font-weight: 500; color: var(--ink-text2); }
.link-pill { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; height: 24px; padding: 0 10px; border-radius: 999px; font-size: 12px; font-weight: 500; background: rgba(255,255,255,0.06); color: var(--ink-text2); border: 1px solid var(--ink-line); }
.link-pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--ink-text3); }
.link-pill.ok { color: var(--ror); }
.link-pill.ok::before { background: var(--ror); box-shadow: 0 0 8px var(--ror); }
.link-pill.connecting::before { background: var(--et); animation: pulse 1s infinite; }
.link-pill.down { color: #ff8a7a; border-color: rgba(255, 138, 122, 0.3); background: rgba(255, 138, 122, 0.08); }
.link-pill.down::before { background: #ff6a4d; }
.inst-legend { display: flex; gap: 14px; font-size: 11.5px; color: var(--ink-text3); }
.inst-legend span { display: inline-flex; align-items: center; gap: 6px; }
.inst-legend i { width: 14px; height: 2px; border-radius: 2px; background: currentColor; display: inline-block; }
.inst-legend i.dash { background: repeating-linear-gradient(90deg, currentColor 0 3px, transparent 3px 5px); }

.live-stats { display: grid; grid-template-columns: 1.15fr 1fr 1fr 1fr; padding: 14px 8px 4px; }
.live-stat { padding: 8px 18px 12px; border-right: 1px solid var(--ink-line); }
.live-stat:last-child { border-right: 0; }
.live-stat .k { font-size: 11.5px; font-weight: 500; color: var(--ink-text3); display: flex; align-items: center; gap: 7px; letter-spacing: 0.02em; }
.live-stat .k i { width: 8px; height: 8px; border-radius: 50%; background: var(--c, var(--ink-text3)); box-shadow: 0 0 10px var(--c, transparent); display: inline-block; }
.live-stat .v { font-family: var(--font-mono); font-size: 44px; font-weight: 400; letter-spacing: -0.04em; line-height: 1; margin-top: 10px; color: var(--ink-text); font-variant-numeric: tabular-nums; white-space: nowrap; }
.live-stat .v.bt { color: var(--bt); text-shadow: 0 0 28px rgba(255, 79, 0, 0.35); }
.live-stat .v.et { color: var(--et); }
.live-stat .v.ror { color: var(--ror); }
.live-unit { font-size: 14px; color: var(--ink-text3); margin-left: 4px; letter-spacing: 0; font-family: var(--font-ui); }

/* Phase bar */
.phase-wrap { padding: 8px 22px 4px; }
.phase-bar { display: flex; height: 8px; border-radius: 999px; overflow: hidden; background: rgba(255,255,255,0.05); gap: 2px; }
.phase-bar > div { height: 100%; transition: flex-basis .6s var(--ease); flex: 0 0 0%; }
.phase-bar .ph-dry { background: linear-gradient(90deg, #7bc59a, #d8c86a); }
.phase-bar .ph-mai { background: linear-gradient(90deg, #e3a95a, #d9733f); }
.phase-bar .ph-dev { background: linear-gradient(90deg, #b45a3a, #7a3e2a); }
.phase-legend { display: flex; justify-content: space-between; gap: 14px; margin-top: 9px; font-size: 12px; color: var(--ink-text3); flex-wrap: wrap; }
.phase-legend > div { display: flex; gap: 18px; flex-wrap: wrap; }
.phase-legend span b { font-family: var(--font-mono); font-weight: 500; color: var(--ink-text2); margin-left: 5px; }
.phase-legend .dtr b { color: var(--ink-text); }
.phase-legend i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; vertical-align: -0.5px; }

#chart { padding: 8px 10px 0 4px; min-height: 420px; }
.instrument .uplot { font-family: var(--font-mono); }
.instrument .u-legend { display: none; }

.events-row { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 8px; padding: 12px 16px 16px; border-top: 1px solid var(--ink-line); }
.evt-btn {
  position: relative; height: auto; padding: 11px 12px 10px; border-radius: 12px;
  display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
  background: rgba(255,255,255,0.035); border: 1px solid var(--ink-line); color: var(--ink-text);
  box-shadow: none; text-align: left; font-size: 13px; font-weight: 500;
  transition: background .15s, border-color .15s, transform .1s;
}
.evt-btn:hover:not(:disabled) { background: rgba(255,255,255,0.07); border-color: var(--ink-line-2); }
.evt-btn:disabled { opacity: .4; }
.evt-btn .evt-top { display: flex; align-items: center; justify-content: space-between; width: 100%; }
.evt-btn .evt-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.evt-btn kbd { background: rgba(255,255,255,0.06); border-color: var(--ink-line-2); color: var(--ink-text3); height: 17px; min-width: 17px; font-size: 10px; }
.evt-btn .evt-time { font-family: var(--font-mono); font-size: 12px; color: var(--ink-text3); }
.evt-btn.fired { background: color-mix(in srgb, var(--c) 14%, transparent); border-color: color-mix(in srgb, var(--c) 55%, transparent); }
.evt-btn.fired .evt-dot { box-shadow: 0 0 10px var(--c); }
.evt-btn.fired .evt-time { color: var(--ink-text); }
.evt-btn.flash { animation: flash .5s var(--ease); }
@keyframes flash { 0% { transform: scale(.97); } 60% { transform: scale(1.02); } 100% { transform: none; } }

/* ---------- Drawer (lots) ---------- */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(20, 16, 14, 0.32); backdrop-filter: blur(2px); z-index: 140; opacity: 0; pointer-events: none; transition: opacity .25s; }
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 8px; right: 8px; bottom: 8px; width: min(620px, calc(100vw - 16px)); z-index: 150;
  background: var(--canvas); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; overflow: hidden;
  transform: translateX(calc(100% + 24px)); transition: transform .35s var(--ease);
}
.drawer.open { transform: none; }
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 22px 24px 18px; border-bottom: 1px solid var(--border); }
.drawer-body { padding: 20px 24px 28px; overflow-y: auto; flex: 1; }
.drawer .composer { box-shadow: none; }
.drawer-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 18px; }
.mini-stat { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.mini-stat .k { font-size: 12px; color: var(--text3); }
.mini-stat .v { font-family: var(--font-ui); font-variant-numeric: tabular-nums; font-size: 19px; font-weight: 500; margin-top: 4px; letter-spacing: -0.02em; }

/* ---------- Modals ---------- */
.modal { position: fixed; inset: 0; z-index: 400; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(20, 16, 14, 0.4); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); opacity: 0; pointer-events: none; transition: opacity .2s; }
.modal.open { opacity: 1; pointer-events: auto; }
.modal-card { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 26px 28px 22px; width: min(680px, 100%); max-height: calc(100vh - 40px); overflow: auto; box-shadow: var(--shadow-lg); transform: translateY(10px) scale(.98); transition: transform .28s var(--ease-spring); }
.modal.open .modal-card { transform: none; }
.modal-card h3 { font-family: var(--font-display); font-weight: 600; font-size: 22px; letter-spacing: -0.018em; margin: 0 0 4px; }
.modal-card .modal-sub { font-size: 13.5px; color: var(--text2); margin: 0 0 20px; }
.modal-x { position: absolute; top: 16px; right: 16px; width: 32px; height: 32px; padding: 0; border-radius: 9px; background: transparent; border-color: transparent; box-shadow: none; color: var(--text3); }
.modal-x:hover { background: var(--hover); color: var(--text); }
.modal-footer { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--border); }
.total-display { display: flex; align-items: baseline; gap: 10px; font-size: 13px; color: var(--text3); font-weight: 500; }
.total-display span { font-family: var(--font-ui); font-variant-numeric: tabular-nums; font-size: 28px; font-weight: 500; color: var(--text); letter-spacing: -0.03em; }

.lines-header { display: flex; align-items: baseline; justify-content: space-between; margin: 22px 0 8px; }
.lines-title { font-size: 13px; font-weight: 600; }
.lines-hint { font-size: 12px; color: var(--text3); }
.lines-wrap { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.lines-table th { padding: 8px 12px; font-size: 11.5px; position: static; }
.lines-table td { padding: 8px 10px; background: transparent !important; }
.lines-table input, .lines-table .cs-button { height: 34px; }
.line-rm { width: 28px; height: 28px; padding: 0; border-radius: 8px; background: transparent; border-color: transparent; box-shadow: none; color: var(--text3); }
.line-rm:hover { background: var(--red-soft); color: var(--red); }
.line-rm svg { width: 13px; height: 13px; }
.line-add { margin-top: 10px; color: var(--accent-text); height: 32px; }
.line-add:hover { background: var(--accent-soft); color: var(--accent-text); }

/* Cupping modal */
.cup-layout { display: grid; grid-template-columns: 230px 1fr; gap: 26px; }
.cup-side { display: flex; flex-direction: column; gap: 14px; }
.score-ring { position: relative; width: 190px; height: 190px; margin: 4px auto 0; }
.score-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.score-ring .track { stroke: var(--surface-3); }
.score-ring .arc { stroke: var(--text); transition: stroke-dashoffset .5s var(--ease); }
.score-ring .center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.score-ring #cup_score { font-family: var(--font-display); font-size: 44px; font-weight: 600; letter-spacing: -0.03em; line-height: 1; font-variant-numeric: tabular-nums; }
.score-ring .of { font-size: 12px; color: var(--text3); margin-top: 6px; }
.cup-tier { text-align: center; }
.cup-tier .chip { height: 24px; }
.cup-attrs { display: flex; flex-direction: column; gap: 4px; }
.cup-attr { display: grid; grid-template-columns: 120px 1fr 46px; align-items: center; gap: 14px; padding: 5px 0; }
.cup-attr label { font-size: 13px; font-weight: 500; color: var(--text2); }
.cup-attr output { font-family: var(--font-ui); font-variant-numeric: tabular-nums; font-size: 13px; text-align: right; font-weight: 500; }
.cup-attr.fixed input[type=range] { --pct: 100%; }
.cup-meta { display: grid; grid-template-columns: 1fr 100px; gap: 12px; margin-bottom: 8px; }

/* ---------- Dialog ---------- */
.dialog { position: fixed; inset: 0; z-index: 700; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(20, 16, 14, 0.42); backdrop-filter: blur(8px); opacity: 0; pointer-events: none; transition: opacity .18s; }
.dialog.open { opacity: 1; pointer-events: auto; }
.dialog-card { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; width: min(440px, 100%); padding: 24px 24px 18px; box-shadow: var(--shadow-lg); display: grid; grid-template-columns: 44px 1fr; grid-template-areas: "icon body" "actions actions"; gap: 14px 16px; transform: translateY(8px) scale(.98); transition: transform .26s var(--ease-spring); }
.dialog.open .dialog-card { transform: none; }
.dialog-icon { grid-area: icon; width: 44px; height: 44px; border-radius: 12px; background: var(--amber-soft); color: var(--amber); display: flex; align-items: center; justify-content: center; }
.dialog-icon svg { width: 21px; height: 21px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.dialog.variant-danger .dialog-icon { background: var(--red-soft); color: var(--red); }
.dialog.variant-success .dialog-icon { background: var(--green-soft); color: var(--green); }
.dialog.variant-info .dialog-icon { background: var(--accent-soft); color: var(--accent-text); }
.dialog-body { grid-area: body; min-width: 0; }
.dialog-body h3 { margin: 2px 0 0; font-size: 16.5px; font-weight: 600; letter-spacing: -0.015em; }
.dialog-body p { margin: 6px 0 0; color: var(--text2); font-size: 13.5px; line-height: 1.55; }
.dialog-body p:empty { display: none; }
.dialog-input-wrap { margin-top: 14px; }
.dialog-input-hint { margin-top: 6px; font-size: 12px; color: var(--text3); }
.dialog-actions { grid-area: actions; display: flex; justify-content: flex-end; gap: 8px; padding-top: 14px; margin-top: 4px; border-top: 1px solid var(--border); }
.dialog.variant-danger #dialog_confirm { background: linear-gradient(180deg, #c22f26, #a3221b); border-color: #8f1e18; box-shadow: 0 1px 2px rgba(150,30,20,.3); }

/* ---------- Toasts ---------- */
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 900; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast-item {
  pointer-events: auto; display: flex; align-items: flex-start; gap: 11px;
  min-width: 280px; max-width: 400px; padding: 12px 14px 12px 12px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 13px;
  box-shadow: var(--shadow-lg); font-size: 13.5px; line-height: 1.45;
  position: relative; overflow: hidden;
  animation: toastIn .32s var(--ease-spring);
}
.toast-item.out { animation: toastOut .22s var(--ease) forwards; }
.toast-item .t-ico { width: 22px; height: 22px; border-radius: 7px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; background: var(--accent-soft); color: var(--accent-text); }
.toast-item .t-ico svg { width: 13px; height: 13px; stroke: currentColor; fill: none; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.toast-item.success .t-ico { background: var(--green-soft); color: var(--green); }
.toast-item.error .t-ico { background: var(--red-soft); color: var(--red); }
.toast-item .t-bar { position: absolute; left: 0; bottom: 0; height: 2px; background: currentColor; opacity: .25; animation: tbar linear forwards; }
.toast-item.success .t-bar { color: var(--green); }
.toast-item.error .t-bar { color: var(--red); }
.toast-item.info .t-bar, .toast-item .t-bar { color: var(--accent); }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateX(16px); } }
@keyframes tbar { from { width: 100%; } to { width: 0; } }

/* ---------- Command palette ---------- */
.palette { position: fixed; inset: 0; z-index: 800; display: flex; justify-content: center; align-items: flex-start; padding: 14vh 20px 20px; background: rgba(20, 16, 14, 0.38); backdrop-filter: blur(6px); opacity: 0; pointer-events: none; transition: opacity .16s; }
.palette.open { opacity: 1; pointer-events: auto; }
.palette-card { width: min(600px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-lg); overflow: hidden; transform: translateY(-6px) scale(.98); transition: transform .22s var(--ease-spring); }
.palette.open .palette-card { transform: none; }
.palette-input { display: flex; align-items: center; gap: 10px; padding: 0 18px; border-bottom: 1px solid var(--border); }
.palette-input svg { width: 18px; height: 18px; color: var(--text3); }
.palette-input input { height: 54px; border: 0; box-shadow: none !important; padding: 0; font-size: 15.5px; background: transparent; }
.palette-list { max-height: 380px; overflow-y: auto; padding: 6px; }
.palette-group { font-size: 11.5px; font-weight: 500; color: var(--text3); padding: 10px 12px 6px; }
.palette-item { display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 9px; cursor: pointer; font-size: 13.5px; }
.palette-item .pi-icon { width: 28px; height: 28px; border-radius: 8px; background: var(--surface-3); color: var(--text2); display: flex; align-items: center; justify-content: center; }
.palette-item .pi-icon svg { width: 15px; height: 15px; }
.palette-item .pi-hint { margin-left: auto; font-size: 12px; color: var(--text3); }
.palette-item.active { background: var(--accent-soft); }
.palette-item.active .pi-icon { background: var(--accent); color: var(--on-accent); }
.palette-empty { padding: 28px; text-align: center; color: var(--text3); font-size: 13.5px; }
.palette-foot { display: flex; gap: 16px; padding: 10px 16px; border-top: 1px solid var(--border); background: var(--surface-2); font-size: 12px; color: var(--text3); }
.palette-foot span { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- Dropzone & bulk import ---------- */
.dropzone { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 30px 20px; border: 1.5px dashed var(--border-strong); border-radius: 14px; background: var(--surface-2); color: var(--text3); cursor: pointer; text-align: center; transition: all .15s; }
.dropzone:hover, .dropzone.drag { border-color: var(--accent); color: var(--accent-text); background: var(--accent-soft); }
.dropzone.has-file { border-color: var(--green); color: var(--green); background: var(--green-soft); }
.dropzone .dz-icon { width: 44px; height: 44px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); display: flex; align-items: center; justify-content: center; margin-bottom: 4px; box-shadow: var(--shadow-sm); }
.dropzone .dz-icon svg { width: 20px; height: 20px; }
.dropzone-title { font-size: 13.5px; font-weight: 550; color: var(--text); }
.dropzone-sub { font-size: 12.5px; color: var(--text3); }
.bulk-list { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; max-height: 210px; overflow-y: auto; }
.bulk-list:empty { display: none; }
.bulk-item { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 10px; padding: 8px 8px 8px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); font-size: 12.5px; }
.bulk-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--font-mono); font-size: 12px; }
.bulk-status { font-size: 11.5px; padding: 2px 8px; border-radius: 999px; font-weight: 500; }
.bulk-status.pending { background: var(--surface-3); color: var(--text3); }
.bulk-status.loading { background: var(--accent-soft); color: var(--accent-text); }
.bulk-status.done { background: var(--green-soft); color: var(--green); }
.bulk-status.error { background: var(--red-soft); color: var(--red); }
.bulk-remove { width: 24px; height: 24px; padding: 0; background: transparent; border-color: transparent; box-shadow: none; color: var(--text3); font-size: 16px; }
.bulk-remove:hover { color: var(--red); background: var(--red-soft); }

/* ---------- Onboarding wizard ---------- */
.wizard { position: fixed; inset: 0; z-index: 500; display: flex; align-items: center; justify-content: center; padding: 24px; background: rgba(20, 16, 14, 0.5); backdrop-filter: blur(10px); opacity: 0; pointer-events: none; transition: opacity .25s; }
.wizard.open { opacity: 1; pointer-events: auto; }
.wizard-card { position: relative; width: min(640px, 100%); max-height: 92vh; overflow-y: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 22px; padding: 34px 38px 26px; box-shadow: var(--shadow-lg); }
.wiz-skip { position: absolute; top: 16px; right: 16px; height: 30px; font-size: 12.5px; }
.wiz-progress { display: flex; gap: 6px; margin-bottom: 26px; padding-right: 70px; }
.wiz-progress span { flex: 1; height: 4px; border-radius: 999px; background: var(--surface-3); transition: background .3s; }
.wiz-progress span.done { background: var(--accent); }
.wiz-progress span.active { background: linear-gradient(90deg, var(--accent), var(--accent-soft-2)); }
.wiz-step { display: none; }
.wiz-step.active { display: block; animation: viewIn .35s var(--ease); }
.wiz-hero { text-align: center; margin-bottom: 8px; }
.wiz-header { margin-bottom: 22px; }
.wiz-step-tag { display: inline-block; font-size: 12px; font-weight: 500; color: var(--accent-text); margin-bottom: 8px; }
.wiz-title { font-family: var(--font-display); font-weight: 600; font-size: 28px; letter-spacing: -0.022em; line-height: 1.1; margin: 0; }
.wiz-sub { font-size: 14px; color: var(--text2); margin: 10px 0 0; line-height: 1.55; }
.wiz-checklist { display: flex; flex-direction: column; gap: 8px; margin: 26px 0 6px; }
.wiz-check { display: flex; align-items: center; gap: 12px; padding: 13px 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); font-size: 13.5px; }
.wiz-check-num { width: 26px; height: 26px; border-radius: 8px; background: var(--accent-soft); color: var(--accent-text); display: inline-flex; align-items: center; justify-content: center; font-family: var(--font-mono); font-weight: 600; font-size: 12px; }
.wiz-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.wiz-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.wiz-divider { display: flex; align-items: center; gap: 12px; margin: 24px 0 14px; color: var(--text3); font-size: 12px; font-weight: 500; }
.wiz-divider::before, .wiz-divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.wiz-actions { display: flex; align-items: center; gap: 10px; margin-top: 28px; padding-top: 20px; border-top: 1px solid var(--border); }
.wiz-spacer { flex: 1; }
.wiz-actions button { height: 40px; }
.wiz-done-icon { width: 68px; height: 68px; border-radius: 50%; margin: 0 auto 18px; display: flex; align-items: center; justify-content: center; background: var(--accent); box-shadow: none; animation: popIn .5s var(--ease-spring); }
.wiz-done-icon svg { width: 30px; height: 30px; stroke: var(--on-accent); fill: none; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.wiz-next-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 24px 0 4px; }
.wiz-next-card { display: flex; flex-direction: column; gap: 4px; padding: 16px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface-2); cursor: pointer; transition: all .18s var(--ease); }
.wiz-next-card:hover { border-color: var(--accent); background: var(--accent-soft); transform: translateY(-2px); }
.wiz-next-card svg { width: 20px; height: 20px; color: var(--text2); margin-bottom: 6px; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.wiz-next-card strong { font-size: 13.5px; font-weight: 600; }
.wiz-next-card span { font-size: 12px; color: var(--text2); }

/* ---------- Login ---------- */
.login-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(420px, 1fr); background: var(--canvas); }
.login-art {
  position: relative; overflow: hidden; margin: 10px; border-radius: 22px; padding: 40px 44px;
  display: flex; flex-direction: column; justify-content: space-between;
  background: var(--signal); color: #0b0908;
}
.login-art > * { position: relative; }
.login-brand svg { display: block; height: 30px; width: auto; color: #0b0908; --signal: #0b0908; }
/* The giant symbol, cropped off the top-right edge; its halves open on load (the first crack). */
.login-mark { position: absolute !important; width: 112%; right: -40%; top: -16%; pointer-events: none; }
.login-mark path { fill: #0b0908; transition: transform 1.1s var(--ease); }
.login-mark .half-a { animation: crackA 1.1s var(--ease) .25s both; }
.login-mark .half-b { animation: crackB 1.1s var(--ease) .25s both; }
@keyframes crackA { from { transform: translate(5px, -14px); } to { transform: none; } }
@keyframes crackB { from { transform: translate(-5px, 14px); } to { transform: none; } }
.login-data { font-family: var(--font-mono); font-size: 12px; line-height: 1.7; letter-spacing: 0.04em; margin-bottom: 22px; opacity: .8; }
.login-quote h2 { font-family: var(--font-display); font-weight: 600; font-size: 46px; line-height: 1.04; letter-spacing: -0.02em; margin: 0; max-width: 520px; text-wrap: balance; }
.login-quote p { color: rgba(11, 9, 8, 0.74); font-size: 15px; max-width: 420px; margin: 14px 0 0; line-height: 1.55; }
.login-pane { display: flex; align-items: center; justify-content: center; padding: 40px 28px; }
.login-card { width: 100%; max-width: 380px; }
.login-card h1 { font-family: var(--font-display); font-weight: 600; font-size: 30px; letter-spacing: -0.025em; margin: 0; }
.login-card .lede { color: var(--text2); margin: 8px 0 26px; font-size: 14px; }
.auth-tabs { margin-bottom: 22px; width: 100%; }
.auth-tabs button { flex: 1; }
.login-fields { display: flex; flex-direction: column; gap: 14px; }
.login-fields input { height: 42px; font-size: 14px; }
#loginBtn { height: 44px; font-size: 14.5px; margin-top: 4px; }
#loginMsg { color: var(--red); font-size: 12.5px; min-height: 18px; }
#loginHint { color: var(--text3); font-size: 12px; text-align: center; }

/* ---------- uPlot ---------- */
.uplot { font-family: var(--font-ui); }
.uplot, .uplot * { box-sizing: border-box; }

/* ---------- Mobile chrome ---------- */
.menu-toggle { display: none; width: 36px; height: 36px; padding: 0; border-radius: 9px; background: transparent; border-color: var(--border); box-shadow: none; }
.menu-toggle svg { width: 18px; height: 18px; }
.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(20,16,14,.4); backdrop-filter: blur(3px); z-index: 90; }
.sidebar-backdrop.open { display: block; }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
  .roast-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .roast-strip .roast-mini:nth-child(n+4) { display: none; }
  .live-form { grid-template-columns: 1fr 1fr 1fr; }
  .live-form-actions { grid-column: 1 / -1; justify-content: flex-end; }
}
@media (max-width: 1024px) {
  .app { grid-template-columns: 220px minmax(0, 1fr); }
  .main { padding: 26px 26px 56px; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .live-stats { grid-template-columns: 1fr 1fr; }
  .live-stat:nth-child(2) { border-right: 0; }
  .events-row { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .login-shell { grid-template-columns: 1fr; }
  .login-art { display: none; }
}
@media (max-width: 768px) {
  .app { grid-template-columns: 1fr; padding: 0; }
  .canvas { border-radius: 0; border: 0; }
  .menu-toggle { display: inline-flex; }
  .sidebar { position: fixed; top: 0; left: 0; bottom: 0; width: 272px; z-index: 100; background: var(--bg); transform: translateX(-100%); transition: transform .28s var(--ease); box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: none; }
  .topbar { padding: 0 12px; gap: 10px; }
  .topbar-crumb .crumb-root, .topbar-crumb .crumb-sep { display: none; }
  .topbar-cta span, .topbar-divider, #helpBtn, #liveStatusText { display: none; }
  .topbar-status { padding: 0; width: 28px; justify-content: center; }
  .main { padding: 20px 16px 64px; }
  .page-header, .hero { flex-direction: column; align-items: stretch; gap: 14px; }
  .page-header .title { font-size: 28px; }
  .hero h1 { font-size: 32px; }
  .grid-2, .grid-3, .form-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-value { font-size: 24px; }
  .roast-strip { grid-template-columns: 1fr 1fr; }
  .roast-strip .roast-mini:nth-child(n+3) { display: none; }
  .live-form { grid-template-columns: 1fr; }
  .live-stat .v { font-size: 32px; }
  .events-row { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; padding: 10px; }
  .evt-btn { padding: 8px 8px 7px; font-size: 12px; }
  .evt-btn kbd { display: none; }
  table { min-width: 620px; }
  .card.flush { overflow-x: auto; }
  .cup-layout { grid-template-columns: 1fr; }
  .cup-attr { grid-template-columns: 100px 1fr 40px; }
  .modal-card { padding: 22px 18px 18px; }
  .wizard-card { padding: 28px 22px 22px; }
  .wiz-grid-2, .wiz-grid-3, .wiz-next-grid { grid-template-columns: 1fr; }
  .drawer-stats { grid-template-columns: 1fr 1fr 1fr; }
  .toast { left: 12px; right: 12px; bottom: 12px; }
  .toast-item { max-width: none; min-width: 0; }
}
@media (max-width: 420px) {
  .stats-grid { grid-template-columns: 1fr; }
}

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

/* ---------- Plans (modules/plan.js) ---------- */
.plan-badge { display: inline-block; margin-top: 3px; font-size: 11px; font-weight: 600; color: var(--accent-text); cursor: pointer; }
.plan-badge:empty { display: none; }
.plan-badge:hover { text-decoration: underline; }
.navitem.locked { color: var(--text3); }
.navitem .nav-plan { margin-left: auto; display: inline-flex; align-items: center; gap: 4px; height: 18px; padding: 0 6px; border-radius: 999px;
  font-size: 10.5px; font-weight: 500; letter-spacing: 0; color: var(--text3); border: 1px solid var(--border); white-space: nowrap; }
.navitem .nav-plan svg { width: 10px; height: 10px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.navitem.locked .icon { opacity: .55; }
.navitem .nav-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.navitem .nav-plan { flex-shrink: 0; }
.navitem.locked:hover .nav-plan { color: var(--text2); border-color: var(--text3); }
.app.rail .navitem .nav-plan { display: none; }
.side-plan-hint { flex-shrink: 0; height: auto; min-height: 0; display: flex; align-items: flex-start; gap: 9px; margin: 8px 4px 6px; padding: 9px 10px; border: 1px dashed var(--border); border-radius: 8px;
  background: transparent; color: var(--text2); font: inherit; font-size: 12.5px; line-height: 1.35; text-align: left; cursor: pointer; }
.side-plan-hint[hidden] { display: none; }
.side-plan-hint:hover { border-style: solid; color: var(--text); background: var(--surface); }
.side-plan-hint svg { width: 14px; height: 14px; margin-top: 1px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.side-plan-hint strong { font-weight: 600; color: var(--text); }
.side-plan-hint small { display: block; font-size: 11.5px; color: var(--text3); margin-top: 1px; }
.app.rail .side-plan-hint { display: none; }
.plan-paid[hidden] { display: none; }
.plan-included { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 22px 28px; padding: 22px 24px; }
.plan-included-name { font-size: 12px; font-weight: 600; color: var(--text3); margin-bottom: 8px; }
.plan-included .plan-card-list { margin: 0; }
.upgrade-panel { max-width: 520px; margin: 72px auto; text-align: center; }
.upgrade-icon { width: 56px; height: 56px; margin: 0 auto 18px; border-radius: 16px; background: var(--accent); color: var(--on-accent); display: flex; align-items: center; justify-content: center; }
.upgrade-icon svg { width: 26px; height: 26px; }
.upgrade-panel h2 { font-family: var(--font-display); font-size: 26px; font-weight: 600; letter-spacing: -0.02em; margin: 0 0 10px; text-wrap: balance; }
.upgrade-panel p { color: var(--text2); margin: 0 auto; max-width: 420px; line-height: 1.55; }
.upgrade-actions { margin-top: 22px; display: flex; justify-content: center; gap: 8px; }

.plan-current-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 20px; }
.plan-current-name { font-family: var(--font-display); font-size: 26px; font-weight: 600; letter-spacing: -0.02em; }
.plan-current-price { color: var(--text2); margin-top: 2px; }
.plan-usage { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px; }
.plan-usage-row .plan-usage-top { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--text2); margin-bottom: 8px; }
.plan-usage-row .meter-track { width: 100%; height: 6px; }
.plan-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.plan-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 22px; display: flex; flex-direction: column; box-shadow: var(--shadow-sm); }
.plan-card.current { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), var(--shadow-md); }
.plan-card-name { font-weight: 600; font-size: 15px; }
.plan-card-price { margin-top: 10px; color: var(--text2); }
.plan-card-price span { font-family: var(--font-display); font-size: 34px; font-weight: 600; color: var(--text); letter-spacing: -0.02em; }
.plan-card-annual { font-size: 12.5px; color: var(--text3); margin-top: 2px; }
.plan-card-list { list-style: none; padding: 0; margin: 18px 0 20px; display: flex; flex-direction: column; gap: 8px; flex: 1; font-size: 13.5px; }
.plan-card-list li { padding-left: 22px; position: relative; }
.plan-card-list li.plan-card-inherit { padding-left: 0; font-weight: 600; color: var(--text2); }
.plan-card-list li.plan-card-inherit::before { display: none; }
.plan-usage-row.over .plan-usage-top { color: var(--red); }
.plan-usage-row.over .meter-fill { background: var(--red); }
.plan-card-list li::before { content: ''; position: absolute; left: 2px; top: 6px; width: 10px; height: 6px; border-left: 2px solid var(--accent); border-bottom: 2px solid var(--accent); transform: rotate(-45deg); }
@media (max-width: 1024px) { .plan-grid { grid-template-columns: 1fr; } .plan-usage { grid-template-columns: 1fr 1fr; } }

/* ---------- EUDR (modules/eudr.js) ---------- */
.eudr-summary { display: grid; grid-template-columns: minmax(220px, 1fr) minmax(0, 2.2fr); gap: 16px; }
.eudr-countdown { display: flex; flex-direction: column; justify-content: center; }
.eudr-days { font-family: var(--font-display); font-size: 40px; font-weight: 600; letter-spacing: -0.02em; line-height: 1; }
.eudr-days .mono { font-family: var(--font-display); }
.eudr-days-sub { color: var(--text2); margin-top: 8px; font-size: 13px; }
.eudr-progress-top { display: flex; justify-content: space-between; font-size: 13px; color: var(--text2); margin-bottom: 12px; }
.eudr-bar { height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.eudr-bar > div { height: 100%; background: var(--green); border-radius: inherit; transition: width .6s var(--ease); }
.eudr-progress-foot { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.eudr-table td { vertical-align: middle; }
.eudr-input { height: 32px; font-size: 13px; min-width: 150px; box-shadow: none; }
.eudr-input.mono { font-family: var(--font-mono); font-size: 12.5px; }
.eudr-hint { background: var(--accent-soft); color: var(--text2); font-size: 13px; }
.eudr-export, .eudr-operator { margin-top: 16px; }
.eudr-export-row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.eudr-export-row .field { width: 180px; }
.eudr-note { color: var(--text2); margin: 0; max-width: 70ch; }
.eudr-operator:empty { display: none; }
.eudr-upsell { display: flex; align-items: center; gap: 14px; }
.eudr-upsell > svg { width: 22px; height: 22px; color: var(--accent-text); flex-shrink: 0; }
.eudr-upsell div { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.eudr-upsell span { color: var(--text2); font-size: 13px; }
@media (max-width: 1024px) { .eudr-summary { grid-template-columns: 1fr; } }
.origin-card { margin-top: 16px; }
.origin-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.origin-actions { display: flex; justify-content: flex-end; margin-top: 14px; }
a.lot-eudr-link { text-decoration: none; }
#lotsTable td.nowrap, #lotsTable td:last-child { white-space: nowrap; }
@media (max-width: 560px) { .origin-grid { grid-template-columns: 1fr; } }

/* ---------- Resumen (dashboard) ---------- */
.btn-signal { width: 7px; height: 7px; border-radius: 50%; background: var(--signal); flex-shrink: 0; }
.period-pill { height: 36px; display: inline-flex; align-items: center; padding: 0 12px; border-radius: 9px; background: var(--surface); border: 1px solid var(--border); color: var(--text2); font-size: 13px; }
.dash-main { overflow: hidden; }
.kpi-strip { display: grid; grid-template-columns: repeat(var(--n, 5), minmax(0, 1fr)); }
.kpi-tile { padding: 18px 20px 16px; border-right: 1px solid var(--border); min-width: 0; }
.kpi-tile:last-child { border-right: 0; }
.kpi-l { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; color: var(--text2); font-size: 13px; }
.kpi-v { font-size: 28px; font-weight: 600; letter-spacing: -0.035em; margin-top: 8px; line-height: 1.1; font-variant-numeric: tabular-nums; white-space: nowrap; }
.kpi-v small { font-size: 14px; font-weight: 500; color: var(--text3); letter-spacing: 0; margin-left: 3px; }
.kpi-s { color: var(--text3); font-size: 12.5px; margin-top: 5px; text-wrap: pretty; }
.kpi-s.warn { color: var(--red); }
.kpi-delta { font-size: 12px; font-weight: 500; color: var(--text3); font-variant-numeric: tabular-nums; white-space: nowrap; }
.kpi-delta.up { color: var(--green); }
.kpi-delta.down { color: var(--red); }

.dash-chart { border-top: 1px solid var(--border); padding: 14px 20px 10px; }
.dash-legend { display: flex; gap: 18px; font-size: 12px; color: var(--text3); margin-bottom: 4px; }
.dash-legend b { font-weight: 400; }
.dash-legend i { display: inline-block; width: 14px; height: 0; border-top: 2px solid var(--text); vertical-align: middle; margin-right: 6px; }
.dash-legend i.prev { border-top: 2px dashed var(--border-strong); }
.dash-plot { position: relative; }
.dash-plot svg { display: block; width: 100%; }
.dash-plot .grid { stroke: var(--border); stroke-width: 1; }
.dash-plot .axis { fill: var(--text3); font-family: var(--font-mono); font-size: 11px; }
.dash-plot .prev { fill: none; stroke: var(--border-strong); stroke-width: 1.5; stroke-dasharray: 4 4; }
.dash-plot .now { fill: none; stroke: var(--text); stroke-width: 2; stroke-linejoin: round; }
.dash-plot .area { fill: var(--text); opacity: .05; }
.dash-plot .today { fill: var(--signal); stroke: var(--surface); stroke-width: 2; }
.dash-plot .hover-line { stroke: var(--border-strong); }
.dash-tip { position: absolute; top: 6px; min-width: 150px; padding: 8px 10px; border-radius: 9px; background: var(--surface); box-shadow: var(--shadow-lg); border: 1px solid var(--border); font-size: 12.5px; pointer-events: none; font-variant-numeric: tabular-nums; }
.dash-tip b { display: block; font-weight: 600; margin-bottom: 4px; }
.dash-tip div { display: flex; align-items: center; gap: 7px; color: var(--text2); }
.dash-tip i { width: 10px; height: 0; border-top: 2px solid var(--text); }
.dash-tip i.prev { border-top: 2px dashed var(--border-strong); }
.dash-empty { padding: 28px 20px; color: var(--text3); font-size: 13px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.dash-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-top: 16px; align-items: start; }
.dash-panel { overflow: hidden; }
.dash-ph { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 16px 20px 12px; }
.dash-ph h3 { font-size: 15px; font-weight: 600; letter-spacing: -0.015em; margin: 0; }
.dash-ph span, .dash-ph a { font-size: 12.5px; color: var(--text3); }
.dash-ph a:hover { color: var(--text); }

.dash-batch, .dash-roast { display: grid; align-items: center; gap: 12px; padding: 10px 20px; border-top: 1px solid var(--border); cursor: pointer; transition: background .12s; }
.dash-batch:hover, .dash-roast:hover { background: var(--hover); }
.dash-batch { grid-template-columns: 18px minmax(0, 1fr) auto 76px; }
.dash-batch .n { font-family: var(--font-mono); font-size: 11.5px; color: var(--text3); }
.dash-batch b, .dash-roast b { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dash-batch div span, .dash-roast div span { display: block; color: var(--text3); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dash-batch .kg, .dash-roast .kg { font-variant-numeric: tabular-nums; font-size: 13px; color: var(--text2); text-align: right; }
.dash-batch .st { font-size: 12px; color: var(--text3); text-align: right; }
.dash-batch.is-done b { color: var(--text2); font-weight: 400; }
.dash-batch.is-in_progress .st { color: var(--text); font-weight: 500; }
.dash-batch.is-next { background: var(--signal-soft); }
.dash-batch.is-next .n, .dash-batch.is-next .st { color: var(--signal-text); font-weight: 500; }
.dash-more { display: block; padding: 10px 20px; border-top: 1px solid var(--border); font-size: 12.5px; color: var(--text3); }
.dash-roast { grid-template-columns: 72px minmax(0, 1fr) auto; }
.dash-roast-curve svg { display: block; width: 72px; height: 28px; }

.dash-rank { position: relative; display: grid; grid-template-columns: minmax(0, 1fr) auto 44px; gap: 12px; align-items: center; padding: 10px 20px 14px; border-top: 1px solid var(--border); }
.dash-rank-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dash-rank-v { font-variant-numeric: tabular-nums; font-weight: 500; }
.dash-rank-sh { color: var(--text3); font-size: 12px; text-align: right; font-variant-numeric: tabular-nums; }
.dash-rank-bar { position: absolute; left: 20px; right: 20px; bottom: 5px; height: 3px; border-radius: 3px; background: var(--hover-strong); }
.dash-rank-bar i { display: block; height: 100%; border-radius: 3px; background: var(--green); opacity: .6; }
.dash-rank:hover .dash-rank-bar i { opacity: .85; }

@media (max-width: 1180px) {
  .kpi-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .kpi-tile { border-bottom: 1px solid var(--border); }
  .kpi-tile:nth-child(3n) { border-right: 0; }
}
@media (max-width: 860px) {
  .dash-grid { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .kpi-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi-tile:nth-child(3n) { border-right: 1px solid var(--border); }
  .kpi-tile:nth-child(2n) { border-right: 0; }
  .kpi-tile:last-child:nth-child(odd) { grid-column: 1 / -1; border-right: 0; }
  .kpi-v { font-size: 24px; }
  .page-header .actions .period-pill { display: none; }
}


/* ---------- Accessibility and states (audit R4) ---------- */
.field-error { color: var(--red); font-size: 12px; font-weight: 500; }
input[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--red); box-shadow: 0 0 0 3px var(--red-soft); }
select:not(.cs-native)[data-no-enhance] {
  appearance: none; -webkit-appearance: none; padding-right: 30px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236e6862' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
}
.skeleton-row td { padding-top: 14px; padding-bottom: 14px; }
.skel { display: block; height: 12px; border-radius: 6px; background: var(--hover-strong); width: 70%; animation: skel 1.2s ease-in-out infinite; }
.skeleton-row td:first-child .skel { width: 30%; }
@keyframes skel { 0%, 100% { opacity: .55; } 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .skel { animation: none; } }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.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; }

/* Touch screens (tablet at the roaster, phones): 44 px targets. */
@media (pointer: coarse) {
  button, .cs-button, .cdp-button { min-height: 44px; }
  button.sm, button.icon-btn { min-height: 40px; min-width: 40px; }
  .navitem { height: 40px; }
  .segmented button { height: 38px; }
  input[type=text], input[type=password], input[type=email], input.num-input, input[type=date], input[type=search], select { height: 44px; font-size: 16px; }
  input[type=checkbox], input[type=radio] { width: 22px; height: 22px; }
  .topbar-status { min-height: 40px; }
}

/* Sidebar and menu entries are real buttons (keyboard reachable); undo button chrome. */
button.navitem, button.topbar-menu-item {
  width: 100%; justify-content: flex-start; background: transparent; box-shadow: none; text-align: left;
  border: 1px solid transparent; line-height: 1.2; white-space: normal; transform: none;
}
button.navitem:hover, button.topbar-menu-item:hover { background: var(--hover); border-color: transparent; }
button.navitem.active, button.navitem.active:hover { background: var(--surface); }
button.topbar-menu-item { height: auto; min-height: 36px; font-weight: 500; color: var(--text); }
button.topbar-menu-item.danger { color: var(--red); }
button.topbar-menu-item.danger:hover { background: var(--red-soft); }
button.navitem:active, button.topbar-menu-item:active { transform: none; }

.eudr-size-label { font-size: 12.5px; color: var(--text3); margin-right: 8px; }
.page-header .actions:has(#eudrSize) { align-items: center; }

.dash-empty.dash-warn { color: var(--text2); }
.dash-empty.dash-warn::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--amber); flex-shrink: 0; }

/* ---------- Live roast at the roaster (tablet) ---------- */
.live-running-line { display: none; align-items: center; gap: 10px; min-width: 0; }
.live-running-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--signal); box-shadow: 0 0 0 4px var(--signal-soft); flex-shrink: 0; animation: pulse 1.4s infinite; }
#liveRunName { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#liveRunMeta { color: var(--text3); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#view-live.is-running .page-header .subtitle { display: none; }
#view-live.is-running .page-header { margin-bottom: 12px; }
#view-live.is-running .live-setup { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 14px 10px 18px; }
#view-live.is-running .live-running-line { display: flex; flex: 1; }
#view-live.is-running .live-form { display: flex; }
#view-live.is-running .live-form > .field { display: none; }
.chart-wrap { position: relative; }
.chart-empty { display: none; position: absolute; inset: 40px 60px 40px 60px; place-items: center; text-align: center; color: var(--ink-text2); font-size: 14px; line-height: 1.5; pointer-events: none; }
.chart-empty.show { display: grid; }
.evt-btn { min-height: 56px; }
.topbar-icon-dot.roasting { background: var(--signal); box-shadow: 0 0 0 3px var(--signal-soft); }
/* Tablet (landscape or portrait): everything on one screen — readings in one
   row, the curve takes what is left, the eight events in one row. */
@media (max-width: 1180px) and (min-width: 761px) {
  #view-live .live-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); padding: 10px 6px 2px; }
  #view-live .live-stat { padding: 6px 12px 8px; }
  #view-live .live-stat .v { font-size: 32px; margin-top: 6px; }
  #view-live .events-row { grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 6px; padding: 10px 12px 12px; }
  #view-live .evt-btn { min-height: 52px; padding: 8px 8px 7px; font-size: 12px; gap: 4px; }
  #chart { min-height: 0; }
}
/* Phone: the event buttons stay pinned at the bottom while the curve scrolls. */
@media (max-width: 760px) {
  .events-row { position: sticky; bottom: 0; z-index: 5; background: var(--ink); }
  #chart { min-height: 0; }
}
@media (max-width: 1180px) and (max-height: 820px) {
  #view-live .page-header { margin-bottom: 10px; }
  #view-live .page-header .subtitle { display: none; }
}
/* The roaster widget at the foot of the sidebar is always visible. */
.side-live { position: sticky; bottom: 0; z-index: 2; }
.sidebar-spacer { min-height: 8px; }
#view-live.is-running #startBtn { display: none; }
.inst-head { flex-wrap: wrap; row-gap: 8px; }
@media (max-width: 760px) { .inst-title { white-space: nowrap; } .chart-empty { inset: 20px 16px; font-size: 13px; } }

/* ---------- Phones: tables become stacked lists ---------- */
@media (max-width: 768px) {
  table.stack { min-width: 0 !important; display: block; }
  table.stack thead { display: none; }
  table.stack tbody { display: block; }
  table.stack tr { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
  table.stack tr:last-child { border-bottom: 0; }
  table.stack td { display: flex; align-items: baseline; gap: 6px; padding: 0 !important; border: 0 !important; text-align: left !important; width: auto; min-width: 0; background: none !important; }
  table.stack td::before { content: attr(data-label); color: var(--text3); font-size: 12px; font-weight: 400; }
  table.stack td[data-label=""]::before, table.stack td.id::before { content: none; }
  table.stack td.id { order: -1; color: var(--text3); font-size: 12px; }
  table.stack td:nth-child(2) { flex: 1 1 100%; order: -1; }           /* the name leads the card */
  table.stack td:nth-child(2)::before { content: none; }
  table.stack td:last-child { margin-left: auto; }
  table.stack.lead-first td:nth-child(2) { flex: 0 1 auto; order: 0; }   /* tables whose first column is the name */
  table.stack.lead-first td:nth-child(2)::before { content: attr(data-label); }
  table.stack.lead-first td:first-child { flex: 1 1 100%; order: -1; }
  table.stack.lead-first td:first-child::before { content: none; }
  table.stack td.empty-cell { flex: 1 1 100%; display: block; }
  table.stack td.empty-cell::before { content: none; }
  table.stack .row-actions { opacity: 1; }
  /* New order and subscription lines: one stacked block per line. */
  table.stack-lines { min-width: 0 !important; }
  table.stack-lines thead { display: none; }
  table.stack-lines tr { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; padding: 12px; border-bottom: 1px solid var(--border); }
  table.stack-lines td { display: block; padding: 0 !important; border: 0 !important; text-align: left !important; }
  table.stack-lines td:last-child { justify-self: end; align-self: end; width: auto !important; }
  table.stack-lines td input { width: 100% !important; }
  table.stack-lines td:first-child { grid-column: 1 / -1; }
  table.stack-lines td::before { content: attr(data-label); display: block; font-size: 12px; color: var(--text3); margin-bottom: 4px; }
  table.stack-lines td:first-child::before, table.stack-lines td[data-label=""]::before { content: none; }
  .segmented { max-width: 100%; overflow-x: auto; scrollbar-width: none; flex-wrap: nowrap; }
  .segmented::-webkit-scrollbar { display: none; }
  .segmented button { flex-shrink: 0; }
}

.btn-link { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--border-strong); color: var(--text); font-size: 13px; font-weight: 500; background: var(--surface); text-decoration: none; }
.btn-link:hover { background: var(--hover); color: var(--text); }
.btn-link svg { width: 14px; height: 14px; }

.login-mobile-brand { display: none; align-items: center; gap: 10px; margin-bottom: 28px; font-weight: 600; letter-spacing: -0.01em; }
.login-mobile-brand svg { width: 32px; height: 32px; border-radius: 8px; }
@media (max-width: 1024px) { .login-mobile-brand { display: flex; } }
