/* ==========================================================================
   Cuadra design system — tokens + components (source of truth: docs/design-system)
   ========================================================================== */
@font-face { font-family: "Bricolage Grotesque"; font-weight: 200 800; font-display: swap;
  src: url(/assets/fonts/bricolage-grotesque-latin-wght-normal.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Bricolage Grotesque"; font-weight: 200 800; font-display: swap;
  src: url(/assets/fonts/bricolage-grotesque-latin-ext-wght-normal.woff2) format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: "Hanken Grotesk"; font-weight: 100 900; font-display: swap;
  src: url(/assets/fonts/hanken-grotesk-latin-wght-normal.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Hanken Grotesk"; font-weight: 100 900; font-display: swap;
  src: url(/assets/fonts/hanken-grotesk-latin-ext-wght-normal.woff2) format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }

:root {
  color-scheme: light;
  --bg: #f1f5f8;
  --surface: #ffffff;
  --surface-2: #e8eef3;
  --ink: #0e1b2c;
  --ink-2: #41546a;
  --ink-3: #5c6e83;
  --line: #d8e1e8;
  --line-strong: #bccad6;

  --brand: #0a7c8c;
  --brand-hover: #07616e;
  --brand-soft: #d9f0f3;
  --on-brand: #ffffff;
  --accent: #d1246b;
  --accent-soft: #fbe2ed;

  --ok: #11785a;      --ok-soft: #d9f2e8;
  --warn: #9a5b00;    --warn-soft: #fff0d3;
  --bad: #b8312b;     --bad-soft: #fce3e1;
  --info: var(--brand); --info-soft: var(--brand-soft);

  /* chart categorical (validated order, see docs) */
  --c1: #2a78d6; --c2: #eb6834; --c3: #1baf7a; --c4: #eda100; --c5: #e87ba4;
  --chart-bar: #0a7c8c; --chart-grid: #e1e8ee;

  --font-display: "Bricolage Grotesque", "Hanken Grotesk", system-ui, sans-serif;
  --font-ui: "Hanken Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;

  --r-sm: 6px; --r-md: 12px; --r-lg: 22px;
  --shadow-1: 0 1px 2px rgba(14, 27, 44, .06), 0 1px 1px rgba(14, 27, 44, .04);
  --shadow-2: 0 12px 32px -8px rgba(14, 27, 44, .18), 0 2px 6px rgba(14, 27, 44, .06);
  --ease: cubic-bezier(.2, .8, .2, 1);
  --sidebar-w: 248px;
}
/* Light is the default theme; dark is opt-in (data-theme="dark", toggled by the user). */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #09131e; --surface: #0f1e2f; --surface-2: #162a3f; --ink: #e8f0f6; --ink-2: #aabccd; --ink-3: #8a9db1;
  --line: #213447; --line-strong: #2f4760;
  --brand: #3cc3d3; --brand-hover: #6fd6e2; --brand-soft: #0f3742; --on-brand: #04202a;
  --accent: #ff6aa2; --accent-soft: #3d1426;
  --ok: #4cd0a0; --ok-soft: #0f3326; --warn: #f2b24d; --warn-soft: #3a2a0a; --bad: #ff8a84; --bad-soft: #3d1816;
  --c1: #3987e5; --c2: #d95926; --c3: #199e70; --c4: #c98500; --c5: #d55181;
  --chart-bar: #3cc3d3; --chart-grid: #1c3045;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .4); --shadow-2: 0 16px 40px -8px rgba(0, 0, 0, .6);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 15px/1.55 var(--font-ui); -webkit-font-smoothing: antialiased; }
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 650; letter-spacing: -.02em; line-height: 1.1; margin: 0; text-wrap: balance; }
p { margin: 0; text-wrap: pretty; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
img, svg { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 4px; }
::selection { background: var(--brand-soft); color: var(--ink); }
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.muted { color: var(--ink-3); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* ---- Buttons ---------------------------------------------------------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 16px; border-radius: var(--r-sm);
  border: 1px solid transparent; font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background .15s, border-color .15s, transform .08s; }
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: var(--on-brand); }
.btn-primary:hover { background: var(--brand-hover); }
.btn-secondary { background: var(--surface); border-color: var(--line-strong); color: var(--ink); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn-danger { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.btn-danger:hover { border-color: var(--bad); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; }
.btn-lg { height: 52px; padding: 0 26px; font-size: 16px; border-radius: 10px; }
.btn svg { width: 16px; height: 16px; flex: none; }
.icon-btn { width: 36px; height: 36px; padding: 0; }

/* ---- Forms ------------------------------------------------------------ */
.field { display: grid; gap: 6px; }
.field > label, .label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.input, .select, .textarea { width: 100%; height: 40px; padding: 0 12px; border-radius: var(--r-sm); border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink); transition: border-color .15s, box-shadow .15s; }
.textarea { height: auto; padding: 10px 12px; min-height: 84px; resize: vertical; }
.input::placeholder { color: var(--ink-3); opacity: .8; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--ink-3); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 25%, transparent); }
.hint { font-size: 12.5px; color: var(--ink-3); }
.form-grid { display: grid; gap: 16px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: 10px; font-size: 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--brand); }
.search { position: relative; }
.search svg { position: absolute; left: 12px; top: 50%; translate: 0 -50%; width: 16px; color: var(--ink-3); pointer-events: none; }
.search .input { padding-left: 36px; }

/* ---- Cards & layout ---------------------------------------------------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--shadow-1); }
.card-pad { padding: 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px 0; }
.card-head h3 { font-size: 16px; font-family: var(--font-ui); font-weight: 700; letter-spacing: -.01em; }
.stack { display: grid; gap: 16px; }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1 1 0; min-width: 0; }
.grid { display: grid; gap: 16px; }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.cols-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }

/* ---- Status & badges --------------------------------------------------- */
.badge { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 999px; font-size: 12.5px; font-weight: 650; white-space: nowrap; background: var(--surface-2); color: var(--ink-2); }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--brand-soft); color: var(--brand); }
.badge.plain::before { display: none; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 12px; border-radius: 999px; background: var(--surface-2); font-size: 13px; color: var(--ink-2); border: 1px solid transparent; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--brand-soft); color: var(--brand); border-color: var(--brand); font-weight: 650; }

/* ---- Tables ------------------------------------------------------------ */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-weight: 600; font-size: 12.5px; color: var(--ink-3); padding: 10px 16px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--surface); position: sticky; top: 0; }
.table td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr.clickable:hover { background: color-mix(in srgb, var(--brand) 6%, transparent); }
.table .right, .table th.right { text-align: right; }
.table .strong { font-weight: 650; }

/* ---- Tabs / segmented -------------------------------------------------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab { padding: 10px 14px; border: 0; background: none; font-weight: 600; color: var(--ink-3); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: var(--brand); border-bottom-color: var(--brand); }
.seg { display: inline-flex; padding: 3px; background: var(--surface-2); border-radius: 9px; gap: 2px; }
.seg button { border: 0; background: none; height: 30px; padding: 0 12px; border-radius: 7px; font-weight: 600; font-size: 13px; color: var(--ink-3); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }

/* ---- Overlays ---------------------------------------------------------- */
.overlay { position: fixed; inset: 0; background: rgba(8, 17, 28, .5); backdrop-filter: blur(2px); z-index: 80; display: grid; place-items: center; padding: 16px; animation: fade .18s var(--ease); }
.modal { width: min(560px, 100%); max-height: calc(100dvh - 32px); overflow: auto; background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-2); animation: pop .22s var(--ease); }
.modal.wide { width: min(860px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.modal-head h3 { font-size: 18px; }
.modal-body { padding: 22px; display: grid; gap: 16px; }
.modal-foot { padding: 14px 22px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }
.drawer-overlay { place-items: stretch end; padding: 0; }
.drawer { width: min(520px, 100%); height: 100%; overflow: auto; background: var(--surface); box-shadow: var(--shadow-2); animation: slide .26s var(--ease); }
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 100; display: grid; gap: 8px; }
.toast { background: var(--ink); color: var(--bg); padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow-2); font-weight: 600; font-size: 14px; animation: pop .22s var(--ease); max-width: 360px; }
.toast.bad { background: var(--bad); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
@keyframes slide { from { transform: translateX(32px); opacity: 0; } }
@keyframes spin { to { rotate: 360deg; } }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line-strong); border-top-color: var(--brand); animation: spin .7s linear infinite; }
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--line), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: 6px; min-height: 14px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---- Empty & KPI ------------------------------------------------------- */
.empty { display: grid; justify-items: center; gap: 10px; text-align: center; padding: 48px 24px; color: var(--ink-3); }
.empty svg { width: 56px; height: 56px; color: var(--line-strong); }
.empty h4 { font-family: var(--font-ui); font-size: 16px; color: var(--ink); font-weight: 700; }
.empty p { max-width: 44ch; }
.kpi { padding: 18px 20px; display: grid; gap: 4px; }
.kpi .k-label { font-size: 13px; font-weight: 600; color: var(--ink-3); }
.kpi .k-value { font-family: var(--font-display); font-size: 30px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi .k-foot { font-size: 12.5px; color: var(--ink-3); }
.delta { font-weight: 650; }
.delta.up { color: var(--ok); } .delta.down { color: var(--bad); }
.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--brand); border-radius: 99px; }
.progress.warn > i { background: var(--warn); } .progress.bad > i { background: var(--bad); }

/* ---- Signature: the tear-off ticket edge ------------------------------- */
.ticket { position: relative; background: var(--surface); --notch: 7px;
  -webkit-mask: radial-gradient(circle var(--notch) at 50% 100%, #0000 98%, #000) 50% / calc(var(--notch) * 3) 100% repeat-x,
                linear-gradient(#000, #000) 0 0 / 100% calc(100% - var(--notch)) no-repeat;
  mask: radial-gradient(circle var(--notch) at 50% 100%, #0000 98%, #000) 50% / calc(var(--notch) * 3) 100% repeat-x,
        linear-gradient(#000, #000) 0 0 / 100% calc(100% - var(--notch)) no-repeat; }
.perforation { height: 0; border-top: 2px dashed var(--line-strong); }

/* ---- Brand mark -------------------------------------------------------- */
.brand { display: inline-flex; align-items: center; gap: 10px; font-family: var(--font-display); font-weight: 750; font-size: 22px; letter-spacing: -.03em; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand svg { width: 30px; height: 30px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
@media (max-width: 760px) {
  .cols-2, .cols-3, .cols-4, .cols-main, .form-grid { grid-template-columns: 1fr; }
  .modal-body { padding: 16px; }
}
