/* CUATICO Visión — dashboard extension of the CUATICO Design System.
 *
 * The DS (static/cuatico/tokens.css) is imported unchanged into the `tokens` layer.
 * Everything here lives in later layers, so it can fix DS tokens without editing them:
 *   tokens      DS tokens, untouched
 *   tokens-app  token fixes and dashboard tokens (AA colors, chart palette, heat ramp, layout sizes)
 *   base        element defaults
 *   layout      app shell: sidebar / rail / bottom tabs, topbar, page grid
 *   components  ui/*.html partials
 *   charts      chart cards, sparklines, gauges, heat legend
 *   utilities   single-purpose helpers (last, so they win)
 *
 * Light theme only. Dark mode would redefine the tokens-app block under [data-theme="dark"].
 */
@layer tokens, tokens-app, base, layout, components, charts, utilities;
@import url("../cuatico/tokens.css") layer(tokens);

/* ======================================================================== tokens-app */
@layer tokens-app {
  :root,
  [data-theme="default"],
  [data-theme="light"] {
    color-scheme: light;

    /* AA fixes. #009c5c stays for marks, icons, charts and KPI numbers >= 24px. */
    --c-green-700: #00804b;      /* buttons, links, green text: 5.0:1 on white */
    --c-green-800: #006b3f;      /* hover; text on green-050: 5.8:1 */
    --c-blue-700: #04679a;       /* DS gap: blue text on blue-050 (blue-600 is 4.2:1 there) */
    --c-red-600: #c2372f;        /* critical: 5.4:1 on white, 4.7:1 on red-050 */
    --c-red-050: #fbeceb;
    --c-orange-700: #a4511c;     /* warning text */
    --c-orange-100: #fbe9dd;     /* warning surface (from the DS Badge). orange-200 fails AA under orange-700 (3.3:1) */
    --text-muted-aa: #6b6b6b;    /* 5.3:1 on white, 4.85:1 on gray-100 */

    --text-link: var(--c-green-700);
    --text-link-hover: var(--c-green-800);
    --focus-ring: var(--c-blue-600); /* DS blue-400 is 2.9:1 on white; the ring needs 3:1 */

    /* Headings: Sora 700 (the DS type scale wrongly maps headings to Quicksand 400). */
    --fw-heading: var(--fw-bold);
    --app-fs-h1: 1.75rem;   /* 28px page title */
    --app-fs-h2: 1.125rem;  /* 18px card title */
    --app-fs-h3: 1rem;
    --app-fs-kpi: 1.75rem;  /* 28px KPI value */
    --app-fs-body: 0.9375rem; /* 15px: dense dashboard body */
    --app-fs-sm: 0.8125rem;   /* 13px */
    --app-fs-xs: 0.75rem;     /* 12px */

    /* Status */
    --status-ok: var(--c-green-800);
    --status-ok-bg: var(--c-green-050);
    --status-ok-dot: var(--c-green-600);
    --status-warn: var(--c-orange-700);
    --status-warn-bg: var(--c-orange-100);
    --status-warn-dot: var(--c-orange-500);
    --status-crit: var(--c-red-600);
    --status-crit-bg: var(--c-red-050);
    --status-crit-dot: var(--c-red-600);
    --status-info: var(--c-blue-700);
    --status-info-bg: var(--c-blue-050);
    --status-info-dot: var(--c-blue-600);
    --status-off: var(--text-muted-aa);
    --status-off-bg: var(--c-gray-100);
    --status-off-dot: var(--c-gray-500);

    /* Chart palette, in series order */
    --chart-1: var(--c-green-600);
    --chart-2: var(--c-blue-600);
    --chart-3: var(--c-orange-500);
    --chart-4: var(--c-gray-700);
    --chart-5: var(--c-blue-400);
    --chart-6: var(--c-green-400);
    --chart-grid: #e7ece9;
    --chart-tick: var(--text-muted-aa);
    --chart-tooltip-bg: var(--c-black);
    --chart-band: rgba(70, 158, 215, 0.16); /* p25–p75 typical-day band */

    /* Heat ramp, low → high; alpha = 0.15 + 0.6 v */
    --heat-0: #eaf4fa;
    --heat-1: #aed4e7;
    --heat-2: #469ed7;
    --heat-3: #057ab4;
    --heat-4: #009c5c;
    --heat-5: #00663c;
    --heat-peak: var(--c-orange-500);
    --heat-ramp: linear-gradient(90deg, var(--heat-0), var(--heat-1), var(--heat-2), var(--heat-3), var(--heat-4), var(--heat-5));

    /* Zone kinds on the editor canvas (drawn over a dark, pixelated image). DS gap: no
       categorical set exists, so these are brand tints; kinds also differ by dash pattern and label. */
    --zone-line: var(--c-orange-500);
    --zone-queue: var(--c-blue-400);
    --zone-screen: var(--c-blue-200);
    --zone-area: var(--c-green-400);
    --zone-staff: #f2f5f3;
    --zone-storefront: var(--c-orange-200);
    --zone-queue-front: var(--c-blue-700); /* "Frente de la fila" sub-polygon inside a queue */

    /* Shell */
    --sidebar-w: 264px;
    --rail-w: 76px;
    --topbar-h: 64px;
    --tabbar-h: 64px;
    --tap: 44px;
    --page-max: 1440px;
    --page-pad: var(--sp-6);
    --card-pad: var(--sp-5);
    --gap: var(--sp-5);
    --surface-sidebar: var(--c-white);
    --surface-app: #f7f9f8;
    --border-card: #e3e9e5;
  }
}

/* ======================================================================== base */
@layer base {
  *, *::before, *::after { box-sizing: border-box; }
  [hidden] { display: none !important; }
  html { -webkit-text-size-adjust: 100%; }
  body {
    margin: 0;
    font-family: var(--font-body);
    font-size: var(--app-fs-body);
    font-weight: var(--fw-medium);
    line-height: 1.5;
    color: var(--text-body);
    background: var(--surface-app);
    font-variant-numeric: tabular-nums;
    -webkit-font-smoothing: antialiased;
  }
  h1, h2, h3, h4 {
    font-family: var(--font-display);
    font-weight: var(--fw-heading);
    color: var(--text-heading);
    line-height: var(--lh-heading);
    letter-spacing: var(--ls-tight);
    margin: 0;
  }
  h1 { font-size: var(--app-fs-h1); }
  h2 { font-size: var(--app-fs-h2); }
  h3 { font-size: var(--app-fs-h3); }
  p { margin: 0 0 var(--sp-3); }
  p:last-child { margin-bottom: 0; }
  strong, b { font-weight: var(--fw-bold); color: var(--text-heading); }
  a { color: var(--text-link); text-decoration-thickness: 1px; text-underline-offset: 2px; }
  a:hover { color: var(--text-link-hover); }
  img, svg, canvas { max-width: 100%; }
  button, input, select, textarea { font: inherit; color: inherit; }
  button { cursor: pointer; }
  :focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; border-radius: 4px; }
  ::selection { background: var(--c-green-200); color: var(--c-black); }
  code, kbd {
    font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
    font-size: 0.9em;
  }
  kbd {
    padding: 1px 6px; border: 1px solid var(--c-gray-300); border-bottom-width: 2px;
    border-radius: var(--radius-xs); background: var(--c-white); color: var(--text-heading);
  }
  table { border-collapse: collapse; }
  fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
  legend { padding: 0; }
  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; scroll-behavior: auto !important; }
  }
}

/* ======================================================================== layout */
@layer layout {
  .skip-link {
    position: absolute; left: var(--sp-3); top: -100px; z-index: 100;
    background: var(--c-green-700); color: var(--c-white); padding: var(--sp-3) var(--sp-4);
    border-radius: var(--radius-sm); font-family: var(--font-display); font-weight: 600;
  }
  .skip-link:focus { top: var(--sp-3); color: var(--c-white); }

  .shell { min-height: 100vh; min-height: 100dvh; }
  .shell-main { margin-left: var(--sidebar-w); min-width: 0; }

  /* ---- sidebar (expanded ≥1280) */
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 30;
    width: var(--sidebar-w);
    display: flex; flex-direction: column;
    background: var(--surface-sidebar);
    border-right: 1px solid var(--border-card);
  }
  .sidebar-brand {
    display: flex; align-items: center; gap: var(--sp-3);
    height: var(--topbar-h); padding: 0 var(--sp-5); flex: 0 0 auto;
    text-decoration: none; color: var(--text-heading);
  }
  .brand-link { display: flex; align-items: center; gap: var(--sp-3); min-height: var(--tap); text-decoration: none; color: var(--text-heading); border-radius: var(--radius-sm); }
  .brand-mark { width: 32px; height: 32px; flex: 0 0 auto; }
  .brand-word { display: flex; flex-direction: column; line-height: 1.05; }
  .brand-word b { font-family: var(--font-display); font-weight: 800; color: var(--c-green-700); letter-spacing: 0.02em; font-size: 1.05rem; }
  .brand-word span { font-family: var(--font-display); font-size: var(--app-fs-xs); font-weight: 600; color: var(--c-blue-700); letter-spacing: var(--ls-caps); text-transform: uppercase; }

  .sidebar-nav { flex: 1 1 auto; overflow-y: auto; padding: var(--sp-2) var(--sp-3) var(--sp-4); }
  .nav-section + .nav-section { margin-top: var(--sp-4); }
  .nav-heading {
    font-family: var(--font-display); font-size: 0.6875rem; font-weight: 700;
    letter-spacing: var(--ls-caps); text-transform: uppercase; color: var(--text-muted-aa);
    padding: 0 var(--sp-3); margin: 0 0 var(--sp-1);
  }
  .nav-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
  .nav-link {
    position: relative;
    display: flex; align-items: center; gap: var(--sp-3);
    min-height: var(--tap); padding: 0 var(--sp-3);
    border-radius: var(--radius-sm);
    color: var(--text-body); text-decoration: none; font-weight: 600;
    transition: background var(--dur-fast) var(--ease-standard), color var(--dur-fast) var(--ease-standard);
  }
  .nav-link .icon { width: 20px; height: 20px; flex: 0 0 auto; color: var(--text-muted-aa); }
  .nav-link:hover { background: var(--surface-muted); color: var(--text-heading); }
  .nav-link[aria-current="page"] { background: var(--c-green-050); color: var(--c-green-800); }
  .nav-link[aria-current="page"] .icon { color: var(--c-green-600); }
  .nav-link[aria-current="page"]::before {
    content: ""; position: absolute; left: -12px; top: 10px; bottom: 10px; width: 4px;
    border-radius: 0 4px 4px 0; background: var(--c-green-600);
  }
  .nav-label { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .nav-link .badge-staff { flex: 0 0 auto; padding: 2px 7px; font-size: 0.625rem; letter-spacing: 0.02em; }
  .nav-link { gap: 10px; }
  .nav-link .nav-count {
    min-width: 22px; height: 22px; padding: 0 6px; border-radius: var(--radius-pill);
    background: var(--c-red-600); color: var(--c-white); font-size: var(--app-fs-xs); font-weight: 700;
    display: inline-grid; place-items: center;
  }
  .sidebar-foot { flex: 0 0 auto; padding: var(--sp-3) var(--sp-4) var(--sp-4); border-top: 1px solid var(--border-card); }

  /* ---- topbar */
  .topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; gap: var(--sp-3);
    height: var(--topbar-h); padding: 0 var(--page-pad);
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: saturate(1.4) blur(8px);
    border-bottom: 1px solid var(--border-card);
  }
  .topbar-brand { display: none; }
  .topbar-crumbs { flex: 1 1 auto; min-width: 0; }
  .topbar-controls { display: flex; align-items: center; gap: var(--sp-2); flex: 0 0 auto; }
  .topbar-tools { display: flex; align-items: center; gap: var(--sp-1); flex: 0 0 auto; }

  /* ---- page */
  .page { max-width: var(--page-max); margin: 0 auto; padding: var(--sp-6) var(--page-pad) var(--sp-8); }
  .page:focus { outline: none; }
  .page-head {
    display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between;
    gap: var(--sp-4); margin-bottom: var(--sp-5);
  }
  .page-title { display: flex; flex-direction: column; gap: var(--sp-1); min-width: 0; }
  .page-title-row { display: flex; align-items: center; flex-wrap: wrap; gap: var(--sp-3); }
  .page-sub { color: var(--text-muted-aa); font-size: var(--app-fs-sm); margin: 0; }
  .page-actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
  .page-section { margin-top: var(--gap); }
  .page-section > h2 { margin-bottom: var(--sp-3); }

  .kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--gap); }
  .grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--gap); }
  .grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--gap); }
  .grid-main-side { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: var(--gap); align-items: start; }
  .stack { display: flex; flex-direction: column; gap: var(--gap); }
  .stack-sm { display: flex; flex-direction: column; gap: var(--sp-3); }
  .cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); }
  .span-2 { grid-column: span 2; }

  /* ---- bottom tab bar (< 768) */
  .tabbar { display: none; }

  /* ---- rail: 768–1279 */
  @media (max-width: 1279px) {
    .shell-main { margin-left: var(--rail-w); }
    .sidebar { width: var(--rail-w); }
    .sidebar-brand { padding: 0; justify-content: center; }
    .sidebar-brand .brand-word { display: none; }
    .sidebar-nav { padding: var(--sp-2) var(--sp-2) var(--sp-4); }
    .nav-heading { height: 1px; overflow: hidden; margin: var(--sp-3) var(--sp-3); background: var(--border-card); color: transparent; padding: 0; }
    .nav-section:first-child .nav-heading { display: none; }
    .nav-section + .nav-section { margin-top: 0; }
    .nav-link { justify-content: center; padding: 0; width: 100%; }
    .nav-link .nav-label, .nav-link .badge-staff { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
    .nav-link .nav-count { position: absolute; top: 2px; right: 6px; min-width: 18px; height: 18px; font-size: 0.6875rem; padding: 0 4px; }
    .nav-link[aria-current="page"]::before { left: -8px; }
    .nav-link[data-staff-only]::after {
      content: ""; position: absolute; top: 8px; left: 10px; width: 8px; height: 8px; border-radius: 50%;
      background: var(--c-orange-500); box-shadow: 0 0 0 2px var(--c-white);
    }
    /* tooltip from data-tip */
    .nav-link[data-tip]:hover::after, .nav-link[data-tip]:focus-visible::after {
      content: attr(data-tip); position: absolute; left: calc(100% + 10px); top: 50%; transform: translateY(-50%);
      width: max-content; max-width: 240px; padding: 6px 10px; border-radius: var(--radius-xs);
      background: var(--c-black); color: var(--c-white); font-size: var(--app-fs-sm); font-weight: 600;
      box-shadow: var(--shadow-md); pointer-events: none; z-index: 40;
    }
    .sidebar-foot { padding: var(--sp-3) var(--sp-2); display: flex; justify-content: center; }
    .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-main-side { grid-template-columns: minmax(0, 1fr); }
    .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  }

  @media (max-width: 1023px) {
    :root { --page-pad: var(--sp-5); --gap: var(--sp-4); }
    .grid-2 { grid-template-columns: minmax(0, 1fr); }
    .span-2 { grid-column: auto; }
  }

  /* ---- topbar on two rows below 1024: breadcrumbs + tools, then scope + period */
  @media (max-width: 1023px) {
    .topbar {
      height: auto; min-height: var(--topbar-h); flex-wrap: wrap; row-gap: var(--sp-2);
      padding: var(--sp-2) var(--page-pad);
    }
    .topbar-crumbs { order: 1; flex: 1 1 0; }
    .topbar-tools { order: 2; }
    .topbar-controls { order: 3; flex: 1 1 100%; }
    .topbar-controls > * { flex: 1 1 0; min-width: 0; }
    .topbar-controls .popover-wrap { min-width: 0; }
    .topbar-controls .control-btn { width: 100%; max-width: none; }
  }

  /* ---- phone: < 768 */
  @media (max-width: 767px) {
    :root { --page-pad: var(--sp-4); --card-pad: var(--sp-4); }
    .shell-main { margin-left: 0; padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
    .sidebar { display: none; }
    /* "Más" opens the full nav as a drawer */
    body[data-drawer-open] .sidebar {
      display: flex; width: min(320px, 88vw); z-index: 60; box-shadow: var(--shadow-lg);
    }
    body[data-drawer-open] .sidebar .sidebar-brand { justify-content: flex-start; padding: 0 var(--sp-5); }
    body[data-drawer-open] .sidebar .brand-word { display: flex; }
    body[data-drawer-open] .nav-heading { height: auto; overflow: visible; margin: 0 0 var(--sp-1); background: none; color: var(--text-muted-aa); padding: 0 var(--sp-3); }
    body[data-drawer-open] .nav-section:first-child .nav-heading { display: block; }
    body[data-drawer-open] .nav-section + .nav-section { margin-top: var(--sp-4); }
    body[data-drawer-open] .nav-link { justify-content: flex-start; padding: 0 var(--sp-3); }
    body[data-drawer-open] .nav-link .nav-label,
    body[data-drawer-open] .nav-link .badge-staff { position: static; width: auto; height: auto; overflow: hidden; clip-path: none; }
    body[data-drawer-open] .nav-link .nav-count { position: static; }
    body[data-drawer-open] .nav-link[data-staff-only]::after,
    body[data-drawer-open] .nav-link[data-tip]:hover::after,
    body[data-drawer-open] .nav-link[data-tip]:focus-visible::after { content: none; }
    body[data-drawer-open] .sidebar-foot { justify-content: flex-start; padding: var(--sp-3) var(--sp-4) var(--sp-4); }
    .nav-scrim { position: fixed; inset: 0; z-index: 55; background: rgba(26, 26, 26, 0.4); }

    .topbar-brand { display: inline-flex; align-items: center; }

    .page { padding-top: var(--sp-5); }
    .page-head { align-items: stretch; flex-direction: column; }
    .page-actions > * { flex: 1 1 auto; }
    .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-3); }
    .grid-3 { grid-template-columns: minmax(0, 1fr); }

    .tabbar {
      position: fixed; inset: auto 0 0 0; z-index: 40;
      display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
      height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
      background: var(--c-white); border-top: 1px solid var(--border-card);
      box-shadow: 0 -4px 16px rgba(26, 26, 26, 0.05);
    }
    .tab-link {
      position: relative;
      display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
      min-height: var(--tap); border: 0; background: none; padding: 0 2px;
      color: var(--text-muted-aa); text-decoration: none;
      font-family: var(--font-display); font-size: 0.6875rem; font-weight: 600;
    }
    .tab-link .icon { width: 22px; height: 22px; }
    .tab-link[aria-current="page"] { color: var(--c-green-800); }
    .tab-link[aria-current="page"] .icon { color: var(--c-green-600); }
    .tab-link[aria-current="page"]::before {
      content: ""; position: absolute; top: 0; left: 25%; right: 25%; height: 3px; border-radius: 0 0 3px 3px; background: var(--c-green-600);
    }
    .tab-link .nav-count {
      position: absolute; top: 6px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 4px;
      border-radius: var(--radius-pill); background: var(--c-red-600); color: var(--c-white);
      font-size: 0.6875rem; display: inline-grid; place-items: center;
    }
  }
  @media (max-width: 399px) {
    .kpi-grid { grid-template-columns: minmax(0, 1fr); }
  }
}

/* ======================================================================== components */
@layer components {
  /* ---- icons (Lucide, inline sprite in ui/icons.html) */
  .icon {
    width: 20px; height: 20px; flex: 0 0 auto; display: inline-block; vertical-align: middle;
    fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
  }
  .icon-sm { width: 16px; height: 16px; }
  .icon-lg { width: 24px; height: 24px; }

  /* ---- brand mark (placeholder until the DS ships a vector logo) */
  .brand-mark circle.ring { fill: var(--c-green-600); stroke: var(--c-blue-600); stroke-width: 1.5; }

  /* ---- buttons */
  .btn {
    display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
    min-height: var(--tap); padding: 0 var(--sp-5);
    border: var(--border-width) solid transparent; border-radius: var(--radius-pill);
    font-family: var(--font-display); font-weight: var(--fw-semibold); font-size: var(--app-fs-sm); line-height: 1;
    text-decoration: none; white-space: nowrap; cursor: pointer;
    transition: background var(--dur-fast) var(--ease-standard), border-color var(--dur-fast) var(--ease-standard),
      box-shadow var(--dur-med) var(--ease-standard), transform var(--dur-fast) var(--ease-standard);
  }
  .btn:active:not(:disabled) { transform: scale(0.97); }
  .btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }
  .btn-primary { background: var(--c-green-700); color: var(--c-white); }
  .btn-primary:hover:not(:disabled) { background: var(--c-green-800); color: var(--c-white); box-shadow: var(--shadow-brand); }
  .btn-secondary { background: var(--c-blue-600); color: var(--c-white); }
  .btn-secondary:hover:not(:disabled) { background: var(--c-blue-700); color: var(--c-white); }
  .btn-outline { background: var(--c-white); color: var(--c-green-800); border-color: var(--c-green-700); }
  .btn-outline:hover:not(:disabled) { background: var(--c-green-050); color: var(--c-green-800); }
  .btn-quiet { background: var(--c-white); color: var(--text-heading); border-color: var(--c-gray-300); }
  .btn-quiet:hover:not(:disabled) { border-color: var(--c-gray-500); color: var(--text-heading); }
  .btn-ghost { background: transparent; color: var(--c-green-800); }
  .btn-ghost:hover:not(:disabled) { background: var(--c-green-050); color: var(--c-green-800); }
  .btn-danger { background: var(--c-white); color: var(--c-red-600); border-color: var(--c-red-600); }
  .btn-danger:hover:not(:disabled) { background: var(--c-red-050); color: var(--c-red-600); }
  .btn-sm { padding: 0 var(--sp-4); }
  .btn-block { width: 100%; }
  .btn-icon { width: var(--tap); padding: 0; border-radius: 50%; }
  .btn-icon.btn-ghost { color: var(--text-body); }
  .btn-icon.btn-ghost:hover { background: var(--surface-muted); color: var(--text-heading); }
  .btn[aria-pressed="true"] { background: var(--c-green-050); color: var(--c-green-800); border-color: var(--c-green-700); }

  /* ---- cards */
  .card {
    background: var(--surface-card); border: 1px solid var(--border-card);
    border-radius: var(--radius-md); box-shadow: var(--shadow-sm);
    padding: var(--card-pad); min-width: 0;
  }
  .card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-3); margin-bottom: var(--sp-4); }
  .card-head h2, .card-head h3 { font-size: var(--app-fs-h2); }
  .card-sub { color: var(--text-muted-aa); font-size: var(--app-fs-sm); margin: 2px 0 0; }
  .card-actions { display: flex; gap: var(--sp-1); flex: 0 0 auto; }
  .card-flush { padding: 0; overflow: hidden; }
  .card-flush > .card-head { padding: var(--card-pad) var(--card-pad) 0; }

  /* ---- KPI tile */
  .kpi { display: flex; flex-direction: column; gap: var(--sp-2); position: relative; overflow: hidden; }
  .kpi-label {
    display: flex; align-items: center; gap: var(--sp-2);
    font-family: var(--font-display); font-weight: 600; font-size: var(--app-fs-sm); color: var(--text-body);
  }
  .kpi-label .icon { width: 18px; height: 18px; color: var(--c-green-600); }
  .kpi-value {
    font-family: var(--font-display); font-weight: 700; font-size: var(--app-fs-kpi); line-height: 1.1;
    color: var(--text-heading); letter-spacing: var(--ls-tight);
  }
  .kpi-unit { font-size: 0.55em; font-weight: 600; color: var(--text-muted-aa); margin-left: 4px; letter-spacing: 0; }
  .kpi { gap: 6px; }
  .kpi-main { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--sp-3); }
  .kpi-main .kpi-value { min-width: 0; white-space: nowrap; }
  .kpi-unit:empty { display: none; }
  .kpi-note { font-size: var(--app-fs-xs); color: var(--text-muted-aa); }
  .delta { display: block; font-size: var(--app-fs-xs); font-weight: 700; color: var(--text-muted-aa); line-height: 1.35; }
  .delta .icon { width: 14px; height: 14px; stroke-width: 2.5; margin-right: 2px; vertical-align: -2px; }
  .delta[data-tone="good"] { color: var(--c-green-800); }
  .delta[data-tone="bad"] { color: var(--c-red-600); }
  .delta-vs { font-weight: 500; color: var(--text-muted-aa); }
  .kpi.is-loading .kpi-value { color: transparent; background: var(--surface-muted); border-radius: var(--radius-xs); width: 60%; }

  /* ---- pills, badges, chips */
  .pill {
    display: inline-flex; align-items: center; gap: 6px;
    min-height: 26px; padding: 0 10px; border-radius: var(--radius-pill);
    font-size: var(--app-fs-xs); font-weight: 700; white-space: nowrap;
    background: var(--status-off-bg); color: var(--status-off);
  }
  .pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--status-off-dot); flex: 0 0 auto; }
  .pill[data-tone="ok"] { background: var(--status-ok-bg); color: var(--status-ok); }
  .pill[data-tone="ok"]::before { background: var(--status-ok-dot); }
  .pill[data-tone="warn"] { background: var(--status-warn-bg); color: var(--status-warn); }
  .pill[data-tone="warn"]::before { background: var(--status-warn-dot); }
  .pill[data-tone="crit"] { background: var(--status-crit-bg); color: var(--status-crit); }
  .pill[data-tone="crit"]::before { background: var(--status-crit-dot); border-radius: 2px; transform: rotate(45deg); }
  .pill[data-tone="info"] { background: var(--status-info-bg); color: var(--status-info); }
  .pill[data-tone="info"]::before { background: var(--status-info-dot); }
  .pill[data-tone="off"]::before { background: transparent; box-shadow: inset 0 0 0 2px var(--status-off-dot); }

  .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--status-off-dot); flex: 0 0 auto; }
  .dot[data-tone="ok"] { background: var(--status-ok-dot); }
  .dot[data-tone="warn"] { background: var(--status-warn-dot); }
  .dot[data-tone="crit"] { background: var(--status-crit-dot); }
  .dot[data-tone="off"] { background: transparent; box-shadow: inset 0 0 0 2px var(--status-off-dot); }

  .badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 10px; border-radius: var(--radius-pill);
    font-family: var(--font-display); font-weight: 600; font-size: 0.6875rem; letter-spacing: var(--ls-wide);
    text-transform: uppercase; line-height: 1.4; white-space: nowrap;
    background: var(--c-green-050); color: var(--c-green-800);
  }
  .badge[data-tone="blue"] { background: var(--c-blue-050); color: var(--c-blue-700); }
  .badge[data-tone="neutral"] { background: var(--surface-muted); color: var(--text-body); }
  .badge[data-tone="orange"] { background: var(--c-orange-100); color: var(--c-orange-700); }
  .badge .icon { width: 12px; height: 12px; stroke-width: 2.5; }
  .badge-staff { background: var(--c-orange-100); color: var(--c-orange-700); box-shadow: inset 0 0 0 1px var(--c-orange-200); }

  .chip {
    display: inline-flex; align-items: center; gap: 6px;
    min-height: 32px; padding: 0 12px; border-radius: var(--radius-pill);
    background: var(--c-green-050); color: var(--c-green-800);
    font-family: var(--font-display); font-weight: 600; font-size: var(--app-fs-sm); line-height: 1;
    border: 0; text-decoration: none;
  }
  .chip .icon { width: 16px; height: 16px; color: var(--c-green-600); }
  button.chip:hover { background: var(--c-green-200); color: var(--c-black); }

  /* ---- icon badge (DS IconBadge) */
  .icon-badge {
    --size: 48px;
    display: inline-flex; align-items: center; justify-content: center;
    width: var(--size); height: var(--size); border-radius: 50%; flex: 0 0 auto;
    background: var(--gradient-brand); color: var(--c-white); box-shadow: var(--shadow-brand);
  }
  .icon-badge .icon { width: calc(var(--size) * 0.5); height: calc(var(--size) * 0.5); }
  .icon-badge[data-tone="green"] { background: var(--c-green-600); }
  .icon-badge[data-tone="blue"] { background: var(--c-blue-600); }
  .icon-badge[data-size="sm"] { --size: 32px; box-shadow: none; }
  .icon-badge[data-size="lg"] { --size: 72px; }

  /* ---- privacy chip */
  .privacy-chip {
    display: inline-flex; align-items: center; gap: 6px;
    min-height: var(--tap); padding: 0 14px; border-radius: var(--radius-pill);
    background: var(--c-green-050); color: var(--c-green-800); border: 0;
    font-family: var(--font-display); font-weight: 600; font-size: var(--app-fs-sm);
  }
  .privacy-chip .icon { width: 18px; height: 18px; color: var(--c-green-600); }
  @media (min-width: 768px) and (max-width: 1279px) {
    .sidebar .privacy-chip { width: var(--tap); padding: 0; justify-content: center; }
    .sidebar .privacy-chip span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  }

  /* ---- popovers */
  .popover-wrap { position: relative; }
  .popover {
    position: absolute; top: calc(100% + 8px); right: 0; z-index: 50;
    width: max-content; min-width: 260px; max-width: min(420px, calc(100vw - 24px));
    background: var(--c-white); border: 1px solid var(--border-card); border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg); padding: var(--sp-3);
    animation: pop-in var(--dur-med) var(--ease-out);
  }
  .popover[data-align="left"] { right: auto; left: 0; }
  .popover-up { top: auto; bottom: calc(100% + 8px); }
  @keyframes pop-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
  .popover-text { max-width: 320px; font-size: var(--app-fs-sm); }
  .menu { list-style: none; margin: 0; padding: 0; }
  .menu a, .menu button {
    display: flex; align-items: center; gap: var(--sp-3); width: 100%;
    min-height: var(--tap); padding: 0 var(--sp-3); border: 0; border-radius: var(--radius-sm);
    background: none; color: var(--text-heading); text-decoration: none; font-weight: 600; text-align: left;
  }
  .menu a:hover, .menu button:hover { background: var(--surface-muted); color: var(--text-heading); }
  .menu .icon { width: 18px; height: 18px; color: var(--text-muted-aa); }
  .menu-head { padding: var(--sp-2) var(--sp-3) var(--sp-3); border-bottom: 1px solid var(--border-card); margin-bottom: var(--sp-2); }
  .menu-head strong { display: block; }
  .menu-head span { color: var(--text-muted-aa); font-size: var(--app-fs-sm); }

  /* ---- topbar controls (scope / period) */
  .control-btn {
    display: inline-flex; align-items: center; gap: var(--sp-2);
    min-height: var(--tap); max-width: 280px; padding: 0 var(--sp-3) 0 var(--sp-3);
    border: 1px solid var(--c-gray-300); border-radius: var(--radius-pill); background: var(--c-white);
    color: var(--text-heading); font-family: var(--font-display); font-weight: 600; font-size: var(--app-fs-sm);
  }
  .control-btn:hover { border-color: var(--c-gray-500); }
  .control-btn[aria-expanded="true"] { border-color: var(--c-green-700); box-shadow: 0 0 0 3px rgba(0, 156, 92, 0.15); }
  .control-btn .icon { width: 18px; height: 18px; color: var(--c-green-600); }
  .control-btn .icon.chev { width: 16px; height: 16px; color: var(--text-muted-aa); margin-left: auto; }
  .control-btn .control-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .control-btn .control-sub { color: var(--text-muted-aa); font-weight: 500; }
  .control-locked { cursor: default; background: var(--surface-muted); border-color: transparent; }
  .control-locked:hover { border-color: transparent; }

  .scope-pop { width: min(380px, calc(100vw - 24px)); padding: 0; }
  @media (max-width: 767px) {
    .topbar-controls .control-sub { display: none; }
    .period-pop { width: min(340px, calc(100vw - 24px)); }
  }
  .scope-search { padding: var(--sp-3); border-bottom: 1px solid var(--border-card); }
  .scope-list { list-style: none; margin: 0; padding: var(--sp-2); max-height: 340px; overflow-y: auto; }
  .scope-group { font-family: var(--font-display); font-size: 0.6875rem; font-weight: 700; letter-spacing: var(--ls-caps); text-transform: uppercase; color: var(--text-muted-aa); padding: var(--sp-2) var(--sp-3) var(--sp-1); }
  .scope-opt {
    display: grid; grid-template-columns: 20px minmax(0, 1fr) auto auto; align-items: center; gap: var(--sp-3);
    min-height: var(--tap); padding: 0 var(--sp-3); border-radius: var(--radius-sm); cursor: pointer;
  }
  .scope-opt:hover { background: var(--surface-muted); }
  .scope-opt:focus { outline: 2px solid var(--focus-ring); outline-offset: -2px; background: var(--surface-muted); }
  .scope-opt[aria-current="true"] .scope-name { color: var(--c-green-800); }
  .scope-check {
    width: 20px; height: 20px; border-radius: 6px; border: 1.5px solid var(--c-gray-500);
    display: grid; place-items: center; background: var(--c-white);
  }
  .scope-check .icon { width: 14px; height: 14px; stroke-width: 3; color: var(--c-white); opacity: 0; }
  .scope-opt[aria-selected="true"] .scope-check { background: var(--c-green-700); border-color: var(--c-green-700); }
  .scope-opt[aria-selected="true"] .scope-check .icon { opacity: 1; }
  .scope-opt[data-all] .scope-check { border-radius: 50%; }
  .scope-name { font-weight: 700; color: var(--text-heading); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .scope-meta { display: block; font-size: var(--app-fs-xs); color: var(--text-muted-aa); font-weight: 500; }
  .scope-star { display: inline-grid; place-items: center; width: 32px; height: 32px; border: 0; background: none; border-radius: 50%; color: var(--c-gray-500); padding: 0; }
  .scope-star:hover { background: var(--c-white); color: var(--c-orange-700); }
  .scope-star[aria-pressed="true"] { color: var(--c-orange-500); }
  .scope-star[aria-pressed="true"] .icon { fill: currentColor; }
  .scope-foot { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-3); border-top: 1px solid var(--border-card); }
  .scope-hint { font-size: var(--app-fs-xs); color: var(--text-muted-aa); }
  .scope-empty { padding: var(--sp-4); color: var(--text-muted-aa); text-align: center; }

  .period-pop { width: 340px; }
  .period-pop fieldset + fieldset { margin-top: var(--sp-4); padding-top: var(--sp-4); border-top: 1px solid var(--border-card); }
  .period-pop legend { font-family: var(--font-display); font-weight: 700; font-size: var(--app-fs-sm); color: var(--text-heading); margin-bottom: var(--sp-2); }
  .radio-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-1); }
  .radio-row {
    display: flex; align-items: center; gap: var(--sp-2);
    min-height: 40px; padding: 0 var(--sp-2); border-radius: var(--radius-sm); cursor: pointer; font-weight: 600; color: var(--text-heading);
  }
  .radio-row:hover { background: var(--surface-muted); }
  .radio-row input { width: 18px; height: 18px; margin: 0; accent-color: var(--c-green-700); }
  .period-custom { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-2); margin-top: var(--sp-2); }
  .period-foot { display: flex; justify-content: flex-end; gap: var(--sp-2); margin-top: var(--sp-4); }

  .live-status { display: inline-flex; align-items: center; gap: 6px; font-size: var(--app-fs-xs); color: var(--text-muted-aa); white-space: nowrap; padding: 0 var(--sp-2); }
  .live-status .dot { background: var(--c-green-600); box-shadow: 0 0 0 3px rgba(0, 156, 92, 0.18); }
  .live-status[data-state="paused"] .dot { background: var(--c-gray-500); box-shadow: none; }
  .live-status[data-state="error"] .dot { background: var(--c-red-600); box-shadow: none; }

  .bell { position: relative; }
  .bell .nav-count {
    position: absolute; top: 4px; right: 2px; min-width: 18px; height: 18px; padding: 0 4px;
    border-radius: var(--radius-pill); background: var(--c-red-600); color: var(--c-white);
    font-size: 0.6875rem; font-weight: 700; display: inline-grid; place-items: center; box-shadow: 0 0 0 2px var(--c-white);
  }
  .avatar {
    display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 50%;
    background: var(--c-blue-050); color: var(--c-blue-700); font-family: var(--font-display); font-weight: 700; font-size: var(--app-fs-sm);
  }

  /* ---- breadcrumbs */
  .crumbs ol { list-style: none; display: flex; align-items: center; flex-wrap: nowrap; gap: var(--sp-1); margin: 0; padding: 0; min-width: 0; }
  .crumbs li { display: flex; align-items: center; gap: var(--sp-1); min-width: 0; font-size: var(--app-fs-sm); }
  .crumbs li + li::before {
    content: ""; width: 14px; height: 14px; flex: 0 0 auto;
    background: var(--text-muted-aa);
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m9 18 6-6-6-6'/%3E%3C/svg%3E") center / contain no-repeat;
            mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m9 18 6-6-6-6'/%3E%3C/svg%3E") center / contain no-repeat;
  }
  .crumbs a { color: var(--text-body); text-decoration: none; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 10px 2px; }
  .crumbs a:hover { color: var(--c-green-800); text-decoration: underline; }
  .crumbs [aria-current="page"] { color: var(--text-heading); font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  @media (max-width: 1023px) {
    .crumbs li:not(:nth-last-child(-n+2)) { display: none; }
  }
  @media (max-width: 767px) {
    .crumbs li:not(:last-child) { display: none; }
    .crumbs li + li::before { content: none; }
  }

  /* ---- forms */
  .field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
  .field + .field { margin-top: var(--sp-4); }
  .field-label { font-family: var(--font-display); font-weight: 600; font-size: var(--app-fs-sm); color: var(--text-heading); }
  .field-label .req { color: var(--c-red-600); margin-left: 2px; }
  .field-help { font-size: var(--app-fs-xs); color: var(--text-muted-aa); margin: 0; }
  .field-error { display: flex; align-items: center; gap: 6px; font-size: var(--app-fs-xs); font-weight: 700; color: var(--c-red-600); margin: 0; }
  .field-error .icon { width: 14px; height: 14px; }
  .input, .select, .textarea {
    width: 100%; min-height: var(--tap); padding: 0 14px;
    background: var(--c-white); color: var(--text-heading);
    border: var(--border-width) solid var(--c-gray-300); border-radius: var(--radius-sm);
    font-family: var(--font-body); font-weight: 600; font-size: var(--app-fs-body);
    transition: border-color var(--dur-fast) var(--ease-standard), box-shadow var(--dur-fast) var(--ease-standard);
  }
  .textarea { padding: 10px 14px; min-height: 96px; resize: vertical; }
  .select {
    appearance: none; padding-right: 40px;
    background: var(--c-white) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b6b6b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 12px center / 18px;
  }
  .input:hover, .select:hover, .textarea:hover { border-color: var(--c-gray-500); }
  .input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--c-green-700); box-shadow: 0 0 0 3px rgba(0, 156, 92, 0.18); }
  .input[aria-invalid="true"], .select[aria-invalid="true"] { border-color: var(--c-red-600); }
  .input::placeholder { color: var(--text-muted-aa); font-weight: 500; }
  .input-group { display: flex; gap: var(--sp-2); }
  .check-row { display: flex; align-items: flex-start; gap: var(--sp-2); min-height: var(--tap); padding-top: 11px; cursor: pointer; font-weight: 600; color: var(--text-heading); }
  .check-row input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--c-green-700); flex: 0 0 auto; }

  /* 6-character pairing code */
  .code-input { display: flex; gap: var(--sp-2); }
  .code-input input {
    width: 52px; height: 64px; padding: 0; text-align: center;
    font-family: var(--font-display); font-weight: 700; font-size: 1.75rem; text-transform: uppercase; color: var(--text-heading);
    border: var(--border-width) solid var(--c-gray-300); border-radius: var(--radius-sm); background: var(--c-white);
  }
  .code-input input:focus { outline: none; border-color: var(--c-green-700); box-shadow: 0 0 0 3px rgba(0, 156, 92, 0.18); }
  .code-input input[aria-invalid="true"] { border-color: var(--c-red-600); }
  .code-input .code-sep { align-self: center; width: 12px; height: 2px; background: var(--c-gray-300); border-radius: 2px; }
  @media (max-width: 420px) { .code-input { gap: 4px; } .code-input input { width: 42px; height: 56px; font-size: 1.4rem; } }

  /* segmented control (radio based) */
  .segmented { display: inline-flex; padding: 3px; gap: 2px; border-radius: var(--radius-pill); background: var(--surface-muted); }
  .segmented label { position: relative; }
  .segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
  .segmented span {
    display: inline-flex; align-items: center; min-height: 38px; padding: 0 14px; border-radius: var(--radius-pill);
    font-family: var(--font-display); font-weight: 600; font-size: var(--app-fs-sm); color: var(--text-body); white-space: nowrap;
  }
  .segmented input:checked + span { background: var(--c-white); color: var(--c-green-800); box-shadow: var(--shadow-sm); }
  .segmented input:focus-visible + span { outline: 2px solid var(--focus-ring); outline-offset: 1px; }

  /* ---- filter bar */
  .filter-bar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--sp-3) var(--sp-4); margin-bottom: var(--gap); }
  .filter-bar .field { margin: 0; min-width: 180px; }
  .filter-bar .field + .field { margin: 0; }
  .filter-bar .filter-spacer { flex: 1 1 auto; }
  @media (max-width: 767px) { .filter-bar .field { flex: 1 1 100%; } }

  /* ---- alert banner */
  .banner {
    display: flex; align-items: flex-start; gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-4); border-radius: var(--radius-md);
    background: var(--status-info-bg); color: var(--text-heading);
    border: 1px solid transparent; border-left-width: 4px; border-left-color: var(--status-info-dot);
  }
  .banner + .banner { margin-top: var(--sp-2); }
  .banner > .icon { margin-top: 2px; color: var(--status-info); }
  .banner-body { flex: 1 1 auto; min-width: 0; }
  .banner-title { font-family: var(--font-display); font-weight: 700; color: var(--text-heading); }
  .banner-text { font-size: var(--app-fs-sm); color: var(--text-body); }
  .banner-actions { display: flex; gap: var(--sp-2); align-items: center; flex: 0 0 auto; }
  .banner-actions a { font-weight: 700; font-size: var(--app-fs-sm); }
  .banner[data-tone="crit"] { background: var(--status-crit-bg); border-left-color: var(--status-crit-dot); }
  .banner[data-tone="crit"] > .icon { color: var(--status-crit); }
  .banner[data-tone="crit"] .banner-actions a { color: var(--c-red-600); }
  .banner[data-tone="warn"] { background: var(--status-warn-bg); border-left-color: var(--status-warn-dot); }
  .banner[data-tone="warn"] > .icon { color: var(--status-warn); }
  .banner[data-tone="warn"] .banner-actions a { color: var(--c-orange-700); }
  .banner[data-tone="ok"] { background: var(--status-ok-bg); border-left-color: var(--status-ok-dot); }
  .banner[data-tone="ok"] > .icon { color: var(--status-ok); }
  .banner .btn-icon { width: 36px; height: 36px; min-height: 36px; margin: -6px -6px -6px 0; }
  .banners { display: flex; flex-direction: column; gap: var(--sp-2); margin-bottom: var(--gap); }
  .banners:empty { display: none; }

  /* ---- toasts */
  .toast-region {
    position: fixed; z-index: 80; right: var(--sp-5); bottom: var(--sp-5);
    display: flex; flex-direction: column; gap: var(--sp-2); width: min(380px, calc(100vw - 32px)); pointer-events: none;
  }
  @media (max-width: 767px) { .toast-region { right: 16px; bottom: calc(var(--tabbar-h) + 12px + env(safe-area-inset-bottom)); } }
  .toast {
    pointer-events: auto;
    display: flex; align-items: flex-start; gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-3) var(--sp-3) var(--sp-4);
    border-radius: var(--radius-md); background: var(--c-black); color: var(--c-white);
    box-shadow: var(--shadow-lg); animation: toast-in var(--dur-slow) var(--ease-out);
  }
  .toast > .icon { margin-top: 2px; color: var(--c-green-200); }
  .toast[data-tone="crit"] > .icon { color: #f3a39d; }
  .toast[data-tone="warn"] > .icon { color: var(--c-orange-200); }
  .toast-body { flex: 1 1 auto; font-size: var(--app-fs-sm); padding-top: 1px; }
  .toast-body strong { color: var(--c-white); }
  .toast .btn-icon { width: 32px; height: 32px; min-height: 32px; color: #d4d4d4; margin: -4px -4px -4px 0; }
  .toast .btn-icon:hover { background: rgba(255, 255, 255, 0.12); color: var(--c-white); }
  .toast.is-leaving { opacity: 0; transform: translateY(6px); transition: all var(--dur-med) var(--ease-standard); }
  @keyframes toast-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

  /* ---- modal (native <dialog>) */
  .modal {
    width: min(560px, calc(100vw - 32px)); max-height: calc(100dvh - 48px);
    padding: 0; border: 0; border-radius: var(--radius-lg); background: var(--c-white); color: var(--text-body);
    box-shadow: var(--shadow-lg);
  }
  .modal[open] { display: flex; flex-direction: column; animation: pop-in var(--dur-med) var(--ease-out); }
  .modal::backdrop { background: rgba(26, 26, 26, 0.45); }
  .modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-5) var(--sp-5) var(--sp-3); }
  .modal-head h2 { font-size: 1.25rem; }
  .modal-body { padding: 0 var(--sp-5); overflow-y: auto; }
  .modal-foot { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: var(--sp-2); padding: var(--sp-5); }
  @media (max-width: 767px) {
    .modal { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
    .modal-foot > .btn { flex: 1 1 auto; }
  }

  /* ---- tabs */
  .tabs { display: flex; gap: var(--sp-1); border-bottom: 1px solid var(--border-card); margin-bottom: var(--sp-4); overflow-x: auto; scrollbar-width: none; }
  .tab {
    position: relative; flex: 0 0 auto;
    min-height: var(--tap); padding: 0 var(--sp-4); border: 0; background: none;
    font-family: var(--font-display); font-weight: 600; font-size: var(--app-fs-sm); color: var(--text-body);
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  }
  .tab:hover { color: var(--text-heading); background: var(--surface-muted); }
  .tab[aria-selected="true"] { color: var(--c-green-800); }
  .tab[aria-selected="true"]::after { content: ""; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 3px; border-radius: 3px 3px 0 0; background: var(--c-green-600); }
  .tab:focus-visible { outline-offset: -2px; }
  .tab .badge { margin-left: 6px; }

  /* ---- stepper */
  .stepper { list-style: none; display: flex; gap: var(--sp-2); margin: 0 0 var(--sp-6); padding: 0; counter-reset: step; }
  .step { flex: 1 1 0; display: flex; flex-direction: column; gap: var(--sp-2); min-width: 0; counter-increment: step; }
  .step-bar { height: 4px; border-radius: 4px; background: var(--c-gray-300); }
  .step-row { display: flex; align-items: center; gap: var(--sp-2); }
  .step-num {
    display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; flex: 0 0 auto;
    background: var(--c-white); color: var(--text-muted-aa); box-shadow: inset 0 0 0 1.5px var(--c-gray-300);
    font-family: var(--font-display); font-weight: 700; font-size: var(--app-fs-sm);
  }
  .step-num::before { content: counter(step); }
  .step-num .icon { display: none; width: 16px; height: 16px; stroke-width: 3; }
  .step-label { font-family: var(--font-display); font-weight: 600; font-size: var(--app-fs-sm); color: var(--text-muted-aa); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .step[data-state="done"] .step-bar { background: var(--c-green-600); }
  .step[data-state="done"] .step-num { background: var(--c-green-600); color: var(--c-white); box-shadow: none; }
  .step[data-state="done"] .step-num::before { content: none; }
  .step[data-state="done"] .step-num .icon { display: block; }
  .step[data-state="done"] .step-label { color: var(--text-body); }
  .step[aria-current="step"] .step-bar { background: var(--gradient-brand); }
  .step[aria-current="step"] .step-num { background: var(--c-green-700); color: var(--c-white); box-shadow: 0 0 0 4px var(--c-green-050); }
  .step[aria-current="step"] .step-label { color: var(--text-heading); }
  @media (max-width: 767px) {
    .step:not([aria-current="step"]) .step-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  }

  /* ---- data table */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table { width: 100%; font-size: var(--app-fs-sm); }
  .table caption { text-align: left; padding: 0 0 var(--sp-3); color: var(--text-muted-aa); font-size: var(--app-fs-xs); }
  .table th, .table td { padding: 10px var(--sp-4); text-align: left; border-bottom: 1px solid var(--border-card); white-space: nowrap; vertical-align: middle; }
  .table th {
    font-family: var(--font-display); font-weight: 600; font-size: var(--app-fs-xs); color: var(--text-muted-aa);
    letter-spacing: 0.02em; background: #fafcfb; position: sticky; top: 0;
  }
  .table thead th:first-child { border-top-left-radius: 0; }
  .table tbody tr:last-child td { border-bottom: 0; }
  .table tbody tr:hover td { background: #fafcfb; }
  .table td { color: var(--text-heading); font-weight: 600; }
  .table .num { text-align: right; font-variant-numeric: tabular-nums; }
  .table .muted { color: var(--text-muted-aa); font-weight: 500; }
  .table .sub { display: block; color: var(--text-muted-aa); font-weight: 500; font-size: var(--app-fs-xs); }
  .table .row-link { color: var(--text-heading); text-decoration: none; font-weight: 700; }
  .table .row-link:hover { color: var(--c-green-800); text-decoration: underline; }
  .table tr[data-href] { cursor: pointer; }
  .table .empty-row td { text-align: center; color: var(--text-muted-aa); padding: var(--sp-6); white-space: normal; }
  .th-sort {
    display: inline-flex; align-items: center; gap: 4px; min-height: 32px; margin: -6px -8px; padding: 0 8px;
    border: 0; background: none; border-radius: var(--radius-xs);
    font: inherit; color: inherit; letter-spacing: inherit; text-transform: inherit;
  }
  .th-sort:hover { color: var(--text-heading); background: var(--surface-muted); }
  .th-sort .icon { width: 14px; height: 14px; opacity: 0.55; }
  th[aria-sort="ascending"] .th-sort, th[aria-sort="descending"] .th-sort { color: var(--c-green-800); }
  th[aria-sort="ascending"] .th-sort .icon, th[aria-sort="descending"] .th-sort .icon { opacity: 1; }
  th[aria-sort="descending"] .th-sort .icon { transform: scaleY(-1); }
  .num .th-sort { flex-direction: row-reverse; }
  .card-flush .table th:first-child, .card-flush .table td:first-child { padding-left: var(--card-pad); }
  .card-flush .table th:last-child, .card-flush .table td:last-child { padding-right: var(--card-pad); }
  .card-flush .table-wrap { margin-top: var(--sp-2); }

  /* ---- empty state (one of two places where waves/dots are allowed) */
  .empty {
    position: relative; overflow: hidden;
    display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--sp-3);
    padding: var(--sp-7) var(--sp-5) var(--sp-8); border-radius: var(--radius-md);
    background: var(--c-white); border: 1px solid var(--border-card);
  }
  .empty h2, .empty h3 { font-size: 1.125rem; }
  .empty p { max-width: 46ch; color: var(--text-body); }
  .empty .btn { margin-top: var(--sp-2); position: relative; }
  .empty-deco { position: absolute; inset: auto 0 0 0; height: 56px; pointer-events: none; opacity: 0.9; }
  .empty-dots { position: absolute; inset: 0; pointer-events: none; }
  .empty-compact { padding: var(--sp-6) var(--sp-4); border: 0; background: transparent; }
  .empty-compact .empty-deco, .empty-compact .empty-dots { display: none; }

  /* ---- staff-only page marker */
  .staff-note { display: inline-flex; align-items: center; gap: var(--sp-2); }

  /* ---- branch ranking inline bar */
  .rank-bar { position: relative; width: 160px; height: 10px; border-radius: 5px; background: var(--surface-muted); }
  .rank-bar span { position: absolute; inset: 0 auto 0 0; border-radius: 5px; background: var(--c-green-600); }
  .rank-bar[data-below] span { background: var(--c-blue-400); }
  .rank-bar i { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--c-black); border-radius: 1px; }
  .rank-cell { display: flex; align-items: center; gap: var(--sp-3); }
  .rank-cell b { min-width: 56px; text-align: right; }
  .legend-inline { display: inline-flex; align-items: center; gap: var(--sp-2); font-size: var(--app-fs-xs); color: var(--text-muted-aa); }
  .legend-inline i { display: inline-block; width: 2px; height: 14px; background: var(--c-black); }

  /* ---- definitions list (metric glossary) */
  .defs { display: grid; grid-template-columns: max-content 1fr; gap: var(--sp-2) var(--sp-4); margin: 0; font-size: var(--app-fs-sm); }
  .defs dt { font-weight: 700; color: var(--text-heading); }
  .defs dd { margin: 0; }
  @media (max-width: 767px) { .defs { grid-template-columns: 1fr; } .defs dd { margin-bottom: var(--sp-2); } }

  /* ---- wizard */
  .wizard { max-width: 760px; }
  .wizard-panel h2 { font-size: 1.375rem; margin-bottom: var(--sp-2); }
  .wizard-panel .lead { font-size: 1rem; color: var(--text-body); margin-bottom: var(--sp-5); }
  .wizard-foot { display: flex; justify-content: space-between; gap: var(--sp-3); margin-top: var(--sp-6); padding-top: var(--sp-5); border-top: 1px solid var(--border-card); }
  .checklist { list-style: none; margin: 0 0 var(--sp-4); padding: 0; display: flex; flex-direction: column; gap: var(--sp-3); }
  .checklist li { display: flex; gap: var(--sp-3); align-items: flex-start; }
  .checklist .icon { color: var(--c-green-600); margin-top: 2px; }
  .wait-row { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-4); border-radius: var(--radius-md); background: var(--surface-muted); }
  .spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--c-green-200); border-top-color: var(--c-green-600); animation: spin 0.9s linear infinite; flex: 0 0 auto; }
  @keyframes spin { to { transform: rotate(360deg); } }
  .success-mark { display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--sp-3); padding: var(--sp-5) 0; }
  .kv { display: grid; grid-template-columns: max-content 1fr; gap: var(--sp-2) var(--sp-5); margin: 0; }
  .kv dt { color: var(--text-muted-aa); font-size: var(--app-fs-sm); }
  .kv dd { margin: 0; font-weight: 700; color: var(--text-heading); }

  /* ---- zone editor */
  .editor { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: var(--gap); align-items: start; }
  .editor-toolbar { display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--sp-2); margin-bottom: var(--sp-3); }
  .tool-group { display: flex; flex-wrap: wrap; gap: 4px; padding: 4px; background: var(--c-white); border: 1px solid var(--border-card); border-radius: var(--radius-pill); }
  .tool {
    display: inline-flex; align-items: center; gap: 6px;
    min-height: 40px; padding: 0 12px; border: 0; border-radius: var(--radius-pill); background: none;
    font-family: var(--font-display); font-weight: 600; font-size: var(--app-fs-sm); color: var(--text-body);
  }
  .tool:hover:not(:disabled) { background: var(--surface-muted); color: var(--text-heading); }
  .tool[aria-pressed="true"] { background: var(--c-black); color: var(--c-white); }
  .tool:disabled { opacity: 0.45; cursor: not-allowed; }
  .tool kbd { font-size: 0.6875rem; padding: 0 5px; border-bottom-width: 1px; color: var(--text-muted-aa); }
  .tool[aria-pressed="true"] kbd { background: transparent; color: #d4d4d4; border-color: #555; }
  .sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; flex: 0 0 auto; box-shadow: inset 0 0 0 1px rgba(26, 26, 26, 0.25); }
  .sw-line { background: var(--zone-line); height: 4px; border-radius: 2px; }
  .sw-queue { background: var(--zone-queue); }
  .sw-screen { background: var(--zone-screen); }
  .sw-area { background: var(--zone-area); }
  .sw-staff { background: repeating-linear-gradient(45deg, var(--c-gray-500) 0 2px, var(--zone-staff) 2px 4px); }
  .sw-storefront { background: repeating-linear-gradient(90deg, var(--c-orange-500) 0 3px, var(--zone-storefront) 3px 6px); }
  .stage {
    position: relative; overflow: hidden; user-select: none;
    aspect-ratio: 16 / 9; border-radius: var(--radius-md); background: #15191d;
  }
  .stage img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: fill; filter: grayscale(1); }
  .stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
  .stage:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 3px; }
  .stage-empty, .stage-msg {
    position: absolute; inset: 0; margin: auto; height: fit-content; width: min(440px, calc(100% - 32px));
    padding: var(--sp-4) var(--sp-5); border-radius: var(--radius-md); text-align: center;
    background: rgba(26, 26, 26, 0.9); color: #e9ecea; border: 1px solid #3a403c;
  }
  .stage-empty strong, .stage-msg strong { display: block; color: var(--c-white); font-family: var(--font-display); margin-bottom: 4px; }
  .stage-empty b, .stage-msg b { color: var(--c-white); }
  .stage-msg a { color: var(--c-green-200); }
  .stage-badge {
    position: absolute; top: 12px; left: 12px;
    display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: var(--radius-pill);
    background: var(--c-red-600); color: var(--c-white); font-family: var(--font-display); font-weight: 700; font-size: var(--app-fs-xs); letter-spacing: 0.04em;
  }
  .stage-pixel {
    position: absolute; right: 12px; bottom: 12px;
    display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: var(--radius-pill);
    background: rgba(26, 26, 26, 0.75); color: #e9ecea; font-size: var(--app-fs-xs); font-weight: 600;
  }
  .stage-pixel .icon { width: 14px; height: 14px; color: var(--c-green-200); }
  .editor-hint { margin: var(--sp-2) 2px 0; min-height: 22px; font-size: var(--app-fs-sm); color: var(--text-muted-aa); }
  .editor-hint[data-tone="crit"] { color: var(--c-red-600); font-weight: 700; }
  .zone-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
  .zone-item {
    display: flex; align-items: center; gap: var(--sp-2); width: 100%;
    min-height: var(--tap); padding: 0 var(--sp-3); border: 1.5px solid transparent; border-radius: var(--radius-sm);
    background: none; text-align: left; font-weight: 700; color: var(--text-heading);
  }
  .zone-item:hover { background: var(--surface-muted); }
  .zone-item[aria-pressed="true"] { border-color: var(--c-green-700); background: var(--c-green-050); }
  .zone-item .zone-kind { margin-left: auto; font-size: var(--app-fs-xs); font-weight: 600; color: var(--text-muted-aa); }
  .zone-item .zone-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .props-actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-top: var(--sp-4); }
  .save-bar { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; }
  .save-bar .save-status { flex: 1 1 100%; min-height: 20px; margin: 0; font-size: var(--app-fs-sm); color: var(--text-muted-aa); }
  .save-bar .save-status[data-tone="ok"] { color: var(--c-green-800); font-weight: 700; }
  .save-bar .save-status[data-tone="crit"] { color: var(--c-red-600); font-weight: 700; }
  .view-only-note { display: none; }
  @media (max-width: 1023px) { .editor { grid-template-columns: minmax(0, 1fr); } }
  @media (max-width: 767px) {
    .view-only-note { display: flex; }
    .editor[data-view-only] .editor-toolbar .tool-group:first-child,
    .editor[data-view-only] .props-edit,
    .editor[data-view-only] .save-bar { display: none; }
  }
}

/* ======================================================================== charts */
@layer charts {
  .chart-card .chart-box { position: relative; height: 280px; }
  .chart-card .chart-box.is-tall { height: 340px; }
  .chart-card .chart-box.is-short { height: 220px; }
  .chart-card canvas { display: block; }
  .chart-card .chart-data { margin-top: var(--sp-4); max-height: 320px; overflow: auto; border: 1px solid var(--border-card); border-radius: var(--radius-sm); }
  .chart-legend { display: flex; flex-wrap: wrap; gap: var(--sp-2) var(--sp-4); margin: 0 0 var(--sp-3); padding: 0; list-style: none; font-size: var(--app-fs-xs); font-weight: 600; color: var(--text-body); }
  .chart-legend li { display: inline-flex; align-items: center; gap: 6px; }
  .chart-legend .key { width: 16px; height: 4px; border-radius: 2px; background: currentColor; }
  .chart-legend .key-dash { background: repeating-linear-gradient(90deg, currentColor 0 4px, transparent 4px 7px); opacity: 0.6; }
  .chart-legend .key-band { height: 10px; border-radius: 2px; background: var(--chart-band); }
  .chart-note { font-size: var(--app-fs-xs); color: var(--text-muted-aa); margin-top: var(--sp-2); }
  .small-multiples { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: var(--sp-4); }
  .small-multiples .chart-box { height: 180px; }
  .small-multiples h3 { font-size: var(--app-fs-sm); margin-bottom: var(--sp-2); }

  /* sparkline inside KPI tiles (inline SVG drawn by core.js) */
  .sparkline { width: 96px; height: 32px; flex: 0 1 auto; min-width: 48px; overflow: visible; }
  @media (max-width: 767px) { .sparkline { width: 64px; height: 28px; } }
  .sparkline path.line { fill: none; stroke: var(--chart-1); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
  .sparkline path.area { fill: var(--chart-1); opacity: 0.1; stroke: none; }
  .sparkline circle { fill: var(--chart-1); }

  /* occupancy gauge vs capacity */
  .gauge { display: flex; flex-direction: column; align-items: center; gap: var(--sp-2); }
  .gauge svg { width: 220px; max-width: 100%; height: auto; overflow: visible; }
  .gauge .track { fill: none; stroke: var(--surface-muted); stroke-width: 16; stroke-linecap: round; }
  .gauge .value { fill: none; stroke: var(--chart-1); stroke-width: 16; stroke-linecap: round; transition: stroke-dashoffset var(--dur-slow) var(--ease-out); }
  .gauge[data-tone="warn"] .value { stroke: var(--c-orange-500); }
  .gauge[data-tone="crit"] .value { stroke: var(--c-red-600); }
  .gauge-num { font-family: var(--font-display); font-weight: 700; font-size: 2.5rem; line-height: 1; fill: var(--text-heading); }
  .gauge-of { font-size: 0.8125rem; fill: var(--text-muted-aa); font-weight: 600; }
  .gauge-caption { font-size: var(--app-fs-sm); color: var(--text-body); text-align: center; }

  /* heat legend */
  .heat-legend { display: inline-flex; flex-direction: column; gap: 6px; min-width: 220px; }
  .heat-legend-title { font-family: var(--font-display); font-weight: 600; font-size: var(--app-fs-xs); color: var(--text-heading); }
  .heat-ramp { height: 12px; border-radius: 6px; background: var(--heat-ramp); box-shadow: inset 0 0 0 1px rgba(26, 26, 26, 0.08); }
  .heat-scale { display: flex; justify-content: space-between; font-size: var(--app-fs-xs); color: var(--text-muted-aa); font-weight: 600; }
  .heat-peak { display: inline-flex; align-items: center; gap: 6px; font-size: var(--app-fs-xs); color: var(--text-body); font-weight: 600; }
  .heat-peak i { width: 14px; height: 14px; border-radius: 50%; border: 3px solid var(--heat-peak); }

  /* hour-of-day queue strip */
  .heat-strip { display: grid; grid-template-columns: repeat(24, minmax(0, 1fr)); gap: 2px; }
  .heat-strip span { height: 24px; border-radius: 3px; background: var(--heat-0); }
}

/* ======================================================================== utilities */
@layer utilities {
  .sr-only { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip-path: inset(50%) !important; white-space: nowrap !important; border: 0 !important; }
  .muted { color: var(--text-muted-aa); }
  .text-sm { font-size: var(--app-fs-sm); }
  .text-xs { font-size: var(--app-fs-xs); }
  .text-heading { color: var(--text-heading); }
  .text-ok { color: var(--c-green-800); }
  .text-crit { color: var(--c-red-600); }
  .text-warn { color: var(--c-orange-700); }
  .num { font-variant-numeric: tabular-nums; }
  .nowrap { white-space: nowrap; }
  .mt-0 { margin-top: 0 !important; }
  .mt-2 { margin-top: var(--sp-2); }
  .mt-4 { margin-top: var(--sp-4); }
  .mt-5 { margin-top: var(--gap); }
  .mb-0 { margin-bottom: 0 !important; }
  .mb-4 { margin-bottom: var(--sp-4); }
  .mb-5 { margin-bottom: var(--gap); }
  .ml-auto { margin-left: auto; }
  .w-full { width: 100%; }
  .hide-phone { }
  @media (max-width: 767px) { .hide-phone { display: none !important; } }
  .only-phone { display: none !important; }
  @media (max-width: 767px) { .only-phone { display: revert !important; } }

  /* shell toggles that must beat component display values (.btn, .live-status) */
  .sidebar-close { display: none; }
  @media (max-width: 767px) {
    body[data-drawer-open] .sidebar-close { display: inline-flex; margin-left: auto; }
    .topbar .live-status { display: none; }
  }
}

/* ======================================================================== auth + org picker */
/* Standalone pages outside the shell (login, client picker). Same tokens, a centered card. */
@layer components {
  .auth { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: var(--sp-6) var(--page-pad); position: relative; overflow: hidden; }
  .auth-deco { position: absolute; left: 0; right: 0; bottom: 0; width: 100%; height: 140px; pointer-events: none; }
  .auth-card { width: min(100%, 420px); position: relative; z-index: 1; }
  .auth-card.auth-wide { width: min(100%, 640px); }
  .auth-brand { display: flex; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-5); }
  .auth-brand .brand-mark { width: 40px; height: 40px; }
  .auth-brand .brand-word { font-family: var(--font-display); font-size: 1.15rem; color: var(--text-heading); }
  .auth-brand .brand-word span { margin-left: 6px; color: var(--c-green-700); font-weight: 600; }
  .auth-card h1 { font-size: var(--app-fs-h1); margin-bottom: var(--sp-2); }
  .auth-card .lead { color: var(--text-muted-aa); margin-bottom: var(--sp-5); }
  .auth-card form .btn { width: 100%; justify-content: center; margin-top: var(--sp-5); }
  .auth-foot { margin-top: var(--sp-5); display: flex; justify-content: center; }
  .org-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--sp-2); }
  .org-link {
    display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
    min-height: 56px; padding: var(--sp-3) var(--sp-4); border: 1px solid var(--border-card); border-radius: var(--radius-sm);
    text-decoration: none; color: var(--text-heading); font-family: var(--font-display); font-weight: 600; background: var(--surface-card);
  }
  .org-link:hover { border-color: var(--c-green-700); color: var(--c-green-800); box-shadow: var(--shadow-sm); }
  .org-link .icon { color: var(--c-green-700); }
}

/* ======================================================================== Phase 3: Conversión + Ventas (POS) */
@layer components {
  /* Funnel: horizontal bars, one per step, with the step-to-step rate above each bar. */
  .funnel { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--sp-1); }
  .funnel-rate { display: flex; align-items: center; gap: var(--sp-2); margin: 0 0 var(--sp-1); padding-left: calc(200px + var(--sp-4)); font-size: var(--app-fs-sm); color: var(--text-body); }
  .funnel-rate .icon { width: 16px; height: 16px; color: var(--text-muted-aa); }
  .funnel-rate b { color: var(--text-heading); }
  .funnel-row { display: grid; grid-template-columns: 200px minmax(0, 1fr) 96px; align-items: center; gap: var(--sp-4); }
  .funnel-label { font-weight: 700; color: var(--text-heading); line-height: 1.25; }
  .funnel-label .sub { display: block; font-weight: 500; font-size: var(--app-fs-xs); color: var(--text-muted-aa); }
  .funnel-bar { position: relative; height: 28px; border-radius: var(--radius-sm); background: var(--surface-muted); overflow: hidden; }
  .funnel-bar span { position: absolute; inset: 0 auto 0 0; min-width: 4px; border-radius: var(--radius-sm); background: var(--c-blue-400); }
  .funnel-step[data-part="store"] .funnel-bar span { background: var(--c-green-600); }
  .funnel-step[data-part="pos"] .funnel-bar span { background: var(--c-green-800); }
  .funnel-value { font-family: var(--font-display); font-weight: 700; font-size: 1.125rem; color: var(--text-heading); text-align: right; font-variant-numeric: tabular-nums; }
  .funnel-step + .funnel-step { margin-top: var(--sp-2); }
  @media (max-width: 767px) {
    .funnel-rate { padding-left: 0; }
    .funnel-row { grid-template-columns: minmax(0, 1fr) auto; gap: var(--sp-1) var(--sp-3); }
    .funnel-bar { grid-column: 1 / -1; grid-row: 2; }
  }

  /* File drop zone (Ventas: step 1). The native input stays focusable for the keyboard. */
  .dropzone { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--sp-2);
    text-align: center; padding: var(--sp-6) var(--sp-4); border: 2px dashed var(--c-gray-500); border-radius: var(--radius-md);
    background: var(--surface-muted); color: var(--text-body); cursor: pointer; transition: border-color 0.15s, background 0.15s; }
  .dropzone:hover, .dropzone[data-over] { border-color: var(--c-green-600); background: var(--c-green-050); }
  .dropzone:focus-within { outline: 3px solid var(--focus-ring); outline-offset: 3px; }
  .dropzone > .icon { width: 32px; height: 32px; color: var(--c-green-700); }
  .dropzone strong { color: var(--text-heading); }
  .dropzone input[type="file"] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
  .dropzone[aria-busy="true"] { opacity: 0.7; pointer-events: none; }

  .map-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--sp-4); }
  .map-grid .field + .field { margin-top: 0; }
  .preview-table th .map-tag { display: block; margin-top: 2px; font-size: var(--app-fs-xs); font-weight: 700; color: var(--c-green-800); text-transform: none; letter-spacing: 0; }
  .preview-table th[data-mapped] { background: var(--c-green-050); }

  /* API key shown once + copyable snippets */
  .secret-box { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); margin-top: var(--sp-3); }
  .secret-box code { flex: 1 1 280px; min-width: 0; overflow-wrap: anywhere; padding: var(--sp-2) var(--sp-3); border-radius: var(--radius-sm);
    background: var(--c-white); border: 1px solid var(--border-card); font-size: var(--app-fs-sm); color: var(--text-heading); }
  .code-block { position: relative; margin: var(--sp-3) 0 0; }
  .code-block pre { margin: 0; padding: var(--sp-4); padding-right: 112px; border-radius: var(--radius-md); background: var(--c-black); color: #e8ece9;
    font-size: var(--app-fs-xs); line-height: 1.6; overflow-x: auto; white-space: pre; }
  .code-block .btn { position: absolute; top: var(--sp-2); right: var(--sp-2); }
  .key-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--sp-3); }
  .key-form .field { flex: 1 1 240px; margin: 0; }
}
