/* ===== MH Analyst ===== */
:root {
  --bg: #F2F3F5; --panel: #FFFFFF; --panel-2: #F7F8FA; --line: #E4E6EA; --line-soft: #EEF0F3; --control: #C9CCC5;
  --ink: #14171C; --muted: #5A6068; --faint: #737880;
  --accent: #1F5FD1; --accent-ink: #163E8C; --accent-bg: #E7EEFB; --on-accent: #FFFFFF;
  --green: #1E7A4C; --green-ink: #14532D; --green-bg: #E3F1E8;
  --orange: #C2620A; --orange-ink: #7A3A06; --orange-bg: #FBEEE1;
  --red-ink: #9A3412; --red-line: #E8C3A6;
  --grey-bg: #ECEEF1; --grey-ink: #3F4651;
  --shadow: 0 1px 2px rgba(20, 23, 28, .05), 0 4px 16px rgba(20, 23, 28, .04);
  --radius: 20px; --bar-muted: #D9DDE3;
  --logo: #14171C; --logo-ink: #FFFFFF;
  --hover: #F3F5F1;
  --focus-bg: #FFF6CC; --focus-line: #E2C76A;
  --blue: var(--accent); --blue-ink: var(--accent-ink); --blue-bg: var(--accent-bg);
  --chart-1: #1F5FD1; --chart-2: #E08A2E; --chart-3: #1E7A4C; --chart-grid: #E6E8E3; --chart-text: #5A6068;
  --sans: 'Segoe UI', system-ui, -apple-system, 'Noto Sans', 'Helvetica Neue', sans-serif;
  --mono: Consolas, 'SF Mono', ui-monospace, monospace;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0F1216; --panel: #171B21; --panel-2: #1C2128; --line: #2A3039; --line-soft: #232930; --control: #3A414B;
  --ink: #E8EAED; --muted: #A2A9B3; --faint: #8A919B;
  --accent: #5B8DEF; --accent-ink: #A9C4F7; --accent-bg: #1C2A44; --on-accent: #0B1220;
  --green: #4CC38A; --green-ink: #9FE3C0; --green-bg: #15302A;
  --orange: #F0A35B; --orange-ink: #F6C796; --orange-bg: #3A2716;
  --red-ink: #F4A58A; --red-line: #6B3A2A;
  --grey-bg: #252B33; --grey-ink: #C3C8CF;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
  --logo: #E8EAED; --logo-ink: #0F1216;
  --hover: #1F252D;
  --focus-bg: #2E2A16; --focus-line: #8C7A33;
  --chart-1: #6E9CF2; --chart-2: #F0A35B; --chart-3: #4CC38A; --chart-grid: #2A3039; --chart-text: #A2A9B3; --bar-muted: #333A44;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--sans); font-size: 15px; line-height: 1.45; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-ink); text-decoration: underline; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 24px; font-weight: 700; letter-spacing: -0.015em; }
h2 { font-size: 16px; font-weight: 650; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
code { font-family: var(--mono); font-size: .92em; background: var(--grey-bg); padding: 1px 5px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 13px; }
.nowrap { white-space: nowrap; }
.hint { font-size: 13px; color: var(--muted); }
.icon { flex: none; }
.selectable { user-select: all; }

/* ---------- header ---------- */
.top { background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.top-inner { max-width: 1280px; margin: 0 auto; padding: 10px 20px; display: flex; align-items: center; gap: 10px 14px; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 750; font-size: 18px; color: var(--ink); letter-spacing: -0.01em; white-space: nowrap; }
.brand:hover { color: var(--ink); text-decoration: none; }
.logo { width: 34px; height: 34px; border-radius: 9px; object-fit: contain; flex: none; }
.logo-mark { color: var(--logo); display: inline-block; }
.logo.big { width: 52px; height: 52px; border-radius: 13px; }
.company-switch { min-width: 0; }
.company-switch select { min-height: 38px; padding: 0 30px 0 10px; border: 1px solid var(--control); border-radius: 10px; background: var(--panel); color: var(--ink); font: inherit; font-weight: 600; max-width: 34vw; }
.company-name { font-weight: 600; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: 10px; border: 1px solid transparent; background: transparent; color: var(--muted); cursor: pointer; list-style: none; }
.icon-btn::-webkit-details-marker { display: none; }
.icon-btn:hover { background: var(--hover); color: var(--ink); }
[data-theme-icon] { display: none; }
:root[data-theme-choice="light"] [data-theme-icon="light"], :root[data-theme-choice="dark"] [data-theme-icon="dark"], :root[data-theme-choice="system"] [data-theme-icon="system"], :root:not([data-theme-choice]) [data-theme-icon="system"] { display: inline-flex; }
.menu { position: relative; }
.menu > summary { list-style: none; cursor: pointer; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-panel { position: absolute; right: 0; top: calc(100% + 6px); min-width: 230px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 32px rgba(0,0,0,.18); padding: 6px; z-index: 30; display: flex; flex-direction: column; }
.menu-panel a, .menu-panel button { display: block; width: 100%; text-align: left; padding: 9px 10px; border-radius: 8px; color: var(--ink); background: none; border: 0; font: inherit; font-size: 14px; cursor: pointer; }
.menu-panel a:hover, .menu-panel button:hover { background: var(--hover); text-decoration: none; }
.menu-who { padding: 8px 10px 10px; border-bottom: 1px solid var(--line-soft); margin-bottom: 4px; display: flex; flex-direction: column; font-size: 14px; }
.menu-who span { color: var(--muted); font-size: 12px; }
.tabs { max-width: 1280px; margin: 0 auto; padding: 0 14px; display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { padding: 9px 11px 11px; color: var(--muted); font-weight: 600; font-size: 14px; white-space: nowrap; border-bottom: 3px solid transparent; }
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); }

/* ---------- layout ---------- */
.wrap { max-width: 1280px; margin: 0 auto; padding: 22px 20px 40px; display: flex; flex-direction: column; gap: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.card h2 + * { margin-top: 10px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.card-head h2 + * { margin-top: 0; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px 20px; flex-wrap: wrap; }
.page-head .muted { margin-top: 4px; }
.crumbs { font-size: 13px; color: var(--muted); }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; align-items: start; }
.spaced { margin-top: 22px; }
.sync-line { margin-top: 6px; font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.dot.ok { background: var(--green); }
.dot.off { background: var(--orange); }

/* ---------- buttons, forms ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--control); background: var(--panel); color: var(--ink); font: inherit; font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap; list-style: none; }
.btn::-webkit-details-marker { display: none; }
.btn:hover { background: var(--hover); text-decoration: none; color: var(--ink); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { filter: brightness(1.07); color: var(--on-accent); }
.btn.small { min-height: 34px; padding: 0 10px; font-size: 13px; }
.btn.danger { color: var(--red-ink); border-color: var(--red-line); }
.btn.wide { width: 100%; }
.link-btn { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; font-weight: 600; }
.link-btn:hover { text-decoration: underline; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field label, fieldset legend { font-size: 13px; font-weight: 600; }
input, select, textarea { font: inherit; color: inherit; }
.field input, .field select, .field textarea, .inline-form select { min-height: 40px; padding: 6px 10px; border: 1px solid var(--control); border-radius: 10px; background: var(--panel); color: var(--ink); width: 100%; }
.field input[type="file"] { padding: 6px; }
.field input[type="range"] { padding: 0; border: 0; min-height: 30px; accent-color: var(--accent); }
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; padding: 14px 16px; }
.filters .field { flex: 0 1 180px; }
.filters .field.grow { flex: 1 1 240px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.inline-form { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin-top: 14px; }
.inline-form .field { flex: 1 1 180px; }
.form-grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; align-items: end; }
fieldset.checks { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px 10px; margin: 0; display: flex; flex-wrap: wrap; gap: 6px 16px; }
fieldset.checks label, label.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 400; }
fieldset.checks input, label.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.button-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.button-row form { display: inline; }
.code-input { font-family: var(--mono); font-size: 22px !important; letter-spacing: .18em; text-align: center; }
.big-code { font-size: 17px; padding: 4px 8px; background: var(--panel); border: 1px dashed var(--control); border-radius: 8px; display: inline-block; margin-top: 6px; }

/* ---------- notices, tags ---------- */
.notice { background: var(--accent-bg); color: var(--accent-ink); border-radius: 12px; padding: 12px 14px; font-size: 14px; }
.notice.ok { background: var(--green-bg); color: var(--green-ink); }
.notice.warn { background: var(--orange-bg); color: var(--orange-ink); }
.notice a { color: inherit; text-decoration: underline; font-weight: 600; }
.notice code { background: rgba(127,127,127,.15); }
.tag { display: inline-block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; padding: 1px 6px; border-radius: 4px; background: var(--grey-bg); color: var(--grey-ink); vertical-align: middle; }
.pill { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pill.green { background: var(--green-bg); color: var(--green-ink); }
.pill.blue { background: var(--accent-bg); color: var(--accent-ink); }
.pill.grey { background: var(--grey-bg); color: var(--grey-ink); }
.pill.orange { background: var(--orange-bg); color: var(--orange-ink); }
.type-tag { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 12px; font-weight: 700; }
.type-tag.sales { background: var(--green-bg); color: var(--green-ink); }
.type-tag.purchase { background: var(--orange-bg); color: var(--orange-ink); }
.error-text { font-size: 13px; color: var(--orange-ink); margin-top: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips a { padding: 6px 12px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); color: var(--ink); font-size: 13px; font-weight: 600; }
.chips a span { color: var(--muted); font-weight: 400; margin-left: 4px; }
.chips a[aria-current="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chips a[aria-current="true"] span { color: inherit; opacity: .7; }

/* ---------- KPIs, facts ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.kpi { display: flex; flex-direction: column; gap: 3px; color: var(--ink); }
.kpi:hover { border-color: var(--accent); text-decoration: none; color: var(--ink); }
.kpi .k, .fact .k, .big-amount .k { font-size: 12px; font-weight: 600; color: var(--muted); }
.kpi .v { font-size: 24px; font-weight: 750; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.kpi .note, .fact .note { font-size: 12px; color: var(--muted); }
.trend { font-weight: 700; }
.trend.up { color: var(--green); }
.trend.down { color: var(--orange); }
.charts { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }
.chart-card.wide { grid-column: 1 / -1; }
.chart-box { position: relative; height: 260px; }
.chart-box.tall { height: 300px; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px 20px; }
.fact { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.fact.wide { grid-column: 1 / -1; }
.fact .v { font-weight: 600; overflow-wrap: anywhere; }
.fact .v.normal { font-weight: 400; }
.big-amount { display: flex; flex-direction: column; align-items: flex-end; font-size: 22px; font-weight: 700; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -18px; padding: 0 18px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; font-weight: 650; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
th:first-child, td:first-child { padding-left: 0; }
th:last-child, td:last-child { padding-right: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
tfoot td { font-weight: 700; border-bottom: 0; border-top: 1px solid var(--line); }
.row-link { cursor: pointer; }
.row-link:hover td { background: var(--hover); }
.cancelled td { color: var(--faint); text-decoration: line-through; }
.cancelled td .tag { text-decoration: none; }
.muted-row td { color: var(--muted); background: var(--panel-2); }
.warn-row td { background: var(--orange-bg); }
.row-detail td { border-bottom: 1px solid var(--line); padding-top: 0; }
.row-detail summary { cursor: pointer; color: var(--accent); font-size: 13px; font-weight: 600; padding: 4px 0; }
.manage { padding: 10px 0 6px; }
td .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
td.actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; align-items: center; }
td.actions form { display: inline; }
.empty { color: var(--muted); padding: 14px 0; }
.empty-card { display: flex; flex-direction: column; gap: 8px; }
.pager { display: flex; gap: 16px; align-items: center; justify-content: center; padding-top: 12px; font-size: 14px; }
.day-nav { display: flex; gap: 8px; flex-wrap: wrap; }

/* instant-search tables */
.table-card { padding-top: 12px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 10px; }
.search-box { flex: 1 1 260px; display: flex; align-items: center; gap: 8px; min-height: 42px; padding: 0 12px; border: 1px solid var(--control); border-radius: 10px; background: var(--panel); color: var(--muted); }
.search-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); }
.search-box input { flex: 1; border: 0; outline: 0; background: transparent; color: var(--ink); min-height: 40px; font-size: 15px; min-width: 0; }
.toolbar select { min-height: 42px; padding: 0 10px; border: 1px solid var(--control); border-radius: 10px; background: var(--panel); color: var(--ink); max-width: 100%; }
.columns-menu .menu-panel { min-width: 220px; padding: 8px 12px; gap: 2px; }
.columns-menu label { display: flex; align-items: center; gap: 8px; padding: 6px 2px; font-size: 14px; cursor: pointer; }
.columns-menu input { width: 16px; height: 16px; accent-color: var(--accent); }
.data-table th { position: sticky; top: 0; background: var(--panel); z-index: 1; }
.data-table th[data-sort] { cursor: pointer; user-select: none; }
.data-table th[data-sort]:hover { color: var(--ink); }
.data-table th[aria-sort="ascending"]::after { content: " ▲"; font-size: 10px; }
.data-table th[aria-sort="descending"]::after { content: " ▼"; font-size: 10px; }
.data-table mark { background: var(--focus-bg); color: inherit; border-radius: 3px; padding: 0 1px; }
.qty-neg { color: var(--orange-ink); font-weight: 600; }
.table-more { display: flex; justify-content: center; padding-top: 10px; }
.table-more [hidden] { display: none; }

/* ---------- combobox (smart search boxes in the voucher form) ---------- */
.combo-list { position: absolute; z-index: 50; max-height: 320px; overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 14px 34px rgba(0,0,0,.2); padding: 4px; margin: 0; list-style: none; }
.combo-list[hidden] { display: none; }
.combo-list li { padding: 7px 10px; border-radius: 7px; cursor: pointer; display: flex; justify-content: space-between; gap: 12px; font-size: 14px; }
.combo-list li .meta { color: var(--muted); font-size: 12px; white-space: nowrap; }
.combo-list li[aria-selected="true"] { background: var(--accent-bg); color: var(--accent-ink); }
.combo-list li.none { color: var(--muted); cursor: default; }

/* ---------- login ---------- */
body.login-page { min-height: 100vh; }
.bare { min-height: 100vh; }
.login-bg { position: fixed; inset: 0; background: radial-gradient(1200px 700px at 20% 10%, #2B4C8F 0%, transparent 60%), radial-gradient(900px 600px at 90% 90%, #7A3A06 0%, transparent 55%), #0F1216; background-size: cover; background-position: center; }
.login-bg.has-image { background-color: #0F1216; }
.login-shade { position: fixed; inset: 0; background: #000; }
.login-wrap { position: relative; min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px; gap: 14px; }
.login-box { width: min(420px, 100%); padding: 28px; display: flex; flex-direction: column; gap: 16px; background: color-mix(in srgb, var(--panel) 94%, transparent); backdrop-filter: blur(8px); }
.login-brand { display: flex; align-items: center; gap: 12px; }
.login-brand h1 { font-size: 22px; }
.login-foot { color: rgba(255,255,255,.75); font-size: 12px; }
.cancel-form { text-align: center; }
.qr { display: flex; justify-content: center; padding: 12px; background: #fff; border-radius: 12px; border: 1px solid var(--line); }
.qr img { width: 200px; height: 200px; image-rendering: pixelated; }
.manual-key summary { cursor: pointer; font-size: 13px; color: var(--accent); }
.manual-key .key { font-size: 16px; letter-spacing: .08em; margin-top: 8px; user-select: all; }
.codes { columns: 2; padding-left: 22px; margin: 8px 0; font-size: 16px; line-height: 1.9; }
.danger-zone { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
.danger-zone summary { cursor: pointer; font-weight: 600; font-size: 14px; color: var(--muted); }
.danger-zone form { margin-top: 10px; }

/* ---------- settings ---------- */
.upload-row { display: flex; align-items: center; gap: 12px; }
.upload-preview .logo { width: 44px; height: 44px; }
.bg-preview { width: 100%; max-height: 140px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }
.key-reveal { border-color: var(--green); }

@media (max-width: 720px) {
  body { font-size: 15px; }
  .wrap { padding: 14px 12px 32px; gap: 12px; }
  .top-inner { padding: 8px 12px; flex-wrap: wrap; }
  .brand .brand-name { display: none; }
  .company-switch { order: 5; flex: 1 1 100%; }
  .company-switch select { max-width: 100%; width: 100%; }
  .new-btn span { display: none; }
  .new-btn { padding: 0 10px; }
  .card { padding: 14px; border-radius: 12px; }
  .table-wrap { margin: 0 -14px; padding: 0 14px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi .v { font-size: 20px; }
  .charts, .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .chart-box, .chart-box.tall { height: 230px; }
  h1 { font-size: 21px; }
  .big-amount { align-items: flex-start; }
  .filters .field { flex: 1 1 140px; }
  .codes { columns: 1; }
}
/* ===== Voucher entry, laid out like Tally's invoice screen ===== */
.tv { --tv-bg: #F4FBE9; --tv-line: #C9D8B8; --tv-head: #1F5FD1; background: var(--tv-bg); border: 1px solid var(--tv-line); border-radius: 10px; padding: 0 0 16px; font-size: 14px; overflow: hidden; }
.tv input, .tv select, .tv textarea { font: inherit; color: var(--ink); background: transparent; border: 1px solid transparent; border-radius: 4px; padding: 4px 6px; min-height: 32px; width: 100%; }
.tv input:hover, .tv textarea:hover { border-color: var(--tv-line); }
.tv input:focus, .tv select:focus, .tv textarea:focus { outline: none; background: #FFF6CC; border-color: #E2C76A; }
.tv input.num { text-align: right; font-variant-numeric: tabular-nums; }
.tv .colon { color: var(--muted); padding: 0 6px; }

.tv-top { display: flex; align-items: center; gap: 12px 20px; flex-wrap: wrap; padding: 8px 12px; border-bottom: 1px solid var(--tv-line); }
.tv-type { border: 0; margin: 0; padding: 0; display: flex; }
.tv-type label { cursor: pointer; }
.tv-type input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.tv-type span { display: inline-block; padding: 4px 18px; font-weight: 700; color: var(--muted); border: 1px solid var(--tv-line); background: #fff; }
.tv-type label:first-child span { border-radius: 4px 0 0 4px; }
.tv-type label:last-child span { border-radius: 0 4px 4px 0; border-left: 0; }
.tv-type input:checked + span { background: var(--tv-head); border-color: var(--tv-head); color: #fff; }
.tv-type input:focus-visible + span { outline: 2px solid var(--ink); outline-offset: 2px; }
.tv-no { color: var(--muted); }
.tv-no em { font-style: normal; font-weight: 700; color: var(--ink); margin-left: 6px; }
.tv-date { margin-left: auto; display: flex; flex-direction: column; align-items: flex-end; }
.tv-date input { width: auto; font-weight: 700; background: #FFF6CC; border-color: #E2C76A; text-align: right; }
.tv-date span { font-size: 13px; color: var(--muted); margin-top: 2px; }

.tv-fields { display: grid; grid-template-columns: 150px 18px minmax(0, 460px); justify-content: start; align-items: start; row-gap: 2px; padding: 10px 12px; }
.tv-fields > label { padding-top: 6px; }
.tv-fields > .colon { padding-top: 6px; }
.tv-fields input.strong { font-weight: 700; }
.tv-bal { font-size: 12px; font-style: italic; color: var(--muted); padding: 0 7px 4px; min-height: 4px; }

.tv-grid-wrap { overflow-x: auto; border-top: 1px solid var(--tv-line); }
.tv-items { width: 100%; min-width: 720px; border-collapse: collapse; table-layout: fixed; }
.tv-items th { font-size: 13px; font-weight: 700; color: var(--ink); padding: 6px; border-bottom: 1px solid var(--tv-line); background: #EAF4DC; }
.tv-items th:nth-child(1) { width: 46%; text-align: left; }
.tv-items th:nth-child(2) { width: 11%; }
.tv-items th:nth-child(3) { width: 12%; }
.tv-items th:nth-child(4) { width: 6%; text-align: left; }
.tv-items th:nth-child(5) { width: 8%; }
.tv-items th:nth-child(6) { width: 14%; }
.tv-items th:nth-child(7) { width: 40px; }
.tv-items td { padding: 3px 4px; border: 0; vertical-align: top; }
.tv-items tbody tr:first-child td { padding-top: 8px; }
.tv-item input { font-weight: 700; }
.tv-per { padding-top: 9px !important; color: var(--muted); font-size: 13px; }
.tv-sub { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; padding: 0 7px 4px 22px; font-size: 12px; }
.tv-sub:empty { display: none; }
.tv-sub .mrp i { color: var(--muted); }
.tv-sub .mrp b { font-weight: 700; }
.tv-add { margin: 6px 12px 0; }

.tv-totals { margin: 8px 12px 0 auto; width: min(520px, calc(100% - 24px)); display: flex; flex-direction: column; gap: 2px; }
.tv-line { display: grid; grid-template-columns: minmax(0, 1fr) 70px 130px; align-items: center; gap: 8px; }
.tv-line strong { text-align: right; font-variant-numeric: tabular-nums; padding-right: 6px; }
.tv-line .pct { text-align: right; color: var(--muted); }
.tv-line.subtotal { border-top: 1px solid var(--tv-line); padding-top: 6px; }
.tv-line.tax input { font-weight: 600; }
.tv-line.charge { grid-template-columns: minmax(0, 1fr) 130px 40px; }
.tv-line.round { grid-template-columns: auto minmax(0, 1fr) 130px; }
.round-toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.round-toggle input { width: 16px; height: 16px; min-height: 0; accent-color: var(--blue); }
.tv-line.grand { border-top: 1px solid var(--tv-line); border-bottom: 3px double var(--tv-line); padding: 8px 0; margin-top: 6px; font-size: 17px; }
.tv-line.grand span:first-child { font-weight: 700; }
.tv .link-btn { align-self: flex-start; font-size: 13px; margin: 2px 0 4px 6px; }

.tv-gst { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; padding: 8px 0 4px; }
.switch-row { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.switch-row input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-row .switch { position: relative; width: 40px; height: 24px; border-radius: 12px; background: #A9AEA6; transition: background .2s; flex: none; }
.switch-row .knob { position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .2s; }
.switch-row input:checked + .switch { background: var(--blue); }
.switch-row input:checked + .switch .knob { transform: translateX(16px); }
.switch-row input:focus-visible + .switch { outline: 2px solid var(--ink); outline-offset: 2px; }
.switch-label { font-weight: 700; }
.gst-opts { display: flex; gap: 8px; flex-wrap: wrap; }
.gst-opts select { width: auto; background: #fff; border-color: var(--tv-line); min-height: 34px; }
.gst-opts[hidden], .tv-line[hidden] { display: none; }

.tv-narration { display: grid; grid-template-columns: 150px 18px minmax(0, 1fr); align-items: start; padding: 14px 12px 0; }
.tv-narration label { padding-top: 6px; }
.tv-narration .colon { padding-top: 6px; }
.tv-narration textarea { min-height: 52px; resize: vertical; border-color: var(--tv-line); background: #fff; }
.tv .advanced { margin: 10px 12px 0; }
.tv .advanced .field input { background: #fff; border-color: var(--tv-line); }
.tv .form-actions { margin: 14px 12px 0; align-items: center; border-top-color: var(--tv-line); }
.tv .form-actions .hint { margin-right: auto; }

@media (max-width: 640px) {
  .tv-fields, .tv-narration { grid-template-columns: 1fr; }
  .tv-fields .colon, .tv-narration .colon { display: none; }
  .tv-fields > label { padding-top: 8px; font-size: 13px; color: var(--muted); }
  .tv-date { margin-left: 0; align-items: flex-start; }
  .tv .form-actions .hint { display: none; }
}

/* ---- voucher sheet: dark mode, purchase colour, theme-aware details ---- */
:root[data-theme="dark"] .tv { --tv-bg: #16211A; --tv-line: #2D4231; --tv-head: #5B8DEF; }
.tv[data-type="Purchase"] { --tv-bg: #FFF3E6; --tv-line: #F1CFA6; --tv-head: #C2620A; }
:root[data-theme="dark"] .tv[data-type="Purchase"] { --tv-bg: #2A1D12; --tv-line: #5C4026; --tv-head: #E58E3C; }
.tv { transition: background-color .25s, border-color .25s; color: var(--ink); }
.tv input, .tv select, .tv textarea { color: var(--ink); }
.tv input:focus, .tv select:focus, .tv textarea:focus { background: var(--focus-bg); border-color: var(--focus-line); }
.tv-date input { background: var(--focus-bg); border-color: var(--focus-line); color: var(--ink); }
.tv-type span { background: var(--panel); }
.tv-type input:checked + span { color: #fff; }
:root[data-theme="dark"] .tv-type input:checked + span { color: #0F1216; }
.tv-items th { background: color-mix(in srgb, var(--tv-line) 35%, var(--tv-bg)); }
.tv-narration textarea, .gst-opts select, .tv .advanced .field input { background: var(--panel); }
.tv .form-actions { display: flex; justify-content: flex-end; gap: 8px; border-top: 1px solid var(--tv-line); padding-top: 14px; }
.tv .advanced summary { cursor: pointer; font-weight: 600; font-size: 14px; color: var(--muted); padding: 6px 0; }
.tv .icon-btn { width: 34px; height: 34px; font-size: 20px; line-height: 1; }
.tv .hint-link { border: 1px solid var(--tv-line); background: var(--panel); border-radius: 999px; padding: 2px 9px; font: inherit; font-size: 12px; color: var(--accent-ink); cursor: pointer; text-align: left; }
.tv .hint-link:hover { background: var(--accent-bg); }

/* ---- voucher sheet on phones: each item becomes a small card ---- */
@media (max-width: 720px) {
  .tv-top { padding: 8px 10px; }
  .tv-grid-wrap { overflow: visible; }
  .tv-items, .tv-items tbody { display: block; min-width: 0; width: 100%; }
  .tv-items thead { display: none; }
  .tv-items tr { display: grid; grid-template-columns: 1fr 1fr 64px; grid-template-areas: "item item rm" "qty rate per" "disc amt amt"; gap: 2px 8px; padding: 10px 10px 8px; border-bottom: 1px solid var(--tv-line); }
  .tv-items td { padding: 0 !important; }
  .tv-items td.tv-item { grid-area: item; }
  .tv-items td[data-label="Quantity"] { grid-area: qty; }
  .tv-items td[data-label="Rate"] { grid-area: rate; }
  .tv-items td.tv-per { grid-area: per; align-self: end; padding-bottom: 8px !important; }
  .tv-items td[data-label="Disc %"] { grid-area: disc; }
  .tv-items td[data-label="Amount"] { grid-area: amt; }
  .tv-items td.tv-rm { grid-area: rm; justify-self: end; }
  .tv-items td[data-label]:not(.tv-item):not(.tv-per)::before { content: attr(data-label); display: block; font-size: 11px; color: var(--muted); margin: 2px 0 0 6px; }
  .tv-items input { background: var(--panel); border-color: var(--tv-line); }
  .tv-sub { padding-left: 6px; }
  .tv-totals { width: calc(100% - 20px); margin: 8px 10px 0; }
  .tv-line { grid-template-columns: minmax(0, 1fr) 54px 110px; }
  .tv-line.round { grid-template-columns: auto minmax(0, 1fr) 90px; }
  .tv-line.charge { grid-template-columns: minmax(0, 1fr) 110px 36px; }
  .tv .form-actions { flex-wrap: wrap; }
  .tv .form-actions .btn { flex: 1 1 auto; }
}

/* ---- smooth page changes (supported browsers fade between pages) ---- */
@view-transition { navigation: auto; }
::view-transition-old(root), ::view-transition-new(root) { animation-duration: 160ms; }
@media (prefers-reduced-motion: reduce) { ::view-transition-old(root), ::view-transition-new(root) { animation: none; } }

/* ---- phone bottom tab bar ---- */
.bottom-nav { display: none; }
.phone-only { display: none !important; }
.offline-note { margin-bottom: 4px; }
.ptr { position: fixed; top: 0; left: 50%; z-index: 40; width: 38px; height: 38px; margin-left: -19px; border-radius: 50%; background: var(--panel); box-shadow: 0 4px 14px rgba(0,0,0,.2); display: flex; align-items: center; justify-content: center; color: var(--accent); transform: translateY(-50px); transition: transform .15s; pointer-events: none; }
.ptr svg { transition: transform .1s; }
.ptr.spin svg { animation: ptr-spin .8s linear infinite; }
@keyframes ptr-spin { to { transform: rotate(360deg); } }
@media (max-width: 720px) {
  .tabs { display: none; }
  .phone-only { display: block !important; }
  .bottom-nav { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; background: var(--panel); border-top: 1px solid var(--line); padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); }
  .bottom-nav a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px; border-radius: 10px; color: var(--muted); font-size: 11px; font-weight: 600; text-decoration: none; -webkit-tap-highlight-color: transparent; }
  .bottom-nav a[aria-current="page"] { color: var(--accent); background: var(--accent-bg); }
  .bottom-nav .icon { width: 22px; height: 22px; }
  body:has(.bottom-nav) .wrap { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
  .top { position: sticky; }
  .combo-list { max-height: 45vh; }
}
/* In the Android app, tapping shouldn't flash grey boxes, and text in controls shouldn't be selectable. */
body.in-app { -webkit-tap-highlight-color: transparent; }
body.in-app .btn, body.in-app .tabs a, body.in-app .bottom-nav a, body.in-app summary { -webkit-user-select: none; user-select: none; }
@media (max-width: 720px) {
  #ledger-table th:nth-child(3), #ledger-table td:nth-child(3) { display: none; }
}


/* ===================== 2026 refresh: analytics-app look ===================== */
body { letter-spacing: -0.005em; }
.card { box-shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .04); border-color: transparent; }
:root[data-theme="dark"] .card { border-color: var(--line); }
.top { background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(12px); border-bottom-color: transparent; }
.tabs a[aria-current="page"] { border-bottom-color: var(--ink); }
.sync-btn .icon { transition: transform .2s; }
.sync-btn.spinning .icon { animation: ptr-spin .9s linear infinite; color: var(--accent); }
.toast { position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px); opacity: 0; z-index: 60; max-width: min(92vw, 460px);
  background: var(--ink); color: var(--bg); padding: 11px 16px; border-radius: 14px; font-size: 14px; font-weight: 600; box-shadow: 0 10px 30px rgba(0,0,0,.25);
  transition: opacity .2s, transform .2s; pointer-events: none; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* dashboard */
.dash-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.dash-head h1 { font-size: 28px; letter-spacing: -0.02em; }
.seg { display: inline-flex; background: var(--panel); border-radius: 999px; padding: 4px; box-shadow: 0 1px 2px rgba(16,24,40,.06); }
.seg a { padding: 7px 14px; border-radius: 999px; font-size: 13px; font-weight: 650; color: var(--muted); white-space: nowrap; }
.seg a:hover { text-decoration: none; color: var(--ink); }
.seg a[aria-current="true"] { background: var(--ink); color: var(--bg); }
.dash { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.dcard { background: var(--panel); border-radius: 22px; padding: 18px 20px; box-shadow: 0 1px 2px rgba(16,24,40,.04), 0 8px 24px rgba(16,24,40,.05); display: flex; flex-direction: column; gap: 6px; min-width: 0; }
:root[data-theme="dark"] .dcard { border: 1px solid var(--line); }
.dcard.span-2 { grid-column: span 2; }
.dcard-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.dcard-head h2 { font-size: 15px; font-weight: 600; color: var(--muted); }
.dcard-link { width: 32px; height: 32px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; color: var(--ink); background: var(--panel-2); font-weight: 700; }
.dcard-link:hover { text-decoration: none; background: var(--hover); color: var(--ink); }
.big { font-size: 34px; font-weight: 750; letter-spacing: -0.03em; line-height: 1.1; font-variant-numeric: tabular-nums; display: flex; align-items: baseline; flex-wrap: wrap; gap: 0 2px; }
.big.small-big { font-size: 26px; }
.big .cur { font-size: .62em; font-weight: 650; margin-right: 2px; opacity: .8; }
.big .dec { color: var(--faint); font-weight: 600; }
.trend-chip { align-self: center; margin-left: 10px; font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 999px; letter-spacing: 0; }
.trend-chip.up { background: #20B15A; color: #fff; }
.trend-chip.down { background: #E5484D; color: #fff; }
.dcard .sub { font-size: 13px; color: var(--muted); }
.dcard .chart-box { height: 220px; margin-top: 8px; }
.dcard .chart-box.short { height: 150px; }
.dcard .chart-box.donut { height: 190px; }
.dcard.dark { background: #14171C; color: #F2F3F5; }
.dcard.dark .dcard-head h2, .dcard.dark .sub, .muted-inv { color: rgba(255,255,255,.62); font-size: 13px; }
.dcard.dark .big .dec { color: rgba(255,255,255,.45); }
.dcard.blue { background: #2563EB; color: #fff; }
.dcard.blue .dcard-head h2, .dcard.blue .sub { color: rgba(255,255,255,.8); }
.dcard.blue .big .dec { color: rgba(255,255,255,.6); }
.dcard.blue .dcard-link { background: rgba(255,255,255,.18); color: #fff; }
:root[data-theme="dark"] .dcard.dark { background: #0B0D10; }
:root[data-theme="dark"] .dcard.blue { background: #1D4ED8; border-color: #1D4ED8; }
.split { display: flex; height: 54px; border-radius: 12px; overflow: hidden; margin-top: 10px; font-weight: 700; font-size: 14px; }
.split span { display: flex; align-items: flex-end; padding: 8px 10px; min-width: 44px; }
.split .a { background: #fff; color: #14171C; }
.split .b { background: #14171C; color: #fff; justify-content: flex-end; }
.split-legend { display: flex; justify-content: space-between; font-size: 12px; color: rgba(255,255,255,.85); margin-top: 6px; }
.split-legend i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.split-legend i.a { background: #fff; } .split-legend i.b { background: #14171C; }
.legend { list-style: none; margin: 4px 0 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; font-size: 13px; }
.legend li { display: flex; align-items: center; gap: 6px; min-width: 0; }
.legend li span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.legend li b { margin-left: auto; font-weight: 650; }
.legend i { width: 9px; height: 9px; border-radius: 3px; flex: none; }
.mini-title { font-size: 13px; color: var(--muted); font-weight: 600; margin: 14px 0 2px; }
.rank, .shares, .vlist { list-style: none; margin: 0; padding: 0; }
.rank li { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line-soft); }
.rank li:first-child { border-top: 0; }
.rank-n { width: 26px; height: 26px; border-radius: 8px; background: var(--panel-2); display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; color: var(--muted); flex: none; }
.rank-name { flex: 1; min-width: 0; display: flex; flex-direction: column; font-size: 14px; font-weight: 600; }
.rank-name a { color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank-name small { color: var(--muted); font-weight: 400; font-size: 12px; }
.rank-v { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.shares li { padding: 9px 0; }
.share-top { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; font-weight: 600; }
.share-top a { color: var(--ink); }
.share-top span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.share-top .muted { font-weight: 400; font-size: 12px; white-space: nowrap; }
.share-bar { height: 8px; border-radius: 999px; background: var(--panel-2); margin-top: 6px; overflow: hidden; }
.share-bar span { display: block; height: 100%; border-radius: 999px; background: var(--ink); }
.vlist li a { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line-soft); color: var(--ink); }
.vlist li:first-child a { border-top: 0; }
.vlist li a:hover { text-decoration: none; background: var(--hover); border-radius: 12px; }
.vicon { width: 38px; height: 38px; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center; font-weight: 800; flex: none; background: var(--grey-bg); color: var(--grey-ink); }
.vicon.sales { background: var(--green-bg); color: var(--green-ink); }
.vicon.purchase { background: var(--orange-bg); color: var(--orange-ink); }
.vmain { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.vmain strong { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vmain small { font-size: 12px; color: var(--muted); }
.vamt { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* stock: filter chips and product cards */
.filter-chips { margin: 0 0 10px; overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
.filter-chips::-webkit-scrollbar { display: none; }
.filter-chips button { padding: 7px 14px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); color: var(--ink); font: inherit; font-size: 13px; font-weight: 600; white-space: nowrap; cursor: pointer; }
.filter-chips button[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.phone-only-block { display: none; }
.pcards { display: flex; flex-direction: column; gap: 12px; }
.pcard { display: flex; flex-direction: column; gap: 8px; padding: 14px; border-radius: 18px; background: var(--panel-2); color: var(--ink); border: 1px solid var(--line-soft); }
.pcard:hover { text-decoration: none; color: var(--ink); }
.pc-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.pc-top strong { display: block; font-size: 15px; }
.pc-top small { color: var(--muted); font-size: 12px; }
.status { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 6px; white-space: nowrap; }
.status.in { background: #20B15A; color: #fff; }
.status.low { background: #F59E0B; color: #1F1300; }
.status.out { background: var(--grey-bg); color: var(--grey-ink); }
.pc-row { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; color: var(--muted); }
.pc-row b { color: var(--ink); font-weight: 700; }
.pc-stock { display: flex; justify-content: space-between; font-size: 12px; font-weight: 700; margin-top: 2px; }
.pc-stock span:last-child { color: var(--muted); font-weight: 600; }
.pc-bar { height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; }
.pc-bar span { display: block; height: 100%; border-radius: 999px; background: var(--ink); }
.pc-bar span.low { background: #F59E0B; }

@media (max-width: 1080px) {
  .dash { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .dash { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .dcard.span-2 { grid-column: auto; }
  .dcard { border-radius: 20px; padding: 16px; }
  .big { font-size: 30px; }
  .dash-head h1 { font-size: 26px; }
  .seg { width: 100%; justify-content: space-between; }
  .seg a { flex: 1; text-align: center; padding: 8px 6px; }
  .desk-only { display: none; }
  .phone-only-block { display: flex; }
  .table-card { background: transparent; box-shadow: none; padding: 0; border: 0; }
  .toast { bottom: calc(86px + env(safe-area-inset-bottom)); }
  /* bottom tab bar: dark rounded active tab, like the reference */
  .bottom-nav { background: var(--panel); border-top: 0; box-shadow: 0 -6px 20px rgba(16,24,40,.06); padding-top: 6px; }
  .bottom-nav a[aria-current="page"] { background: transparent; color: var(--ink); }
  .bottom-nav a[aria-current="page"] .icon { background: var(--ink); color: var(--bg); border-radius: 9px; padding: 4px; width: 30px; height: 30px; }
  .bottom-nav a .icon { padding: 4px; width: 30px; height: 30px; }
}
@media (max-width: 720px) { .columns-menu { display: none; } }
