/* Prodigi Shelf · shared product UI kit
   One light theme, restrained color, one type family, brand via --brand.
   Neutrals are mixed from --brand so a white-label re-tints the whole surface. */

:root {
  --brand: oklch(0.52 0.16 265);
  --brand-ink: #fff;
  --brand-hover: color-mix(in oklch, var(--brand) 88%, black);
  --brand-soft: color-mix(in oklch, var(--brand) 10%, white);
  --brand-soft-2: color-mix(in oklch, var(--brand) 18%, white);
  --brand-text: color-mix(in oklch, var(--brand) 85%, black);

  --bg: color-mix(in oklch, white 96.5%, var(--brand));
  --surface: #fff;
  --surface-2: color-mix(in oklch, white 94%, var(--brand));
  --surface-3: color-mix(in oklch, white 90%, var(--brand));
  --line: color-mix(in oklch, oklch(0.9 0 0) 85%, var(--brand));
  --line-2: color-mix(in oklch, oklch(0.82 0 0) 85%, var(--brand));

  --ink: oklch(0.21 0.012 265);
  --ink-2: oklch(0.40 0.015 265);
  --ink-3: oklch(0.52 0.012 265);
  --ink-4: oklch(0.66 0.01 265);

  --ok: oklch(0.58 0.15 152);      --ok-soft: oklch(0.95 0.04 152);     --ok-text: oklch(0.38 0.12 152);
  --warn: oklch(0.72 0.15 75);     --warn-soft: oklch(0.96 0.05 85);    --warn-text: oklch(0.45 0.12 70);
  --bad: oklch(0.58 0.19 25);      --bad-soft: oklch(0.95 0.035 25);    --bad-text: oklch(0.42 0.16 25);
  --info: oklch(0.58 0.13 240);    --info-soft: oklch(0.95 0.03 240);   --info-text: oklch(0.40 0.11 240);
  --neutral-soft: oklch(0.94 0.005 265);

  --r-control: 8px;
  --r-card: 12px;
  --r-pill: 999px;

  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 20px; --s-6: 24px; --s-8: 32px; --s-10: 40px; --s-12: 48px;

  --t-xs: 0.75rem; --t-sm: 0.8125rem; --t-base: 0.875rem; --t-md: 1rem; --t-lg: 1.125rem; --t-xl: 1.375rem; --t-2xl: 1.75rem; --t-3xl: 2.25rem;

  --sh-1: 0 1px 2px oklch(0 0 0 / 0.06), 0 1px 1px oklch(0 0 0 / 0.04);
  --sh-2: 0 4px 12px oklch(0 0 0 / 0.08), 0 1px 3px oklch(0 0 0 / 0.06);
  --sh-3: 0 16px 40px oklch(0 0 0 / 0.16), 0 4px 12px oklch(0 0 0 / 0.08);

  --z-dropdown: 10; --z-sticky: 20; --z-backdrop: 30; --z-drawer: 40; --z-toast: 50; --z-tooltip: 60;

  --sidebar-w: 236px;
  --topbar-h: 56px;
  --font: "Instrument Sans", "Noto Sans Khmer", system-ui, -apple-system, "Segoe UI", sans-serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --dur: 180ms;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--font); font-size: var(--t-base); line-height: 1.5;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; text-wrap: balance; }
h1 { font-size: var(--t-xl); }
h2 { font-size: var(--t-lg); }
h3 { font-size: var(--t-md); }
p { margin: 0; }
a { color: var(--brand-text); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img, svg { display: block; max-width: 100%; }
.num, td.num, .tabular { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-3); }
.small { font-size: var(--t-sm); }
.xs { font-size: var(--t-xs); }
.strong { font-weight: 600; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.mono { font-family: ui-monospace, "JetBrains Mono", Menlo, monospace; font-size: 0.92em; }
.hide { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.row { display: flex; align-items: center; gap: var(--s-2); }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.stack { display: flex; flex-direction: column; gap: var(--s-3); min-width: 0; }
.grow { flex: 1; min-width: 0; }
.gap-1 { gap: var(--s-1); } .gap-2 { gap: var(--s-2); } .gap-4 { gap: var(--s-4); } .gap-6 { gap: var(--s-6); }
.mt-2 { margin-top: var(--s-2); } .mt-4 { margin-top: var(--s-4); } .mt-6 { margin-top: var(--s-6); } .mb-4 { margin-bottom: var(--s-4); }
:focus-visible { outline: none; box-shadow: 0 0 0 3px color-mix(in oklch, var(--brand) 35%, white); border-radius: var(--r-control); }

/* ---------- App shell ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100dvh; }
.sidebar {
  background: var(--surface-2); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100dvh; overflow-y: auto;
  user-select: none;
}
.sidebar .brand { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-4) var(--s-4) var(--s-3); min-height: var(--topbar-h); }
.mark {
  width: 32px; height: 32px; border-radius: 9px; background: var(--brand); color: var(--brand-ink);
  display: grid; place-items: center; font-weight: 700; font-size: 15px; letter-spacing: 0; flex: none;
}
.mark img { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; }
.brand-name { font-weight: 650; font-size: var(--t-md); line-height: 1.2; letter-spacing: -0.01em; }
.brand-sub { font-size: var(--t-xs); color: var(--ink-3); }
.nav { padding: var(--s-2); display: flex; flex-direction: column; gap: 2px; }
.nav-h { font-size: var(--t-xs); color: var(--ink-3); padding: var(--s-3) var(--s-3) var(--s-1); font-weight: 600; }
.nav a {
  display: flex; align-items: center; gap: var(--s-3); padding: 8px 10px; border-radius: var(--r-control);
  color: var(--ink-2); font-weight: 500; text-decoration: none; min-height: 38px;
}
.nav a svg { width: 18px; height: 18px; color: var(--ink-3); flex: none; }
@media (hover:hover) { .nav a:hover { background: var(--surface-3); color: var(--ink); text-decoration: none; } }
.nav a.active { background: var(--surface); color: var(--brand-text); box-shadow: var(--sh-1); font-weight: 600; }
.nav a.active svg { color: var(--brand); }
.nav .count { margin-left: auto; font-size: var(--t-xs); background: var(--brand-soft); color: var(--brand-text); padding: 1px 7px; border-radius: var(--r-pill); font-weight: 600; }
.sidebar-foot { margin-top: auto; padding: var(--s-3) var(--s-4); border-top: 1px solid var(--line); font-size: var(--t-xs); color: var(--ink-3); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: var(--topbar-h); display: flex; align-items: center; gap: var(--s-3); padding: 0 var(--s-6);
  background: color-mix(in oklch, var(--bg) 85%, transparent); backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: var(--z-sticky); border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: var(--t-lg); }
.topbar .crumb { color: var(--ink-3); font-size: var(--t-sm); }
.topbar .spacer { flex: 1; }
.search { position: relative; }
.search input { padding-left: 34px; width: 240px; }
.search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--ink-3); pointer-events: none; }
.content { padding: var(--s-6); max-width: 1280px; width: 100%; min-width: 0; }
/* grid/flex children default to min-width:auto and grow to a table's intrinsic width; .table scrolls instead */
.grid-2 > *, .grid-3 > *, .grid-32 > *, .grid-23 > *, .stack > *, .card { min-width: 0; max-width: 100%; }
.page-h { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s-4); margin-bottom: var(--s-5); flex-wrap: wrap; }
.page-h h2 { font-size: var(--t-xl); }
.page-h .sub { color: var(--ink-3); margin-top: 2px; }
.section { margin-top: var(--s-8); }
.section-h { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s-3); margin-bottom: var(--s-3); }
.section-h h3 { font-size: var(--t-md); }
.section-h .more { font-size: var(--t-sm); }

.hamb { display: none; }
.tabbar { display: none; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 36px; padding: 0 14px; border-radius: var(--r-control); border: 1px solid var(--line-2);
  background: var(--surface); color: var(--ink); font-weight: 500; white-space: nowrap; user-select: none;
  transition: background var(--dur) var(--ease), transform 90ms var(--ease), box-shadow var(--dur) var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.btn svg { width: 16px; height: 16px; }
@media (hover:hover) { .btn:hover { background: var(--surface-2); } }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
@media (hover:hover) { .btn.primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); } }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
@media (hover:hover) { .btn.ghost:hover { background: var(--surface-3); color: var(--ink); } }
.btn.danger { color: var(--bad-text); border-color: color-mix(in oklch, var(--bad) 40%, white); }
@media (hover:hover) { .btn.danger:hover { background: var(--bad-soft); } }
.btn.small { min-height: 30px; padding: 0 10px; font-size: var(--t-sm); }
.btn.icon { padding: 0; width: 36px; }
.btn.icon.small { width: 30px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn.block { width: 100%; }

/* ---------- Forms ---------- */
input, select, textarea {
  width: 100%; min-height: 36px; padding: 6px 10px; border: 1px solid var(--line-2); border-radius: var(--r-control);
  background: var(--surface); color: var(--ink); font-size: var(--t-base);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
input::placeholder, textarea::placeholder { 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 oklch, var(--brand) 22%, white); }
input[type="color"] { padding: 2px; width: 44px; height: 36px; }
input[type="checkbox"], input[type="radio"] { width: 16px; height: 16px; min-height: 0; accent-color: var(--brand); }
textarea { min-height: 84px; resize: vertical; }
select { appearance: none; padding-right: 30px; background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23777' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='m6 9 6 6 6-6'/></svg>"); background-repeat: no-repeat; background-position: right 8px center; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field > label { font-size: var(--t-sm); font-weight: 500; color: var(--ink-2); }
.field .hint { font-size: var(--t-xs); color: var(--ink-3); }
.field .err { font-size: var(--t-xs); color: var(--bad-text); display: none; }
.field.invalid input, .field.invalid select { border-color: var(--bad); }
.field.invalid .err { display: block; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--s-4); }
.form-grid .full { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: var(--s-2); min-height: 36px; font-weight: 500; cursor: pointer; }
.segmented { display: inline-flex; background: var(--surface-3); padding: 3px; border-radius: var(--r-control); gap: 2px; max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.segmented button { flex: none; border: 0; background: transparent; padding: 5px 12px; border-radius: 6px; color: var(--ink-2); font-weight: 500; font-size: var(--t-sm); min-height: 30px; }
.segmented button.active { background: var(--surface); color: var(--ink); box-shadow: var(--sh-1); }
.switch { position: relative; width: 36px; height: 20px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; width: 100%; height: 100%; }
.switch span { position: absolute; inset: 0; background: var(--line-2); border-radius: var(--r-pill); transition: background var(--dur); }
.switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; background: #fff; border-radius: 50%; transition: transform var(--dur) var(--ease); box-shadow: var(--sh-1); }
.switch input:checked + span { background: var(--brand); }
.switch input:checked + span::after { transform: translateX(16px); }

/* ---------- Stats row (not the hero-metric template: quiet, in a ruled row) ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card); overflow: hidden; }
.stat { padding: var(--s-4) var(--s-5); border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stat:last-child { border-right: 0; }
.stat .label { font-size: var(--t-sm); color: var(--ink-3); }
.stat .value { font-size: var(--t-xl); font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat .value small { font-size: var(--t-sm); font-weight: 500; color: var(--ink-3); margin-left: 4px; letter-spacing: 0; }
.stat .delta { font-size: var(--t-xs); display: inline-flex; align-items: center; gap: 4px; margin-top: 2px; }
.stat .delta.up { color: var(--ok-text); } .stat .delta.down { color: var(--bad-text); } .stat .delta.flat { color: var(--ink-3); }
.stat svg.spark { margin-top: 6px; width: 100%; height: 28px; }

/* ---------- Cards / panels ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card); }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); padding: var(--s-4) var(--s-5); border-bottom: 1px solid var(--line); }
.card-h h3 { font-size: var(--t-base); font-weight: 600; }
.card-b { padding: var(--s-5); }
.card-b.tight { padding: 0; }
.card-f { padding: var(--s-3) var(--s-5); border-top: 1px solid var(--line); font-size: var(--t-sm); color: var(--ink-3); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-5); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s-5); }
.grid-32 { display: grid; grid-template-columns: 3fr 2fr; gap: var(--s-5); }
.grid-23 { display: grid; grid-template-columns: 2fr 3fr; gap: var(--s-5); }

/* ---------- Tables ---------- */
.table { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: var(--t-base); }
thead th { text-align: left; font-size: var(--t-xs); font-weight: 600; color: var(--ink-3); letter-spacing: 0.01em; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; white-space: nowrap; }
tbody td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; }
@media (hover:hover) { tbody tr.click:hover td { background: var(--surface-2); } }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td .sub { display: block; font-size: var(--t-xs); color: var(--ink-3); margin-top: 1px; }
.tfoot td { font-weight: 600; background: var(--surface-2); }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; opacity: 0.85; }
.table-tools { display: flex; align-items: center; gap: var(--s-2); padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.table-tools input { width: 220px; }
.table-tools .spacer { flex: 1; }

/* ---------- Badges / chips / avatars ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: var(--r-pill); font-size: var(--t-xs); font-weight: 600; white-space: nowrap; background: var(--neutral-soft); color: var(--ink-2); line-height: 1.5; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.8; }
.badge.ok { background: var(--ok-soft); color: var(--ok-text); }
.badge.warn { background: var(--warn-soft); color: var(--warn-text); }
.badge.bad { background: var(--bad-soft); color: var(--bad-text); }
.badge.info { background: var(--info-soft); color: var(--info-text); }
.badge.brand { background: var(--brand-soft); color: var(--brand-text); }
.badge.plain::before { display: none; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border: 1px solid var(--line-2); border-radius: var(--r-pill); font-size: var(--t-sm); background: var(--surface); }
.chip.active { border-color: var(--brand); background: var(--brand-soft); color: var(--brand-text); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--brand-soft-2); color: var(--brand-text); display: inline-grid; place-items: center; font-size: 12px; font-weight: 700; flex: none; user-select: none; }
.avatar.lg { width: 44px; height: 44px; font-size: 15px; }
.avatar.xl { width: 64px; height: 64px; font-size: 22px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--ink-4); }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--bad); } .dot.info { background: var(--info); } .dot.brand { background: var(--brand); }

/* ---------- Progress / meters ---------- */
.bar { height: 8px; background: var(--surface-3); border-radius: var(--r-pill); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--brand); border-radius: inherit; transition: width 400ms var(--ease); }
.bar.ok > i { background: var(--ok); } .bar.warn > i { background: var(--warn); } .bar.bad > i { background: var(--bad); }
.bar.thin { height: 5px; }
.meter { display: flex; flex-direction: column; gap: 6px; }
.meter .row { font-size: var(--t-sm); }

/* ---------- Lists ---------- */
.list { display: flex; flex-direction: column; }
.list-item { display: flex; align-items: center; flex-wrap: wrap; gap: var(--s-3); padding: 11px var(--s-5); border-bottom: 1px solid var(--line); min-height: 52px; }
.list-item > .grow { flex: 1 1 220px; }
.list-item:last-child { border-bottom: 0; }
.list-item.click { cursor: pointer; }
@media (hover:hover) { .list-item.click:hover { background: var(--surface-2); } }
.list-item .t { font-weight: 500; }
.list-item .d { font-size: var(--t-xs); color: var(--ink-3); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; font-size: var(--t-base); }
.kv dt { color: var(--ink-3); margin: 0; }
.kv dd { margin: 0; font-weight: 500; }
.timeline { display: flex; flex-direction: column; gap: 0; }
.tl { display: grid; grid-template-columns: 18px 1fr; gap: 12px; padding: 4px 0 14px; position: relative; }
.tl::before { content: ""; position: absolute; left: 8px; top: 20px; bottom: 0; width: 2px; background: var(--line); }
.tl:last-child::before { display: none; }
.tl .pt { width: 18px; height: 18px; border-radius: 50%; background: var(--surface); border: 2px solid var(--line-2); display: grid; place-items: center; margin-top: 2px; }
.tl .pt.ok { border-color: var(--ok); background: var(--ok); }
.tl .pt.brand { border-color: var(--brand); background: var(--brand); }
.tl .pt svg { width: 10px; height: 10px; color: #fff; }
.tl .when { font-size: var(--t-xs); color: var(--ink-3); }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: var(--s-5); overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 10px 14px; color: var(--ink-3); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; min-height: 40px; }
.tabs button.active { color: var(--ink); border-bottom-color: var(--brand); }
@media (hover:hover) { .tabs button:hover { color: var(--ink); } }

/* ---------- Empty state ---------- */
.empty { text-align: center; padding: var(--s-12) var(--s-6); color: var(--ink-3); }
.empty .glyph { width: 44px; height: 44px; border-radius: 12px; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; margin: 0 auto var(--s-4); }
.empty .glyph svg { width: 22px; height: 22px; }
.empty h3 { color: var(--ink); margin-bottom: 4px; }
.empty .btn { margin-top: var(--s-4); }

/* ---------- Drawer ---------- */
.backdrop { position: fixed; inset: 0; background: oklch(0.2 0.02 265 / 0.35); z-index: var(--z-backdrop); opacity: 0; pointer-events: none; transition: opacity 200ms var(--ease); }
.backdrop.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(480px, 100%); background: var(--surface); z-index: var(--z-drawer);
  box-shadow: var(--sh-3); display: flex; flex-direction: column; transform: translateX(100%); transition: transform 260ms var(--ease);
}
.drawer.wide { width: min(720px, 100%); }
.drawer.open { transform: translateX(0); }
.drawer-h { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); padding: var(--s-4) var(--s-5); border-bottom: 1px solid var(--line); }
.drawer-h h3 { font-size: var(--t-md); }
.drawer-b { padding: var(--s-5); overflow-y: auto; flex: 1; }
.drawer-f { display: flex; justify-content: flex-end; gap: var(--s-2); padding: var(--s-3) var(--s-5); border-top: 1px solid var(--line); background: var(--surface-2); }
.drawer-f .left { margin-right: auto; }

/* ---------- Confirm (inline dialog, never window.confirm) ---------- */
.dialog { position: fixed; inset: 0; z-index: var(--z-drawer); display: grid; place-items: center; padding: var(--s-4); pointer-events: none; }
.dialog .box { background: var(--surface); border-radius: var(--r-card); box-shadow: var(--sh-3); padding: var(--s-6); width: min(420px, 100%); transform: translateY(8px) scale(0.98); opacity: 0; transition: all 200ms var(--ease); pointer-events: none; visibility: hidden; }
.dialog.open .box { transform: none; opacity: 1; pointer-events: auto; visibility: visible; }
.dialog h3 { margin-bottom: 6px; }
.dialog p { color: var(--ink-2); }
.dialog .acts { display: flex; justify-content: flex-end; gap: var(--s-2); margin-top: var(--s-5); }

/* ---------- Toasts ---------- */
.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: var(--z-toast); display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: min(460px, calc(100% - 32px)); }
.toast { background: var(--ink); color: #fff; padding: 10px 14px; border-radius: 10px; box-shadow: var(--sh-3); font-size: var(--t-sm); display: flex; align-items: center; gap: 10px; animation: toast-in 240ms var(--ease); pointer-events: auto; max-width: 100%; }
.toast svg { width: 16px; height: 16px; flex: none; }
.toast.ok svg { color: oklch(0.8 0.15 152); } .toast.bad svg { color: oklch(0.75 0.18 25); } .toast.info svg { color: oklch(0.8 0.1 240); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Telegram preview ---------- */
.tg { background: #e7ebf0; border-radius: 14px; padding: 12px; font-size: var(--t-sm); max-width: 360px; }
.tg .tg-h { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; color: #1a1f24; }
.tg .tg-h .avatar { background: #2aabee; color: #fff; }
.tg .tg-h b { display: block; font-size: 13px; }
.tg .tg-h span { font-size: 11px; color: #5a6470; }
.tg .bubble { background: #fff; border-radius: 12px 12px 12px 4px; padding: 8px 10px; color: #1a1f24; white-space: pre-line; line-height: 1.45; box-shadow: 0 1px 1px rgba(0,0,0,0.06); }
.tg .bubble .time { display: block; text-align: right; font-size: 10px; color: #8a949e; margin-top: 2px; }
.tg .bubble a { color: #2481cc; }

/* ---------- KHQR card ---------- */
.khqr { background: #fff; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; width: 240px; box-shadow: var(--sh-1); }
.khqr .head { background: #e1232e; color: #fff; padding: 10px 14px; font-weight: 800; letter-spacing: 0.06em; font-size: 14px; }
.khqr .body { padding: 12px 14px 6px; }
.khqr .who { font-weight: 600; font-size: 13px; }
.khqr .amt { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; margin: 2px 0 8px; }
.khqr svg { width: 100%; height: auto; }
.khqr .foot { padding: 6px 14px 12px; font-size: 10px; color: var(--ink-3); display: flex; justify-content: space-between; }
.stamp { display: inline-block; border: 2px solid var(--bad); color: var(--bad-text); font-weight: 800; font-size: 11px; letter-spacing: 0.12em; padding: 2px 8px; border-radius: 4px; transform: rotate(-6deg); text-transform: uppercase; }

/* ---------- Splash / login ---------- */
.splash { min-height: 100dvh; display: grid; grid-template-columns: 1.1fr 1fr; }
.splash .pane { background: var(--brand); color: var(--brand-ink); padding: var(--s-12); display: flex; flex-direction: column; justify-content: space-between; }
.splash .pane .mark { background: rgba(255,255,255,0.18); color: #fff; width: 44px; height: 44px; font-size: 19px; border-radius: 12px; }
.splash .pane h1 { font-size: clamp(1.75rem, 3.5vw, 2.75rem); line-height: 1.12; letter-spacing: -0.02em; max-width: 18ch; }
.splash .pane p { opacity: 0.85; max-width: 46ch; margin-top: var(--s-3); font-size: var(--t-md); }
.splash .pane .foot { font-size: var(--t-sm); opacity: 0.75; }
.splash .points { display: flex; flex-direction: column; gap: 10px; margin-top: var(--s-8); font-size: var(--t-md); }
.splash .points li { display: flex; gap: 10px; align-items: flex-start; list-style: none; }
.splash .points svg { width: 18px; height: 18px; flex: none; margin-top: 3px; opacity: 0.9; }
.splash .points ul { margin: 0; padding: 0; }
.splash .form { display: grid; place-items: center; padding: var(--s-8); }
.splash .form > div { width: min(360px, 100%); }
.splash .form h2 { font-size: var(--t-xl); margin-bottom: 4px; }
.splash .roles { display: grid; gap: 8px; margin: var(--s-5) 0; }
.splash .roles button { text-align: left; display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--line-2); background: var(--surface); border-radius: var(--r-control); min-height: 56px; }
.splash .roles button b { display: block; }
.splash .roles button small { color: var(--ink-3); }
@media (hover:hover) { .splash .roles button:hover { border-color: var(--brand); background: var(--brand-soft); } }
.splash .form h2 + p { margin-bottom: var(--s-3); }
.auth { display: grid; gap: 8px; margin-bottom: var(--s-2); }
.auth button { text-align: left; display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--line-2); background: var(--surface); border-radius: var(--r-control); min-height: 56px; position: relative; }
.auth button .g { width: 34px; height: 34px; border-radius: 9px; background: var(--surface-2); display: grid; place-items: center; flex: none; }
.auth button .g svg { width: 18px; height: 18px; }
.auth button b { display: block; }
.auth button small { color: var(--ink-3); display: block; }
.auth button.primary { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.auth button .badge { margin-left: auto; }
@media (hover:hover) { .auth button:hover { border-color: var(--brand); background: var(--brand-soft); } }
@media (max-width: 560px) { .auth button .badge { display: none; } }

/* ---------- Brand panel ---------- */
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0; }
.swatch.active { border-color: var(--ink); box-shadow: 0 0 0 2px #fff inset; }
.presets { display: grid; gap: 8px; }
.preset { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--r-control); background: var(--surface); text-align: left; min-height: 48px; }
.preset .mark { width: 26px; height: 26px; font-size: 12px; border-radius: 7px; }
@media (hover:hover) { .preset:hover { background: var(--surface-2); } }

/* ---------- Dropdown menu ---------- */
.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card); box-shadow: var(--sh-2); min-width: 220px; padding: 6px; z-index: var(--z-dropdown); display: none; }
.menu.open { display: block; }
.menu button, .menu a { display: flex; width: 100%; align-items: center; gap: 10px; padding: 8px 10px; border: 0; background: none; border-radius: 6px; text-align: left; color: var(--ink); min-height: 36px; }
@media (hover:hover) { .menu button:hover, .menu a:hover { background: var(--surface-2); text-decoration: none; } }
.menu .sep { height: 1px; background: var(--line); margin: 6px 0; }
.menu .lbl { font-size: var(--t-xs); color: var(--ink-3); padding: 6px 10px 2px; font-weight: 600; }
.menu button.active { color: var(--brand-text); font-weight: 600; }

/* ---------- Calendar / schedule grid ---------- */
.week { display: grid; grid-template-columns: 60px repeat(5, 1fr); border: 1px solid var(--line); border-radius: var(--r-card); overflow: hidden; background: var(--surface); font-size: var(--t-sm); }
.week .hd { padding: 8px; background: var(--surface-2); font-weight: 600; text-align: center; border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); }
.week .cell { min-height: 56px; border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); padding: 4px; }
.week .time { padding: 8px 6px; color: var(--ink-3); font-size: var(--t-xs); text-align: right; border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); background: var(--surface-2); }
.week .ev { background: var(--brand-soft); color: var(--brand-text); border-radius: 6px; padding: 4px 6px; font-size: var(--t-xs); font-weight: 600; line-height: 1.3; }
.week .ev small { display: block; font-weight: 400; color: var(--ink-2); }
.heat { display: grid; grid-template-columns: repeat(auto-fill, minmax(26px, 1fr)); gap: 3px; }
.heat i { aspect-ratio: 1; border-radius: 4px; background: var(--surface-3); display: block; }
.heat i.p { background: var(--ok); } .heat i.a { background: var(--bad); } .heat i.l { background: var(--warn); } .heat i.h { background: var(--line-2); }

/* ---------- Kanban ---------- */
.kanban { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(240px, 1fr); gap: var(--s-4); overflow-x: auto; padding-bottom: var(--s-2); }
.col { background: var(--surface-2); border-radius: var(--r-card); padding: var(--s-3); display: flex; flex-direction: column; gap: 8px; min-height: 200px; }
.col-h { display: flex; justify-content: space-between; align-items: center; font-size: var(--t-sm); font-weight: 600; padding: 2px 4px 6px; color: var(--ink-2); }
.kcard { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; cursor: pointer; box-shadow: var(--sh-1); }
@media (hover:hover) { .kcard:hover { border-color: var(--line-2); box-shadow: var(--sh-2); } }
.kcard .t { font-weight: 500; line-height: 1.35; }
.kcard .m { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: var(--t-xs); color: var(--ink-3); }

/* ---------- Print (report cards, invoices, reports) ---------- */
.doc { background: #fff; border: 1px solid var(--line); border-radius: var(--r-card); padding: var(--s-8); max-width: 800px; }
.doc-h { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--s-6); padding-bottom: var(--s-5); border-bottom: 2px solid var(--ink); margin-bottom: var(--s-5); }
.doc-h .mark { width: 40px; height: 40px; font-size: 18px; }
.doc h2 { font-size: var(--t-xl); }
.doc table td, .doc table th { padding: 8px 10px; }
@media print {
  .sidebar, .topbar, .tabbar, .no-print, .toasts, .drawer, .backdrop { display: none !important; }
  .app { display: block; }
  .content { padding: 0; max-width: none; }
  .doc { border: 0; padding: 0; max-width: none; }
  body { background: #fff; }
}

/* ---------- Responsive ---------- */
@media (max-width: 1024px) {
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .grid-32, .grid-23 { grid-template-columns: 1fr; }
  .search input { width: 180px; }
}
@media (max-width: 768px) {
  :root { --sidebar-w: 260px; }
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: var(--sidebar-w); z-index: var(--z-drawer); transform: translateX(-100%); transition: transform 240ms var(--ease); border-right: 1px solid var(--line); }
  .sidebar.open { transform: none; }
  .hamb { display: inline-flex; }
  .topbar { padding: 0 var(--s-4); gap: var(--s-2); }
  .topbar h1 { font-size: var(--t-md); }
  .search input { width: 40px; padding-left: 34px; }
  .search input:focus { width: 180px; }
  .content { padding: var(--s-4) var(--s-4) 88px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  input, select, textarea { font-size: 16px; }
  .stats { grid-template-columns: 1fr 1fr; }
  .stat { border-bottom: 1px solid var(--line); }
  .stat:nth-child(2n) { border-right: 0; }
  .stat:nth-last-child(-n+2) { border-bottom: 0; }
  .splash { grid-template-columns: 1fr; }
  .splash .pane { padding: var(--s-8) var(--s-6); min-height: 40dvh; }
  .tabbar { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; background: var(--surface); border-top: 1px solid var(--line); z-index: var(--z-sticky); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
  .tabbar a, .tabbar button { display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 10.5px; color: var(--ink-3); text-decoration: none; border: 0; background: none; padding: 4px 0; min-height: 44px; font-weight: 500; }
  .tabbar a svg, .tabbar button svg { width: 20px; height: 20px; }
  .tabbar a.active { color: var(--brand-text); }
  .tabbar a.active svg { color: var(--brand); }
  .doc { padding: var(--s-5); }
  .kanban { grid-auto-columns: minmax(78vw, 1fr); }
  .drawer-f { flex-wrap: wrap; }
  .page-h .btn:not(.primary) span.lbl { display: none; }
  .list-item { padding-left: var(--s-4); padding-right: var(--s-4); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 1ms !important; animation-duration: 1ms !important; }
}
