:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e3e6eb;
  --text: #1b1f24;
  --muted: #667085;
  --accent: #2f6bf5;
  --accent-ink: #ffffff;
  --c1: #2f6bf5;   /* invoiced */
  --c2: #e0793a;   /* spend */
  --c3: #1e9e72;   /* collected / positive */
  --neg: #c9372c;
  --warn-bg: #fff6e0;
  --warn-ink: #7a5300;
  --err-bg: #fdecea;
  --err-ink: #a1261b;
  --grid: #eceef2;
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #171b21;
    --border: #262c35;
    --text: #e7eaee;
    --muted: #8d97a5;
    --accent: #5b8ff0;
    --c1: #5b8ff0;
    --c2: #f0935a;
    --c3: #3cc493;
    --neg: #f0706a;
    --warn-bg: #332810;
    --warn-ink: #f2cf7c;
    --err-bg: #3a1714;
    --err-ink: #f7a49c;
    --grid: #232932;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2 { margin: 0; font-weight: 600; }
h1 { font-size: 18px; }
h2 { font-size: 14px; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
code { font-size: 12.5px; padding: 1px 5px; border-radius: 4px; background: rgba(127,127,127,.15); }
.num { font-variant-numeric: tabular-nums; }

button, select, input {
  font: inherit; color: inherit;
}
button {
  cursor: pointer; border: 0; border-radius: 8px; padding: 8px 14px;
  background: var(--accent); color: var(--accent-ink); font-weight: 600;
}
button.ghost, select {
  background: var(--surface); color: var(--text); border: 1px solid var(--border); font-weight: 500;
}
select { border-radius: 8px; padding: 7px 10px; }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- brand ---- */
.brand { display: flex; gap: 12px; align-items: center; }
.brand-mark { width: 34px; height: 34px; fill: var(--accent); flex: none; }
.brand.small .brand-mark { width: 28px; height: 28px; }
.brand p { margin: 2px 0 0; font-size: 13px; }

/* ---- login ---- */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 28px;
}
.login-card form { display: grid; gap: 6px; margin-top: 18px; }
.login-card label { font-size: 13px; font-weight: 500; margin-top: 8px; }
.login-card input {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg);
}
.login-card button { margin-top: 16px; padding: 11px; }
.error { margin: 16px 0 0; padding: 10px 12px; border-radius: 8px; background: var(--err-bg); color: var(--err-ink); font-size: 13px; }
.fine { font-size: 12px; margin: 16px 0 0; }

/* ---- dashboard layout ---- */
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 16px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 2;
}
.actions { display: flex; gap: 8px; align-items: center; }
.actions form { margin: 0; }
.banner { margin: 16px 24px 0; padding: 10px 14px; border-radius: 10px; background: var(--warn-bg); color: var(--warn-ink); }
.banner.error { background: var(--err-bg); color: var(--err-ink); margin-top: 16px; }

.grid {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px;
  padding: 16px 24px 8px; max-width: 1400px; margin: 0 auto;
}
.span-2 { grid-column: span 2; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.small-text { font-size: 12px; }

.kpis { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; min-width: 0; }
.kpi .label { font-size: 12.5px; color: var(--muted); }
.kpi .value { font-size: 24px; font-weight: 650; margin-top: 4px; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi .value.neg { color: var(--neg); }
.kpi .value.pos { color: var(--c3); }

/* ---- chart ---- */
.legend { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.key { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-left: 8px; }
.key.k1 { background: var(--c1); }
.key.k2 { background: var(--c2); }
.key.k3 { background: var(--c3); height: 3px; border-radius: 2px; }
.chart svg { width: 100%; height: 260px; display: block; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .b1 { fill: var(--c1); }
.chart .b2 { fill: var(--c2); }
.chart .line { fill: none; stroke: var(--c3); stroke-width: 2.25; }
.chart .dot { fill: var(--c3); }
.chart .hit { fill: transparent; }
.chart .hit:hover { fill: rgba(127,127,127,.08); }
.tip {
  position: fixed; pointer-events: none; z-index: 10; background: var(--text); color: var(--bg);
  padding: 8px 10px; border-radius: 8px; font-size: 12px; line-height: 1.5; white-space: nowrap;
}

/* ---- horizontal bars ---- */
.bars { display: grid; gap: 10px; }
.bar-row .top { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }
.bar-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .amt { font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar-row .track { height: 6px; background: var(--grid); border-radius: 3px; margin-top: 5px; overflow: hidden; }
.bar-row .fill { height: 100%; background: var(--c1); border-radius: 3px; }
#categories .fill { background: var(--c2); }
#aging .fill { background: var(--c3); }
#aging .bar-row:nth-child(n+2) .fill { background: #e0a43a; }
#aging .bar-row:nth-child(n+4) .fill { background: var(--neg); }

/* ---- lists & tables ---- */
.list { display: grid; }
.list-row { display: flex; justify-content: space-between; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.list-row:last-child { border-bottom: 0; }
.list-row .type { font-size: 11.5px; color: var(--muted); }
.list-row.total { font-weight: 600; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 0 8px 8px 0; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 8px 8px 8px 0; border-bottom: 1px solid var(--border); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
th.r, td.r { text-align: right; padding-right: 0; }
.pill { display: inline-block; font-size: 11.5px; padding: 1px 8px; border-radius: 999px; background: var(--err-bg); color: var(--err-ink); }
.pill.soon { background: var(--warn-bg); color: var(--warn-ink); }
.pill.ok { background: rgba(127,127,127,.12); color: var(--muted); }
.empty { color: var(--muted); font-size: 13px; padding: 12px 0; }

.foot { text-align: center; font-size: 12px; padding: 8px 24px 24px; }

.loading .kpi .value, .loading .card > :not(.card-head) { opacity: .35; }

@media (max-width: 1050px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 680px) {
  .topbar { padding: 12px 16px; }
  .grid { grid-template-columns: minmax(0, 1fr); padding: 16px; }
  .span-2 { grid-column: auto; }
  .banner { margin: 16px 16px 0; }
  .kpi .value { font-size: 20px; }
  .actions { width: 100%; }
  .actions select { flex: 1; }
}

/* ===== App shell with left panel ===== */
h3 { margin: 0; font-size: 14px; font-weight: 600; }
.app .topbar { padding: 10px 20px; height: 56px; flex-wrap: nowrap; }
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-left h1 { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .brand { min-width: 0; }
.user { font-size: 13px; }
.icon-btn { display: inline-flex; padding: 6px; line-height: 0; }
.icon-btn svg { width: 20px; height: 20px; stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; }

.shell { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: calc(100vh - 56px); }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 12px 10px 24px; position: sticky; top: 56px; height: calc(100vh - 56px); overflow-y: auto;
}
.nav-group { margin-top: 14px; }
.nav-heading { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 0 10px 4px; }
.nav-link {
  display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 8px;
  color: var(--text); text-decoration: none; font-size: 13.5px;
}
.nav-link svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; }
.nav-link:hover { background: var(--bg); }
.nav-link.active { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); font-weight: 600; }
.nav-link.off { color: var(--muted); }
.nav-link.off::after { content: ''; margin-left: auto; width: 6px; height: 6px; border-radius: 50%; background: var(--border); flex: none; }
.nav-link:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
/* Desktop: the menu button hides and shows the left panel (body.nav-collapsed). */
@media (min-width: 901px) {
  body.nav-collapsed .shell { grid-template-columns: minmax(0, 1fr); }
  body.nav-collapsed .sidebar { display: none; }
}
.scrim { position: fixed; inset: 56px 0 0 0; background: rgba(0,0,0,.35); z-index: 4; }

.content { min-width: 0; padding-bottom: 24px; }
.content .banner { margin: 16px 24px 0; }
.page-head {
  display: flex; justify-content: space-between; align-items: flex-end; gap: 12px 16px; flex-wrap: wrap;
  padding: 20px 24px 0; max-width: 1400px; margin: 0 auto;
}
.page-title { font-size: 20px; font-weight: 650; }
.page-head p { margin: 4px 0 0; font-size: 13px; max-width: 70ch; }
.eyebrow { font-size: 11px !important; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; margin: 0 0 2px !important; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar input[type=date] { border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 6px 8px; }
.toolbar select:disabled, .toolbar input:disabled { opacity: .6; }

/* ===== Report pages ===== */
.report-body { display: grid; gap: 16px; padding: 16px 24px 8px; max-width: 1400px; margin: 0 auto; }
.report-body .kpis { grid-column: auto; }
.report-body.loading > * { opacity: .45; transition: opacity .2s; }
.title-line { display: flex; align-items: baseline; gap: 10px; }
.table-tools { display: flex; gap: 8px; align-items: center; }
.search { border: 1px solid var(--border); background: var(--bg); border-radius: 8px; padding: 5px 10px; width: 200px; }
button.small { padding: 5px 10px; font-size: 12.5px; }
button.more { margin-top: 10px; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
th[aria-sort=ascending]::after { content: ' ↑'; }
th[aria-sort=descending]::after { content: ' ↓'; }
tfoot td { font-weight: 650; border-top: 1px solid var(--border); border-bottom: 0; }
.chart .fill-c1 { fill: var(--c1); }
.chart .fill-c2 { fill: var(--c2); }
.chart .fill-c3 { fill: var(--c3); }
.key.key-c1 { background: var(--c1); }
.key.key-c2 { background: var(--c2); }
.key.key-c3 { background: var(--c3); }
.bar-row .fill.negfill { background: var(--neg); }
.card.empty { text-align: center; padding: 32px; }
.card.connect ol { margin: 8px 0 0; padding-left: 20px; line-height: 1.9; }
.card.connect p { margin: 6px 0 0; }
.notes { font-size: 12.5px; }
.notes p { margin: 0 0 4px; }

@media (max-width: 900px) {
  .icon-btn { display: inline-flex; }
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; left: 0; top: 56px; bottom: 0; width: 260px; height: auto; z-index: 5;
    transform: translateX(-100%); transition: transform .2s ease; box-shadow: 0 0 24px rgba(0,0,0,.15);
  }
  .nav-open .sidebar { transform: none; }
  .user { display: none; }
}
@media (max-width: 680px) {
  .app .topbar { padding: 10px 16px; }
  .page-head { padding: 16px 16px 0; }
  .report-body { padding: 16px; }
  .content .banner { margin: 16px 16px 0; }
  .search { width: 140px; }
  .toolbar input[type=date] { flex: 1; min-width: 0; }
}

/* Keep adjacent number columns apart */
.report-body th + th, .report-body td + td { padding-left: 16px; }

/* ===== AppSquadz branding ===== */
.login-body { flex-direction: column; display: flex; align-items: center; justify-content: center; gap: 16px; }
.login-brand { text-align: center; padding-bottom: 18px; border-bottom: 1px solid var(--border); }
.login-logo { width: 220px; height: auto; display: block; margin: 0 auto; }
.login-company { margin: 10px 0 0; font-size: 13px; }
.login-title { text-align: center; margin-top: 18px; }
.login-title h1 { font-size: 22px; font-weight: 650; }
.login-title p { margin: 4px 0 0; font-size: 13px; }
.login-foot { font-size: 12px; margin: 0; }

.portal-brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: var(--text); min-width: 0; }
.brand-logo { height: 24px; width: auto; display: block; }
.brand-mark-img { display: none; height: 28px; width: 28px; }
.brand-divider { width: 1px; height: 22px; background: var(--border); }
.portal-name { font-weight: 650; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Module sections in the left panel */
.nav-section { margin-top: 10px; border-top: 1px solid var(--border); padding-top: 10px; }
.nav-module {
  width: 100%; display: flex; align-items: center; gap: 8px; background: none; color: var(--text);
  padding: 7px 10px; border-radius: 8px; font-weight: 650; font-size: 13.5px; text-align: left;
}
.nav-module:hover { background: var(--bg); }
.nav-module svg, .module-icon svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.nav-module .chev { margin-left: auto; width: 8px; height: 8px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); transition: transform .15s; }
.nav-module[aria-expanded=false] .chev { transform: rotate(-45deg); }
.nav-module-links { padding-left: 6px; }
.nav-module-links .nav-group { margin-top: 10px; }

/* Home */
.home-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; padding: 16px 24px; max-width: 1400px; margin: 0 auto; }
.module-card { display: flex; flex-direction: column; gap: 16px; }
.module-head { display: flex; gap: 12px; align-items: flex-start; }
.module-head p { margin: 4px 0 0; }
.module-icon { flex: none; width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }
.module-icon svg { width: 20px; height: 20px; }
.home-kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.home-kpi .label { font-size: 12px; }
.home-kpi .value { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; }
.home-kpi .value.neg { color: var(--neg); }
.home-kpi-note { grid-column: 1 / -1; }
.module-links { display: flex; flex-wrap: wrap; gap: 8px; margin-top: auto; }
.btn { background: var(--accent); color: var(--accent-ink); text-decoration: none; padding: 7px 14px; border-radius: 8px; font-weight: 600; font-size: 13px; }
.chip { border: 1px solid var(--border); color: var(--text); text-decoration: none; padding: 6px 12px; border-radius: 999px; font-size: 12.5px; }
.chip:hover { background: var(--bg); }
.module-card.placeholder { border-style: dashed; background: transparent; }
.module-card.placeholder .module-icon { background: var(--bg); color: var(--muted); }

@media (max-width: 680px) {
  .brand-logo, .brand-divider { display: none; }
  .brand-mark-img { display: block; }
  .home-grid { padding: 16px; grid-template-columns: minmax(0, 1fr); }
}

/* Data-source notices belong to Finance pages, not Home */
body[data-view=home] #snapshot-banner, body[data-view=home] #demo-banner { display: none !important; }
.topbar-left { flex: 1; }
.app .topbar .actions { flex: none; }
@media (max-width: 680px) { .portal-brand { gap: 8px; } .topbar-left { gap: 6px; } .portal-name { font-size: 14px; } }
@media (max-width: 680px) { .app .topbar .actions { width: auto; } }

/* ===== Alerts ===== */
.alerts-card { grid-column: 1 / -1; }
.alerts-sub { margin: 2px 0 0; }
.sev-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.sev-chip { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 999px; padding: 4px 10px; font-size: 12.5px; font-weight: 500; display: inline-flex; gap: 6px; align-items: center; }
.sev-chip .n { font-variant-numeric: tabular-nums; color: var(--muted); }
.sev-chip.on { border-color: var(--accent); color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.alert-list { display: grid; gap: 8px; }
.alert { border: 1px solid var(--border); border-left: 4px solid var(--border); border-radius: 8px; background: var(--surface); }
.alert.sev-critical { border-left-color: var(--neg); }
.alert.sev-warning { border-left-color: #e0a43a; }
.alert.sev-info { border-left-color: var(--accent); }
.alert summary { list-style: none; cursor: pointer; display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; gap: 10px; align-items: center; padding: 10px 12px; }
.alert summary::-webkit-details-marker { display: none; }
.alert summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 6px; }
.alert-title { font-weight: 600; font-size: 13.5px; }
.alert-area { font-size: 12px; white-space: nowrap; }
.alert .chev { width: 8px; height: 8px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); transition: transform .15s; margin-right: 4px; }
.alert[open] .chev { transform: rotate(-135deg); }
.alert-body { padding: 0 12px 12px 12px; font-size: 13px; }
.alert-body p { margin: 0 0 8px; color: var(--muted); max-width: 90ch; }
.alert-body ul { margin: 0 0 8px; padding-left: 18px; }
.alert-body li { margin: 2px 0; font-variant-numeric: tabular-nums; }
.alert-link { color: var(--accent); text-decoration: none; font-weight: 600; font-size: 12.5px; }
.alert-link:hover { text-decoration: underline; }
.sev-badge { display: inline-block; font-size: 11px; font-weight: 650; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.sev-badge.critical { background: var(--err-bg); color: var(--err-ink); }
.sev-badge.warning { background: var(--warn-bg); color: var(--warn-ink); }
.sev-badge.info { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); }
.sev-badge.ok { background: color-mix(in srgb, var(--c3) 14%, transparent); color: var(--c3); }
.home-alerts { display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; text-decoration: none; color: var(--text); padding: 10px 12px; border-radius: 8px; background: var(--bg); }
.home-alerts:hover { outline: 1px solid var(--border); }
@media (max-width: 680px) {
  .alert summary { grid-template-columns: auto minmax(0, 1fr) auto; }
  .alert-area { display: none; }
}

/* Several charts on one report (e.g. Sales overview): first one full width */
.chart-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.chart-grid > :first-child { grid-column: 1 / -1; }
@media (max-width: 900px) { .chart-grid { grid-template-columns: minmax(0, 1fr); } }

/* Payroll module: import page and report action buttons */
.payroll-import { max-width: 860px; margin: 0 auto; padding: 24px 16px 48px; display: grid; gap: 16px; }
.payroll-import h1 { margin: 0; font-size: 22px; }
.payroll-import table { width: 100%; border-collapse: collapse; }
.payroll-import th, .payroll-import td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.report-actions { display: flex; flex-wrap: wrap; gap: 8px; }
