/* =====================================================================
   Bahi — design system
   Ledger binding green + brass, cool paper, tabular figures everywhere.
   ===================================================================== */

:root {
  --binding: #0f3d35;
  --binding-2: #13493f;
  --binding-3: #1b5a4e;
  --binding-ink: #d9e6e1;
  --binding-mute: #8fb1a7;
  --brass: #b88a2e;
  --brass-soft: #f3e7cc;
  --brass-ink: #6e5016;

  --paper: #f3f5f3;
  --surface: #ffffff;
  --surface-2: #f8faf9;
  --sunken: #eef2f0;
  --ink: #16211f;
  --ink-2: #33403c;
  --muted: #5e6b67;
  --faint: #8b9793;
  --line: #dde3e0;
  --line-2: #e9eeec;

  --primary: #0f3d35;
  --primary-hover: #1b5a4e;
  --on-primary: #ffffff;

  --pos: #1f7a4d;   /* money in / credit balance good */
  --pos-bg: #e3f2ea;
  --neg: #b23a2b;   /* money out / overdue */
  --neg-bg: #f8e5e1;
  --warn: #9a6a10;
  --warn-bg: #fbf0d6;
  --info: #3c5486;
  --info-bg: #e5ebf6;

  --book-gst: #1f6b5b;
  --book-nongst: #4b5d86;
  --book-all: #b88a2e;

  --r-lg: 12px;
  --r: 8px;
  --r-sm: 6px;
  --shadow-pop: 0 12px 32px -8px rgba(15, 40, 35, .22), 0 2px 6px rgba(15, 40, 35, .08);
  --focus: 0 0 0 3px rgba(184, 138, 46, .45);

  --font: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-brand: "Fraunces", Georgia, serif;
  --side-w: 252px;
  --top-h: 60px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --binding: #0b2a25;
  --binding-2: #0f342e;
  --binding-3: #164339;
  --paper: #0e1513;
  --surface: #151e1c;
  --surface-2: #19231f;
  --sunken: #111917;
  --ink: #e6eeeb;
  --ink-2: #c3d0cb;
  --muted: #93a39e;
  --faint: #6c7c77;
  --line: #26332f;
  --line-2: #1f2a27;
  --primary: #2f8a74;
  --primary-hover: #39a088;
  --brass-soft: #3a2f17;
  --brass-ink: #e7c681;
  --pos: #4cc08a;
  --pos-bg: #133325;
  --neg: #ef7b6a;
  --neg-bg: #3a1d18;
  --warn: #e4b45a;
  --warn-bg: #352a12;
  --info: #9db3e6;
  --info-bg: #1d2740;
  --book-gst: #3fa58c;
  --book-nongst: #8297c9;
  color-scheme: dark;
}

*, *::before, *::after { 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(--ink);
  background: var(--paper);
  font-feature-settings: "tnum" 1, "lnum" 1;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
:root[data-theme="dark"] a { color: #7fd0b9; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -.01em; line-height: 1.25; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p { margin: 0 0 .6em; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
small, .small { font-size: 12.5px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.num, td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
.ic { width: 18px; height: 18px; stroke-width: 1.75; flex: none; }
.ic-sm .ic, .ic.sm { width: 15px; height: 15px; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--r-sm); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- shell */
.shell { display: grid; grid-template-columns: var(--side-w) 1fr; min-height: 100vh; }
.side {
  background: var(--binding);
  color: var(--binding-ink);
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column;
  border-right: 1px solid rgba(0,0,0,.2);
  z-index: 30;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 16px 18px 14px; color: #fff; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px;
  background: var(--brass); color: var(--binding);
  display: grid; place-items: center;
  font-family: var(--font-brand); font-style: italic; font-weight: 700; font-size: 20px;
  box-shadow: inset 0 -2px 0 rgba(0,0,0,.18);
}
.brand-name { font-family: var(--font-brand); font-size: 21px; font-weight: 600; font-style: italic; letter-spacing: -.01em; line-height: 1; }
.brand-co { display: block; font-family: var(--font); font-style: normal; font-size: 11.5px; font-weight: 400; color: var(--binding-mute); margin-top: 3px; max-width: 170px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.nav { flex: 1; overflow-y: auto; padding: 4px 10px 16px; scrollbar-width: thin; scrollbar-color: var(--binding-3) transparent; }
.nav-group { margin-top: 14px; }
.nav-group > span { display: block; padding: 0 10px 4px; font-size: 11.5px; color: var(--binding-mute); font-weight: 500; }
.nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 7px 10px; margin: 1px 0;
  color: var(--binding-ink); border-radius: 7px;
  font-size: 13.5px; position: relative;
}
.nav a:hover { background: var(--binding-2); text-decoration: none; color: #fff; }
.nav a.active { background: var(--binding-3); color: #fff; font-weight: 500; }
.nav a.active::before { content: ""; position: absolute; left: -10px; top: 7px; bottom: 7px; width: 3px; border-radius: 0 3px 3px 0; background: var(--brass); }
.nav a .ic { width: 17px; height: 17px; opacity: .9; }
.nav .badge { margin-left: auto; background: var(--brass); color: var(--binding); font-size: 11px; font-weight: 700; padding: 0 6px; border-radius: 99px; line-height: 18px; }
.side-foot { border-top: 1px solid rgba(255,255,255,.08); padding: 12px 14px; display: flex; align-items: center; gap: 10px; }
.side-foot .who { min-width: 0; flex: 1; }
.side-foot .who b { display: block; font-size: 13px; color: #fff; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-foot .who span { font-size: 11.5px; color: var(--binding-mute); }
.side-foot a { color: var(--binding-mute); padding: 6px; border-radius: 6px; display: grid; }
.side-foot a:hover { color: #fff; background: var(--binding-2); }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--brass-soft); color: var(--brass-ink); display: grid; place-items: center; font-size: 12px; font-weight: 600; flex: none; }

.main { min-width: 0; display: flex; flex-direction: column; }
.top {
  height: var(--top-h); position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px; padding: 0 24px;
}
.top::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 3px; background: var(--book-color, var(--book-all)); transition: background .25s; }
.book-gst { --book-color: var(--book-gst); }
.book-nongst { --book-color: var(--book-nongst); }
.book-all { --book-color: var(--book-all); }

.books { display: inline-flex; background: var(--sunken); border: 1px solid var(--line); border-radius: 9px; padding: 3px; gap: 2px; }
.books a { padding: 5px 12px; border-radius: 6px; font-size: 13px; color: var(--muted); font-weight: 500; display: inline-flex; align-items: center; gap: 7px; }
.books a:hover { color: var(--ink); text-decoration: none; }
.books a .dot { width: 8px; height: 8px; border-radius: 50%; }
.books a.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08), 0 0 0 1px var(--line); }
.dot-gst { background: var(--book-gst); }
.dot-nongst { background: var(--book-nongst); }
.dot-all { background: var(--book-all); }

.searchbtn {
  display: flex; align-items: center; gap: 10px; flex: 0 1 340px;
  height: 36px; padding: 0 10px 0 12px; margin-left: 8px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px;
  color: var(--faint); font: inherit; font-size: 13.5px; cursor: pointer; text-align: left;
}
.searchbtn:hover { border-color: var(--faint); }
.searchbtn span { flex: 1; }
kbd { font-family: var(--font); font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; background: var(--surface); line-height: 18px; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.iconbtn { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 8px; color: var(--muted); background: none; border: 0; cursor: pointer; position: relative; }
.iconbtn:hover { background: var(--sunken); color: var(--ink); text-decoration: none; }
.iconbtn .count { position: absolute; top: 4px; right: 3px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 99px; background: var(--neg); color: #fff; font-size: 10px; font-weight: 700; display: grid; place-items: center; }
.menu-toggle { display: none; }

.content { padding: 24px 28px 64px; max-width: 1440px; width: 100%; }

/* ---------------------------------------------------------------- page head */
.phead { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.phead .crumb { font-size: 13px; color: var(--muted); margin-bottom: 4px; display: flex; gap: 6px; align-items: center; }
.phead .crumb a { color: var(--muted); }
.phead p { margin: 4px 0 0; color: var(--muted); }
.phead .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.title-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 14px; border-radius: var(--r);
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font: inherit; font-size: 13.5px; font-weight: 500; cursor: pointer; white-space: nowrap;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); border-color: var(--faint); text-decoration: none; }
.btn .ic { width: 16px; height: 16px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
:root[data-theme="dark"] .btn-primary, :root[data-theme="dark"] .btn-primary:hover { color: #fff; }
.btn-brass { background: var(--brass); border-color: var(--brass); color: #1b1404; }
.btn-brass:hover { background: #a67a22; border-color: #a67a22; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--sunken); border-color: transparent; }
.btn-danger { color: var(--neg); }
.btn-danger:hover { background: var(--neg-bg); border-color: var(--neg); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; border-radius: 7px; }
.btn-lg { height: 44px; padding: 0 20px; font-size: 15px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn-group { display: inline-flex; }
.btn-group .btn + .btn { margin-left: -1px; }
.btn-group .btn:not(:first-child) { border-top-left-radius: 0; border-bottom-left-radius: 0; }
.btn-group .btn:not(:last-child) { border-top-right-radius: 0; border-bottom-right-radius: 0; }

/* ---------------------------------------------------------------- dropdown */
.dd { position: relative; }
.dd > summary { list-style: none; }
.dd > summary::-webkit-details-marker { display: none; }
.dd-menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 230px; z-index: 50;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow-pop);
  padding: 6px;
}
.dd-menu a, .dd-menu button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 8px 10px; border-radius: 7px; color: var(--ink); font: inherit; font-size: 13.5px;
  background: none; border: 0; cursor: pointer; text-align: left;
}
.dd-menu a:hover, .dd-menu button:hover { background: var(--sunken); text-decoration: none; }
.dd-menu .ic { color: var(--muted); width: 16px; height: 16px; }
.dd-menu kbd { margin-left: auto; }
.dd-menu hr { margin: 5px 4px; }
.dd-menu .sub { padding: 6px 10px 2px; font-size: 11.5px; color: var(--faint); }

/* ---------------------------------------------------------------- panels */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line-2); }
.panel-head h2, .panel-head h3 { font-size: 15px; }
.panel-head .muted { font-size: 13px; }
.panel-body { padding: 18px; }
.panel-foot { padding: 12px 18px; border-top: 1px solid var(--line-2); display: flex; justify-content: flex-end; gap: 8px; }
.panel + .panel, .stack > * + * { margin-top: 16px; }
.grid { display: grid; gap: 16px; }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-main { grid-template-columns: minmax(0, 1fr) 360px; align-items: start; }
.g-side { grid-template-columns: 300px minmax(0, 1fr); align-items: start; }
.span-2 { grid-column: span 2; }
.span-all { grid-column: 1 / -1; }

/* KPI strip: one ruled strip, not separate cards */
.strip { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; }
.strip > div { padding: 16px 20px; border-left: 1px solid var(--line-2); min-width: 0; }
.strip > div:first-child { border-left: 0; }
.strip .lbl { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.strip .val { font-size: 24px; font-weight: 600; letter-spacing: -.02em; margin-top: 4px; white-space: nowrap; }
.strip .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.strip a.val { color: var(--ink); display: block; }
.strip .lead { background: var(--binding); color: #fff; }
.strip .lead .lbl, .strip .lead .sub { color: var(--binding-mute); }
.strip .lead .val { color: #fff; }
.delta { font-size: 12px; font-weight: 600; padding: 1px 6px; border-radius: 99px; }
.delta.up { background: var(--pos-bg); color: var(--pos); }
.delta.down { background: var(--neg-bg); color: var(--neg); }

/* ---------------------------------------------------------------- tables */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.t th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12.5px; padding: 9px 14px; border-bottom: 1px solid var(--line); background: var(--surface-2); white-space: nowrap; position: sticky; top: 0; z-index: 1; }
.t td { padding: 10px 14px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.t tbody tr:hover td { background: var(--surface-2); }
.t tbody tr.click { cursor: pointer; }
.t tbody tr:last-child td { border-bottom: 0; }
.t tfoot td { padding: 11px 14px; font-weight: 600; border-top: 1px solid var(--line); background: var(--surface-2); }
.t .sub-row td { font-size: 12.5px; color: var(--muted); padding-top: 0; }
.t td.title a { color: var(--ink); font-weight: 500; }
.t td .meta { display: block; color: var(--muted); font-size: 12.5px; }
.t th:first-child, .t td:first-child { padding-left: 18px; }
.t th:last-child, .t td:last-child { padding-right: 18px; }
.t.compact td { padding: 7px 12px; }
.t .group-row td { background: var(--sunken); font-weight: 600; font-size: 13px; }
.t .indent { padding-left: 34px !important; }
.t .indent-2 { padding-left: 50px !important; }
.t .total-row td { font-weight: 700; border-top: 2px solid var(--ink); }
.panel > .table-wrap:first-child table th:first-child { border-top-left-radius: var(--r-lg); }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; }

/* ---------------------------------------------------------------- pills & tags */
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 500; padding: 2px 9px; border-radius: 99px; white-space: nowrap; line-height: 18px; }
.pill-ok { background: var(--pos-bg); color: var(--pos); }
.pill-warn { background: var(--warn-bg); color: var(--warn); }
.pill-bad { background: var(--neg-bg); color: var(--neg); }
.pill-neutral { background: var(--sunken); color: var(--ink-2); }
.pill-muted { background: var(--sunken); color: var(--faint); }
.pill-info { background: var(--info-bg); color: var(--info); }
.tag-book { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; padding: 1px 7px; border-radius: 5px; border: 1px solid; white-space: nowrap; }
.tag-book.gst { color: var(--book-gst); border-color: color-mix(in srgb, var(--book-gst) 35%, transparent); }
.tag-book.nongst { color: var(--book-nongst); border-color: color-mix(in srgb, var(--book-nongst) 35%, transparent); }
.tag-src { font-size: 11px; color: var(--brass-ink); background: var(--brass-soft); padding: 1px 6px; border-radius: 4px; font-weight: 600; }

/* ---------------------------------------------------------------- forms */
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label, .lbl-text { font-size: 13px; font-weight: 500; color: var(--ink-2); }
.field .hint { font-size: 12px; color: var(--faint); }
.req::after { content: " *"; color: var(--neg); }
.input, input:not([type]), input[type=text], input[type=number], input[type=email], input[type=password], input[type=date], input[type=tel], input[type=search], select, textarea {
  width: 100%; height: 38px; padding: 0 11px;
  font: inherit; font-size: 14px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: 7px;
  transition: border-color .12s, box-shadow .12s;
}
textarea { height: auto; min-height: 76px; padding: 9px 11px; resize: vertical; line-height: 1.45; }
select { appearance: none; padding-right: 30px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%235e6b67' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; }
input:hover, select:hover, textarea:hover { border-color: #c4ceca; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brass); box-shadow: var(--focus); }
input[readonly] { background: var(--surface-2); color: var(--muted); }
input.num { text-align: right; }
.form-grid { display: grid; gap: 14px 16px; grid-template-columns: repeat(12, minmax(0, 1fr)); }
.c-2 { grid-column: span 2; } .c-3 { grid-column: span 3; } .c-4 { grid-column: span 4; } .c-5 { grid-column: span 5; } .c-6 { grid-column: span 6; } .c-8 { grid-column: span 8; } .c-12 { grid-column: span 12; }
.check { display: flex; align-items: flex-start; gap: 9px; font-size: 13.5px; cursor: pointer; }
.check input { width: 17px; height: 17px; margin: 1px 0 0; accent-color: var(--primary); flex: none; }
.check small { display: block; color: var(--muted); }
.input-group { display: flex; }
.input-group > :not(:first-child) { border-top-left-radius: 0; border-bottom-left-radius: 0; margin-left: -1px; }
.input-group > :not(:last-child) { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.addon { display: grid; place-items: center; padding: 0 10px; background: var(--sunken); border: 1px solid var(--line); border-radius: 7px; color: var(--muted); font-size: 13px; white-space: nowrap; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg label { cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg > label > span { display: flex; align-items: center; gap: 7px; padding: 7px 14px; font-size: 13.5px; font-weight: 500; color: var(--muted); border-left: 1px solid var(--line); }
.seg label:first-child > span { border-left: 0; }
.seg input:checked + span { background: var(--binding); color: #fff; }
.seg .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.seg input:checked + span .dot { box-shadow: 0 0 0 2px rgba(255,255,255,.6); }
.seg input:focus-visible + span { box-shadow: inset var(--focus); }
.errors { background: var(--neg-bg); color: var(--neg); border-radius: 8px; padding: 10px 14px; font-size: 13.5px; margin-bottom: 14px; }

/* combobox / autocomplete */
.combo { position: relative; }
.combo-list {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 60; max-height: 300px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 9px; box-shadow: var(--shadow-pop); padding: 4px;
  min-width: 320px;
}
.combo-list .opt { padding: 8px 10px; border-radius: 6px; cursor: pointer; display: flex; justify-content: space-between; gap: 12px; font-size: 13.5px; }
.combo-list .opt small { color: var(--muted); display: block; }
.combo-list .opt.on, .combo-list .opt:hover { background: var(--sunken); }
.combo-list .opt .r { text-align: right; white-space: nowrap; color: var(--muted); font-size: 12.5px; }
.combo-list .opt.add { color: var(--primary); font-weight: 500; }

/* ---------------------------------------------------------------- toolbar / filters */
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 12px 14px; border-bottom: 1px solid var(--line-2); }
.toolbar .grow { flex: 1; }
.toolbar input[type=search] { max-width: 280px; height: 34px; }
.toolbar input[type=date], .toolbar select { height: 34px; width: auto; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 5px 11px; border-radius: 99px; font-size: 13px; border: 1px solid var(--line); color: var(--ink-2); background: var(--surface); }
.chip:hover { border-color: var(--faint); text-decoration: none; }
.chip.on { background: var(--ink); border-color: var(--ink); color: var(--surface); }
.chip .n { color: var(--faint); margin-left: 3px; }
.chip.on .n { color: inherit; opacity: .7; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tabs a { padding: 9px 14px; color: var(--muted); font-weight: 500; font-size: 13.5px; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.on { color: var(--ink); border-bottom-color: var(--brass); }

/* ---------------------------------------------------------------- flash & empty */
.flash { display: flex; gap: 10px; align-items: flex-start; padding: 11px 14px; border-radius: 9px; margin-bottom: 16px; font-size: 13.5px; border: 1px solid; }
.flash-success { background: var(--pos-bg); color: var(--pos); border-color: color-mix(in srgb, var(--pos) 25%, transparent); }
.flash-error { background: var(--neg-bg); color: var(--neg); border-color: color-mix(in srgb, var(--neg) 25%, transparent); }
.flash-info { background: var(--info-bg); color: var(--info); border-color: color-mix(in srgb, var(--info) 25%, transparent); }
.flash .x { margin-left: auto; background: none; border: 0; color: inherit; cursor: pointer; opacity: .7; }
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty .ic { width: 34px; height: 34px; color: var(--faint); margin-bottom: 8px; }
.empty h3 { color: var(--ink); margin-bottom: 4px; }
.empty p { max-width: 380px; margin: 0 auto 14px; }

.toast-wrap { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: grid; gap: 8px; }
.toast { background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 9px; font-size: 13.5px; box-shadow: var(--shadow-pop); animation: toast-in .2s ease-out; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

/* ---------------------------------------------------------------- definition list */
.dl { display: grid; grid-template-columns: 140px 1fr; gap: 8px 14px; font-size: 13.5px; margin: 0; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* ---------------------------------------------------------------- dashboard bits */
.chart-box { position: relative; height: 280px; }
.chart-box.sm { height: 210px; }
.legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.aging { display: flex; height: 10px; border-radius: 99px; overflow: hidden; background: var(--sunken); gap: 2px; }
.aging span { display: block; height: 100%; }
.aging-legend { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 12px; }
.aging-legend div { font-size: 12.5px; color: var(--muted); }
.aging-legend b { display: block; font-size: 14px; color: var(--ink); font-weight: 600; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 11px 18px; border-bottom: 1px solid var(--line-2); }
.list-row:last-child { border-bottom: 0; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .grow b { font-weight: 500; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-row .grow span { font-size: 12.5px; color: var(--muted); }
.list-row:hover { background: var(--surface-2); }
.icon-tile { width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center; background: var(--sunken); color: var(--muted); flex: none; }
.icon-tile.in { background: var(--pos-bg); color: var(--pos); }
.icon-tile.out { background: var(--neg-bg); color: var(--neg); }
.icon-tile.brass { background: var(--brass-soft); color: var(--brass-ink); }
.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--line-2); border-top: 1px solid var(--line-2); }
.quick a { background: var(--surface); padding: 14px 10px; text-align: center; color: var(--ink-2); font-size: 12.5px; display: grid; justify-items: center; gap: 6px; }
.quick a:hover { background: var(--surface-2); text-decoration: none; color: var(--ink); }
.quick a .ic { color: var(--primary); }
.greet { font-size: 13px; color: var(--muted); }

/* ---------------------------------------------------------------- voucher editor */
.doc-head { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 18px; }
.party-card { border: 1px dashed var(--line); border-radius: 9px; padding: 10px 12px; font-size: 13px; color: var(--muted); margin-top: 8px; background: var(--surface-2); }
.party-card b { color: var(--ink); font-weight: 500; }
.party-card .bal { float: right; font-weight: 600; }
.lines { width: 100%; border-collapse: collapse; table-layout: fixed; min-width: 900px; }
.lines th { font-size: 12px; color: var(--muted); font-weight: 500; text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); background: var(--surface-2); white-space: nowrap; }
.lines th.num { text-align: right; }
.lines td { padding: 6px 4px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
.lines td input, .lines td select { height: 34px; font-size: 13.5px; padding: 0 8px; }
.lines td.idx { color: var(--faint); font-size: 12px; text-align: center; padding-top: 14px; width: 28px; }
.lines td.amt { text-align: right; padding: 13px 8px 0; font-weight: 500; white-space: nowrap; }
.lines td.tax { text-align: right; padding: 13px 6px 0; font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.lines td .item-meta { font-size: 11.5px; color: var(--faint); padding: 3px 2px 0; display: flex; gap: 10px; }
.lines td .item-meta .low { color: var(--neg); }
.lines .rm { background: none; border: 0; color: var(--faint); cursor: pointer; padding: 8px 4px; border-radius: 6px; }
.lines .rm:hover { color: var(--neg); background: var(--neg-bg); }
.lines tr:focus-within td { background: color-mix(in srgb, var(--brass-soft) 35%, transparent); }
.add-line { display: flex; gap: 8px; padding: 10px 0 0; }
.totals { font-size: 13.5px; }
.totals .row { display: flex; justify-content: space-between; padding: 6px 0; }
.totals .row span:first-child { color: var(--muted); }
.totals .grand { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 12px; font-size: 20px; font-weight: 700; letter-spacing: -.02em; }
.totals .grand span:first-child { color: var(--ink); font-size: 14px; font-weight: 600; align-self: center; }
.totals .words { font-size: 12px; color: var(--muted); padding-top: 4px; }
.taxnote { font-size: 12.5px; background: var(--info-bg); color: var(--info); border-radius: 7px; padding: 7px 10px; margin-bottom: 10px; display: flex; gap: 8px; align-items: center; }
.sticky-save { position: sticky; bottom: 0; z-index: 10; background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(6px); border-top: 1px solid var(--line); padding: 12px 18px; display: flex; gap: 8px; justify-content: flex-end; align-items: center; margin: 16px -28px -64px; }
.sticky-save .hint { margin-right: auto; font-size: 12.5px; color: var(--faint); }

/* document preview (show page) */
.doc { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 32px 36px; }
.doc-top { display: flex; justify-content: space-between; gap: 24px; padding-bottom: 20px; border-bottom: 2px solid var(--ink); }
.doc-top h1 { font-size: 20px; }
.doc-kind { text-align: right; }
.doc-kind .k { font-size: 13px; color: var(--muted); }
.doc-kind .n { font-size: 20px; font-weight: 700; }
.doc-parties { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; padding: 18px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.doc-parties h4 { font-size: 12px; color: var(--muted); font-weight: 500; margin-bottom: 4px; }
.doc .t th { background: transparent; border-bottom: 1px solid var(--ink); padding-left: 8px; padding-right: 8px; }
.doc .t td { padding-left: 8px; padding-right: 8px; }
.doc-sum { display: grid; grid-template-columns: 1fr 300px; gap: 24px; padding-top: 16px; }
.paid-stamp { display: inline-block; border: 2px solid var(--pos); color: var(--pos); font-weight: 700; padding: 3px 10px; border-radius: 6px; transform: rotate(-4deg); }

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

/* ---------------------------------------------------------------- modal & palette */
dialog { border: 0; padding: 0; border-radius: 14px; background: var(--surface); color: var(--ink); box-shadow: var(--shadow-pop); width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 64px); }
dialog::backdrop { background: rgba(10, 25, 22, .45); backdrop-filter: blur(2px); }
dialog[open] { animation: pop .16s ease-out; }
@keyframes pop { from { transform: translateY(6px) scale(.99); opacity: 0; } }
.dlg-head { padding: 16px 20px; border-bottom: 1px solid var(--line-2); display: flex; align-items: center; justify-content: space-between; }
.dlg-body { padding: 18px 20px; overflow-y: auto; max-height: calc(100vh - 200px); }
.dlg-foot { padding: 12px 20px; border-top: 1px solid var(--line-2); display: flex; justify-content: flex-end; gap: 8px; }

.palette { width: min(640px, calc(100vw - 32px)); margin-top: 12vh; }
.palette input { border: 0; border-bottom: 1px solid var(--line); border-radius: 0; height: 54px; font-size: 16px; padding: 0 20px; box-shadow: none !important; }
.palette-list { max-height: 420px; overflow-y: auto; padding: 6px; }
.palette-list .sec { font-size: 11.5px; color: var(--faint); padding: 10px 12px 4px; }
.palette-list a { display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 8px; color: var(--ink); }
.palette-list a .grow { flex: 1; min-width: 0; }
.palette-list a small { color: var(--muted); display: block; font-size: 12px; }
.palette-list a.on, .palette-list a:hover { background: var(--sunken); text-decoration: none; }
.palette-list a .ic { color: var(--muted); }
.palette-foot { display: flex; gap: 14px; padding: 9px 16px; border-top: 1px solid var(--line-2); font-size: 12px; color: var(--faint); }

/* ---------------------------------------------------------------- auth */
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); }
.auth-art { background: var(--binding); color: var(--binding-ink); padding: 48px 48px 48px 64px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.auth-art .ruled { position: absolute; inset: 0; background-image: repeating-linear-gradient(0deg, rgba(255,255,255,.045) 0 1px, transparent 1px 34px); }
.auth-art .ruled::after { content: ""; position: absolute; top: 0; bottom: 0; left: 26px; width: 1px; background: rgba(184,138,46,.45); box-shadow: 4px 0 0 rgba(184,138,46,.25); }
.auth-art > * { position: relative; }
.auth-art blockquote { margin: 0; font-family: var(--font-brand); font-size: 30px; line-height: 1.25; color: #fff; max-width: 440px; font-weight: 500; }
.auth-art .feat { display: grid; gap: 10px; font-size: 14px; max-width: 400px; }
.auth-art .feat div { display: flex; gap: 10px; align-items: center; }
.auth-art .feat .ic { color: var(--brass); }
.auth-form { display: grid; place-items: center; padding: 40px 24px; background: var(--surface); }
.auth-form form { width: 100%; max-width: 380px; }
.auth-form h1 { font-size: 26px; margin-bottom: 6px; }
.demo-creds { margin-top: 22px; border-top: 1px solid var(--line); padding-top: 14px; font-size: 13px; color: var(--muted); }
.demo-creds button { display: flex; justify-content: space-between; width: 100%; background: none; border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; margin-top: 6px; cursor: pointer; font: inherit; font-size: 13px; color: var(--ink); }
.demo-creds button:hover { border-color: var(--brass); background: var(--surface-2); }
.demo-creds button span { color: var(--muted); }

/* ---------------------------------------------------------------- reports index */
.report-cats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.report-cats .panel-body { padding: 6px; }
.report-cats a.rep { display: flex; gap: 12px; padding: 10px 12px; border-radius: 8px; color: var(--ink); }
.report-cats a.rep:hover { background: var(--sunken); text-decoration: none; }
.report-cats a.rep small { display: block; color: var(--muted); font-size: 12.5px; }
.report-cats a.rep .ic { color: var(--primary); margin-top: 2px; }

/* statement two-column (P&L, balance sheet) */
.tshape { display: grid; grid-template-columns: 1fr 1fr; }
.tshape > div + div { border-left: 1px solid var(--line); }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 1180px) {
  .g-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g-main { grid-template-columns: minmax(0, 1fr); }
  .strip { grid-auto-flow: row; grid-template-columns: repeat(2, 1fr); }
  .strip > div { border-left: 0; border-top: 1px solid var(--line-2); }
  .strip > div:nth-child(-n+2) { border-top: 0; }
  .strip > div:nth-child(even) { border-left: 1px solid var(--line-2); }
  .report-cats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; left: 0; top: 0; bottom: 0; width: 272px; transform: translateX(-100%); transition: transform .2s; }
  body.nav-open .side { transform: none; box-shadow: var(--shadow-pop); }
  body.nav-open::after { content: ""; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 25; }
  .menu-toggle { display: grid; }
  .top { padding: 0 12px; gap: 8px; }
  .searchbtn span, .searchbtn kbd { display: none; }
  .searchbtn { flex: none; width: 36px; padding: 0; justify-content: center; margin: 0; }
  .books a { padding: 5px 8px; }
  .books .full { display: none; }
  .content { padding: 18px 16px 64px; }
  .g-2, .g-3, .g-side, .doc-head, .doc-sum, .doc-parties, .tshape { grid-template-columns: minmax(0, 1fr); }
  .tshape > div + div { border-left: 0; border-top: 1px solid var(--line); }
  .form-grid > * { grid-column: span 12; }
  .report-cats { grid-template-columns: 1fr; }
  .auth { grid-template-columns: 1fr; }
  .auth-art { display: none; }
  .sticky-save { margin: 16px -16px -64px; }
  .doc { padding: 20px 16px; }
  .lines thead { display: none; }
  .lines tr { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; padding: 8px 0; border-bottom: 1px solid var(--line); }
  .lines td { border: 0; padding: 0; }
  .lines td.idx { display: none; }
  .lines td.c-item { grid-column: span 6; }
  .lines td.amt, .lines td.tax { padding-top: 8px; }
}
@media (max-width: 560px) {
  .g-4, .strip { grid-template-columns: 1fr; }
  .strip > div:nth-child(even) { border-left: 0; }
  .strip > div:nth-child(2) { border-top: 1px solid var(--line-2); }
  .dl { grid-template-columns: 1fr; gap: 2px; }
  .dl dd { margin-bottom: 8px; }
  .phead h1 { font-size: 20px; }
  .quick { grid-template-columns: repeat(2, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------------------------------------------------------------- print */
@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; font-size: 12px; }
  .side, .top, .phead .actions, .no-print, .sticky-save, .toast-wrap, .tabs, .toolbar { display: none !important; }
  .shell { display: block; }
  .content { padding: 0; max-width: none; }
  .panel, .doc { border: 0; padding: 0; }
  .t th { background: #fff !important; }
  a { color: inherit; }
}

input.invalid { border-color: var(--neg); box-shadow: 0 0 0 3px color-mix(in srgb, var(--neg) 20%, transparent); }
