/*
 * Nets-afstemning - dashboard stylesheet.
 *
 * A bookkeeping tool, not a marketing page: dense tables, calm surfaces, and
 * numbers that stay readable at a glance. Colour carries meaning here (money
 * out, severity, match state), so every coloured signal is paired with an icon
 * or a word - colour alone would fail anyone who cannot separate red from
 * green, and would vanish entirely in a printout.
 *
 * Theming: `prefers-color-scheme` sets the default, and `[data-theme]` on the
 * root element overrides it in both directions when the user picks explicitly.
 * Every colour is a custom property so the two themes stay in sync by
 * construction rather than by discipline.
 */

/* ---------------------------------------------------------------- tokens */

:root {
  color-scheme: light dark;

  /* Surfaces, from furthest back to nearest the reader. */
  --bg: #f4f5f7;
  --bg-sunken: #eceef1;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --surface-hover: #f0f2f5;
  --border: #dfe3e8;
  --border-strong: #c6ccd4;

  --text: #1a1d21;
  --text-muted: #5b6570;
  --text-faint: #8a939d;

  --accent: #1f5fa8;
  --accent-text: #ffffff;
  --accent-soft: #e8f0fa;
  --focus: #1f5fa8;

  /* Semantic money/state colours. `-soft` variants back the text version so
     contrast survives in both themes. */
  --good: #1a7f4b;
  --good-soft: #e4f4ec;
  --warning: #9a6205;
  --warning-soft: #fdf1dc;
  --critical: #b3261e;
  --critical-soft: #fceceb;
  --fees: #a8560c;
  --fees-soft: #fdeee1;
  --info: #1f5fa8;
  --info-soft: #e8f0fa;

  /* Chart series. Distinguishable without relying on hue alone, because the
     legend and tooltip always name the series too. */
  --series-1: #1f5fa8;
  --series-2: #0f8a7e;
  --series-3: #a8560c;
  --series-4: #6b4ea8;

  --radius: 8px;
  --radius-sm: 5px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 4px 12px rgba(16, 24, 40, .1), 0 12px 28px rgba(16, 24, 40, .1);

  --topbar-h: 56px;
  --sidenav-w: 216px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  /* Tabular figures keep columns of kroner aligned on the decimal. */
  --font-num: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14171a;
    --bg-sunken: #101315;
    --surface: #1c2024;
    --surface-2: #22272c;
    --surface-hover: #272d33;
    --border: #313840;
    --border-strong: #434c56;

    --text: #e8eaed;
    --text-muted: #a3adb8;
    --text-faint: #78828d;

    --accent: #6ea8e8;
    --accent-text: #0f1316;
    --accent-soft: #1a2b3d;
    --focus: #6ea8e8;

    --good: #5cc98d;
    --good-soft: #16301f;
    --warning: #e0aa4a;
    --warning-soft: #33280f;
    --critical: #f08078;
    --critical-soft: #3a1c1a;
    --fees: #e79a5c;
    --fees-soft: #362213;
    --info: #6ea8e8;
    --info-soft: #1a2b3d;

    --series-1: #6ea8e8;
    --series-2: #4ec9b8;
    --series-3: #e79a5c;
    --series-4: #a98ce0;

    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 1px 3px rgba(0, 0, 0, .3);
    --shadow-lg: 0 4px 12px rgba(0, 0, 0, .45), 0 12px 28px rgba(0, 0, 0, .4);
  }
}

/* The explicit toggle must win over the media query in both directions. */
:root[data-theme="dark"] {
  --bg: #14171a;
  --bg-sunken: #101315;
  --surface: #1c2024;
  --surface-2: #22272c;
  --surface-hover: #272d33;
  --border: #313840;
  --border-strong: #434c56;

  --text: #e8eaed;
  --text-muted: #a3adb8;
  --text-faint: #78828d;

  --accent: #6ea8e8;
  --accent-text: #0f1316;
  --accent-soft: #1a2b3d;
  --focus: #6ea8e8;

  --good: #5cc98d;
  --good-soft: #16301f;
  --warning: #e0aa4a;
  --warning-soft: #33280f;
  --critical: #f08078;
  --critical-soft: #3a1c1a;
  --fees: #e79a5c;
  --fees-soft: #362213;
  --info: #6ea8e8;
  --info-soft: #1a2b3d;

  --series-1: #6ea8e8;
  --series-2: #4ec9b8;
  --series-3: #e79a5c;
  --series-4: #a98ce0;

  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 1px 3px rgba(0, 0, 0, .3);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, .45), 0 12px 28px rgba(0, 0, 0, .4);
}

/* ------------------------------------------------------------------ base */

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  /* A dashboard that scrolls sideways has already failed; wide content gets
     its own scroll container instead. */
  overflow-x: hidden;
}

h1, h2, h3 { margin: 0; font-weight: 600; line-height: 1.25; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
p { margin: 0; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 3px;
}

[hidden] { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  top: -100px; left: 8px;
  z-index: 100;
  padding: 8px 14px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
}
.skip-link:focus { top: 8px; }

.muted { color: var(--text-muted); }
.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------- buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 13px;
  font: inherit;
  font-weight: 500;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s ease, border-color .12s ease;
}
.btn:hover:not(:disabled) { background: var(--surface-hover); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }

.btn-danger { color: var(--critical); border-color: var(--critical); background: var(--surface); }
.btn-danger:hover:not(:disabled) { background: var(--critical-soft); }

.btn-quiet { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-quiet:hover:not(:disabled) { background: var(--surface-hover); color: var(--text); }

.btn-sm { padding: 4px 9px; font-size: 12.5px; }
.btn-block { width: 100%; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px; height: 34px;
  padding: 0;
  font: inherit;
  font-size: 16px;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }

/* ---------------------------------------------------------------- inputs */

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 7px 9px;
  min-width: 0;
  max-width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus); outline-offset: -1px; border-color: var(--focus); }
input::placeholder { color: var(--text-faint); }
.num-input { font-family: var(--font-num); }

.field { display: flex; flex-direction: column; gap: 5px; }
.field > label { font-size: 12.5px; font-weight: 500; color: var(--text-muted); }
.field-hint { font-size: 12px; color: var(--text-faint); }

.inline-field { display: flex; align-items: center; gap: 8px; }
.inline-note { font-size: 12.5px; color: var(--text-muted); }

.form { display: flex; flex-direction: column; gap: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.search-field { position: relative; display: flex; align-items: center; }
.search-input { padding-left: 28px; min-width: 210px; }
.search-field::before {
  content: "⌕";
  position: absolute; left: 9px;
  color: var(--text-faint);
  pointer-events: none;
}

.segmented { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; }
.seg-btn {
  padding: 6px 11px;
  font: inherit;
  font-size: 12.5px;
  color: var(--text-muted);
  background: var(--surface);
  border: 0;
  border-right: 1px solid var(--border);
  cursor: pointer;
}
.seg-btn:last-child { border-right: 0; }
.seg-btn:hover { background: var(--surface-hover); color: var(--text); }
.seg-btn.is-active { background: var(--accent); color: var(--accent-text); font-weight: 500; }

/* ------------------------------------------------------------------ boot */

.boot { display: grid; place-items: center; min-height: 100vh; }
.boot-inner { display: flex; flex-direction: column; align-items: center; gap: 12px; color: var(--text-muted); }

.spinner {
  width: 26px; height: 26px;
  border: 2.5px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ----------------------------------------------------------------- login */

.login { display: grid; place-items: center; min-height: 100vh; padding: 20px; }

.login-card {
  width: 100%;
  max-width: 350px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 26px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.login-title { font-size: 19px; }
.login-sub { margin-top: -8px; font-size: 13px; color: var(--text-muted); }

/* ---------------------------------------------------------------- layout */

.app { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 10px;
  height: var(--topbar-h);
  padding: 0 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-spacer { flex: 1; }

.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.brand-mark {
  width: 9px; height: 18px;
  border-radius: 2px;
  background: linear-gradient(180deg, var(--accent), var(--series-2));
}
.brand-text { white-space: nowrap; }

.nav-toggle { display: none; }
.burger, .burger::before, .burger::after {
  display: block;
  width: 16px; height: 2px;
  background: currentColor;
  border-radius: 1px;
}
.burger { position: relative; }
.burger::before, .burger::after { content: ""; position: absolute; left: 0; }
.burger::before { top: -5px; }
.burger::after { top: 5px; }

.user-chip { display: flex; align-items: center; gap: 7px; min-width: 0; }
.user-name { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 160px; }

.layout { flex: 1; display: flex; align-items: stretch; min-height: 0; }

.sidenav {
  flex: 0 0 var(--sidenav-w);
  width: var(--sidenav-w);
  display: flex;
  flex-direction: column;
  padding: 12px 10px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
}

.navlist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }

.navlink {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-weight: 500;
}
.navlink:hover { background: var(--surface-hover); color: var(--text); text-decoration: none; }
.navlink.is-active { background: var(--accent-soft); color: var(--accent); }
.navicon { width: 16px; text-align: center; opacity: .85; }

.navbadge {
  margin-left: auto;
  min-width: 19px;
  padding: 1px 5px;
  font-size: 11px;
  font-weight: 600;
  text-align: center;
  color: #fff;
  background: var(--critical);
  border-radius: 9px;
}
:root[data-theme="dark"] .navbadge,
:root:not([data-theme="light"]) .navbadge { color: #241010; }

.sidenav-foot { margin-top: auto; padding-top: 12px; }
.nav-status { font-size: 11.5px; color: var(--text-faint); display: flex; flex-direction: column; gap: 3px; }
.nav-status-line { display: flex; justify-content: space-between; gap: 6px; }
.nav-status-value { font-family: var(--font-num); }

.view {
  flex: 1;
  min-width: 0;           /* lets wide children scroll instead of stretching */
  padding: 18px;
  outline: none;
}

.page { display: flex; flex-direction: column; gap: 16px; max-width: 1500px; }
.page-head { display: flex; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.page-title { font-size: 20px; }
.page-sub { font-size: 13px; color: var(--text-muted); margin-top: 3px; }
.page-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.section { display: flex; flex-direction: column; gap: 12px; }
.subhead { font-size: 13px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .03em; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); gap: 14px; }

/* ----------------------------------------------------------------- cards */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.card-title { font-size: 14px; font-weight: 600; }
.card-actions { margin-left: auto; display: flex; gap: 7px; flex-wrap: wrap; }
.card-body { padding: 14px; }
.card-note { padding: 10px 14px; font-size: 12.5px; color: var(--text-muted); background: var(--surface-2); border-top: 1px solid var(--border); }

/* ------------------------------------------------------------------- kpi */

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.kpi-grid-4 { grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); }

.kpi {
  display: flex; flex-direction: column; gap: 5px;
  padding: 13px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.kpi-hero { border-left-color: var(--accent); }
.kpi-tone-good, .kpi-good { border-left-color: var(--good); }
.kpi-tone-warning, .kpi-warning { border-left-color: var(--warning); }
.kpi-tone-critical, .kpi-critical { border-left-color: var(--critical); }
.kpi-tone-fees, .kpi-fees { border-left-color: var(--fees); }
.kpi-tone-info, .kpi-info { border-left-color: var(--info); }

.kpi-label { font-size: 12px; font-weight: 500; color: var(--text-muted); display: flex; align-items: center; gap: 5px; }
.kpi-icon { opacity: .8; }
.kpi-value { font-family: var(--font-num); font-variant-numeric: tabular-nums; font-size: 21px; font-weight: 600; letter-spacing: -.01em; }
.kpi-hero .kpi-value { font-size: 25px; }
.kpi-sub, .kpi-meta, .kpi-hint { font-size: 12px; color: var(--text-muted); }
.kpi-hint { color: var(--text-faint); }

button.kpi, .kpi-button { font: inherit; text-align: left; cursor: pointer; }
button.kpi:hover, .kpi-button:hover { background: var(--surface-hover); }

.delta { display: inline-flex; align-items: center; gap: 3px; font-size: 12px; font-weight: 500; }
.delta-good { color: var(--good); }
.delta-bad { color: var(--critical); }
.delta-flat { color: var(--text-faint); }
.delta-arrow { font-size: 10px; }

/* ---------------------------------------------------------------- alerts */

.alert-stack { display: flex; flex-direction: column; gap: 9px; }

.alert {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--text-muted);
  border-radius: var(--radius);
  background: var(--surface);
}
.alert-icon { font-size: 15px; line-height: 1.3; }
.alert-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.alert-title { font-weight: 600; font-size: 13.5px; }
.alert-text { font-size: 13px; color: var(--text-muted); }

.alert-critical { background: var(--critical-soft); border-left-color: var(--critical); }
.alert-critical .alert-icon { color: var(--critical); }
.alert-warning { background: var(--warning-soft); border-left-color: var(--warning); }
.alert-warning .alert-icon { color: var(--warning); }
.alert-good { background: var(--good-soft); border-left-color: var(--good); }
.alert-good .alert-icon { color: var(--good); }
.alert-info { background: var(--info-soft); border-left-color: var(--info); }
.alert-info .alert-icon { color: var(--info); }

/* ---------------------------------------------------------------- badges */

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 7px;
  font-size: 11.5px;
  font-weight: 600;
  border-radius: 20px;
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.badge-icon { font-size: 10px; }
.badge-good { background: var(--good-soft); color: var(--good); border-color: transparent; }
.badge-warning { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.badge-critical, .badge-high { background: var(--critical-soft); color: var(--critical); border-color: transparent; }
.badge-serious { background: var(--critical-soft); color: var(--critical); border-color: transparent; }
.badge-medium { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.badge-low { background: var(--surface-2); color: var(--text-muted); }
.badge-info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.badge-fees { background: var(--fees-soft); color: var(--fees); border-color: transparent; }

.badge-role { text-transform: capitalize; }
.role-admin { background: var(--info-soft); color: var(--info); border-color: transparent; }
.role-editor { background: var(--good-soft); color: var(--good); border-color: transparent; }
.role-viewer { background: var(--surface-2); color: var(--text-muted); }

/* Invoice-match statuses. */
.status-exact, .exact { color: var(--good); }
.status-partial, .partial { color: var(--warning); }
.status-over, .over { color: var(--fees); }
.status-no-invoice, .no-invoice { color: var(--critical); }

/* --------------------------------------------------------------- amounts */

.amount { font-family: var(--font-num); font-variant-numeric: tabular-nums; white-space: nowrap; }
.amount-good { color: var(--good); }
.amount-negative, .amount-serious { color: var(--critical); }
.amount-warning { color: var(--warning); }
.amount-fees { color: var(--fees); }

/* --------------------------------------------------------------- filters */

.filterbar {
  display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap;
  padding: 11px 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.filterbar-extra { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; margin-left: auto; }
.period-readout { font-size: 12.5px; color: var(--text-muted); font-family: var(--font-num); }
.daterange { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 8px;
  font-size: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 20px;
}
.chip-x { cursor: pointer; border: 0; background: transparent; color: inherit; font: inherit; padding: 0 1px; line-height: 1; }
.chip-x:hover { opacity: .65; }

/* ---------------------------------------------------------------- tables */

.datatable { display: flex; flex-direction: column; }

/* The only element allowed to scroll sideways. */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { padding: 8px 11px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.table thead th {
  position: sticky; top: 0; z-index: 1;
  font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em;
  color: var(--text-muted);
  /* Opaque: rows must not show through while scrolling. */
  background: var(--surface-2);
  border-bottom: 1px solid var(--border-strong);
  white-space: nowrap;
}
.table tbody tr:hover { background: var(--surface-hover); }
.table tbody tr:last-child td { border-bottom: 0; }
.table td.num, .table th.num { text-align: right; font-family: var(--font-num); font-variant-numeric: tabular-nums; white-space: nowrap; }
.table-compact th, .table-compact td { padding: 5px 9px; }

.table tr.clickable, .table tr.with-detail { cursor: pointer; }
.table tr.is-active { background: var(--accent-soft); }
.table tr.row-warning { background: var(--warning-soft); }
.table tr.is-differing { background: var(--critical-soft); }
.table tfoot td, .totals-row td { font-weight: 600; background: var(--surface-2); border-top: 1px solid var(--border-strong); }

.th-sort {
  display: inline-flex; align-items: center; gap: 4px;
  font: inherit; font-size: inherit; font-weight: inherit; letter-spacing: inherit; text-transform: inherit;
  color: inherit; background: none; border: 0; padding: 0; cursor: pointer;
}
.th-sort:hover { color: var(--text); }
.sort-arrow { font-size: 9px; opacity: .5; }
.sortable[aria-sort="ascending"] .sort-arrow,
.sortable[aria-sort="descending"] .sort-arrow { opacity: 1; color: var(--accent); }

.table-hint, .table-count { font-size: 12px; color: var(--text-muted); }
.merchant-cell { display: flex; flex-direction: column; gap: 1px; }

.pager {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 9px 12px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}
.pager-info { font-size: 12.5px; color: var(--text-muted); font-family: var(--font-num); }
.pager-btns { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.pager-page { font-size: 12.5px; color: var(--text-muted); padding: 0 4px; }

/* Row detail panel. */
.detail-panel { padding: 13px 14px; background: var(--surface-2); border-top: 1px solid var(--border); }
.detail-head { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; margin-bottom: 9px; }
.detail-title { font-weight: 600; }
.detail-amount { font-family: var(--font-num); font-weight: 600; }
.detail-note, .detail-explain { font-size: 12.5px; color: var(--text-muted); }
.with-detail-main { display: flex; gap: 14px; flex-wrap: wrap; }

.deflist { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: 9px 16px; margin: 0; }
.deflist dt { font-size: 11.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .03em; }
.deflist dd { margin: 0; font-size: 13px; }

/* ------------------------------------------------------------ duplicates */

.sev-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: 10px; }
.sev-tile {
  display: flex; flex-direction: column; gap: 3px;
  padding: 11px 13px;
  font: inherit; text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border-strong);
  border-radius: var(--radius);
  cursor: pointer;
}
.sev-tile:hover { background: var(--surface-hover); }
.sev-tile.is-active { outline: 2px solid var(--accent); outline-offset: -1px; }
.sev-tile.tone-critical { border-left-color: var(--critical); }
.sev-tile.tone-warning { border-left-color: var(--warning); }
.sev-tile.tone-good { border-left-color: var(--good); }
.sev-tile.tone-info { border-left-color: var(--info); }
.sev-icon { font-size: 14px; }
.sev-count { font-family: var(--font-num); font-size: 20px; font-weight: 600; }
.sev-label { font-size: 12px; color: var(--text-muted); }
.sev-amount { font-family: var(--font-num); font-size: 12.5px; color: var(--text-muted); }

.dupe-group { display: flex; flex-direction: column; gap: 10px; }
.dupe-group-head { display: flex; align-items: baseline; gap: 9px; flex-wrap: wrap; }
.dupe-group-title { font-size: 15px; font-weight: 600; }
.dupe-group-meta { font-size: 12.5px; color: var(--text-muted); }
.dupe-list { display: flex; flex-direction: column; gap: 10px; }

.dupe-card {
  padding: 13px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.dupe-card.sev-high { border-left-color: var(--critical); }
.dupe-card.sev-medium { border-left-color: var(--warning); }
.dupe-card.sev-low { border-left-color: var(--text-faint); }

.dupe-head { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; margin-bottom: 7px; }
.dupe-type { font-weight: 600; }
.dupe-amount { margin-left: auto; font-family: var(--font-num); font-weight: 600; font-size: 15px; }
.dupe-reason { font-size: 13px; color: var(--text-muted); margin-bottom: 10px; }
.dupe-reason-label { font-weight: 600; color: var(--text); }
.dupe-note { font-size: 12.5px; color: var(--text-faint); margin-top: 8px; }

/* The two sides of a candidate, so the difference is visible at a glance. */
.dupe-items { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 9px; }
.dupe-item { padding: 9px 11px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.dupe-item-head { display: flex; align-items: baseline; gap: 7px; margin-bottom: 5px; }
.dupe-item-index { font-size: 11px; font-weight: 600; color: var(--text-faint); }
.dupe-item-amount { margin-left: auto; font-family: var(--font-num); font-weight: 600; }
.dupe-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(105px, 1fr)); gap: 4px 10px; font-size: 12px; }
.dupe-field { display: flex; flex-direction: column; }
.dupe-field .label { font-size: 10.5px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .03em; }
.dupe-field .value { font-family: var(--font-num); }

/* ---------------------------------------------------------------- charts */

.chart { position: relative; width: 100%; }
.chart-plot { position: relative; width: 100%; }
.chart-svg { display: block; width: 100%; height: auto; overflow: visible; }

.chart-grid line, line.chart-grid { stroke: var(--border); stroke-width: 1; }
.chart-baseline { stroke: var(--border-strong); stroke-width: 1; }
.chart-axis-label, .chart-axis-y { fill: var(--text-faint); font-size: 10.5px; font-family: var(--font-num); }
.chart-crosshair { stroke: var(--border-strong); stroke-width: 1; stroke-dasharray: 3 3; }
.chart-hover-band { fill: transparent; }
.chart-hover-band:hover { fill: var(--text); opacity: .04; }
.chart-hover-layer { cursor: crosshair; }

.chart-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-dot { stroke: var(--surface); stroke-width: 1.5; }
.chart-bar { }

.series-1 { stroke: var(--series-1); }
.series-2 { stroke: var(--series-2); }
.series-3 { stroke: var(--series-3); }
.series-4 { stroke: var(--series-4); }
.chart-bar.series-1, .chart-dot.series-1, rect.series-1, .dist-seg.series-1 { fill: var(--series-1); }
.chart-bar.series-2, .chart-dot.series-2, rect.series-2, .dist-seg.series-2 { fill: var(--series-2); }
.chart-bar.series-3, .chart-dot.series-3, rect.series-3, .dist-seg.series-3 { fill: var(--series-3); }
.chart-bar.series-4, .chart-dot.series-4, rect.series-4, .dist-seg.series-4 { fill: var(--series-4); }

.chart-legend, .dist-legend { display: flex; gap: 13px; flex-wrap: wrap; margin-top: 9px; font-size: 12px; }
.legend-item, .dist-legend-item { display: inline-flex; align-items: center; gap: 6px; color: var(--text-muted); }
.legend-swatch { width: 10px; height: 10px; border-radius: 2px; background: var(--text-faint); flex: none; }
.legend-swatch.series-1 { background: var(--series-1); }
.legend-swatch.series-2 { background: var(--series-2); }
.legend-swatch.series-3 { background: var(--series-3); }
.legend-swatch.series-4 { background: var(--series-4); }
.legend-swatch.tone-good { background: var(--good); }
.legend-swatch.tone-warning { background: var(--warning); }
.legend-swatch.tone-critical { background: var(--critical); }
.legend-swatch.tone-fees { background: var(--fees); }
.legend-swatch.tone-info { background: var(--info); }
.dist-legend-value { font-family: var(--font-num); color: var(--text); font-weight: 500; }

/* Horizontal distribution bar (invoice-match split). */
.dist-track { display: flex; width: 100%; height: 13px; border-radius: 7px; overflow: hidden; background: var(--surface-2); }
.dist-seg { height: 100%; }
.dist-seg.tone-good { background: var(--good); }
.dist-seg.tone-warning { background: var(--warning); }
.dist-seg.tone-critical { background: var(--critical); }
.dist-seg.tone-fees { background: var(--fees); }
.dist-seg.tone-info { background: var(--info); }

.chart-tooltip {
  position: absolute;
  z-index: 5;
  min-width: 140px;
  padding: 8px 10px;
  font-size: 12px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  pointer-events: none;
}
.tt-title { font-weight: 600; margin-bottom: 5px; }
.tt-rows { display: flex; flex-direction: column; gap: 3px; }
.tt-row { display: flex; align-items: center; gap: 6px; }
.tt-swatch { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.tt-swatch.series-1 { background: var(--series-1); }
.tt-swatch.series-2 { background: var(--series-2); }
.tt-swatch.series-3 { background: var(--series-3); }
.tt-swatch.series-4 { background: var(--series-4); }
.tt-swatch-blank { width: 8px; flex: none; }
.tt-name { color: var(--text-muted); }
.tt-value { margin-left: auto; font-family: var(--font-num); font-weight: 500; }
.tt-total { border-top: 1px solid var(--border); margin-top: 3px; padding-top: 4px; font-weight: 600; }

.chart-empty { display: grid; place-items: center; min-height: 130px; color: var(--text-faint); font-size: 13px; }

/* Screen-reader table behind a chart: the data, not just the picture. */
.chart-table { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ------------------------------------------------------------ explainers */

.explainer {
  display: flex; align-items: flex-start; gap: 9px;
  padding: 10px 13px;
  font-size: 12.5px;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.explainer-icon { color: var(--info); font-size: 14px; }
.explainer-formula { font-family: var(--font-num); color: var(--text); background: var(--surface); padding: 1px 5px; border-radius: 3px; border: 1px solid var(--border); }

/* ------------------------------------------------------- status & coverage */

.status-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(185px, 1fr)); gap: 11px; }
.status-item { display: flex; flex-direction: column; gap: 2px; padding: 9px 11px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.status-label { font-size: 11.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .03em; }
.status-value { font-size: 13px; font-family: var(--font-num); }
.status-item.is-error .status-value, .is-error { color: var(--critical); }

.coverage-list { display: flex; flex-wrap: wrap; gap: 5px; }
.coverage-item { display: inline-flex; align-items: center; gap: 5px; padding: 3px 8px; font-size: 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.coverage-month { font-family: var(--font-num); }
.coverage-count { color: var(--text-muted); font-size: 11.5px; }

.timestamp { font-family: var(--font-num); font-size: 12px; color: var(--text-muted); }

/* Refresh log output. */
.logbox {
  max-height: 260px;
  overflow: auto;
  padding: 10px 12px;
  font-family: var(--font-num);
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
}
.logbox.running { border-color: var(--accent); }

/* ---------------------------------------------- empty, error & skeletons */

.empty { display: flex; flex-direction: column; align-items: center; gap: 7px; padding: 34px 20px; text-align: center; }
.empty-icon { font-size: 26px; opacity: .45; }
.empty-title { font-weight: 600; }
.empty-desc { font-size: 13px; color: var(--text-muted); max-width: 460px; }
.empty-error .empty-icon { color: var(--critical); opacity: .9; }

.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-hover) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
  border-radius: 4px;
  min-height: 12px;
}
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
.skeleton-table { display: flex; flex-direction: column; gap: 8px; padding: 13px; }
.skeleton-row { height: 15px; }

/* ---------------------------------------------------------------- toasts */

.toasts {
  position: fixed;
  top: 12px; right: 12px;
  z-index: 90;
  display: flex; flex-direction: column; gap: 8px;
  max-width: min(380px, calc(100vw - 24px));
}
.toast {
  display: flex; align-items: flex-start; gap: 9px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--info);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  animation: toast-in .16s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(-5px); } to { opacity: 1; transform: none; } }
.toast-good { border-left-color: var(--good); }
.toast-good .toast-icon { color: var(--good); }
.toast-warning { border-left-color: var(--warning); }
.toast-warning .toast-icon { color: var(--warning); }
.toast-critical, .toast-error { border-left-color: var(--critical); }
.toast-critical .toast-icon, .toast-error .toast-icon { color: var(--critical); }
.toast-info .toast-icon { color: var(--info); }
.toast-text { flex: 1; font-size: 13px; }
.toast-x { background: none; border: 0; color: var(--text-faint); cursor: pointer; font: inherit; padding: 0 2px; line-height: 1; }
.toast-x:hover { color: var(--text); }

/* --------------------------------------------------------------- dialogs */

.dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  padding: 0;
  max-width: min(520px, calc(100vw - 32px));
  width: 100%;
}
.dialog::backdrop { background: rgba(10, 14, 18, .45); }
.dialog-title { padding: 13px 16px; border-bottom: 1px solid var(--border); font-size: 15px; font-weight: 600; }
.dialog .card-body { padding: 16px; }
.dialog .form-actions { padding: 0 16px 16px; }

.row-actions { display: flex; gap: 5px; flex-wrap: wrap; }

/* ------------------------------------------------------------ responsive */

@media (max-width: 900px) {
  .nav-toggle { display: inline-flex; }

  .sidenav {
    position: fixed;
    top: var(--topbar-h); left: 0; bottom: 0;
    z-index: 25;
    height: auto;
    box-shadow: var(--shadow-lg);
    transform: translateX(-100%);
    transition: transform .16s ease;
  }
  .sidenav.is-open { transform: none; }

  .view { padding: 14px; }
  .user-name { display: none; }
  .page-actions { width: 100%; margin-left: 0; }
  .filterbar-extra { margin-left: 0; }
}

@media (max-width: 560px) {
  .kpi-grid, .kpi-grid-4, .sev-strip { grid-template-columns: 1fr 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .brand-text { display: none; }
  .dupe-items { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

/* Printing a reconciliation is a real workflow at month end. */
@media print {
  .topbar, .sidenav, .toasts, .filterbar, .page-actions, .pager { display: none !important; }
  body { background: #fff; }
  .card, .kpi, .dupe-card { box-shadow: none; break-inside: avoid; }
  .table-scroll { overflow: visible; }
}
