:root {
  /* Classic (the original purple dark look). The templates below redefine these tokens; see docs/THEMES in README. */
  --primary: #6C5CE7;
  --primary-dark: #5A4BD1;
  --primary-light: #A29BFE;
  --secondary: #00CEC9;
  --text: #DFE6E9;
  --text-muted: #9AA7AD;
  --success: #00B894;
  --warning: #FDCB6E;
  --danger: #FF7675;
  --info: var(--info);
  --bg: #0D1117;
  --card: #161B22;
  --card-2: #1C2128;
  --border: #30363D;
  --on-primary: #fff;
  --link: var(--primary-light);
  --link-hover: #c3bdff;
  --nav-bg: var(--card);
  --nav-text: var(--text);
  --nav-active-bg: color-mix(in srgb, var(--primary) 18%, transparent);
  --nav-active-text: #fff;
  --toast-bg: #222a33;
  --btn-hover-border: #4a525b;
  /* Chart series: fixed order, validated for colour-vision deficiency against the card surface; "Other" is always grey */
  --s1: #7C6CF0; --s2: #1FAAA5; --s3: #C98500; --s4: #D55181; --s5: #3987E5; --s6: #D95926; --other: #6b7480;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 20px rgba(0,0,0,.3);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: dark;
}
/* Appearance (Settings → Appearance): a template sets the accent and the sidebar, the mode (day / night) sets the surfaces.
   Custom colours are inline variables on <html> on top of a template. */
html[data-base="dark"] {
  --text: #E8ECF1; --text-muted: #98A3B3; --success: #2FBF5B; --warning: #E3A33B; --danger: #F06A5E; --info: #6EA8F5;
  --bg: #0F1318; --card: #171D25; --card-2: #1F2731; --border: #27303B;
  --toast-bg: #1F2731; --btn-hover-border: #3A4552; --shadow: 0 4px 20px rgba(0,0,0,.35);
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #9085e9; --other: #6B7684;
  color-scheme: dark;
}
html[data-base="light"] {
  --text: #14213D; --text-muted: #5B6577; --success: #1F7A32; --warning: #B26B00; --danger: #C0392B; --info: #1C5CAB;
  --bg: #F3F5F8; --card: #FFFFFF; --card-2: #EEF2F7; --border: #DDE3EC;
  --toast-bg: #FFFFFF; --btn-hover-border: #B9C3D1; --shadow: 0 4px 20px rgba(20,33,61,.10);
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #6250d6; --other: #8893A1;
  --nav-active-bg: rgba(255,255,255,.14); --nav-active-text: #fff;
  color-scheme: light;
}
html[data-theme="classic"][data-base="dark"] { --bg: #0D1117; --card: #161B22; --card-2: #1C2128; --border: #30363D; --text: #DFE6E9; --text-muted: #9AA7AD; --success: #00B894; --warning: #FDCB6E; --danger: #FF7675; --info: #74b9ff; --s1: #7C6CF0; --s2: #1FAAA5; --s3: #C98500; --s4: #D55181; --s5: #3987E5; --s6: #D95926; --other: #6b7480; --nav-bg: var(--card); --nav-text: var(--text); }
html[data-theme="classic"][data-base="light"] { --primary: #5A4BD1; --primary-dark: #4A3CB8; --primary-light: #4A3CB8; --link: #4A3CB8; --link-hover: #6C5CE7; --nav-bg: #FFFFFF; --nav-text: #14213D; --nav-active-bg: color-mix(in srgb, var(--primary) 14%, transparent); --nav-active-text: var(--text); }
html[data-theme="graphite"] { --primary: #3987E5; --primary-dark: #2A6FC4; --primary-light: #6EA8F5; --secondary: #199E70; --link: #6EA8F5; --link-hover: #9CC3F8; --nav-bg: #0B0F14; --nav-text: #C9D2DD; --nav-active-bg: color-mix(in srgb, var(--primary) 22%, transparent); --nav-active-text: #fff; }
html[data-theme="graphite"][data-base="light"] { --primary: #2A78D6; --primary-dark: #1F5FAE; --primary-light: #1C5CAB; --link: #1C5CAB; --link-hover: #2A78D6; --nav-bg: #1C2430; --nav-text: #D5DCE6; --nav-active-bg: rgba(255,255,255,.14); }
html[data-theme="navy"] { --primary: #2A78D6; --primary-dark: #1F5FAE; --primary-light: #1C5CAB; --secondary: #1BAF7A; --link: #1C5CAB; --link-hover: #2A78D6; --nav-bg: #1F3A5F; --nav-text: #DCE4F0; --nav-active-bg: rgba(255,255,255,.14); --nav-active-text: #fff; --bg: #F3F5F8; }
html[data-theme="navy"][data-base="dark"] { --primary: #3987E5; --primary-dark: #2A6FC4; --primary-light: #6EA8F5; --link: #6EA8F5; --link-hover: #9CC3F8; --nav-bg: #16294A; --bg: #0F1318; }
html[data-theme="forest"] { --primary: #1B8A5A; --primary-dark: #14694A; --primary-light: #146B48; --secondary: #2A78D6; --link: #146B48; --link-hover: #1B8A5A; --nav-bg: #0B3B2E; --nav-text: #D5E6DC; --nav-active-bg: rgba(255,255,255,.14); --nav-active-text: #fff; }
html[data-theme="forest"][data-base="light"] { --bg: #F7F6F2; --card-2: #F0EFE9; --border: #E1DFD6; --text: #1B2A24; --text-muted: #5E6B66; --btn-hover-border: #BDBBB0; --other: #8A928C; }
html[data-theme="forest"][data-base="dark"] { --primary: #2FB37A; --primary-dark: #1B8A5A; --primary-light: #5FD39C; --link: #5FD39C; --link-hover: #8CE4B8; --nav-bg: #0A2E24; --bg: #0E1512; --card: #15201B; --card-2: #1C2922; --border: #263630; }

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg); color: var(--text); min-height: 100vh; line-height: 1.45;
  font-size: 15px;
}
[hidden] { display: none !important; }
a { color: var(--link); text-decoration: none; }
a:hover { color: var(--link-hover); }
h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; font-weight: 650; }
h3 { font-size: 1rem; font-weight: 600; }
p { margin: 0; }
.muted { color: var(--text-muted); }
.small { font-size: .85rem; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.pos { color: var(--success); }
.neg { color: var(--danger); }
.error { color: var(--danger); font-size: .9rem; }
.notice { background: color-mix(in srgb, var(--warning) 12%, transparent); border: 1px solid color-mix(in srgb, var(--warning) 40%, transparent); color: var(--warning); padding: 10px 12px; border-radius: var(--radius-sm); font-size: .9rem; }
.ok { background: color-mix(in srgb, var(--success) 12%, transparent); border: 1px solid color-mix(in srgb, var(--success) 40%, transparent); color: var(--success); padding: 10px 12px; border-radius: var(--radius-sm); font-size: .9rem; }
.warn { background: color-mix(in srgb, var(--danger) 10%, transparent); border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent); color: var(--danger); padding: 10px 12px; border-radius: var(--radius-sm); font-size: .9rem; }
.spacer { flex: 1; }

/* Brand */
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.1rem; color: var(--text); }
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary), var(--secondary)); color: var(--on-primary); font-size: .8rem; font-weight: 800;
}

/* Buttons & inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--card-2); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; min-height: 40px;
}
.btn:hover { border-color: var(--btn-hover-border); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; }
.btn-danger { background: transparent; border-color: color-mix(in srgb, var(--danger) 50%, transparent); color: var(--danger); }
.btn-sm { padding: 5px 10px; min-height: 32px; font-size: .85rem; }
input, select, textarea {
  width: 100%; padding: 9px 11px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font: inherit; min-height: 40px;
}
textarea { min-height: 60px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: var(--primary); }
label { display: block; font-size: .9rem; color: var(--text-muted); margin-bottom: 12px; }
label > span { display: block; margin-bottom: 5px; font-weight: 600; color: var(--text); }
label > input, label > select, label > textarea { margin-top: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .grid2 { grid-template-columns: 1fr; } }

/* Gate */
.gate { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.gate-card { width: 100%; max-width: 440px; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px 24px; box-shadow: var(--shadow); display: grid; gap: 16px; }
.gate-card h1 { font-size: 1.3rem; }
.gate-foot { text-align: center; font-size: .9rem; }
.qr { display: grid; place-items: center; background: #fff; border-radius: var(--radius-sm); padding: 12px; }
.qr svg { width: 200px; height: 200px; }
.secret { display: block; font-family: var(--mono); letter-spacing: .08em; word-break: break-all; background: var(--bg); padding: 10px; border-radius: var(--radius-sm); border: 1px solid var(--border); font-size: .9rem; user-select: all; }
.code-form { display: grid; gap: 8px; }
.code-form input { font-size: 1.6rem; letter-spacing: .3em; text-align: center; font-family: var(--mono); }

/* App layout */
.app { display: grid; grid-template-columns: 220px 1fr; grid-template-rows: 84px 1fr; min-height: 100vh; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; justify-content: flex-end; gap: 12px; padding: 0 20px; background: var(--card); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar .brand { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); font-size: 1.35rem; gap: 14px; }
.topbar .brand-logo { width: 60px; height: 60px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.lang { width: auto; min-height: 36px; padding: 6px 10px; }
.sidenav { background: var(--nav-bg); border-right: 1px solid var(--border); padding: 12px; display: flex; flex-direction: column; gap: 2px; }
.sidenav a { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; border-radius: var(--radius-sm); color: var(--nav-text); font-weight: 500; }
.sidenav a:hover { background: var(--nav-active-bg); color: var(--nav-active-text); }
.sidenav a.active { background: var(--nav-active-bg); color: var(--nav-active-text); }
.sidenav .tag { font-size: .7rem; color: var(--text-muted); border: 1px solid var(--border); padding: 1px 6px; border-radius: 999px; }
.content { padding: 24px; max-width: 1200px; width: 100%; min-width: 0; }
.sidenav { min-width: 0; }
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 64px auto 1fr; }
  .sidenav { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--border); padding: 8px 12px; }
  .sidenav a { white-space: nowrap; padding: 8px 12px; }
  .sidenav .tag { display: none; }
  .content { padding: 16px; }
  .topbar { padding: 0 12px; }
  .topbar .brand span:last-child { display: none; }
  .topbar .brand { left: 16px; transform: translateY(-50%); }
  .topbar .brand-logo { width: 44px; height: 44px; }
  .topbar a[data-link="home"] { display: none; }
  .topbar .btn-ghost { padding: 9px 10px; }
}

/* Page pieces */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.card + .card, .section + .section, .card + .section { margin-top: 18px; }
.section h2 { margin-bottom: 10px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat .label { color: var(--text-muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 1.35rem; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .sub { color: var(--text-muted); font-size: .85rem; margin-top: 2px; }
.empty { color: var(--text-muted); padding: 24px; text-align: center; border: 1px dashed var(--border); border-radius: var(--radius); }
.pill { display: inline-block; font-size: .75rem; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--text-muted); white-space: nowrap; }
.pill.ok { color: var(--success); border-color: color-mix(in srgb, var(--success) 50%, transparent); background: transparent; padding: 2px 8px; }
.pill.bad { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 50%, transparent); }
.pill.unknown { color: var(--warning); border-color: color-mix(in srgb, var(--warning) 50%, transparent); }

/* Account list */
.account-list { display: grid; gap: 10px; }
.account { display: flex; align-items: center; gap: 14px; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; flex-wrap: wrap; }
.account .name { font-weight: 650; }
.account .meta { color: var(--text-muted); font-size: .85rem; }
.account .actions { margin-left: auto; display: flex; gap: 8px; }
.account.inactive { opacity: .6; }
@media (max-width: 560px) { .account .actions { margin-left: 0; width: 100%; } }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--text-muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; background: var(--card-2); }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--card-2); }
td.clip { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sample th, .sample td { font-family: var(--mono); font-size: .78rem; white-space: nowrap; }
.sample th.mapped { color: var(--primary-light); }

/* Transactions on phones: card rows */
@media (max-width: 700px) {
  .tx-table thead { display: none; }
  .tx-table tr { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
  .tx-table td { border: 0; padding: 0; display: block; }
  .tx-table td.clip { white-space: normal; max-width: none; grid-column: 1; }
  .tx-table td.t-date { color: var(--text-muted); font-size: .8rem; grid-column: 1; order: -1; }
  .tx-table td.t-amount { grid-column: 2; grid-row: 1 / span 2; align-self: center; font-weight: 650; }
  .tx-table td.t-bal, .tx-table td.t-account { display: none; }
  .tx-table td.t-cp { color: var(--text-muted); font-size: .85rem; grid-column: 1; }
  .tx-table td.t-actions { grid-column: 2; }
}
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; align-items: center; }
.filters input, .filters select { width: auto; min-width: 140px; min-height: 38px; }
.filters input[type=search] { flex: 1; min-width: 180px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.seg button { background: transparent; border: 0; color: var(--text-muted); padding: 8px 12px; font: inherit; cursor: pointer; }
.seg button.active { background: color-mix(in srgb, var(--primary) 20%, transparent); color: var(--text); }
.table-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 2px; color: var(--text-muted); font-size: .85rem; }

/* Import wizard */
.steps { display: flex; gap: 6px; margin-bottom: 18px; counter-reset: s; }
.steps span { flex: 1; text-align: center; padding: 8px; border-radius: var(--radius-sm); background: var(--card-2); color: var(--text-muted); font-size: .85rem; border: 1px solid var(--border); }
.steps span.active { color: var(--text); border-color: var(--primary); background: color-mix(in srgb, var(--primary) 20%, transparent); }
.steps span.done { color: var(--success); }
.dropzone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 32px 16px; text-align: center; color: var(--text-muted); background: var(--card); cursor: pointer; }
.dropzone:hover, .dropzone.over { border-color: var(--primary); color: var(--text); }
.dropzone input { display: none; }
.mapping { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px 16px; }
.mapping label { margin: 0; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: .95rem; }
.kv dt { color: var(--text-muted); }
.kv dd { font-variant-numeric: tabular-nums; }
.wizard-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }

/* Dialogs & toast */
.dialog { margin: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); color: var(--text); padding: 22px; width: min(520px, calc(100vw - 32px)); box-shadow: var(--shadow); }
.dialog::backdrop { background: rgba(0,0,0,.6); }
.dialog h2 { margin-bottom: 12px; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--toast-bg); border: 1px solid var(--border); color: var(--text); padding: 10px 16px; border-radius: 999px; box-shadow: var(--shadow); z-index: 50; max-width: calc(100vw - 32px); font-size: .9rem; }
.toast.err { border-color: color-mix(in srgb, var(--danger) 60%, transparent); color: var(--danger); }

.audit { font-size: .85rem; }
.audit td:first-child { white-space: nowrap; color: var(--text-muted); }
.audit code { font-family: var(--mono); font-size: .78rem; color: var(--text-muted); word-break: break-all; }

/* Invoices & customers */
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .grid3 { grid-template-columns: 1fr; } }
.review { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; align-items: start; }
@media (max-width: 960px) { .review { grid-template-columns: 1fr; } }
.preview { display: flex; flex-direction: column; min-height: 320px; }
.preview-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; font-size: .85rem; color: var(--text-muted); }
.preview-head .clip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview iframe { width: 100%; flex: 1; min-height: 560px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: #fff; }
@media (max-width: 960px) { .preview iframe { min-height: 420px; } }
input.conf-medium, select.conf-medium { border-color: var(--warning); box-shadow: inset 3px 0 0 var(--warning); }
input.conf-low, input.conf-none { border-color: var(--danger); box-shadow: inset 3px 0 0 var(--danger); }
.conf-hint { display: block; font-size: .75rem; margin: -2px 0 4px; }
.conf-hint.conf-medium { color: var(--warning); }
.conf-hint.conf-low, .conf-hint.conf-none { color: var(--danger); }
label.check { display: flex; align-items: center; gap: 8px; color: var(--text); }
label.check input { width: auto; min-height: 0; }
.stat.link { display: block; color: inherit; }
.stat.link:hover { border-color: var(--primary); }
tr.link { cursor: pointer; }
@media (max-width: 700px) {
  .inv-table thead, .cust-table thead { display: none; }
  .inv-table tr, .cust-table tr { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
  .inv-table td, .cust-table td { border: 0; padding: 0; display: block; }
  .inv-table td.num, .cust-table td.num { text-align: left; }
  .inv-table td.t-actions { grid-column: 2; grid-row: 1 / span 3; align-self: center; }
}

/* Logo and footer */
.brand-logo { width: 30px; height: 30px; object-fit: contain; flex: none; }
.brand.stacked { flex-direction: column; justify-content: center; gap: 10px; width: 100%; padding: 6px 0 2px; }
.brand.stacked .brand-logo { width: 216px; height: 216px; }
.brand.stacked .brand-name { font-size: 2.1rem; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; }
.powered { color: var(--text-muted); font-size: .8rem; text-align: center; }
.powered a { color: var(--text-muted); text-decoration: underline; text-underline-offset: 3px; }
.powered a:hover { color: var(--text); }
.app-foot { grid-column: 1 / -1; padding: 14px 24px 18px; border-top: 1px solid var(--border); background: var(--card); }
.app { grid-template-rows: 84px 1fr auto; }
@media (max-width: 860px) { .app { grid-template-rows: 64px auto 1fr auto; } .app-foot { padding: 12px 16px 16px; } }

/* Phase 2: matching and categories */
.proposal { padding: 14px 16px; margin-bottom: 10px; }
.pair { display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px; align-items: center; }
.pair .arrow { color: var(--text-muted); font-size: 1.3rem; }
@media (max-width: 640px) { .pair { grid-template-columns: 1fr; } .pair .arrow { display: none; } }
.cat-select { min-height: 32px; padding: 4px 8px; font-size: .85rem; max-width: 220px; }
td.t-cat { max-width: 240px; }
#match-list tr.sel td { background: color-mix(in srgb, var(--primary) 12%, transparent); }
#match-list td { vertical-align: middle; }
.attention { list-style: none; display: grid; gap: 6px; }
.attention li a { display: block; padding: 10px 12px; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text); }
.attention li a:hover { border-color: var(--primary); }
.toast .btn { margin-left: 8px; }
@media (max-width: 700px) { .tx-table td.t-cat { grid-column: 1; } .tx-table td.t-cat select { max-width: 100%; } }

/* Phase 3: dashboard charts, reminders, customer behaviour, reports, settings */
.charts { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; margin-top: 20px; }
.charts .wide { grid-column: 1 / -1; }
.chart-card h3 { margin-bottom: 10px; }
.chart-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.chart-head .btn { flex: none; margin-top: -4px; color: var(--text-muted); }
.chart-head .btn.active { color: var(--text); border-color: var(--primary); }
.chart-table table { width: 100%; }
.chart-table th.num, .chart-table td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.sub-h { margin: 14px 0 6px; font-size: .9rem; color: var(--text-muted); font-weight: 600; }
.sec-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.sec-head h2 { margin-bottom: 0; }
.open-table.collapsed tr.extra { display: none; }
.open-table tr.overdue td:first-child { box-shadow: inset 3px 0 0 var(--danger); }
.open-table tfoot td { border-top: 2px solid var(--border); font-variant-numeric: tabular-nums; }
.open-table td.num, .open-table th.num, .open-table td.mono, .open-table td.small { white-space: nowrap; }
.open-table td:first-child { min-width: 170px; }
.open-table .pill { margin-top: 2px; }
@media (max-width: 700px) { .hide-phone { display: none; } }
.cards-6, .cards-7 { grid-template-columns: repeat(4, 1fr); } .cards-5 { grid-template-columns: repeat(5, 1fr); }
@media (max-width: 1250px) { .cards-6, .cards-7 { grid-template-columns: repeat(3, 1fr); } .cards-5 { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 900px) { .cards-6, .cards-7, .cards-5 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 420px) { .cards-6, .cards-7, .cards-5 { grid-template-columns: 1fr; } }
.stat .spark { display: block; width: 100%; max-width: 160px; height: 28px; margin-top: 8px; opacity: .9; }
.stat .spark polyline { stroke: var(--text-muted); }
.donut-row { display: grid; grid-template-columns: 160px 1fr; gap: 14px; align-items: center; }
.donut { width: 160px; height: 160px; display: block; }
.donut .donut-value { fill: var(--text); font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.donut .bar { cursor: pointer; }
.donut .bar:hover { opacity: .8; }
.dl { display: grid; gap: 4px; min-width: 0; }
.dl-row { display: flex; align-items: center; gap: 8px; padding: 3px 6px; border-radius: 6px; color: var(--text); font-size: .9rem; min-width: 0; }
a.dl-row:hover { background: var(--card-2); color: var(--text); }
.dl-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dl-value { font-variant-numeric: tabular-nums; white-space: nowrap; }
.dl .swatch { margin-right: 0; flex: none; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: 1px; }
.hstack { display: flex; height: 18px; border-radius: 6px; overflow: hidden; background: var(--card-2); gap: 2px; }
.hs-seg { display: block; height: 100%; min-width: 2px; cursor: pointer; }
.hs-seg:hover { opacity: .8; }
.meter { display: grid; gap: 6px; }
.meter-track { position: relative; height: 12px; border-radius: 6px; background: var(--card-2); overflow: visible; }
.meter-fill { height: 100%; border-radius: 6px; background: var(--primary); transition: width .3s; }
.meter.good .meter-fill { background: var(--success); } .meter.warn .meter-fill { background: var(--warning); } .meter.bad .meter-fill { background: var(--danger); }
.meter-target { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--text); border-radius: 1px; cursor: help; }
.meter-text { font-size: .9rem; }
.viz-tip { position: fixed; z-index: 60; pointer-events: none; background: var(--card-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 6px 10px; font-size: .8rem; color: var(--text); box-shadow: var(--shadow); max-width: 280px; }
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .axis { fill: var(--text-muted); font-size: 11px; font-family: var(--mono); }
.chart .bar { cursor: pointer; }
.chart .bar:hover { opacity: .75; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 8px; font-size: .8rem; color: var(--text-muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; }
.hbars { display: grid; gap: 6px; }
.hbar { display: grid; grid-template-columns: minmax(90px, 32%) 1fr auto; gap: 10px; align-items: center; color: var(--text); font-size: .9rem; padding: 2px 4px; border-radius: 6px; }
a.hbar:hover { background: var(--card-2); color: var(--text); }
.hb-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hb-track { display: flex; height: 12px; background: var(--card-2); border-radius: 6px; overflow: hidden; }
.hb-fill { display: block; height: 100%; min-width: 2px; }
.hb-value { font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.pill.label-early { color: var(--success); border-color: color-mix(in srgb, var(--success) 50%, transparent); }
.pill.label-on_time { color: var(--info); border-color: color-mix(in srgb, var(--info) 50%, transparent); }
.pill.label-late { color: var(--warning); border-color: color-mix(in srgb, var(--warning) 50%, transparent); }
.pill.label-very_late { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 50%, transparent); }
.pill.label-recurring, .pill.label-new, .pill.label-one_time { color: var(--text-muted); }
.score { font-weight: 700; font-variant-numeric: tabular-nums; }
.trend { margin-left: 4px; font-weight: 700; }
.trend.up { color: var(--success); } .trend.down { color: var(--danger); } .trend.flat { color: var(--text-muted); }
.sidenav .badge { font-size: .7rem; font-weight: 700; color: var(--on-primary); background: var(--danger); padding: 1px 7px; border-radius: 999px; min-width: 20px; text-align: center; }
.reminders { display: grid; gap: 10px; }
.reminder { display: flex; justify-content: space-between; gap: 14px; align-items: center; padding: 14px 16px; }
.reminder.bad { border-color: color-mix(in srgb, var(--danger) 50%, transparent); }
.reminder .rem-type { font-weight: 600; margin-bottom: 4px; }
.reminder .rem-main { min-width: 0; display: grid; gap: 2px; }
.reminder .rem-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; flex: none; max-width: 46%; }
.export { display: inline-flex; align-items: center; gap: 6px; }
.fieldset { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px 4px; margin-top: 8px; }
.fieldset legend { padding: 0 6px; color: var(--text-muted); font-size: .85rem; }
.rep-table td { vertical-align: middle; }
@media (max-width: 960px) { .charts { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 700px) {
  .reminder { flex-direction: column; align-items: stretch; }
  .reminder .rem-actions { max-width: none; justify-content: flex-start; }
  .page-head .actions .export { width: 100%; }
  .hbar { grid-template-columns: minmax(70px, 38%) 1fr auto; }
  .cust-table td[data-label]::before { content: attr(data-label) ": "; color: var(--text-muted); font-size: .8rem; }
  .donut-row { grid-template-columns: 1fr; justify-items: center; }
  .donut-row .dl { width: 100%; }
  .stat .spark { height: 22px; }
}

/* Help: the in-app guide */
.help-layout { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 18px; align-items: start; }
.help-toc { position: sticky; top: 84px; }
.help-toc ol { list-style: none; counter-reset: ch; display: grid; gap: 2px; }
.help-toc li { counter-increment: ch; }
.help-toc a { display: flex; gap: 8px; align-items: baseline; padding: 8px 10px; border-radius: var(--radius-sm); color: var(--text); font-size: .92rem; }
.help-toc a::before { content: counter(ch); color: var(--text-muted); font-family: var(--mono); font-size: .8rem; min-width: 16px; }
.help-toc a:hover { background: var(--card-2); }
.help-toc a.active { background: color-mix(in srgb, var(--primary) 18%, transparent); color: var(--text); }
.help-note { margin-top: 12px; padding: 0 10px; }
.help-body { padding: 24px 28px; }
.help-chapter h2 { font-size: 1.5rem; margin: 2px 0 8px; }
.help-intro { color: var(--text); line-height: 1.55; margin-bottom: 18px; }
.help-steps { list-style: none; display: grid; gap: 22px; }
.help-step-text { display: flex; gap: 12px; align-items: flex-start; line-height: 1.5; }
.help-num { flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--primary); color: var(--on-primary); font-weight: 700; display: inline-flex; align-items: center; justify-content: center; font-size: .85rem; margin-top: 1px; }
.help-step figure { margin: 12px 0 0 38px; }
.help-step figure img { display: block; max-width: 100%; height: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg); }
.help-step figcaption { color: var(--text-muted); font-size: .8rem; margin-top: 6px; }
.help-tip { margin-top: 18px; padding: 10px 14px; border-left: 3px solid var(--secondary); background: color-mix(in srgb, var(--secondary) 8%, transparent); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; line-height: 1.5; }
.help-nav { display: flex; justify-content: space-between; gap: 10px; margin-top: 26px; flex-wrap: wrap; }
.help-sep { border: 0; border-top: 1px solid var(--border); margin: 30px 0; }
.start-here { margin-bottom: 20px; border-color: color-mix(in srgb, var(--primary) 50%, transparent); }
.start-steps { margin: 0 0 12px 22px; display: grid; gap: 6px; line-height: 1.5; }
@media (max-width: 960px) { .help-layout { grid-template-columns: 1fr; } .help-toc { position: static; } .help-toc ol { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); } .help-toc a { font-size: .85rem; padding: 6px 8px; } .help-body { padding: 16px; } .help-step figure { margin-left: 0; } }
@media print {
  .topbar, .sidenav, .help-toc, .page-head .actions, .help-nav, .app-foot, #toast { display: none !important; }
  .app { display: block; } .content { padding: 0; }
  .help-layout { display: block; } .help-body { border: 0; padding: 0; background: #fff; }
  body, .card { background: #fff !important; color: #000 !important; }
  .help-step figure img { border-color: #ccc; } .help-num { background: #000; }
  .help-chapter { break-inside: avoid-page; page-break-inside: avoid; }
}

/* Guided tours */
.tour-btn { position: fixed; right: 18px; bottom: 18px; z-index: 55; display: inline-flex; align-items: center; gap: 8px; padding: 10px 14px; border-radius: 999px; border: 1px solid var(--primary); background: var(--card); color: var(--text); font-weight: 600; box-shadow: var(--shadow); cursor: pointer; }
.tour-btn:hover { background: var(--card-2); }
.tour-btn .tour-q { display: inline-flex; width: 22px; height: 22px; border-radius: 50%; background: var(--primary); color: var(--on-primary); align-items: center; justify-content: center; font-weight: 700; }
.tour-layer { position: fixed; inset: 0; z-index: 70; }
.tour-spot { position: fixed; border-radius: 10px; box-shadow: 0 0 0 9999px rgba(0, 0, 0, .62), 0 0 0 3px var(--primary); transition: left .25s, top .25s, width .25s, height .25s; pointer-events: auto; }
.tour-bubble { position: fixed; background: var(--card); border: 1px solid var(--primary); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); color: var(--text); line-height: 1.5; transition: left .25s, top .25s; }
.tour-bubble .tour-head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; margin-bottom: 6px; }
.tour-bubble p { font-size: .93rem; }
.tour-actions { display: flex; gap: 8px; align-items: center; margin-top: 12px; }
.tour-list { display: flex; flex-wrap: wrap; gap: 8px; }
.tour-list .btn.done { border-color: var(--success); color: var(--success); }
@media (max-width: 700px) { .tour-btn { right: 12px; bottom: 12px; padding: 9px 12px; font-size: .9rem; } }
@media print { .tour-btn, .tour-layer { display: none !important; } }

.recovery-codes { white-space: pre; text-align: left; line-height: 1.7; font-size: 1rem; letter-spacing: .08em; column-count: 2; padding: 14px 18px; }
@media print { .gate-card { background: #fff; color: #000; } .recovery-codes { color: #000; } }

th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { color: var(--text); }
th.sortable.sorted { color: var(--text); }
.sort-arrow { font-size: .65rem; margin-left: 4px; color: var(--primary-light); }
.inv-table tr.link:hover td { background: var(--card-2); }

.row-inline { display: flex; gap: 8px; align-items: center; }
.row-inline > select, .row-inline > input { flex: 1; min-width: 0; }

/* Employee cards */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; margin: 18px 0; }
.card-tile { display: block; color: inherit; text-decoration: none; padding: 14px 16px; }
.card-tile:hover { border-color: var(--primary); }
.card-tile.inactive { opacity: .6; }
.card-tile-head { display: flex; align-items: center; gap: 8px; margin-bottom: 2px; }
.card-tile-value { font-size: 1.35rem; font-weight: 600; margin-top: 8px; }
.limit { margin-top: 8px; }
.limit-bar { height: 6px; border-radius: 3px; background: var(--border); overflow: hidden; margin-bottom: 4px; }
.limit-bar i { display: block; height: 100%; background: var(--success); }
.limit-bar i.warn { background: var(--warning); }
.limit-bar i.over { background: var(--danger); }
.card-pill { text-decoration: none; }
.cards-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 900px) { .cards-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
h1 .swatch { display: inline-block; width: 14px; height: 14px; border-radius: 4px; vertical-align: -1px; }

/* Appearance settings */
.theme-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.theme-tile { display: grid; gap: 8px; padding: 10px; border-radius: var(--radius-sm); border: 2px solid var(--border); background: var(--card-2); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; text-align: left; }
.theme-tile.active { border-color: var(--primary); }
.theme-prev { display: grid; grid-template-columns: 28px 1fr; height: 54px; border-radius: 6px; overflow: hidden; border: 1px solid rgba(0,0,0,.15); }
.theme-prev i { display: block; } .theme-prev b { display: block; position: relative; }
.theme-prev b::after { content: ""; position: absolute; left: 10px; top: 10px; width: 55%; height: 10px; border-radius: 3px; }
.theme-prev-navy { background: #F3F5F8; } .theme-prev-navy i { background: #1F3A5F; } .theme-prev-navy b::after { background: #2A78D6; }
.theme-prev-graphite { background: #0F1318; } .theme-prev-graphite i { background: #0B0F14; } .theme-prev-graphite b::after { background: #3987E5; }
.theme-prev-forest { background: #F7F6F2; } .theme-prev-forest i { background: #0B3B2E; } .theme-prev-forest b::after { background: #1B8A5A; }
.theme-prev-classic { background: #0D1117; } .theme-prev-classic i { background: #161B22; } .theme-prev-classic b::after { background: #6C5CE7; }
.color-row { display: flex; gap: 8px; align-items: center; }
.color-row input[type="color"] { width: 56px; min-height: 36px; padding: 2px; }
#mode-btn { font-size: 1.1rem; min-width: 40px; }

/* Dashboard additions: net labels, category bars, waterfall, heat map, users side by side */
.chart .top-label { font-size: 10px; font-weight: 600; font-family: var(--mono); fill: var(--text-muted); }
.chart .top-label.pos { fill: var(--success); } .chart .top-label.neg { fill: var(--danger); }
.dl-main { flex: 1; min-width: 0; display: grid; gap: 3px; }
.dl-track { display: block; height: 6px; border-radius: 3px; background: var(--card-2); overflow: hidden; }
.dl-fill { display: block; height: 100%; border-radius: 3px; min-width: 2px; }
.heat { display: grid; grid-template-columns: minmax(70px, 110px) repeat(var(--cols), minmax(0, 1fr)); gap: 3px; align-items: center; font-size: .75rem; }
.heat-h { color: var(--text-muted); text-align: center; font-family: var(--mono); overflow: hidden; }
.heat-n { color: var(--text); padding-right: 4px; }
.heat-c { aspect-ratio: 1.5; border-radius: 4px; background: var(--card-2); cursor: default; }
.heat-c:hover { outline: 2px solid var(--text); outline-offset: -2px; }
.cmp-grid { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.stat.cmp .label { display: flex; align-items: center; gap: 6px; text-transform: none; letter-spacing: 0; font-size: .9rem; font-weight: 600; color: var(--text); }
.stat.cmp .meter { margin-top: 6px; }
.stat .meter-track { height: 8px; }
.tod-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 10px; }
.tod { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 10px; display: grid; gap: 2px; min-width: 0; }
.tod.peak { border-color: var(--c); box-shadow: inset 3px 0 0 var(--c); }
.tod-h { font-size: .85rem; font-weight: 600; display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.tod-h .swatch { background: var(--c); margin: 0; }
.tod-v { font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.tod-top { color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
