/* ============================================================
   KDM CMS - design system (v2.1.0)
   One stylesheet for every page; pages carry no CSS of their own.
   Brand: blue and orange on white, with a touch of red.
   Blue carries every action, orange marks where you are and what is
   waiting, red appears only in the brand mark and for danger.
   Light by default, dark when the device asks for it or the user
   picks it (Theme button in the sidebar, stored per browser).
   ============================================================ */

:root{
  --paper:#f6f8fc;
  --surface:#ffffff;
  --surface-2:#f8fafd;
  --surface-3:#eef3f9;
  --ink:#13213a;
  --ink-2:#44526a;
  --ink-3:#66738a;
  --rule:#dfe6ef;
  --rule-strong:#c5d0de;
  --accent:#1570c4;
  --accent-hover:#0f5ca3;
  --accent-ink:#ffffff;
  --accent-soft:#e6f1fb;
  --orange:#f28c18;
  --brand-grad:linear-gradient(135deg,#f7a234 0%,#ef6a24 60%,#e0352b 100%);
  --focus:0 0 0 3px rgba(21,112,196,.28);

  --side:#0d2341;
  --side-ink:#d2deee;
  --side-ink-2:#8fa6c4;
  --side-active:#f5a03a;

  --ok:#0b7a43;      --ok-bg:#e6f5ec;
  --warn:#b35c00;    --warn-bg:#fff1e0;
  --bad:#c4271d;     --bad-bg:#fdecea;
  --info:#1570c4;    --info-bg:#e6f1fb;
  --track:#6b46c1;   --track-bg:#f0ebfb;
  --muted:#4a5770;   --muted-bg:#edf1f6;

  --radius:10px;
  --radius-sm:8px;
  --shadow:0 1px 2px rgba(13,35,65,.06),0 1px 1px rgba(13,35,65,.03);
  --shadow-lg:0 18px 50px rgba(13,35,65,.22);
  --font:'Atkinson Hyperlegible Next',system-ui,-apple-system,'Segoe UI',sans-serif;
  --mono:'Atkinson Hyperlegible Mono',ui-monospace,'Cascadia Mono',Consolas,monospace;
  --ease:cubic-bezier(.2,.8,.3,1);
  color-scheme:light;
}

/* dark: follows the device unless the user picked light */
@media (prefers-color-scheme:dark){
  :root:not([data-theme=light]){
    --paper:#0b1322; --surface:#111b2d; --surface-2:#152137; --surface-3:#1b2943;
    --ink:#e7edf7; --ink-2:#aebbd0; --ink-3:#8796ad;
    --rule:#233250; --rule-strong:#33466a;
    --accent:#4ea3f5; --accent-hover:#74b8f8; --accent-ink:#04162b; --accent-soft:#12294a;
    --focus:0 0 0 3px rgba(78,163,245,.38);
    --side:#07101f; --side-ink:#cbd8ea; --side-ink-2:#7f95b5;
    --ok:#4cd187; --ok-bg:#10301f; --warn:#f8a94a; --warn-bg:#3a2510; --bad:#ff7a6e; --bad-bg:#3d1613;
    --info:#74b8f8; --info-bg:#12294a; --track:#b9a2ff; --track-bg:#251d42; --muted:#aebbd0; --muted-bg:#1f2b42;
    --shadow:0 1px 2px rgba(0,0,0,.4); --shadow-lg:0 18px 50px rgba(0,0,0,.6);
    color-scheme:dark;
  }
}
:root[data-theme=dark]{
  --paper:#0b1322; --surface:#111b2d; --surface-2:#152137; --surface-3:#1b2943;
  --ink:#e7edf7; --ink-2:#aebbd0; --ink-3:#8796ad;
  --rule:#233250; --rule-strong:#33466a;
  --accent:#4ea3f5; --accent-hover:#74b8f8; --accent-ink:#04162b; --accent-soft:#12294a;
  --focus:0 0 0 3px rgba(78,163,245,.38);
  --side:#07101f; --side-ink:#cbd8ea; --side-ink-2:#7f95b5;
  --ok:#4cd187; --ok-bg:#10301f; --warn:#f8a94a; --warn-bg:#3a2510; --bad:#ff7a6e; --bad-bg:#3d1613;
  --info:#74b8f8; --info-bg:#12294a; --track:#b9a2ff; --track-bg:#251d42; --muted:#aebbd0; --muted-bg:#1f2b42;
  --shadow:0 1px 2px rgba(0,0,0,.4); --shadow-lg:0 18px 50px rgba(0,0,0,.6);
  color-scheme:dark;
}

/* ---------- base ---------- */
*,*::before,*::after{ box-sizing:border-box; }
html{ -webkit-text-size-adjust:100%; }
body{
  margin:0; background:var(--paper); color:var(--ink);
  font:15px/1.5 var(--font); letter-spacing:.005em;
  -webkit-font-smoothing:antialiased;
}
h1,h2,h3,h4,p{ margin:0; }
h1{ font-size:23px; line-height:1.25; font-weight:650; letter-spacing:-.01em; }
h2{ font-size:17px; line-height:1.3; font-weight:650; }
h3{ font-size:15px; font-weight:650; }
a{ color:var(--accent); text-underline-offset:2px; }
a:hover{ color:var(--accent-hover); }
code,.num,.mono{ font-family:var(--mono); font-size:.93em; }
.num, td, .tabular{ font-variant-numeric:tabular-nums; }
hr{ border:0; border-top:1px solid var(--rule); margin:20px 0; }
.sr{ position:absolute; width:1px; height:1px; overflow:hidden; clip:rect(0 0 0 0); white-space:nowrap; }
.skip{ position:absolute; left:-9999px; top:0; z-index:100; background:var(--accent); color:var(--accent-ink); padding:10px 14px; border-radius:0 0 8px 0; }
.skip:focus{ left:0; }
[hidden]{ display:none !important; }
:focus-visible{ outline:none; box-shadow:var(--focus); border-radius:6px; }
.muted{ color:var(--ink-3); }
.small{ font-size:13px; }
.nowrap{ white-space:nowrap; }
.right{ text-align:right; }
.stack{ display:grid; gap:16px; }
.row{ display:flex; gap:10px; align-items:center; flex-wrap:wrap; }
.row.end{ justify-content:flex-end; }
.spread{ display:flex; gap:12px; align-items:center; justify-content:space-between; flex-wrap:wrap; }
.icon{ flex:none; }

/* ---------- app shell ---------- */
.app{ display:grid; grid-template-columns:236px minmax(0,1fr); min-height:100vh; }
.side{
  position:sticky; top:0; height:100vh; overflow-y:auto;
  background:var(--side); color:var(--side-ink);
  display:flex; flex-direction:column; padding:18px 12px;
  border-top:3px solid transparent; border-image:var(--brand-grad) 1;   /* the brand's touch of red */
}
.brand{ display:flex; align-items:center; gap:10px; padding:4px 8px 18px; color:inherit; text-decoration:none; }
.brand:hover{ color:inherit; }
.brand-mark{
  width:34px; height:34px; border-radius:9px; flex:none;
  display:inline-grid; place-items:center;
  background:var(--brand-grad); color:#fff; font-weight:700; font-size:18px;
}
.brand-text{ display:flex; flex-direction:column; line-height:1.2; }
.brand-text strong{ font-size:16px; letter-spacing:.04em; color:#fff; }
.brand-text span{ font-size:12.5px; color:var(--side-ink-2); }
.side-nav{ display:flex; flex-direction:column; gap:2px; }
.nav-item{
  display:flex; align-items:center; gap:11px; min-height:40px; padding:8px 10px;
  border-radius:8px; color:var(--side-ink); text-decoration:none; font-size:14.5px;
  position:relative;
}
.nav-item:hover{ background:rgba(255,255,255,.06); color:#fff; }
.nav-item.is-active{ background:rgba(255,255,255,.09); color:#fff; font-weight:600; }
.nav-item.is-active::before{ content:""; position:absolute; left:-12px; top:8px; bottom:8px; width:3px; border-radius:0 3px 3px 0; background:var(--side-active); }
.side-foot{ margin-top:auto; padding-top:16px; border-top:1px solid rgba(255,255,255,.08); display:grid; gap:10px; }
.me{ padding:0 8px; display:flex; flex-direction:column; line-height:1.35; }
.me strong{ color:#fff; font-size:14px; font-weight:600; }
.me span{ color:var(--side-ink-2); font-size:12.5px; }
.side-actions{ display:flex; gap:4px; flex-wrap:wrap; }
.side .btn-ghost{ color:var(--side-ink); }
.side .btn-ghost:hover{ background:rgba(255,255,255,.07); color:#fff; }
.side-scrim{ display:none; }

.main{ min-width:0; display:flex; flex-direction:column; }
.topbar{ display:none; }
.page{ width:100%; max-width:1480px; padding:28px 32px 56px; margin:0 auto; }
.page-head{ display:flex; gap:16px; align-items:flex-end; justify-content:space-between; flex-wrap:wrap; margin-bottom:20px; }
.page-sub{ color:var(--ink-3); margin-top:4px; max-width:72ch; }
.page-actions{ display:flex; gap:8px; flex-wrap:wrap; }

.banner{ padding:12px 32px; font-size:14.5px; border-bottom:1px solid var(--rule); background:var(--info-bg); color:var(--info); }
.banner.is-warning{ background:var(--warn-bg); color:var(--warn); }
.banner.is-danger{ background:var(--bad-bg); color:var(--bad); }
.banner.is-success{ background:var(--ok-bg); color:var(--ok); }

@media (max-width:980px){
  .app{ grid-template-columns:1fr; }
  .side{
    position:fixed; inset:0 auto 0 0; width:272px; z-index:60;
    transform:translateX(-100%); transition:transform .22s var(--ease);
  }
  .side.is-open{ transform:none; box-shadow:var(--shadow-lg); }
  .side-scrim.is-open{ display:block; position:fixed; inset:0; z-index:55; background:rgba(6,14,28,.45); }
  .topbar{
    display:flex; align-items:center; gap:10px; position:sticky; top:0; z-index:40;
    background:var(--side); color:var(--side-ink); padding:8px 12px;
    border-top:3px solid transparent; border-image:var(--brand-grad) 1;
  }
  .topbar .btn-ghost{ color:var(--side-ink); }
  .brand-small{ padding:0; gap:8px; color:#fff; }
  .brand-small .brand-mark{ width:28px; height:28px; font-size:15px; border-radius:7px; }
  .page{ padding:20px 16px 48px; }
  .banner{ padding:10px 16px; }
}

/* ---------- cards ---------- */
.card{ background:var(--surface); border:1px solid var(--rule); border-radius:var(--radius); box-shadow:var(--shadow); }
.card + .card, .card + .grid-2, .grid-2 + .card{ margin-top:20px; }
.card-head{ display:flex; gap:12px; align-items:center; justify-content:space-between; flex-wrap:wrap; padding:16px 20px; border-bottom:1px solid var(--rule); }
.card-head p{ color:var(--ink-3); font-size:13.5px; margin-top:2px; }
.card-body{ padding:18px 20px; }
.card-foot{ padding:12px 20px; border-top:1px solid var(--rule); }
.grid-2{ display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:20px; align-items:start; }
.grid-2 > .card{ margin-top:0; }
@media (max-width:1100px){ .grid-2{ grid-template-columns:1fr; } }

/* ---------- buttons ---------- */
.btn,.btn-secondary,.btn-danger,.btn-ghost{
  display:inline-flex; align-items:center; justify-content:center; gap:7px;
  min-height:38px; padding:0 15px; border-radius:var(--radius-sm);
  font:inherit; font-size:14px; font-weight:600; line-height:1; white-space:nowrap;
  cursor:pointer; text-decoration:none; border:1px solid transparent;
  transition:background .15s, border-color .15s, color .15s;
}
.btn{ background:var(--accent); color:var(--accent-ink); }
.btn:hover{ background:var(--accent-hover); color:var(--accent-ink); }
.btn-secondary{ background:var(--surface); color:var(--ink); border-color:var(--rule-strong); }
.btn-secondary:hover{ background:var(--surface-3); color:var(--ink); }
.btn-danger{ background:var(--surface); color:var(--bad); border-color:var(--rule-strong); }
.btn-danger:hover{ background:var(--bad-bg); border-color:var(--bad); color:var(--bad); }
.btn-ghost{ background:transparent; color:var(--ink-2); padding:0 10px; font-weight:500; }
.btn-ghost:hover{ background:var(--surface-3); color:var(--ink); }
.btn-sm{ min-height:32px; padding:0 11px; font-size:13px; }
button:disabled,.btn[aria-disabled=true]{ opacity:.5; cursor:not-allowed; }
.is-busy{ position:relative; color:transparent !important; pointer-events:none; }
.is-busy::after{
  content:""; position:absolute; inset:0; margin:auto; width:16px; height:16px; border-radius:50%;
  border:2px solid currentColor; border-color:var(--rule-strong) var(--rule-strong) var(--rule-strong) var(--ink-2);
  animation:spin .7s linear infinite;
}
.btn.is-busy::after{ border-color:rgba(255,255,255,.4) rgba(255,255,255,.4) rgba(255,255,255,.4) #fff; }
@keyframes spin{ to{ transform:rotate(360deg); } }

/* ---------- forms ---------- */
.field{ display:flex; flex-direction:column; gap:5px; min-width:0; }
.field > span, .field > label, .label{ font-size:13px; font-weight:600; color:var(--ink-2); }
.req::after{ content:" *"; color:var(--bad); }
input:not([type=checkbox]):not([type=radio]):not([type=file]), select, textarea{
  width:100%; min-height:38px; padding:7px 11px;
  font:inherit; font-size:14.5px; color:var(--ink);
  background:var(--surface); border:1px solid var(--rule-strong); border-radius:var(--radius-sm);
  transition:border-color .15s, box-shadow .15s;
}
textarea{ min-height:96px; resize:vertical; line-height:1.5; }
select[multiple]{ min-height:120px; padding:4px; }
select[multiple] option{ padding:6px 8px; border-radius:5px; }
input:hover, select:hover, textarea:hover{ border-color:var(--ink-3); }
input:focus, select:focus, textarea:focus{ outline:none; border-color:var(--accent); box-shadow:var(--focus); }
input[readonly], input:disabled, select:disabled, textarea:disabled{ background:var(--surface-3); color:var(--ink-3); cursor:not-allowed; }
input.is-shared{ border-style:dashed; }
input[type=checkbox], input[type=radio]{ width:17px; height:17px; accent-color:var(--accent); margin:0; vertical-align:middle; }
.help{ font-size:12.5px; color:var(--ink-3); }
.form-grid{ display:grid; grid-template-columns:repeat(auto-fill,minmax(210px,1fr)); gap:14px 16px; }
.form-grid .wide{ grid-column:1 / -1; }
.form-section{ margin-top:20px; }
.form-section > h3{ margin-bottom:10px; }
.check{ display:flex; gap:10px; align-items:flex-start; padding:10px 12px; border:1px solid var(--rule); border-radius:var(--radius-sm); cursor:pointer; }
.check:hover{ background:var(--surface-2); }
.check small{ display:block; color:var(--ink-3); }

/* ---------- filters ---------- */
.filters{ display:flex; gap:12px; flex-wrap:wrap; align-items:flex-end; padding:16px 20px; border-bottom:1px solid var(--rule); }
.filters .field{ flex:1 1 170px; max-width:260px; }
.filters .field.grow{ flex:2 1 240px; max-width:none; }
.filters .row{ flex:0 0 auto; }
.filters-more{ flex-basis:100%; }
.filters-more > summary{ cursor:pointer; color:var(--accent); font-weight:600; font-size:14px; list-style:none; display:inline-flex; gap:6px; align-items:center; }
.filters-more > summary::-webkit-details-marker{ display:none; }
.filters-more > summary::after{ content:""; width:7px; height:7px; border:solid currentColor; border-width:0 2px 2px 0; transform:rotate(45deg) translateY(-2px); transition:transform .15s; }
.filters-more[open] > summary::after{ transform:rotate(-135deg) translate(-1px,-1px); }
.filters-more .filters{ padding:12px 0 0; border:0; }
.filter-count{ display:inline-grid; place-items:center; min-width:20px; height:20px; padding:0 6px; border-radius:999px; background:var(--accent); color:var(--accent-ink); font-size:12px; }

/* ---------- tables ---------- */
.table-wrap{ overflow-x:auto; }
table.data{ width:100%; border-collapse:separate; border-spacing:0; font-size:14px; }
table.data th{
  position:sticky; top:0; z-index:1; text-align:left; white-space:nowrap;
  padding:10px 12px; font-size:13px; font-weight:600; color:var(--ink-2);
  background:var(--surface-2); border-bottom:1px solid var(--rule);
}
table.data td{ padding:10px 12px; border-bottom:1px solid var(--rule); vertical-align:middle; }
table.data tbody tr:last-child td{ border-bottom:0; }
table.data tbody tr:hover td{ background:var(--surface-2); }
table.data tr.is-link{ cursor:pointer; }
table.data th.sortable{ cursor:pointer; user-select:none; }
table.data th.sortable:hover{ color:var(--ink); }
table.data th[aria-sort=ascending]::after{ content:" \2191"; }
table.data th[aria-sort=descending]::after{ content:" \2193"; }
table.data .cell-check{ width:36px; padding-right:0; }
table.data .right{ text-align:right; }
table.data .cell-actions{ text-align:right; white-space:nowrap; }
.cell-main strong{ display:block; font-weight:600; }
.cell-main span{ display:block; color:var(--ink-3); font-size:13px; }
/* status rule on the left edge of client rows: the row's state at a glance */
table.data tr[data-status] td:first-child{ box-shadow:inset 3px 0 0 var(--row-rule,transparent); }
tr[data-status=active]{ --row-rule:var(--ok); }
tr[data-status=pending]{ --row-rule:var(--warn); }
tr[data-status=settled]{ --row-rule:var(--info); }
tr[data-status=suspended],tr[data-status=terminated],tr[data-status=rejected]{ --row-rule:var(--bad); }
tr[data-status=canceled],tr[data-status=inactive]{ --row-rule:var(--rule-strong); }
.empty{ text-align:center; padding:40px 20px; color:var(--ink-3); }
.empty strong{ display:block; color:var(--ink); font-size:15px; margin-bottom:4px; }
.skel{ display:block; height:12px; border-radius:6px; background:linear-gradient(90deg,var(--surface-3) 25%,var(--surface-2) 40%,var(--surface-3) 60%); background-size:300% 100%; animation:shimmer 1.2s ease infinite; }
@keyframes shimmer{ from{ background-position:100% 0; } to{ background-position:0 0; } }

@media (max-width:760px){
  table.data.rwd thead{ display:none; }
  table.data.rwd, table.data.rwd tbody, table.data.rwd tr, table.data.rwd td{ display:block; width:100%; }
  table.data.rwd tr{ border-bottom:1px solid var(--rule); padding:8px 4px; }
  table.data.rwd tbody tr:last-child{ border-bottom:0; }
  /* label on the left, every part of the value stacked on the right */
  table.data.rwd td{ border:0; padding:5px 12px; display:grid; grid-template-columns:minmax(96px,auto) minmax(0,1fr); column-gap:16px; justify-items:end; align-items:center; text-align:right; }
  table.data.rwd td::before{ content:attr(data-label); grid-row:1 / span 9; justify-self:start; color:var(--ink-3); font:13px/1.4 var(--font); text-align:left; }
  table.data.rwd td > *{ grid-column:2; }
  table.data.rwd td[data-label=""]::before{ content:none; }
  table.data.rwd tr[data-status] td:first-child{ box-shadow:none; }
  table.data.rwd tr[data-status]{ box-shadow:inset 3px 0 0 var(--row-rule,transparent); }
  table.data.rwd td.cell-actions{ display:flex; justify-content:flex-end; flex-wrap:wrap; }
  table.data.rwd td.cell-actions::before{ content:none; }
  table.data.rwd td.cell-check, table.data.rwd td[colspan]{ display:block; text-align:left; }
  table.data.rwd td[colspan]::before{ content:none; }
  .filters .field, .filters .field.grow{ flex:1 1 100%; max-width:none; }
}

/* ---------- pager ---------- */
.pager{ display:flex; align-items:center; justify-content:space-between; gap:10px 16px; flex-wrap:wrap; padding:12px 20px; border-top:1px solid var(--rule); font-size:13.5px; }
.pager-count{ color:var(--ink-3); }
.pager-links{ display:flex; gap:4px; flex-wrap:wrap; align-items:center; }
.pg{
  min-width:34px; height:34px; padding:0 10px; display:inline-flex; align-items:center; justify-content:center;
  border:1px solid var(--rule); border-radius:7px; color:var(--ink-2); background:var(--surface);
  text-decoration:none; font:inherit; cursor:pointer;
}
a.pg:hover, button.pg:hover{ border-color:var(--rule-strong); background:var(--surface-3); color:var(--ink); }
.pg.is-current{ background:var(--accent); border-color:var(--accent); color:var(--accent-ink); font-weight:600; }
.pg.is-off{ opacity:.45; cursor:default; }
.pg-gap{ padding:0 4px; color:var(--ink-3); }
.pager-size{ display:flex; align-items:center; gap:8px; color:var(--ink-3); }
.pager-size select{ width:auto; min-height:32px; padding:3px 8px; font-size:13.5px; }
.card-body > .pager, .tab-panel > .pager{ padding:12px 0 0; border-top:0; }

/* ---------- badges & chips ---------- */
.badge{
  display:inline-flex; align-items:center; gap:6px; padding:2px 9px 2px 8px; border-radius:999px;
  font-size:12.5px; font-weight:600; white-space:nowrap; line-height:1.6;
  background:var(--muted-bg); color:var(--muted); border:1px solid transparent;
}
.badge::before{ content:""; width:6px; height:6px; border-radius:50%; background:currentColor; }
.badge.is-active,.badge.is-paid,.badge.is-paid-in-full{ background:var(--ok-bg); color:var(--ok); }
.badge.is-settled{ background:var(--info-bg); color:var(--info); }
.badge.is-pending,.badge.is-on-hold{ background:var(--warn-bg); color:var(--warn); }
.badge.is-failed,.badge.is-rejected,.badge.is-terminated,.badge.is-disputed,.badge.is-suspended{ background:var(--bad-bg); color:var(--bad); }
.badge.is-tracking{ background:var(--track-bg); color:var(--track); }
.badge.is-canceled{ background:transparent; color:var(--muted); border:1px dashed var(--rule-strong); }
.badge.is-none{ background:transparent; color:var(--ink-3); }
/* who can read a comment */
.badge.is-office{ background:var(--warn-bg); color:var(--warn); }
.badge.is-franchise{ background:var(--info-bg); color:var(--info); }
.badge.is-agents{ background:var(--ok-bg); color:var(--ok); }
.chip{ display:inline-block; padding:1px 8px; margin:1px 3px 1px 0; border-radius:6px; font-size:12.5px; background:var(--surface-3); color:var(--ink-2); border:1px solid var(--rule); }

/* ---------- notices ---------- */
.notice{ padding:12px 14px; border-radius:var(--radius-sm); background:var(--info-bg); color:var(--ink); border:1px solid transparent; font-size:14px; }
.notice strong{ display:block; margin-bottom:2px; }
.notice.is-warn{ background:var(--warn-bg); }
.notice.is-bad{ background:var(--bad-bg); }
.notice.is-ok{ background:var(--ok-bg); }
.notice p + p{ margin-top:6px; }
.sibling{ display:flex; justify-content:space-between; align-items:center; gap:10px; flex-wrap:wrap; padding:8px 10px; margin-top:8px; background:var(--surface); border:1px solid var(--rule); border-radius:var(--radius-sm); }

/* ---------- dashboard ---------- */
.status-bar{ display:flex; height:14px; border-radius:7px; overflow:hidden; background:var(--surface-3); gap:2px; }
.status-bar > span{ display:block; min-width:3px; background:var(--muted); }
.status-bar .is-active{ background:var(--ok); }
.status-bar .is-pending{ background:var(--orange); }
.status-bar .is-settled{ background:var(--info); }
.status-bar .is-suspended{ background:#d4622a; }
.status-bar .is-terminated{ background:var(--bad); }
.status-bar .is-rejected{ background:#8c1d18; }
.status-bar .is-inactive{ background:var(--rule-strong); }
.status-bar .is-canceled{ background:repeating-linear-gradient(135deg,var(--rule-strong) 0 4px,transparent 4px 7px); }
.status-legend{ display:grid; grid-template-columns:repeat(auto-fill,minmax(150px,1fr)); gap:4px 16px; margin-top:16px; }
.status-legend a{ display:flex; justify-content:space-between; gap:8px; padding:8px 10px; border-radius:8px; text-decoration:none; color:var(--ink); }
.status-legend a:hover{ background:var(--surface-2); }
.status-legend b{ font-weight:650; font-variant-numeric:tabular-nums; }
.total-line{ display:flex; align-items:baseline; gap:10px; flex-wrap:wrap; margin-bottom:14px; }
.total-line strong{ font-size:34px; line-height:1; font-weight:700; letter-spacing:-.02em; font-variant-numeric:tabular-nums; }
.total-line span{ color:var(--ink-3); }
.figures{ display:grid; grid-template-columns:repeat(auto-fit,minmax(128px,1fr)); gap:12px; }
.figure{ padding:12px 14px; border:1px solid var(--rule); border-radius:var(--radius-sm); background:var(--surface-2); }
.figure b{ display:block; font-size:22px; font-weight:700; font-variant-numeric:tabular-nums; }
.figure span{ color:var(--ink-3); font-size:13px; }

/* ---------- dialogs (native <dialog>) ---------- */
dialog{ color:var(--ink); background:var(--surface); border:1px solid var(--rule); padding:0; box-shadow:var(--shadow-lg); }
dialog::backdrop{ background:rgba(6,14,28,.48); }
body:has(dialog[open]){ overflow:hidden; }
dialog.modal{ width:min(560px,calc(100% - 32px)); border-radius:14px; }
dialog.modal[open]{ animation:pop .2s var(--ease); }
@keyframes pop{ from{ opacity:0; transform:translateY(8px) scale(.985); } }
.dlg-head{ display:flex; align-items:flex-start; justify-content:space-between; gap:12px; padding:18px 20px 12px; }
.dlg-head p{ color:var(--ink-3); font-size:13.5px; margin-top:3px; }
.dlg-body{ padding:6px 20px 18px; }
.dlg-foot{ display:flex; justify-content:flex-end; gap:8px; padding:14px 20px; border-top:1px solid var(--rule); background:var(--surface-2); border-radius:0 0 14px 14px; }
.dlg-close{ flex:none; }

/* client drawer: a dialog that slides in from the right */
dialog.drawer{
  margin:0 0 0 auto; height:100vh; max-height:100vh; width:min(820px,100vw); max-width:100vw;
  border-radius:0; border-width:0 0 0 1px; display:none; flex-direction:column;
}
dialog.drawer[open]{ display:flex; animation:slide .24s var(--ease); }
@keyframes slide{ from{ transform:translateX(40px); opacity:0; } }
.drawer-head{ padding:18px 22px 0; border-bottom:1px solid var(--rule); }
.drawer-title{ display:flex; justify-content:space-between; gap:12px; align-items:flex-start; }
.drawer-title p{ color:var(--ink-3); font-size:13.5px; margin-top:3px; }
.drawer-body{ flex:1; overflow-y:auto; padding:20px 22px 28px; }
.drawer-foot{ display:flex; justify-content:flex-end; gap:8px; padding:12px 22px; border-top:1px solid var(--rule); background:var(--surface-2); }

/* ---------- tabs ---------- */
.tabs{ display:flex; gap:2px; overflow-x:auto; margin-top:12px; }
.tab{
  font:inherit; font-size:14px; font-weight:600; color:var(--ink-3); background:none; cursor:pointer;
  border:0; border-bottom:2px solid transparent; padding:10px 12px; white-space:nowrap; text-decoration:none;
  display:inline-flex; gap:8px; align-items:center;
}
.tab:hover{ color:var(--ink); }
.tab[aria-selected=true], .tab.is-active{ color:var(--ink); border-bottom-color:var(--orange); }
.tab .count{ font-size:12px; font-weight:600; padding:0 7px; border-radius:999px; background:var(--surface-3); color:var(--ink-2); }
.tabs-line{ border-bottom:1px solid var(--rule); margin:0 0 20px; }

/* ---------- comments ---------- */
.comments{ display:grid; gap:12px; }
.comment{ border:1px solid var(--rule); border-radius:var(--radius); padding:12px 14px; background:var(--surface); }
.comment-meta{ display:flex; justify-content:space-between; gap:8px 12px; flex-wrap:wrap; font-size:13px; color:var(--ink-3); margin-bottom:6px; }
.comment-meta strong{ color:var(--ink); font-weight:600; }
.comment-text{ white-space:pre-wrap; overflow-wrap:anywhere; }
.comment-edited{ margin-top:10px; padding-top:8px; border-top:1px dashed var(--rule); font-size:13px; color:var(--ink-3); display:flex; gap:8px 14px; align-items:center; flex-wrap:wrap; }
.edits{ margin-top:10px; display:grid; gap:8px; }
.edit{ padding:10px 12px; border-radius:var(--radius-sm); background:var(--surface-2); border:1px solid var(--rule); }
.edit-who{ font-size:13px; color:var(--ink-3); margin-bottom:4px; }
.edit-who strong{ color:var(--ink); font-weight:600; }
.diff{ white-space:pre-wrap; overflow-wrap:anywhere; line-height:1.6; }
.diff del{ background:var(--bad-bg); color:var(--bad); text-decoration:line-through; border-radius:3px; padding:0 2px; }
.diff ins{ background:var(--ok-bg); color:var(--ok); text-decoration:none; border-radius:3px; padding:0 2px; }

/* ---------- history timeline ---------- */
.timeline{ list-style:none; margin:0; padding:0 0 0 18px; border-left:2px solid var(--rule); }
.timeline li{ position:relative; padding:0 0 16px 14px; }
.timeline li::before{ content:""; position:absolute; left:-25px; top:5px; width:12px; height:12px; border-radius:50%; background:var(--surface); border:3px solid var(--accent); }
.timeline li.ev-created::before,.timeline li.ev-imported::before{ border-color:var(--ok); }
.timeline li.ev-deleted::before,.timeline li.ev-product_removed::before,.timeline li.ev-creditor_deleted::before{ border-color:var(--bad); }
.timeline li.ev-api::before{ border-color:var(--track); }
.timeline li.ev-comment_edited::before{ border-color:var(--warn); }
.tl-head{ font-weight:600; }
.tl-meta{ font-size:13px; color:var(--ink-3); margin-top:2px; }
.tl-diff{ display:flex; gap:8px; align-items:center; flex-wrap:wrap; margin-top:4px; font-size:14px; }
.old{ color:var(--bad); text-decoration:line-through; }
.new{ color:var(--ok); }

/* ---------- steps (bulk upload is a real sequence) ---------- */
.steps{ list-style:none; display:flex; gap:8px; padding:0; margin:0 0 22px; counter-reset:step; flex-wrap:wrap; }
.steps li{ counter-increment:step; display:flex; align-items:center; gap:8px; color:var(--ink-3); font-weight:600; font-size:14px; }
.steps li::before{ content:counter(step); width:26px; height:26px; border-radius:50%; display:inline-grid; place-items:center; border:2px solid var(--rule-strong); font-size:13px; }
.steps li + li::after{ order:-1; content:""; width:28px; height:2px; background:var(--rule); }
.steps li.is-active{ color:var(--ink); }
.steps li.is-active::before{ border-color:var(--accent); background:var(--accent); color:var(--accent-ink); }
.steps li.is-done::before{ content:"\2713"; border-color:var(--ok); background:var(--ok); color:#fff; }
.drop{ display:grid; place-items:center; gap:6px; text-align:center; padding:40px 20px; border:2px dashed var(--rule-strong); border-radius:var(--radius); cursor:pointer; color:var(--ink-2); }
.drop:hover,.drop.is-over{ border-color:var(--accent); background:var(--accent-soft); }
.drop strong{ color:var(--ink); font-size:16px; }
.meter{ height:8px; border-radius:4px; background:var(--surface-3); overflow:hidden; }
.meter > span{ display:block; height:100%; width:0; background:var(--accent); transition:width .3s; }

/* ---------- definition lists (details, stats) ---------- */
.dl{ display:grid; grid-template-columns:minmax(120px,auto) 1fr; gap:8px 20px; margin:0; }
.dl dt{ color:var(--ink-3); }
.dl dd{ margin:0; overflow-wrap:anywhere; }
@media (max-width:560px){ .dl{ grid-template-columns:1fr; gap:2px; } .dl dd{ margin-bottom:8px; } }

/* ---------- code (API docs) ---------- */
pre.code{ margin:12px 0; padding:14px 16px; border-radius:var(--radius-sm); background:#0d1b30; color:#dbe6f5; font:13px/1.6 var(--mono); overflow:auto; }
.method{ font:600 12px/1 var(--mono); padding:4px 7px; border-radius:5px; }
.m-GET{ background:var(--ok-bg); color:var(--ok); }
.m-POST{ background:var(--info-bg); color:var(--info); }
.m-PUT,.m-PATCH{ background:var(--warn-bg); color:var(--warn); }
.m-DELETE{ background:var(--bad-bg); color:var(--bad); }

/* ---------- login ---------- */
.auth{ min-height:100vh; display:grid; grid-template-columns:minmax(0,1fr) minmax(0,1.1fr); }
.auth-side{ background:var(--side); color:var(--side-ink); padding:48px; display:flex; flex-direction:column; justify-content:space-between;
  border-top:3px solid transparent; border-image:var(--brand-grad) 1; }
.auth-side .brand{ padding:0; }
.auth-side h1{ color:#fff; font-size:30px; max-width:16ch; line-height:1.2; }
.auth-side p{ color:var(--side-ink-2); max-width:42ch; margin-top:12px; }
.auth-main{ display:grid; place-items:center; padding:32px 20px; }
.auth-form{ width:100%; max-width:380px; display:grid; gap:16px; }
.auth-form h2{ font-size:22px; }
@media (max-width:860px){ .auth{ grid-template-columns:1fr; } .auth-side{ padding:24px 20px; gap:16px; } .auth-side h1{ font-size:22px; } }

/* ---------- progress / overlay ---------- */
#kdm-progress{ position:fixed; top:0; left:0; height:3px; width:0; background:var(--brand-grad); z-index:200; opacity:0; transition:width .2s, opacity .3s; }
#kdm-progress.is-on{ opacity:1; }
.overlay{ position:fixed; inset:0; z-index:150; display:none; place-items:center; background:rgba(6,14,28,.5); }
.overlay.is-on{ display:grid; }
.overlay-box{ background:var(--surface); border-radius:12px; padding:22px 26px; display:flex; gap:14px; align-items:center; box-shadow:var(--shadow-lg); }
.spinner{ width:26px; height:26px; border-radius:50%; border:3px solid var(--rule); border-top-color:var(--accent); animation:spin .8s linear infinite; }

/* ---------- SweetAlert2 skin ---------- */
.swal2-container{ z-index:300 !important; }
.swal2-popup.kdm-swal{ background:var(--surface); color:var(--ink); border:1px solid var(--rule); border-radius:14px; font-family:var(--font); }
.swal2-popup.kdm-swal .swal2-title{ color:var(--ink); font-size:19px; font-weight:650; }
.swal2-popup.kdm-swal .swal2-html-container{ color:var(--ink-2); font-size:15px; }
.swal2-popup.kdm-swal .swal2-input,.swal2-popup.kdm-swal .swal2-textarea{ background:var(--surface); color:var(--ink); border:1px solid var(--rule-strong); border-radius:8px; box-shadow:none; font-size:15px; }
.swal2-popup.kdm-swal .swal2-confirm{ background:var(--accent); color:var(--accent-ink); border-radius:8px; font-weight:600; }
.swal2-popup.kdm-swal .swal2-cancel{ background:var(--surface-3); color:var(--ink); border-radius:8px; font-weight:600; }
.swal2-popup.kdm-swal.is-danger .swal2-confirm{ background:var(--bad); color:#fff; }
.swal2-popup.kdm-swal.swal2-toast{ box-shadow:var(--shadow-lg); }

@media print{
  .side,.topbar,.pager,.page-actions,.filters,button{ display:none !important; }
  .app{ display:block; }
  body{ background:#fff; color:#000; }
}
@media (prefers-reduced-motion:reduce){
  *,*::before,*::after{ animation-duration:.01ms !important; animation-iteration-count:1 !important; transition-duration:.01ms !important; }
}
