/* ---------- fonts ---------- */
@font-face {
  font-family: 'Inter';
  src: url('fonts/inter-400.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

/* ---------- tokens ---------- */
:root {
  --navy-950: #080f1b;
  --navy-900: #0c1626;
  --navy-800: #132133;
  --navy-700: #1b2c42;
  --navy-line: rgba(255, 255, 255, 0.08);

  --ink: #101828;
  --ink-2: #344054;
  --muted: #667085;
  --muted-2: #8a94a6;
  --line: #e4e7ec;
  --line-soft: #eef1f5;
  --bg: #f6f7f9;
  --bg-2: #fafbfc;
  --card: #ffffff;

  --brand: #1f6f5c;
  --brand-dark: #175244;
  --brand-soft: #e8f3ef;
  --brand-line: #cfe6dd;
  --accent: #2b6cf6;
  --accent-soft: #eaf1ff;

  --pos: #157f5b;
  --pos-soft: #e7f5ee;
  --neg: #b42318;
  --neg-soft: #fdecea;
  --warn: #b54708;
  --warn-soft: #fef3e2;
  --info: #175cd3;
  --info-soft: #eaf1ff;
  --grey-soft: #f2f4f7;

  --radius: 14px;
  --radius-sm: 9px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.06), 0 8px 24px -12px rgba(16, 24, 40, 0.12);
  --shadow-lg: 0 24px 64px -20px rgba(8, 15, 27, 0.35);

  --sidebar-w: 250px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* ---------- base ---------- */
*,
*::before,
*::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.015em; color: var(--ink); }
p { margin: 0; }
button { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
svg { display: block; }
input, select, textarea { font: inherit; color: inherit; }
::selection { background: #d7e9e2; }

.num, td.num, .tnum { font-variant-numeric: tabular-nums; font-feature-settings: 'tnum' 1; }

/* ---------- app shell ---------- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.sidebar {
  background: var(--navy-900);
  color: #cdd6e1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid rgba(0, 0, 0, 0.25);
  z-index: 40;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 18px 12px;
  color: #fff;
}
.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: linear-gradient(150deg, #2f9e7f, #175244);
  color: #fff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25);
}
.brand-mark svg { width: 19px; height: 19px; }
.brand-text {
  display: flex;
  flex-direction: column;
  font-weight: 600;
  font-size: 16px;
  letter-spacing: -0.02em;
  color: #fff;
}
.brand-text i {
  font-style: normal;
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #7f8fa4;
  font-weight: 500;
}

.company-chip {
  margin: 4px 14px 10px;
  padding: 9px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--navy-line);
  display: flex;
  align-items: center;
  gap: 9px;
  cursor: default;
}
.company-chip .cc-badge {
  width: 26px; height: 26px;
  border-radius: 7px;
  background: #ffffff14;
  color: #9fd3c2;
  display: grid; place-items: center;
  font-size: 11px; font-weight: 700;
}
.company-chip .cc-name { font-size: 12.5px; color: #e6ebf2; font-weight: 600; line-height: 1.25; }
.company-chip .cc-meta { font-size: 10.5px; color: #7f8fa4; }
.company-chip { cursor: pointer; transition: background 0.12s; }
.company-chip:hover { background: rgba(255, 255, 255, 0.09); }
.cc-caret { width: 14px; height: 14px; margin-left: auto; opacity: 0.5; flex: none; }

/* company switcher */
.company-menu {
  position: fixed;
  left: 12px;
  top: 96px;
  width: 306px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  padding: 6px;
  z-index: 80;
  animation: pop 0.14s ease-out;
}
.company-menu .cm-head {
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted-2);
  font-weight: 600;
  padding: 7px 9px 5px;
}
.company-menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px;
  border: 0;
  background: none;
  border-radius: 10px;
  text-align: left;
  cursor: pointer;
}
.company-menu button:hover { background: var(--bg); }
.company-menu button.on { background: var(--brand-soft); }
.company-menu .cm-badge {
  width: 30px; height: 30px;
  border-radius: 8px;
  display: grid; place-items: center;
  font-size: 11px; font-weight: 700;
  flex: none;
}
.company-menu .cm-name { display: block; font-size: 13px; font-weight: 600; color: var(--ink); }
.company-menu .cm-note { display: block; font-size: 11px; color: var(--muted); line-height: 1.35; margin-top: 1px; }
.company-menu .cm-tick { margin-left: auto; color: var(--brand); font-weight: 700; }
.company-menu .cm-sep { height: 1px; background: var(--line-soft); margin: 6px 0; }
.company-menu .cm-foot {
  font-size: 11px;
  color: var(--muted);
  padding: 8px 10px 6px;
  border-top: 1px solid var(--line-soft);
  margin-top: 5px;
  line-height: 1.45;
}

.nav {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 10px 12px;
  scrollbar-width: thin;
}
.nav-group { padding: 10px 0 2px; }
.nav-group-label {
  font-size: 10px;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: #64748b;
  padding: 0 10px 6px;
  font-weight: 600;
}
.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7.5px 10px;
  border-radius: 8px;
  color: #c3cdda;
  font-size: 13px;
  font-weight: 450;
  transition: background 0.12s, color 0.12s;
}
.nav a svg { width: 16px; height: 16px; opacity: 0.75; flex: none; }
.nav a:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.nav a.active { background: rgba(47, 158, 127, 0.16); color: #fff; font-weight: 550; }
.nav a.active svg { opacity: 1; color: #63c9a8; }
.nav a .nav-count {
  margin-left: auto;
  font-size: 10.5px;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.09);
  color: #b7c3d2;
  padding: 1px 6px;
  border-radius: 20px;
  font-variant-numeric: tabular-nums;
}
.nav a .nav-count.warn { background: rgba(240, 147, 60, 0.2); color: #f5b57b; }

.sidebar-foot {
  padding: 8px 12px 14px;
  border-top: 1px solid var(--navy-line);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.fy-badge {
  font-size: 11px;
  color: #8b98a9;
  padding: 2px 8px 6px;
  letter-spacing: 0.01em;
}
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 7px 8px;
  background: none;
  border: 0;
  border-radius: 8px;
  color: #c3cdda;
  font-size: 13px;
  cursor: pointer;
}
.sidebar-link svg { width: 16px; height: 16px; opacity: 0.75; }
.sidebar-link:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }

/* ---------- main / topbar ---------- */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.topbar {
  height: 62px;
  flex: none;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 26px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.topbar-title { min-width: 0; }
.topbar-title h1 { font-size: 16.5px; font-weight: 600; letter-spacing: -0.01em; }
.page-sub { font-size: 12px; color: var(--muted); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.search {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 9px;
  min-width: 250px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg-2);
  color: var(--muted-2);
  transition: border-color 0.15s, background 0.15s;
}
.search:focus-within { border-color: #b9c6d6; background: #fff; box-shadow: 0 0 0 3px rgba(43, 108, 246, 0.08); }
.search svg { width: 15px; height: 15px; flex: none; }
.search input { border: 0; outline: 0; background: none; width: 100%; font-size: 12.5px; }
.search input::placeholder { color: var(--muted-2); }
.search kbd {
  font-family: var(--font);
  font-size: 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 4px;
  color: var(--muted-2);
  background: #fff;
}

.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: #0c1626;
  color: #9fd3c2;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  flex: none;
}

/* secondary navigation */
.section-tabs {
  flex: none;
  background: #fff;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
}
.section-tabs[hidden] { display: none; }
.section-tabs::-webkit-scrollbar { display: none; }
.section-tabs-inner {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 22px;
  height: 42px;
  min-width: max-content;
}
.st-label {
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted-2);
  font-weight: 600;
  margin-right: 12px;
}
.st-tab {
  display: inline-flex;
  align-items: center;
  height: 100%;
  padding: 0 10px;
  font-size: 12.5px;
  color: var(--muted);
  font-weight: 500;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: color 0.12s, border-color 0.12s;
}
.st-tab:hover { color: var(--ink); }
.st-tab.on { color: var(--ink); border-bottom-color: var(--brand); font-weight: 600; }

.content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 22px 26px 72px;
  scroll-behavior: smooth;
}
.page { max-width: 1240px; margin: 0 auto; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 13px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, box-shadow 0.12s;
}
.btn svg { width: 15px; height: 15px; }
.btn:hover { background: var(--bg); border-color: #d3d9e2; }
.btn:active { transform: translateY(0.5px); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; box-shadow: 0 1px 2px rgba(23, 82, 68, 0.25); }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-ghost { border-color: transparent; background: none; color: var(--ink-2); }
.btn-ghost:hover { background: var(--grey-soft); }
.btn-sm { height: 28px; padding: 0 9px; font-size: 12px; border-radius: 7px; }
.btn-danger { color: var(--neg); border-color: #f0c9c4; background: #fff; }
.btn-danger:hover { background: var(--neg-soft); border-color: #e6a9a1; }
.btn-icon { width: 34px; padding: 0; }
.icon-btn {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border: 1px solid transparent;
  border-radius: 8px;
  background: none;
  color: var(--ink-2);
  cursor: pointer;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover { background: var(--grey-soft); }
.new-wrap { position: relative; }
.new-menu {
  position: absolute;
  right: 0;
  top: 40px;
  width: 232px;
  padding: 5px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  z-index: 60;
}
.new-menu[hidden] { display: none; }
.new-menu button {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 8px 9px;
  border: 0;
  background: none;
  border-radius: 8px;
  text-align: left;
  font-size: 13px;
  cursor: pointer;
  color: var(--ink-2);
}
.new-menu button:hover { background: var(--bg); color: var(--ink); }
.new-menu .mi { width: 18px; height: 18px; display: grid; place-items: center; color: var(--muted); }
.new-menu .mi svg { width: 16px; height: 16px; }
.menu-sep { height: 1px; background: var(--line-soft); margin: 5px 6px; }

/* ---------- cards & layout ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 15px 18px;
  border-bottom: 1px solid var(--line-soft);
}
.card-head h2 { font-size: 14px; font-weight: 600; }
.card-head .sub { font-size: 12px; color: var(--muted); }
.card-head .right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.card-body { padding: 18px; }
.card-body.tight { padding: 0; }

.grid { display: grid; gap: 14px; }
.g-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-21 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.g-12 { grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); }
.gap-18 { gap: 18px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.stack { display: flex; flex-direction: column; }
.row { display: flex; align-items: center; }
.right { margin-left: auto; }

/* ---------- KPI ---------- */
.kpi { padding: 16px 18px 14px; position: relative; overflow: hidden; }
.kpi-label {
  display: flex; align-items: center; gap: 6px;
  font-size: 11.5px; font-weight: 550; letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--muted);
}
.kpi-label .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--brand); }
.kpi-value {
  font-size: 25px;
  font-weight: 600;
  letter-spacing: -0.025em;
  margin-top: 7px;
  font-variant-numeric: tabular-nums;
}
.kpi-value.sm { font-size: 21px; }
.kpi-foot { display: flex; align-items: center; gap: 6px; margin-top: 4px; font-size: 11.5px; color: var(--muted); }
.kpi-foot .up { color: var(--pos); font-weight: 600; }
.kpi-foot .down { color: var(--neg); font-weight: 600; }
.kpi-spark { position: absolute; right: 0; bottom: 0; opacity: 0.9; pointer-events: none; }

/* ---------- pills & tags ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 21px;
  padding: 0 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.pill::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: currentColor; opacity: 0.85; }
.pill.paid { background: var(--pos-soft); color: #0f6a49; }
.pill.open { background: var(--info-soft); color: #175cd3; }
.pill.overdue { background: var(--neg-soft); color: #b42318; }
.pill.part-paid { background: var(--warn-soft); color: #b54708; }
.pill.draft { background: var(--grey-soft); color: #475467; }
.pill.void { background: var(--grey-soft); color: #98a2b3; }
.pill.matched { background: var(--pos-soft); color: #0f6a49; }
.pill.unmatched { background: var(--warn-soft); color: #b54708; }
.pill.plain { background: var(--grey-soft); color: var(--ink-2); }
.pill.plain::before { display: none; }

.tag {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 7px;
  border-radius: 5px;
  background: var(--bg);
  border: 1px solid var(--line-soft);
  color: var(--muted);
  font-size: 11px;
  font-weight: 550;
  white-space: nowrap;
}

/* ---------- tables ---------- */
.table-wrap { width: 100%; overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th {
  text-align: left;
  font-size: 10.5px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
  padding: 9px 14px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
}
table.tbl td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}
table.tbl tbody tr:last-child td { border-bottom: 0; }
table.tbl tbody tr.clickable { cursor: pointer; }
table.tbl tbody tr.clickable:hover td { background: #fbfcfd; }
table.tbl td.num, table.tbl th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.tbl td.right, table.tbl th.right { text-align: right; }
table.tbl .cell-main { font-weight: 550; color: var(--ink); }
table.tbl .nw, table.tbl td.nw { white-space: nowrap; }
table.tbl .cell-sub { font-size: 11.5px; color: var(--muted); margin-top: 1px; }
table.tbl tfoot td { background: var(--bg-2); font-weight: 600; border-top: 1px solid var(--line); }
.tbl .neg { color: var(--neg); }
.tbl .pos { color: var(--pos); }
.tbl-narrow th, .tbl-narrow td { padding-left: 10px; padding-right: 10px; }

.empty {
  padding: 30px 18px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}
.empty strong { display: block; color: var(--ink-2); margin-bottom: 3px; }

/* ---------- filters ---------- */
.filters { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.seg {
  display: inline-flex;
  padding: 2px;
  background: var(--grey-soft);
  border-radius: 8px;
  gap: 1px;
}
.seg button {
  border: 0;
  background: none;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 550;
  color: var(--muted);
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
}
.seg button.active { background: #fff; color: var(--ink); box-shadow: var(--shadow-sm); }
.seg button .c { font-size: 10.5px; color: var(--muted-2); margin-left: 4px; }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label { font-size: 11.5px; font-weight: 600; color: var(--ink-2); letter-spacing: 0.01em; }
.field .hint { font-size: 11px; color: var(--muted); }
.input, .select, .textarea {
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-size: 13px;
  outline: none;
  width: 100%;
  transition: border-color 0.14s, box-shadow 0.14s;
}
.textarea { height: auto; padding: 8px 10px; resize: vertical; min-height: 66px; }
.input:focus, .select:focus, .textarea:focus { border-color: #9fb6c9; box-shadow: 0 0 0 3px rgba(31, 111, 92, 0.1); }
.input.num-input { text-align: right; font-variant-numeric: tabular-nums; }
.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23667085' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 8px center; background-size: 15px; padding-right: 28px; }
.form-grid { display: grid; gap: 14px; }
.form-row { display: grid; gap: 12px; }

/* ---------- charts ---------- */
.chart { width: 100%; display: block; }
.chart-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 11.5px; color: var(--muted); }
.chart-legend i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; }
.chart-tip {
  font-size: 11px;
  fill: var(--ink-2);
}

/* ---------- misc widgets ---------- */
.bar-row { display: grid; grid-template-columns: 120px 1fr 74px; align-items: center; gap: 10px; padding: 7px 0; font-size: 12.5px; }
.bar-track { height: 7px; background: var(--grey-soft); border-radius: 20px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 20px; background: var(--brand); }
.bar-fill.warn { background: #f0932b; }
.bar-fill.neg { background: #d92d20; }

.avatar-sq {
  width: 30px; height: 30px;
  border-radius: 8px;
  display: grid; place-items: center;
  font-size: 11px; font-weight: 700;
  background: var(--brand-soft); color: #175244;
  flex: none;
}
.avatar-sq.alt { background: #eef1f7; color: #475467; }

.person { display: flex; align-items: center; gap: 10px; }
.person .p-name { font-weight: 550; font-size: 13px; }
.person .p-sub { font-size: 11.5px; color: var(--muted); }

.kv { display: grid; grid-template-columns: 130px 1fr; gap: 8px 14px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; color: var(--ink); }

.stat-line { display: flex; align-items: baseline; justify-content: space-between; padding: 8px 0; border-bottom: 1px dashed var(--line-soft); font-size: 13px; }
.stat-line:last-child { border-bottom: 0; }
.stat-line .lbl { color: var(--muted); }
.stat-line .val { font-weight: 600; font-variant-numeric: tabular-nums; }

.banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--brand-line);
  background: var(--brand-soft);
  color: #14503f;
  font-size: 12.5px;
}
.banner.warn { border-color: #f3d9b7; background: var(--warn-soft); color: #8a4a06; }
.banner .b-actions { margin-left: auto; display: flex; gap: 8px; flex: none; }

/* ---------- modal ---------- */
.modal-scrim {
  position: fixed;
  inset: 0;
  background: rgba(8, 15, 27, 0.45);
  backdrop-filter: blur(2px);
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 24px;
  animation: fade 0.14s ease-out;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  width: 100%;
  max-width: 520px;
  max-height: calc(100vh - 48px);
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 32px 80px -24px rgba(8, 15, 27, 0.5);
  display: flex;
  flex-direction: column;
  animation: pop 0.16s cubic-bezier(0.2, 0.8, 0.3, 1);
}
@keyframes pop { from { transform: translateY(8px) scale(0.99); opacity: 0; } to { transform: none; opacity: 1; } }
.modal.wide { max-width: 860px; }
.modal.xwide { max-width: 1000px; }
.modal-head { padding: 18px 20px 12px; display: flex; align-items: flex-start; gap: 12px; }
.modal-head h2 { font-size: 16px; }
.modal-head .m-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.modal-head .icon-btn { margin: -4px -6px 0 auto; }
.modal-body { padding: 4px 20px 18px; overflow-y: auto; }
.modal-foot {
  padding: 13px 20px;
  border-top: 1px solid var(--line-soft);
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-2);
  border-radius: 0 0 16px 16px;
}
.modal-foot .right { margin-left: auto; display: flex; gap: 8px; }

/* ---------- toast ---------- */
#toast-root {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}
.toast {
  background: #101828;
  color: #fff;
  font-size: 12.5px;
  font-weight: 500;
  padding: 9px 15px;
  border-radius: 9px;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 8px;
  animation: toastIn 0.18s ease-out;
}
.toast.ok::before { content: '✓'; color: #6ee7b7; font-weight: 700; }
.toast.err::before { content: '!'; color: #fca5a5; font-weight: 700; }
@keyframes toastIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- welcome / feed / snippets ---------- */
.hero {
  background: linear-gradient(135deg, #0c1626, #16304a 60%, #1c4a3f);
  color: #fff;
  border-radius: var(--radius-lg);
  padding: 30px 32px;
  position: relative;
  overflow: hidden;
}
.hero-eyebrow { font-size: 10.5px; letter-spacing: 0.16em; text-transform: uppercase; color: #8fd3bd; font-weight: 600; }
.hero h2 { color: #fff; font-size: 24px; margin: 8px 0 8px; letter-spacing: -0.02em; }
.hero p { color: #b6c6d6; font-size: 13.5px; max-width: 620px; line-height: 1.6; }

.template-card { padding: 22px; display: flex; flex-direction: column; gap: 6px; border-width: 1.5px; }
.template-card.on { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(31, 111, 92, 0.08); }
.tc-icon { width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; font-size: 19px; margin-bottom: 6px; }
.template-card h3 { font-size: 16px; }
.tc-sub { font-size: 12px; color: var(--muted); }
.tc-list { margin: 10px 0 16px; padding-left: 18px; font-size: 12.5px; color: var(--ink-2); line-height: 1.75; }
.tc-list li { list-style: disc; }

.feed-card { display: flex; gap: 14px; padding: 16px 18px; align-items: flex-start; }
.feed-icon {
  width: 34px; height: 34px; border-radius: 10px; flex: none;
  display: grid; place-items: center;
  background: var(--brand-soft); color: var(--brand-dark); font-size: 15px;
}
.file-card { padding: 16px; }
.file-kind {
  display: inline-block; font-size: 9.5px; letter-spacing: 0.08em; font-weight: 700;
  padding: 2px 6px; border-radius: 4px; background: var(--grey-soft); color: var(--muted);
}
.file-name { font-size: 13px; font-weight: 550; margin-top: 8px; line-height: 1.4; }
.file-meta { font-size: 11.5px; color: var(--muted); margin-top: 3px; }

.app-card { padding: 16px; }
.app-logo {
  width: 34px; height: 34px; border-radius: 9px; flex: none;
  display: grid; place-items: center; font-size: 11px; font-weight: 700;
  background: var(--bg); color: var(--ink-2); border: 1px solid var(--line);
}

.style-card { overflow: hidden; border-width: 1.5px; }
.style-card.on { border-color: var(--brand); }
.style-preview { background: var(--bg); padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.sp-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.sp-logo { width: 18px; height: 18px; border-radius: 5px; display: block; }
.sp-line { height: 7px; border-radius: 3px; background: #dfe5ee; display: block; }
.sp-row { display: flex; justify-content: space-between; gap: 10px; }
.sp-total { display: flex; justify-content: space-between; gap: 10px; border-top: 1.5px solid var(--brand); padding-top: 8px; }

.toggle {
  display: inline-block; width: 30px; height: 17px; border-radius: 20px;
  background: #dfe5ee; position: relative; transition: background 0.15s;
}
.toggle::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 13px; height: 13px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(16,24,40,.2); transition: left 0.15s;
}
.toggle.on { background: var(--brand); }
.toggle.on::after { left: 15px; }

/* ---------- doc (invoice / report) ---------- */
.doc {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 34px 38px 30px;
  max-width: 860px;
  margin: 0 auto;
}
.doc-head { display: flex; justify-content: space-between; gap: 24px; align-items: flex-start; }
.doc-brand { display: flex; gap: 11px; align-items: flex-start; }
.doc-logo {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: var(--brand);
  color: #fff;
  display: grid; place-items: center;
  font-weight: 700; font-size: 14px;
}
.doc-co { font-size: 14px; font-weight: 650; letter-spacing: -0.01em; }
.doc-co small { display: block; font-size: 11.5px; font-weight: 400; color: var(--muted); line-height: 1.5; margin-top: 2px; }
.doc-title { text-align: right; }
.doc-title h2 { font-size: 22px; letter-spacing: -0.02em; }
.doc-title .doc-no { font-size: 12.5px; color: var(--muted); margin-top: 2px; font-variant-numeric: tabular-nums; }
.doc-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin: 26px 0 22px; }
.doc-parties .lbl { font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted-2); font-weight: 600; margin-bottom: 5px; }
.doc-parties .who { font-size: 13.5px; font-weight: 600; }
.doc-parties p { font-size: 12.5px; color: var(--muted); line-height: 1.55; }
.doc table { width: 100%; border-collapse: collapse; }
.doc table th {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted);
  text-align: left; padding: 8px 0; border-bottom: 1.5px solid var(--ink);
  font-weight: 600;
}
.doc table td { padding: 10px 0; border-bottom: 1px solid var(--line-soft); font-size: 13px; vertical-align: top; }
.doc table td.num, .doc table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.doc-totals { margin-left: auto; width: 268px; margin-top: 14px; }
.doc-totals .trow { display: flex; justify-content: space-between; padding: 6px 0; font-size: 13px; color: var(--ink-2); }
.doc-totals .trow.grand { border-top: 1.5px solid var(--ink); margin-top: 4px; padding-top: 9px; font-size: 15px; font-weight: 650; color: var(--ink); }
.doc-note { margin-top: 26px; padding-top: 14px; border-top: 1px solid var(--line-soft); font-size: 11.5px; color: var(--muted); line-height: 1.6; }
.doc-stamp {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 4px 9px;
  border-radius: 5px;
  border: 1.5px solid currentColor;
}
.doc-stamp.paid { color: #0f6a49; }
.doc-stamp.overdue { color: #b42318; }

/* report tables */
.rep table.aging { font-size: 12px; }
.rep table.aging th { padding: 6px 10px; font-size: 9.5px; letter-spacing: 0.06em; }
.rep table.aging td { padding: 7px 10px; }
.rep table.aging td.num { white-space: nowrap; }
.rep { font-size: 13px; }
.rep .rep-title { text-align: center; margin-bottom: 4px; }
.rep .rep-title h2 { font-size: 17px; }
.rep .rep-title p { font-size: 12px; color: var(--muted); margin-top: 3px; }
.rep table { width: 100%; border-collapse: collapse; margin-top: 20px; }
.rep th { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); text-align: right; padding: 6px 8px; border-bottom: 1px solid var(--line); font-weight: 600; }
.rep th:first-child { text-align: left; }
.rep td { padding: 6px 8px; border-bottom: 1px solid var(--line-soft); }
.rep td.num { text-align: right; font-variant-numeric: tabular-nums; }
.rep tr.section td { padding-top: 16px; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 700; border-bottom: 1px solid var(--line); }
.rep tr.total td { font-weight: 650; border-top: 1.5px solid var(--ink); border-bottom: 0; padding-top: 9px; }
.rep tr.subtotal td { font-weight: 600; background: var(--bg-2); }
.rep tr.indent td:first-child { padding-left: 24px; }
.rep tr.grand td { font-size: 15px; font-weight: 700; border-top: 1.5px solid var(--ink); border-bottom: 3px double var(--ink); padding: 11px 8px; }
.rep .code { color: var(--muted-2); font-size: 11px; font-variant-numeric: tabular-nums; margin-right: 8px; }

/* ---------- responsive ---------- */
.only-mobile { display: none; }
.nav-scrim { position: fixed; inset: 0; background: rgba(8, 15, 27, 0.4); z-index: 35; }
.nav-scrim[hidden] { display: none; }

@media (max-width: 1180px) {
  .g-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .search { min-width: 190px; }
}
@media (max-width: 980px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    width: 258px;
    transform: translateX(-102%);
    transition: transform 0.2s ease;
    z-index: 45;
  }
  .sidebar.open { transform: none; box-shadow: 0 0 60px rgba(8, 15, 27, 0.4); }
  .only-mobile { display: grid; }
  .g-21, .g-12, .g-3, .g-2 { grid-template-columns: minmax(0, 1fr); }
  .topbar { padding: 0 14px; gap: 10px; }
  .content { padding: 16px 14px 80px; }
  .search { display: none; }
}
@media (max-width: 620px) {
  .g-4 { grid-template-columns: minmax(0, 1fr); }
  .page-sub { display: none; }
  .doc { padding: 22px 18px; }
  .doc-head { flex-direction: column; }
  .doc-title { text-align: left; }
  .doc-parties { grid-template-columns: 1fr; gap: 14px; }
  .kpi-value { font-size: 22px; }
  .modal-scrim { padding: 0; place-items: end stretch; }
  .modal { max-width: none; border-radius: 16px 16px 0 0; max-height: 92vh; }
}

/* ---------- print ---------- */
@media print {
  .sidebar, .topbar, .nav-scrim, #toast-root, .no-print { display: none !important; }
  .app { display: block; height: auto; }
  .content { overflow: visible; padding: 0; }
  body { background: #fff; }
  .doc { border: 0; box-shadow: none; padding: 0; max-width: none; }
  .doc table th { border-bottom-color: #000; }
}
