/* SMB ERP desk UI. Plain CSS, no build step. No inline styles in templates: the CSP forbids them. */
:root {
  /* Surfaces and text */
  --bg: #f6f7f9; --panel: #fff; --surface-2: #fafbfc; --topbar: #18213a;
  --text: #1d2330; --muted: #667085; --line: #e3e6eb; --line-strong: #c5cad3;
  --field-border: #7d8696;            /* 3.67:1 on white, 3.42:1 on --bg (WCAG 1.4.11 needs 3:1) */
  --accent: #2f5bd3; --accent-dark: #2448ab; --accent-tint: #eef3fd;
  --code-bg: #0f172a; --code-text: #e2e8f0;
  /* Status: text colour, then tint */
  --ok: #1f7a4a; --ok-tint: #e3f4ea;
  --danger: #c0352b; --danger-tint: #fbe6e4;
  --warn: #a15c00; --warn-tint: #fff3db;
  --info: #233f86; --info-tint: #eef3fd; --info-line: #c8d6f6;
  --neutral: #5d6577; --neutral-tint: #eef0f4;   /* 5.12:1 */
  /* Messages after a POST */
  --msg-ok-bg: #e9f6ef; --msg-ok-line: #b9e0c9; --msg-ok-text: #155c37;
  --msg-error-bg: #fdecea; --msg-error-line: #f2c1bc; --msg-error-text: #8f241c;
  /* Shape and spacing */
  --radius-sm: 4px; --radius: 5px; --radius-md: 6px; --radius-lg: 8px; --radius-pill: 999px;
  --control-h: 2.3rem;                /* inputs, selects and buttons share one height, so a row of them lines up */
  --topbar-h: 52px;
  --sp-1: .2rem; --sp-2: .4rem; --sp-3: .8rem; --sp-4: 1rem; --sp-5: 1.4rem;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif; font-size: 14px; color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0 0 .25rem; }
h2 { font-size: 1.1rem; margin: 1.6rem 0 .6rem; }
h3 { font-size: 1rem; margin: 1.2rem 0 .5rem; }
.muted { color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Keyboard focus: one visible ring for every control (WCAG 2.4.7, 2.4.11). */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.topbar :focus-visible { outline-color: #fff; }
.skip { position: absolute; left: -9999px; top: 0; }
.skip:focus { left: var(--sp-2); top: var(--sp-2); z-index: 10; padding: var(--sp-2) var(--sp-3); background: var(--panel);
  color: var(--accent); border-radius: var(--radius); }

.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 1rem; height: var(--topbar-h);
  padding: 0 1.2rem; background: var(--topbar); color: #fff; box-shadow: 0 1px 0 rgba(0,0,0,.25); }
.topbar a { color: #fff; }
.topbar a:hover { text-decoration: none; }
.brand { display: inline-flex; align-items: center; gap: .55rem; font-weight: 700; font-size: 1.02rem; letter-spacing: .02em; }
.brand-mark { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: var(--radius-md);
  background: var(--accent); font-size: .9rem; }
/* The company, set off from the brand by a rule; clicking it switches company. */
.company { padding-left: 1rem; border-left: 1px solid rgba(255,255,255,.2); color: rgba(255,255,255,.85) !important; }
.company:hover { color: #fff !important; }
.lang { margin-left: auto; }
.logout { margin-left: auto; display: flex; gap: .9rem; align-items: center; }
.lang ~ .logout { margin-left: 0; }
.who { display: inline-flex; align-items: center; gap: .5rem; }
.avatar { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%;
  background: rgba(255,255,255,.14); font-weight: 600; font-size: .85rem; }
.who-role { padding: .05rem .5rem; border-radius: var(--radius-pill); background: rgba(255,255,255,.1);
  color: rgba(255,255,255,.8); font-size: .78rem; }
/* Quiet buttons on the dark bar: language switch and sign out. */
.top-btn { padding: .3rem .75rem; border: 1px solid rgba(255,255,255,.28); border-radius: var(--radius); background: transparent;
  color: #fff; font: inherit; font-size: .88rem; line-height: 1.25; cursor: pointer; }
.top-btn:hover { background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.45); }

.shell { display: flex; min-height: calc(100vh - var(--topbar-h)); }
/* Stays in view while the page scrolls; scrolls itself if it is taller than the window. */
.sidebar { position: sticky; top: var(--topbar-h); align-self: flex-start; height: calc(100vh - var(--topbar-h)); overflow-y: auto;
  width: 210px; flex-shrink: 0; padding: 1rem .8rem; border-right: 1px solid var(--line); background: var(--panel); }
.sidebar h4 { margin: 1rem 0 .3rem; font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.sidebar a { display: block; padding: .25rem .4rem; border-radius: var(--radius-sm); color: var(--text); }
.sidebar a:hover { background: var(--bg); text-decoration: none; }
.sidebar a[aria-current="page"] { background: var(--accent-tint); color: var(--accent-dark); font-weight: 600; }
main { flex: 1; padding: 1.4rem 1.8rem 3rem; min-width: 0; }

.pagehead { display: flex; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.pagehead .actions { margin-left: auto; display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.actions form { display: inline; }
.lede { font-size: 1.05rem; margin-top: .3rem; }

/* One class, so the variants below (.btn-primary, .btn-danger, .btn-small) win on <button> as well as <a>. */
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: var(--control-h); padding: .3rem .85rem;
  border-radius: var(--radius); border: 1px solid var(--line); background: var(--panel); color: var(--text); font: inherit;
  line-height: 1.25; cursor: pointer; text-decoration: none; white-space: nowrap; vertical-align: middle; }
.btn:hover { border-color: var(--line-strong); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); }
.btn-small { min-height: 0; padding: .2rem .5rem; font-size: .85rem; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 1rem 1.2rem; }
.panel > :first-child { margin-top: 0; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 1rem 1.2rem; }
.card .label { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; }
.card .value { font-size: 1.5rem; font-weight: 600; margin: .3rem 0; font-variant-numeric: tabular-nums; }
.card .sub { color: var(--muted); font-size: .85rem; }
.card .sub.alert { color: var(--danger); }

table.grid { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); overflow: hidden; }
table.grid.borderless { border: 0; }
table.grid + table.grid { margin-top: var(--sp-4); }   /* report sections */
/* A report's bottom line (net profit, liabilities + equity): one row, set off like a total. */
.grid.grand-total td { font-weight: 700; font-size: 1.02rem; background: var(--surface-2); border-top: 2px solid var(--line-strong); }
/* Baseline, so text lines up with the inputs and buttons in the same row; multi-line cells start on the first line. */
.grid th, .grid td { padding: .5rem .7rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: baseline; }
.grid th { background: var(--surface-2); font-weight: 600; font-size: .82rem; color: var(--muted); }
.grid tbody tr:last-child td { border-bottom: 0; }
.grid tfoot td { font-weight: 600; background: var(--surface-2); }
.grid th.num, .grid td.num { text-align: right; }
.grid tr.overdue td.due { color: var(--danger); font-weight: 600; }
.grid input, .grid select { width: 100%; }
.grid td.narrow { width: 1%; white-space: nowrap; }
.grid td > label { margin: 0; color: inherit; font-size: inherit; }   /* a row label for the field in the next cell */

dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1.2rem; margin: 0; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

.totals { margin-left: auto; width: 320px; margin-top: .8rem; }
.totals div { display: flex; justify-content: space-between; padding: .2rem 0; }
.totals .grand { font-weight: 700; border-top: 1px solid var(--line); padding-top: .4rem; }

/* Status badges always carry a word, so colour is never the only signal. */
.badge { display: inline-block; padding: .1rem .5rem; border-radius: var(--radius-pill); font-size: .75rem; font-weight: 600;
  background: var(--neutral-tint); color: var(--neutral); }
.badge-draft { background: var(--info-tint); color: var(--info); }
.badge-submitted, .badge-executed { background: var(--ok-tint); color: var(--ok); }
.badge-cancelled, .badge-failed, .badge-rejected, .badge-overdue { background: var(--danger-tint); color: var(--danger); }
.badge-pending { background: var(--warn-tint); color: var(--warn); }

.messages { list-style: none; padding: 0; margin: 0 0 1rem; }
.msg { padding: .6rem .9rem; border-radius: var(--radius-md); margin-bottom: .4rem; border: 1px solid; }
.msg-success { background: var(--msg-ok-bg); border-color: var(--msg-ok-line); color: var(--msg-ok-text); }
.msg-error { background: var(--msg-error-bg); border-color: var(--msg-error-line); color: var(--msg-error-text); }
.msg-info, .msg-warning { background: var(--info-tint); border-color: var(--info-line); color: var(--info); }

form.stack { display: grid; gap: .8rem; max-width: 640px; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: .8rem 1rem; margin-bottom: 1rem; }
/* A row of one or two fields above a lines table: field-sized, not stretched across the panel. */
.fields.fill { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
label { display: block; font-size: .82rem; color: var(--muted); margin-bottom: .2rem; }
label.check { display: flex; align-items: center; gap: .4rem; color: var(--text); font-size: .9rem; margin-top: 1.3rem; }
input[type=text], input[type=date], input[type=number], input[type=email], input[type=password], input:not([type]), select, textarea {
  width: 100%; min-height: var(--control-h); padding: .3rem .5rem; border: 1px solid var(--field-border); border-radius: var(--radius);
  font: inherit; line-height: 1.25; background: var(--panel); }
textarea { min-height: 70px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.static-value { padding: .45rem 0; }   /* a read-only value lined up with the inputs beside it */
.formbar { display: flex; gap: .5rem; margin-top: 1rem; }

.filters { display: flex; gap: .4rem .6rem; align-items: center; flex-wrap: wrap; margin-bottom: .8rem; }
.filters a.on { font-weight: 700; color: var(--text); }
.filters form { display: flex; gap: .4rem .6rem; align-items: center; flex-wrap: wrap; }
/* A filter or quick-entry row: controls keep their natural width instead of one per line. */
.filters input:not([type=checkbox]):not([type=radio]), .filters select { width: auto; }
.filters label { margin: 0; white-space: nowrap; font-size: inherit; }
.filters label.check { margin: 0; }
.pager { display: flex; gap: 1rem; margin-top: .8rem; }
.empty { padding: 1.4rem; text-align: center; color: var(--muted); }
pre.json { background: var(--code-bg); color: var(--code-text); padding: .9rem; border-radius: var(--radius-md); overflow: auto; font-size: .82rem; }
.login { max-width: 360px; margin: 8vh auto; }
[data-difference].bad { color: var(--danger); font-weight: 600; }
.text-danger { color: var(--danger); }

/* Utilities. They replace inline styles, so they win over component rules as an inline style did. */
.m-0 { margin: 0 !important; }
.mt-0 { margin-top: 0 !important; }
.mt-3 { margin-top: var(--sp-3) !important; }
.mt-4 { margin-top: var(--sp-4) !important; }
.mt-5 { margin-top: var(--sp-5) !important; }
.inline { display: inline !important; }
.text-left { text-align: left !important; }
.w-full { max-width: none !important; }
.w-narrow { max-width: 560px !important; }
.input-4em { width: 4em !important; }
.input-5em { width: 5em !important; }
/* Column widths for tables whose inputs would otherwise share the width evenly. */
.col-9 { width: 9%; } .col-10 { width: 10%; } .col-11 { width: 11%; } .col-12 { width: 12%; } .col-14 { width: 14%; }
.col-15 { width: 15%; } .col-18 { width: 18%; } .col-25 { width: 25%; } .col-26 { width: 26%; } .col-28 { width: 28%; }
.col-30 { width: 30%; } .col-34 { width: 34%; } .col-45 { width: 45%; }
/* Chart of accounts: one step per level in the tree. */
.grid td.indent-1 { padding-left: 1rem; } .grid td.indent-2 { padding-left: 2rem; } .grid td.indent-3 { padding-left: 3rem; }
.grid td.indent-4 { padding-left: 4rem; } .grid td.indent-5 { padding-left: 5rem; } .grid td.indent-6 { padding-left: 6rem; }
.grid td.indent-7 { padding-left: 7rem; } .grid td.indent-8 { padding-left: 8rem; } .grid td.indent-9 { padding-left: 9rem; }
.grid td.indent-10 { padding-left: 10rem; }

/* Dashboard */
.card .sub.split { display: flex; justify-content: space-between; gap: .6rem; }
.negative { color: var(--danger); }
.small { font-size: .82rem; }
ul.todo { list-style: none; margin: 0; padding: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); }
ul.todo li { padding: .55rem .8rem; border-bottom: 1px solid var(--line); }
ul.todo li:last-child { border-bottom: 0; }
ul.todo li.alert a { color: var(--danger); }
/* Fills the width up to the chart's natural size (1100 × 220 units), so labels don't grow on wide screens. */
.chart svg { width: 100%; max-height: 240px; height: auto; display: block; margin: .4rem 0; }
.chart .mark { fill: var(--accent); }
.chart .mark.below { fill: var(--danger); }
.chart .bar:hover .mark { fill: var(--accent-dark); }
.chart .hit { fill: transparent; }
.chart .gridline { stroke: var(--line); stroke-dasharray: 3 3; }
.chart .baseline { stroke: var(--line-strong); }
.chart .axis { fill: var(--muted); font-size: 12px; }
.chart details { margin-top: .4rem; }
.chart summary { cursor: pointer; color: var(--accent); font-size: .85rem; }
.chart details table { margin-top: .5rem; }

/* Narrow screens: one column, the menu behind a toggle, wide tables scroll sideways inside themselves. */
.menu-toggle { display: none; background: none; border: 1px solid rgba(255,255,255,.35); border-radius: var(--radius); color: #fff;
  font: inherit; padding: .2rem .55rem; cursor: pointer; }
@media (max-width: 800px) {
  .two-col { grid-template-columns: 1fr; }
  .menu-toggle { display: inline-block; }
  .topbar { position: static; height: auto; padding: .5rem 1rem; flex-wrap: wrap; gap: .4rem .8rem; }
  .who-name { display: none; }
  .shell { flex-direction: column; }
  .sidebar { display: none; position: static; height: auto; overflow: visible; width: auto; border-right: 0; border-bottom: 1px solid var(--line); columns: 2; column-gap: 1rem; }
  .sidebar h4 { break-after: avoid; }
  .sidebar a { break-inside: avoid; }
  body.menu-open .sidebar { display: block; }
  main { padding: 1rem 1rem 2rem; }
  table.grid { display: block; overflow-x: auto; }
}

/* Print: the page content only, in black on white, for invoices and reports. */
@media print {
  :root { font-size: 11pt; }
  body { background: #fff; }
  .topbar, .sidebar, .skip, .menu-toggle, .pagehead .actions, .formbar, .filters, .pager, .messages, .chart details { display: none !important; }
  .shell { display: block; min-height: 0; }
  main { padding: 0; }
  a { color: inherit; }
  .panel, .card, table.grid, ul.todo { border-color: #999; break-inside: avoid; }
  .grid th, .grid td { border-bottom-color: #bbb; }
  .grid thead { display: table-header-group; }
  .grid tr { break-inside: avoid; }
  .badge { border: 1px solid currentColor; }
  h1, h2, h3 { break-after: avoid; }
}
