/* =====================================================================
   NexGen Finance design system
   Ink indigo + ember orange from the NexGen logo. Light & dark themes.
   Components are plain CSS classes so they theme automatically; Tailwind
   (static/css/tailwind.css) is used for layout utilities only.
   ===================================================================== */

@font-face { font-family: "Inter"; font-weight: 400; font-display: swap; src: url("../fonts/Inter-Regular.woff") format("woff"); }
@font-face { font-family: "Inter"; font-weight: 500; font-display: swap; src: url("../fonts/Inter-Medium.woff") format("woff"); }
@font-face { font-family: "Inter"; font-weight: 600; font-display: swap; src: url("../fonts/Inter-SemiBold.woff") format("woff"); }
@font-face { font-family: "Inter"; font-weight: 700; font-display: swap; src: url("../fonts/Inter-Bold.woff") format("woff"); }
@font-face { font-family: "Inter Display"; font-weight: 600; font-display: swap; src: url("../fonts/InterDisplay-SemiBold.woff") format("woff"); }

:root {
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "Inter Display", "Inter", system-ui, sans-serif;

  /* brand */
  --ink: #1e1b4b;
  --ink-2: #2e2a6e;
  --ember: #ea580c;
  --ember-hover: #c2410c;
  --ember-soft: #fff1e6;

  /* surfaces */
  --bg: #f4f5fa;
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --surface-3: #eef0f6;
  --border: #e3e6ef;
  --border-strong: #cfd4e2;

  /* text */
  --text: #161a2e;
  --text-2: #475069;
  --text-3: #7a8199;
  --text-inverse: #ffffff;

  /* semantic */
  --in: #0f8a5f;  --in-soft: #e5f6ef;
  --out: #c2413a; --out-soft: #fdecea;
  --wait: #b45309; --wait-soft: #fef3e2;
  --info: #4338ca; --info-soft: #eceafe;

  --focus: 0 0 0 3px rgba(234, 88, 12, .28);
  --shadow-1: 0 1px 2px rgba(22, 26, 46, .05);
  --shadow-2: 0 10px 30px -12px rgba(22, 26, 46, .22);
  --shadow-3: 0 24px 60px -20px rgba(22, 26, 46, .35);

  --radius-s: 6px;
  --radius: 10px;
  --radius-l: 14px;

  --sidebar-w: 248px;
  --sidebar-w-collapsed: 72px;
  --topbar-h: 60px;
  --sidebar-bg: #1b1945;
  --sidebar-text: #c8c6ec;
  --sidebar-muted: #8784b8;
  --sidebar-hover: rgba(255, 255, 255, .06);
  --sidebar-active: rgba(255, 255, 255, .1);
  color-scheme: light;
}

html.dark {
  --bg: #0e0f1d;
  --surface: #161829;
  --surface-2: #1b1d31;
  --surface-3: #23263d;
  --border: #2a2d46;
  --border-strong: #383c5c;
  --text: #ecedf7;
  --text-2: #b4b8d3;
  --text-3: #858aa8;
  --ember-soft: rgba(234, 88, 12, .14);
  --in: #34c48f;  --in-soft: rgba(52, 196, 143, .13);
  --out: #f2776f; --out-soft: rgba(242, 119, 111, .13);
  --wait: #f2b257; --wait-soft: rgba(242, 178, 87, .13);
  --info: #a5a0ff; --info-soft: rgba(165, 160, 255, .13);
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-2: 0 12px 30px -12px rgba(0, 0, 0, .6);
  --shadow-3: 0 24px 60px -20px rgba(0, 0, 0, .7);
  --sidebar-bg: #11122a;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: 14px; line-height: 1.5;
  color: var(--text); background: var(--bg);
  font-feature-settings: "cv11" 1, "ss01" 1;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
::selection { background: rgba(234, 88, 12, .22); }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 4px; }
[hidden] { display: none !important; }
.num, .amt { font-variant-numeric: tabular-nums; white-space: nowrap; }
.amt .cur { color: var(--text-3); font-weight: 500; margin-right: .12em; }
.mono { font-variant-numeric: tabular-nums; letter-spacing: .005em; }
.muted { color: var(--text-3); }
.text-2 { color: var(--text-2); }
.c-in { color: var(--in); } .c-out { color: var(--out); } .c-wait { color: var(--wait); } .c-info { color: var(--info); } .c-ember { color: var(--ember); }
.truncate-1 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------------------------------------------------------------- Shell */
.app { display: flex; min-height: 100vh; min-height: 100dvh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 40; width: var(--sidebar-w);
  background: var(--sidebar-bg); color: var(--sidebar-text);
  display: flex; flex-direction: column; transition: width .2s ease, transform .22s ease;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; height: var(--topbar-h); padding: 0 14px 0 16px; flex-shrink: 0; }
.sidebar-brand .mark { width: 36px; height: 36px; border-radius: 9px; background: #fff; display: grid; place-items: center; flex-shrink: 0; overflow: hidden; }
.sidebar-brand .mark img { width: 30px; height: 30px; object-fit: contain; }
.sidebar-brand .word { line-height: 1.15; min-width: 0; }
.sidebar-brand .word b { display: block; color: #fff; font: 600 15px var(--font-display); letter-spacing: -.01em; }
.sidebar-brand .word span { font-size: 11.5px; color: var(--sidebar-muted); }
.sidebar-collapse { margin-left: auto; width: 30px; height: 30px; border-radius: 8px; border: 0; background: transparent; color: var(--sidebar-muted); cursor: pointer; display: grid; place-items: center; flex-shrink: 0; }
.sidebar-collapse:hover { background: var(--sidebar-hover); color: #fff; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 6px 10px 12px; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.15) transparent; }
.nav-group { margin-top: 14px; }
.nav-group-title { padding: 0 10px 6px; font-size: 11.5px; font-weight: 500; color: var(--sidebar-muted); white-space: nowrap; }
.nav-link {
  position: relative; display: flex; align-items: center; gap: 12px; height: 40px; padding: 0 10px; border-radius: 9px;
  color: var(--sidebar-text); text-decoration: none; font-weight: 500; font-size: 13.5px; white-space: nowrap; cursor: pointer;
}
.nav-link i { width: 20px; text-align: center; font-size: 15px; color: var(--sidebar-muted); flex-shrink: 0; }
.nav-link:hover { background: var(--sidebar-hover); color: #fff; }
.nav-link:hover i { color: #fff; }
.nav-link.active { background: var(--sidebar-active); color: #fff; }
.nav-link.active i { color: var(--ember); }
.nav-link.active::before { content: ""; position: absolute; left: -10px; top: 9px; bottom: 9px; width: 3px; border-radius: 0 3px 3px 0; background: var(--ember); }
.nav-link .count { margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--ember); color: #fff; font-size: 11px; font-weight: 600; display: grid; place-items: center; }
.sidebar-user { border-top: 1px solid rgba(255,255,255,.07); padding: 12px; display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 600; font-size: 12.5px; color: #fff; background: var(--ember); flex-shrink: 0; }
.avatar.alt { background: #5b54d6; }
.sidebar-user .who { min-width: 0; line-height: 1.25; flex: 1; }
.sidebar-user .who b { display: block; color: #fff; font-size: 13px; font-weight: 600; }
.sidebar-user .who span { font-size: 11.5px; color: var(--sidebar-muted); }
.sidebar-user .icon-btn { color: var(--sidebar-muted); }
.sidebar-user .icon-btn:hover { color: #fff; background: var(--sidebar-hover); }

.main { flex: 1; min-width: 0; margin-left: var(--sidebar-w); transition: margin-left .2s ease; display: flex; flex-direction: column; }
html.sb-collapsed .sidebar { width: var(--sidebar-w-collapsed); }
html.sb-collapsed .main { margin-left: var(--sidebar-w-collapsed); }
html.sb-collapsed .sidebar .word, html.sb-collapsed .sidebar .nav-link span, html.sb-collapsed .sidebar .nav-group-title,
html.sb-collapsed .sidebar-user .who, html.sb-collapsed .sidebar-user .icon-btn { display: none; }
html.sb-collapsed .sidebar-brand { padding: 0 18px; flex-direction: column; justify-content: center; gap: 4px; height: auto; padding-top: 12px; padding-bottom: 6px; }
html.sb-collapsed .sidebar-collapse { margin: 0; transform: rotate(180deg); }
html.sb-collapsed .nav-link { justify-content: center; padding: 0; }
html.sb-collapsed .nav-link .count { position: absolute; top: 2px; right: 6px; min-width: 16px; height: 16px; font-size: 10px; padding: 0 4px; }
html.sb-collapsed .nav-group { margin-top: 8px; padding-top: 8px; border-top: 1px solid rgba(255,255,255,.06); }
html.sb-collapsed .sidebar-user { justify-content: center; }

.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--topbar-h); display: flex; align-items: center; gap: 12px;
  padding: 0 24px; background: color-mix(in srgb, var(--bg) 86%, transparent); backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { margin: 0; font: 600 19px/1.2 var(--font-display); letter-spacing: -.015em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .spacer { flex: 1; }
.topbar .menu-btn { display: none; }
.content { padding: 24px; width: 100%; max-width: 1480px; margin: 0 auto; flex: 1; }

.bottom-nav { display: none; }
.scrim { position: fixed; inset: 0; background: rgba(10, 10, 30, .45); z-index: 35; opacity: 0; pointer-events: none; transition: opacity .2s; }
.scrim.show { opacity: 1; pointer-events: auto; }

@media (max-width: 1023px) {
  .sidebar { transform: translateX(-100%); width: 280px !important; box-shadow: var(--shadow-3); }
  html.sb-open .sidebar { transform: none; }
  html.sb-collapsed .sidebar .word, html.sb-collapsed .sidebar .nav-link span, html.sb-collapsed .sidebar .nav-group-title,
  html.sb-collapsed .sidebar-user .who, html.sb-collapsed .sidebar-user .icon-btn { display: revert; }
  html.sb-collapsed .nav-link { justify-content: flex-start; padding: 0 10px; }
  .sidebar-collapse { display: none; }
  .main, html.sb-collapsed .main { margin-left: 0; }
  .topbar .menu-btn { display: grid; }
  .topbar { padding: 0 14px; }
  .content { padding: 16px 14px calc(84px + env(safe-area-inset-bottom)); }
  .bottom-nav {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; inset: auto 0 0 0; z-index: 30;
    background: var(--surface); border-top: 1px solid var(--border); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    box-shadow: 0 -6px 20px -12px rgba(0,0,0,.2);
  }
  .bottom-nav a { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 4px 0; color: var(--text-3); text-decoration: none; font-size: 10.5px; font-weight: 500; position: relative; }
  .bottom-nav a i { font-size: 17px; }
  .bottom-nav a.active { color: var(--ember); }
  .bottom-nav a .dot { position: absolute; top: 0; right: calc(50% - 18px); min-width: 16px; height: 16px; border-radius: 8px; background: var(--ember); color: #fff; font-size: 9.5px; font-weight: 600; display: grid; place-items: center; padding: 0 4px; }
  .hide-mobile { display: none !important; }
}
@media (min-width: 1024px) { .show-mobile { display: none !important; } }

/* ---------------------------------------------------------------- Buttons */
.btn {
  --b-bg: var(--surface); --b-fg: var(--text); --b-bd: var(--border-strong);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 38px; padding: 0 14px;
  border-radius: var(--radius-s); border: 1px solid var(--b-bd); background: var(--b-bg); color: var(--b-fg);
  font: 500 13.5px var(--font); text-decoration: none; cursor: pointer; white-space: nowrap; user-select: none;
  transition: background .12s, border-color .12s, color .12s, box-shadow .12s;
}
.btn:hover { background: var(--surface-3); }
.btn:disabled, .btn.disabled { opacity: .5; pointer-events: none; }
.btn i { font-size: .95em; }
.btn-primary { --b-bg: var(--ember); --b-fg: #fff; --b-bd: var(--ember); box-shadow: 0 1px 0 rgba(255,255,255,.2) inset, 0 1px 2px rgba(194, 65, 12, .35); }
.btn-primary:hover { background: var(--ember-hover); border-color: var(--ember-hover); }
.btn-ink { --b-bg: var(--ink); --b-fg: #fff; --b-bd: var(--ink); }
html.dark .btn-ink { --b-bg: #3a3690; --b-bd: #3a3690; }
.btn-ink:hover { background: var(--ink-2); }
.btn-success { --b-bg: var(--in); --b-fg: #fff; --b-bd: var(--in); }
.btn-success:hover { filter: brightness(.95); background: var(--in); }
.btn-danger { --b-bg: var(--surface); --b-fg: var(--out); --b-bd: color-mix(in srgb, var(--out) 40%, var(--border)); }
.btn-danger:hover { background: var(--out-soft); }
.btn-ghost { --b-bg: transparent; --b-bd: transparent; --b-fg: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }
.btn-sm { height: 32px; padding: 0 10px; font-size: 12.5px; gap: 6px; }
.btn-lg { height: 44px; padding: 0 18px; font-size: 14.5px; }
.btn-block { width: 100%; }
.icon-btn { width: 36px; height: 36px; padding: 0; border-radius: 8px; border: 0; background: transparent; color: var(--text-2); cursor: pointer; display: grid; place-items: center; font-size: 15px; flex-shrink: 0; position: relative; }
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn .badge-dot { position: absolute; top: 5px; right: 5px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; background: var(--ember); color: #fff; font-size: 10px; font-weight: 600; display: grid; place-items: center; }
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: var(--radius-s) 0 0 var(--radius-s); margin-left: 0; }
.btn-group .btn:last-child { border-radius: 0 var(--radius-s) var(--radius-s) 0; }

/* ---------------------------------------------------------------- Forms */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.label { font-size: 12.5px; font-weight: 500; color: var(--text-2); }
.label .req { color: var(--ember); }
.hint { font-size: 12px; color: var(--text-3); }
.input, .select, .textarea {
  width: 100%; height: 38px; padding: 0 11px; border-radius: var(--radius-s); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font: 400 14px var(--font); transition: border-color .12s, box-shadow .12s;
}
.textarea { height: auto; min-height: 72px; padding: 9px 11px; resize: vertical; line-height: 1.45; }
.select { appearance: none; padding-right: 32px; background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%), linear-gradient(135deg, var(--text-3) 50%, transparent 50%); background-position: calc(100% - 15px) 16px, calc(100% - 10px) 16px; background-size: 5px 5px; background-repeat: no-repeat; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--text-3); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--ember); box-shadow: var(--focus); }
.input[readonly] { background: var(--surface-2); color: var(--text-2); }
.input.sm, .select.sm { height: 32px; font-size: 13px; }
.input.num { text-align: right; font-variant-numeric: tabular-nums; }
.input-group { display: flex; align-items: stretch; }
.input-group .input { border-radius: var(--radius-s) 0 0 var(--radius-s); }
.input-group .addon { display: grid; place-items: center; padding: 0 10px; border: 1px solid var(--border-strong); border-left: 0; border-radius: 0 var(--radius-s) var(--radius-s) 0; background: var(--surface-2); color: var(--text-3); font-size: 13px; }
.input-group .addon.pre { border-left: 1px solid var(--border-strong); border-right: 0; border-radius: var(--radius-s) 0 0 var(--radius-s); }
.input-group .addon.pre + .input { border-radius: 0 var(--radius-s) var(--radius-s) 0; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--ember); width: 16px; height: 16px; }
input[type="date"]::-webkit-calendar-picker-indicator { opacity: .6; cursor: pointer; }
html.dark input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(1); }

.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: 13.5px; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track { width: 36px; height: 20px; border-radius: 10px; background: var(--border-strong); position: relative; transition: background .15s; flex-shrink: 0; }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .15s; }
.switch input:checked + .track { background: var(--ember); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { box-shadow: var(--focus); }

.segmented { display: inline-flex; padding: 3px; gap: 2px; border-radius: 9px; background: var(--surface-3); }
.segmented button, .segmented a { border: 0; background: transparent; color: var(--text-2); font: 500 13px var(--font); height: 30px; padding: 0 12px; border-radius: 7px; cursor: pointer; white-space: nowrap; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.segmented button.on, .segmented a.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1); }
.segmented.scroll { max-width: 100%; overflow-x: auto; scrollbar-width: none; }

/* ---------------------------------------------------------------- Surfaces */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-l); box-shadow: var(--shadow-1); }
.card-pad { padding: 20px; }
.card-head { display: flex; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.card-head h2, .card-head h3 { margin: 0; font-size: 15px; font-weight: 600; }
.card-head .sub { font-size: 12.5px; color: var(--text-3); }
.card-foot { padding: 12px 20px; border-top: 1px solid var(--border); }
.section-title { margin: 0 0 12px; font-size: 15px; font-weight: 600; }
.panel { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.divider { height: 1px; background: var(--border); margin: 16px 0; }

.page-head { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .lead { flex: 1; min-width: 220px; }
.page-head .lead p { margin: 2px 0 0; color: var(--text-3); font-size: 13px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* KPI */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.kpi { padding: 16px 18px; position: relative; }
.kpi .k-label { font-size: 12.5px; color: var(--text-3); font-weight: 500; display: flex; align-items: center; gap: 8px; }
.kpi .k-value { margin-top: 6px; font: 600 25px/1.15 var(--font-display); letter-spacing: -.02em; font-variant-numeric: tabular-nums; white-space: nowrap; }
.kpi .k-value .cur { font-size: .62em; color: var(--text-3); font-weight: 500; margin-right: 2px; vertical-align: .18em; }
.kpi .k-foot { margin-top: 8px; font-size: 12px; color: var(--text-3); display: flex; gap: 10px; flex-wrap: wrap; }
.kpi .k-foot b { font-weight: 600; color: var(--text-2); }
.kpi .k-ico { width: 26px; height: 26px; border-radius: 7px; display: grid; place-items: center; font-size: 12px; }
.kpi.hero { background: var(--ink); color: #fff; border-color: var(--ink); }
html.dark .kpi.hero { background: #23205a; border-color: #2f2b74; }
.kpi.hero .k-label, .kpi.hero .k-foot { color: #b9b6e6; }
.kpi.hero .k-foot b { color: #fff; }
.kpi.hero .k-value .cur { color: #b9b6e6; }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 9px; border-radius: 11px; font-size: 11.5px; font-weight: 600; white-space: nowrap; background: var(--surface-3); color: var(--text-2); }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
.badge.plain::before { display: none; }
.badge.in { background: var(--in-soft); color: var(--in); }
.badge.out { background: var(--out-soft); color: var(--out); }
.badge.wait { background: var(--wait-soft); color: var(--wait); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.ember { background: var(--ember-soft); color: var(--ember); }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px; border-radius: 13px; border: 1px solid var(--border); background: var(--surface); font-size: 12px; color: var(--text-2); }

/* Tables */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
table.data th { text-align: left; font-weight: 500; font-size: 12px; color: var(--text-3); padding: 10px 14px; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; position: sticky; top: 0; z-index: 1; }
table.data td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr.clickable { cursor: pointer; }
table.data tbody tr.clickable:hover td { background: var(--surface-2); }
table.data tbody tr.selected td { background: var(--ember-soft); }
table.data .r { text-align: right; }
table.data .c { text-align: center; }
table.data .w-check { width: 44px; }
table.data .primary-cell { font-weight: 600; color: var(--text); }
table.data .sub-cell { font-size: 12px; color: var(--text-3); margin-top: 1px; }
table.data tfoot td { font-weight: 600; background: var(--surface-2); border-top: 1px solid var(--border); border-bottom: 0; }

/* Mobile: tables become stacked cards */
@media (max-width: 767px) {
  table.data.stack thead { display: none; }
  table.data.stack, table.data.stack tbody, table.data.stack tr, table.data.stack td { display: block; width: 100%; }
  table.data.stack tr { border-bottom: 1px solid var(--border); padding: 12px 14px; position: relative; }
  table.data.stack tbody tr:last-child { border-bottom: 0; }
  table.data.stack td { border: 0; padding: 2px 0; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
  table.data.stack td[data-label]::before { content: attr(data-label); color: var(--text-3); font-size: 12px; text-align: left; flex-shrink: 0; }
  table.data.stack td.lead-cell { display: block; text-align: left; padding-bottom: 4px; padding-right: 30px; }
  table.data.stack td.lead-cell::before { display: none; }
  table.data.stack td.w-check { position: absolute; right: 12px; top: 12px; width: auto; padding: 0; }
  table.data.stack td.hide-sm { display: none; }
  table.data.stack tfoot { display: block; }
}

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.search { position: relative; flex: 1; min-width: 180px; max-width: 360px; }
.search i { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text-3); font-size: 13px; }
.search .input { padding-left: 32px; }
.bulkbar { display: flex; align-items: center; gap: 10px; padding: 8px 14px; background: var(--ember-soft); border-bottom: 1px solid var(--border); font-size: 13px; font-weight: 500; }

.empty { text-align: center; padding: 48px 20px; color: var(--text-3); }
.empty .ico { width: 52px; height: 52px; border-radius: 14px; background: var(--surface-3); display: grid; place-items: center; margin: 0 auto 12px; font-size: 20px; color: var(--text-3); }
.empty h4 { margin: 0 0 4px; color: var(--text); font-size: 15px; font-weight: 600; }
.empty p { margin: 0 auto 14px; max-width: 360px; font-size: 13px; }

.skeleton { position: relative; overflow: hidden; background: var(--surface-3); border-radius: 6px; min-height: 14px; }
.skeleton::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%); background: linear-gradient(90deg, transparent, rgba(255,255,255,.35), transparent); animation: shimmer 1.3s infinite; }
html.dark .skeleton::after { background: linear-gradient(90deg, transparent, rgba(255,255,255,.06), transparent); }
@keyframes shimmer { to { transform: translateX(100%); } }

/* Description lists */
.dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 13.5px; margin: 0; }
.dl dt { color: var(--text-3); }
.dl dd { margin: 0; font-weight: 500; min-width: 0; overflow-wrap: anywhere; }
.sum-row { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; font-size: 13.5px; }
.sum-row .v { font-variant-numeric: tabular-nums; white-space: nowrap; }
.sum-row.total { margin-top: 6px; padding-top: 10px; border-top: 1px solid var(--border); font-size: 16px; font-weight: 700; }
.sum-row.muted { color: var(--text-3); }

/* ---------------------------------------------------------------- Overlays */
.modal-root { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-root .backdrop { position: absolute; inset: 0; background: rgba(10, 10, 30, .5); animation: fade .15s ease; }
.modal {
  position: relative; width: 100%; max-width: 560px; max-height: calc(100dvh - 40px); display: flex; flex-direction: column;
  background: var(--surface); border-radius: var(--radius-l); box-shadow: var(--shadow-3); border: 1px solid var(--border);
  animation: pop .18s cubic-bezier(.2, .9, .3, 1.2);
}
.modal.lg { max-width: 820px; }
.modal.xl { max-width: 1080px; }
.modal-head { display: flex; align-items: flex-start; gap: 12px; padding: 18px 20px 14px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font: 600 17px/1.3 var(--font-display); letter-spacing: -.01em; }
.modal-head p { margin: 3px 0 0; font-size: 13px; color: var(--text-3); }
.modal-head .icon-btn { margin: -6px -8px 0 auto; }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; align-items: center; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius-l) var(--radius-l); flex-wrap: wrap; }
.modal-foot .left { margin-right: auto; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.985); } }
@media (max-width: 767px) {
  .modal-root { padding: 0; align-items: flex-end; }
  .modal, .modal.lg, .modal.xl { max-width: none; max-height: 94dvh; border-radius: 18px 18px 0 0; animation: slideup .22s ease; }
  .modal-foot { border-radius: 0; padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
  .modal-foot .btn { flex: 1; }
  .modal-foot .left { flex-basis: 100%; }
  @keyframes slideup { from { transform: translateY(40px); opacity: .4; } }
}

/* Full-screen sheet (document editor / detail) */
.sheet-root { position: fixed; inset: 0; z-index: 55; background: var(--bg); display: flex; flex-direction: column; animation: fade .15s; }
.sheet-head { height: var(--topbar-h); flex-shrink: 0; display: flex; align-items: center; gap: 12px; padding: 0 20px; background: var(--surface); border-bottom: 1px solid var(--border); }
.sheet-head h2 { margin: 0; font: 600 17px var(--font-display); letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet-body { flex: 1; overflow-y: auto; }
.sheet-inner { max-width: 1320px; margin: 0 auto; padding: 22px 20px 40px; }
@media (max-width: 767px) { .sheet-head { padding: 0 10px; } .sheet-inner { padding: 14px 12px 120px; } }

/* Dropdown menu */
.menu { position: absolute; z-index: 70; min-width: 210px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-2); padding: 6px; animation: pop .12s; }
.menu button, .menu a { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; background: transparent; color: var(--text); font: 500 13.5px var(--font); border-radius: 6px; cursor: pointer; text-decoration: none; text-align: left; }
.menu button:hover, .menu a:hover { background: var(--surface-3); }
.menu i { width: 16px; color: var(--text-3); text-align: center; }
.menu .sep { height: 1px; background: var(--border); margin: 5px 2px; }
.menu .danger { color: var(--out); } .menu .danger i { color: var(--out); }

/* Toasts */
.toasts { position: fixed; z-index: 80; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; max-width: min(400px, calc(100vw - 24px)); }
.toast { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius); background: #1d1b45; color: #fff; box-shadow: var(--shadow-3); font-size: 13.5px; animation: pop .18s; }
.toast i { margin-top: 2px; }
.toast.ok i { color: #4ade80; } .toast.err { background: #7f1d1d; } .toast.err i { color: #fecaca; }
.toast button { margin-left: auto; background: none; border: 0; color: rgba(255,255,255,.6); cursor: pointer; padding: 0 0 0 6px; }
@media (max-width: 1023px) { .toasts { left: 12px; right: 12px; bottom: calc(76px + env(safe-area-inset-bottom)); max-width: none; } }

/* ---------------------------------------------------------------- Charts */
.chart { width: 100%; display: block; overflow: visible; }
.chart text { fill: var(--text-3); font-size: 11px; font-family: var(--font); }
.chart .grid line { stroke: var(--border); }
.chart .axis-zero { stroke: var(--border-strong); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.chart-tip { position: fixed; z-index: 90; pointer-events: none; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-2); border-radius: 8px; padding: 8px 10px; font-size: 12px; min-width: 150px; }
.chart-tip b { display: block; margin-bottom: 4px; }
.chart-tip div { display: flex; justify-content: space-between; gap: 12px; }
.bar-list { display: flex; flex-direction: column; gap: 10px; }
.bar-list .row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; font-size: 13px; }
.bar-list .track { grid-column: 1 / -1; height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; }
.bar-list .fill { height: 100%; border-radius: 3px; background: var(--ink); }
html.dark .bar-list .fill { background: #7d77f0; }

/* ---------------------------------------------------------------- Document editor */
.editor-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.editor-aside { position: sticky; top: 16px; display: flex; flex-direction: column; gap: 14px; }
@media (max-width: 1100px) { .editor-grid { grid-template-columns: minmax(0, 1fr); } .editor-aside { position: static; } }
.form-grid { display: grid; gap: 14px; grid-template-columns: repeat(12, minmax(0, 1fr)); }
.form-grid > .span-3 { grid-column: span 3; } .form-grid > .span-4 { grid-column: span 4; } .form-grid > .span-5 { grid-column: span 5; }
.form-grid > .span-6 { grid-column: span 6; } .form-grid > .span-8 { grid-column: span 8; } .form-grid > .span-12 { grid-column: span 12; }
@media (max-width: 767px) { .form-grid > [class*="span-"] { grid-column: span 12; } .form-grid > .m-span-6 { grid-column: span 6; } }

.lines { display: flex; flex-direction: column; }
.line-head, .line { display: grid; grid-template-columns: 22px minmax(0, 1fr) 76px 66px 108px 64px 80px 112px 32px; gap: 8px; align-items: start; }
.line-head { padding: 0 12px 8px; font-size: 12px; color: var(--text-3); font-weight: 500; }
.line-head .r, .line .r { text-align: right; }
.line { padding: 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); margin-bottom: 8px; position: relative; }
.line:focus-within { border-color: color-mix(in srgb, var(--ember) 50%, var(--border)); box-shadow: 0 0 0 3px rgba(234, 88, 12, .08); }
.line .idx { padding-top: 9px; color: var(--text-3); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.line .main-col { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.line .sub-row { grid-column: 2 / -2; display: flex; gap: 8px; align-items: flex-start; margin-top: -2px; }
.line .sub-row .desc-input { flex: 1; }
.line .meta-row { flex-shrink: 0; width: 250px; }
.line .meta-row .input { flex: 1; min-width: 0; }
.line .meta-row .select { width: 104px; flex-shrink: 0; }
.line .name-input { font-weight: 600; }
.line .desc-input { min-height: 36px; font-size: 13px; padding: 7px 10px; }
.line .meta-row { display: flex; gap: 6px; }
.line .meta-row .input, .line .meta-row .select { height: 30px; font-size: 12.5px; }
.line .line-total { padding-top: 9px; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.line .mlabel { display: none; }
.line .remove { margin-top: 1px; }
.picker { position: relative; }
.picker-list { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 20; max-height: 280px; overflow-y: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-2); padding: 4px; }
.picker-list button { display: flex; width: 100%; justify-content: space-between; gap: 10px; padding: 8px 10px; border: 0; border-radius: 6px; background: transparent; color: var(--text); text-align: left; cursor: pointer; font: 400 13px var(--font); }
.picker-list button:hover, .picker-list button.hl { background: var(--surface-3); }
.picker-list button small { display: block; color: var(--text-3); font-size: 11.5px; }
@media (max-width: 900px) {
  .line-head { display: none; }
  .line { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; padding: 12px 12px 14px; }
  .line .idx { grid-column: 1 / -1; padding: 0; display: flex; justify-content: space-between; align-items: center; font-weight: 600; color: var(--text-2); }
  .line .main-col { grid-column: 1 / -1; }
  .line .sub-row { grid-column: 1 / -1; flex-direction: column; align-items: stretch; margin: 0; order: 2; }
  .line .idx { order: 0; } .line .main-col { order: 1; } .line > div { order: 3; } .line .line-total { order: 4; }
  .line .remove-wrap, .line > div:has(> .remove) { order: 0; }
  .line .sub-row .desc-input { width: 100%; }
  .line .meta-row { width: 100%; }
  .line .c-qty, .line .c-res, .line .c-rate { grid-column: span 2; }
  .line .c-disc, .line .c-tax { grid-column: span 3; }
  .line .line-total { grid-column: 1 / -1; padding-top: 6px; border-top: 1px dashed var(--border); display: flex; justify-content: space-between; }
  .line .mlabel { display: block; font-size: 11.5px; color: var(--text-3); margin-bottom: 4px; text-align: left; font-weight: 500; }
  .line .remove { position: absolute; top: 6px; right: 6px; }
}
.mobile-savebar { display: none; }
@media (max-width: 1100px) {
  .mobile-savebar { display: flex; position: fixed; inset: auto 0 0 0; z-index: 56; align-items: center; gap: 10px; padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--border); box-shadow: 0 -8px 24px -12px rgba(0,0,0,.25); }
  .mobile-savebar .tot { flex: 1; line-height: 1.2; }
  .mobile-savebar .tot small { display: block; color: var(--text-3); font-size: 11.5px; }
  .mobile-savebar .tot b { font-size: 17px; font-variant-numeric: tabular-nums; }
  .editor-aside .aside-actions { display: none; }
}

/* Document preview (detail view) */
.doc-paper { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-l); box-shadow: var(--shadow-1); padding: 28px; }
.doc-paper .doc-top { display: flex; justify-content: space-between; gap: 20px; flex-wrap: wrap; padding-bottom: 18px; border-bottom: 2px solid var(--ink); }
html.dark .doc-paper .doc-top { border-color: #4b45b5; }
.doc-paper .doc-title { font: 600 26px var(--font-display); letter-spacing: -.02em; margin: 0; }
.doc-paper table.items { width: 100%; border-collapse: collapse; margin-top: 18px; font-size: 13.5px; }
.doc-paper table.items th { text-align: left; font-weight: 500; font-size: 12px; color: var(--text-3); padding: 8px 10px; border-bottom: 1px solid var(--border-strong); }
.doc-paper table.items td { padding: 11px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.doc-paper table.items .r { text-align: right; }
@media (max-width: 767px) { .doc-paper { padding: 16px; } .doc-paper table.items .hide-sm { display: none; } }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 14px 22px; font-size: 13px; }
.timeline li::before { content: ""; position: absolute; left: 5px; top: 6px; width: 8px; height: 8px; border-radius: 50%; background: var(--ember); }
.timeline li::after { content: ""; position: absolute; left: 8.5px; top: 18px; bottom: 0; width: 1px; background: var(--border); }
.timeline li:last-child::after { display: none; }
.timeline .when { color: var(--text-3); font-size: 12px; }

.callout { display: flex; gap: 12px; padding: 12px 14px; border-radius: var(--radius); font-size: 13.5px; align-items: flex-start; }
.callout i { margin-top: 3px; }
.callout.wait { background: var(--wait-soft); color: var(--wait); }
.callout.out { background: var(--out-soft); color: var(--out); }
.callout.info { background: var(--info-soft); color: var(--info); }
.callout.in { background: var(--in-soft); color: var(--in); }
.callout b { color: inherit; }
.callout .txt { color: var(--text); }

.contact-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; background: var(--surface); position: relative; }
.contact-card.primary { border-color: color-mix(in srgb, var(--ember) 55%, var(--border)); }
.contact-option { display: flex; gap: 10px; align-items: center; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; background: var(--surface); }
.contact-option:hover { border-color: var(--text-3); }
.contact-option.on { border-color: var(--ember); box-shadow: var(--focus); }
.contact-option .avatar { width: 30px; height: 30px; font-size: 11px; background: var(--surface-3); color: var(--text-2); }
.contact-option.on .avatar { background: var(--ember); color: #fff; }

.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.perm-group { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.perm-group h5 { margin: 0 0 8px; font-size: 13px; font-weight: 600; display: flex; justify-content: space-between; align-items: center; }
.perm-item { display: flex; gap: 10px; padding: 6px 0; align-items: flex-start; cursor: pointer; }
.perm-item input { margin-top: 2px; flex-shrink: 0; }
.perm-item b { display: block; font-size: 13px; font-weight: 500; }
.perm-item small { color: var(--text-3); font-size: 12px; }

.install-banner { display: none; }
.install-banner.show { display: flex; }

.login-page { min-height: 100dvh; display: grid; grid-template-columns: 1.05fr 1fr; background: var(--bg); }
@media (max-width: 900px) { .login-page { grid-template-columns: 1fr; } .login-art { display: none !important; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
@media print {
  .sidebar, .topbar, .bottom-nav, .toasts { display: none !important; }
  .main { margin: 0 !important; }
}
@media (max-width: 1023px) { html.sb-open .scrim { opacity: 1; pointer-events: auto; } }
@media (max-width: 640px) {
  .kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpis > .hero, .kpis > .span-all { grid-column: 1 / -1; }
  .kpi { padding: 12px 14px; }
  .kpi .k-value { font-size: 19px; }
  .kpi .k-foot { font-size: 11.5px; gap: 6px; }
  .page-head { margin-bottom: 12px; }
}

/* ---- Attachments ---- */
.att-list { display: flex; flex-direction: column; gap: 6px; }
.att-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); min-width: 0; }
.att-ico { width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center; background: var(--surface-3); color: var(--ember); flex-shrink: 0; }
.att-name { flex: 1; min-width: 0; display: flex; flex-direction: column; text-decoration: none; color: inherit; line-height: 1.3; }
.att-name b { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-name small { font-size: 12px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
a.att-name:hover b { color: var(--ember); }
.att-drop { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1.5px dashed var(--border); border-radius: var(--radius); cursor: pointer; background: var(--surface); }
.att-drop:hover { border-color: var(--ember); }
.att-drop > i { font-size: 20px; color: var(--ember); }
.att-drop span { display: flex; flex-direction: column; line-height: 1.35; }
.att-drop b { font-size: 13px; }
.att-drop small { font-size: 12px; color: var(--text-3); }
.att-count { display: inline-flex; align-items: center; gap: 3px; font-size: 11.5px; color: var(--text-3); margin-left: 6px; font-family: var(--font); }

/* ---- Quotation version history ---- */
.vh > li { padding-bottom: 14px; }
.vh-changes { list-style: none; margin: 6px 0 0; padding: 8px 10px; border-radius: var(--radius); background: var(--surface-3); font-size: 12.5px; display: flex; flex-direction: column; gap: 3px; }
.vh-changes li { position: static; padding: 0 0 0 16px; text-indent: -16px; margin: 0; border: 0; }
.vh-changes li::before { position: static; display: inline-block; width: 16px; height: auto; text-indent: 0; border: 0; border-radius: 0; background: none; box-shadow: none; font-weight: 700; }
.vh-changes li::after { display: none; }
.vh-changes li.add::before { content: "+"; color: var(--in); }
.vh-changes li.del::before { content: "−"; color: var(--out); }
.vh-changes li.chg::before { content: "~"; color: var(--wait); }
