/* ------------------------------------------------------------------ *
 * design tokens - light (default) and dark
 * ------------------------------------------------------------------ */
:root {
  --bg: #eef2f8;
  --bg-grad: radial-gradient(1200px 600px at 100% -10%, #e3ecfb 0%, transparent 60%), radial-gradient(900px 500px at 0% 0%, #eaf1fd 0%, transparent 55%);
  --surface: #ffffff;
  --surface-2: #f6f8fc;
  --surface-3: #edf1f8;
  --border: #e1e7f0;
  --border-strong: #cfd9e8;
  --text: #0e1729;
  --muted: #66748e;
  --navy: #14315e;
  --brand: #14315e;   /* filled backgrounds under white text */
  --crit-ink: #b02a2a; --high-ink: #a8520a; --mid-ink: #7a5c00; --good-ink: #126b42; --none-ink: #535c6e;
  --wa: #15803d;
  --accent: #2563eb;
  --accent-2: #1d4ed8;
  --accent-soft: #e8f0fe;
  --accent-ink: #1d4ed8;
  --good: #1e9e63;
  --good-soft: #e3f6ec;
  --mid: #c99a06;
  --mid-soft: #fdf6dc;
  --high: #e07b17;
  --high-soft: #fdeedd;
  --crit: #d23c3c;
  --crit-soft: #fbe4e4;
  --none: #8a93a6;
  --none-soft: #eef0f4;
  --legal: #7a3fa0;
  --legal-ink: #5c2f78;
  --legal-soft: #f3ecf9;
  --shadow-sm: 0 1px 2px rgba(16, 32, 64, .06);
  --shadow: 0 1px 2px rgba(16, 32, 64, .05), 0 12px 28px -18px rgba(16, 32, 64, .35);
  --shadow-lg: 0 24px 60px -28px rgba(16, 32, 64, .45);
  --ring: 0 0 0 3px rgba(37, 99, 235, .18);
  --radius: 16px;
  --radius-sm: 10px;
  --side-bg: linear-gradient(180deg, #16305a 0%, #0d1f3b 100%);
  --side-text: #b9cbe6;
  --side-text-strong: #ffffff;
  --side-hover: rgba(255, 255, 255, .08);
  --side-active: rgba(255, 255, 255, .14);
  --side-border: rgba(255, 255, 255, .10);
  --side-accent: #8fb6ff;
  --topbar-bg: rgba(255, 255, 255, .82);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --auto-dark: 1; }
}
:root[data-theme="dark"] {
  --bg: #0a1120;
  --bg-grad: radial-gradient(1100px 560px at 100% -10%, #12233d 0%, transparent 60%), radial-gradient(800px 460px at 0% 0%, #101d33 0%, transparent 55%);
  --surface: #111c2f;
  --surface-2: #16233a;
  --surface-3: #1b2a45;
  --border: #22314d;
  --border-strong: #2e4266;
  --text: #e8eefb;
  --muted: #93a3bf;
  --navy: #b9cdf3;
  --brand: #1e3a6b;
  --crit-ink: #ff8a8a; --high-ink: #ffb066; --mid-ink: #f0cc55; --good-ink: #5fd69a; --none-ink: #b4bccb;
  --accent: #5b8def;
  --accent-2: #7aa7ff;
  --accent-soft: #172a4d;
  --accent-ink: #8fb6ff;
  --good-soft: #163428;
  --mid-soft: #3a3115;
  --high-soft: #3d2a17;
  --crit-soft: #3f1d1d;
  --none-soft: #232b3a;
  --legal: #b98fe0;
  --legal-ink: #d9bff2;
  --legal-soft: #2e2240;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .5);
  --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 16px 36px -22px rgba(0, 0, 0, .9);
  --shadow-lg: 0 30px 70px -30px rgba(0, 0, 0, .95);
  --ring: 0 0 0 3px rgba(122, 167, 255, .22);
  --side-bg: linear-gradient(180deg, #0e1a2c 0%, #0a1322 100%);
  --side-text: #9db0cd;
  --side-text-strong: #ffffff;
  --side-hover: rgba(122, 167, 255, .10);
  --side-active: rgba(122, 167, 255, .18);
  --side-border: rgba(122, 167, 255, .14);
  --side-accent: #9dc0ff;
  --topbar-bg: rgba(13, 22, 38, .82);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; overflow-x: hidden; }
@supports (overflow: clip) { html, body { overflow-x: clip; } }
body {
  margin: 0; background: var(--bg); background-image: var(--bg-grad); background-attachment: fixed;
  color: var(--text);
  font: 15px/1.6 "Cairo", "Segoe UI", Tahoma, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; line-height: 1.3; letter-spacing: -.01em; }
h2 { font-size: 15px; color: var(--navy); margin-bottom: 12px; }
a { color: var(--accent); text-decoration: none; }
.muted { color: var(--muted); font-size: 13px; }
.num { font-variant-numeric: tabular-nums; unicode-bidi: plaintext; white-space: nowrap; }
[hidden] { display: none !important; }
.neg { color: var(--crit); }
:where(a, button, input, select, textarea):focus-visible { outline: none; box-shadow: var(--ring); }

/* ------------------------------------------------------------------ *
 * app shell: sidebar (right) + content column
 * ------------------------------------------------------------------ */
.sidebar {
  position: fixed; inset-block: 0; inset-inline-start: 0; inset-inline-end: auto; z-index: 40;
  width: 268px; display: flex; flex-direction: column; gap: 6px;
  padding: 18px 14px calc(16px + env(safe-area-inset-bottom));
  background: var(--side-bg); border-inline-end: 1px solid var(--side-border);
  box-shadow: var(--shadow-lg);
  transform: translateX(100%); transition: transform .24s ease;
}
.sidebar.open { transform: none; }
.side-brand { display: flex; align-items: center; gap: 11px; padding: 4px 8px 16px; border-bottom: 1px solid var(--side-border); margin-bottom: 8px; }
.side-brand .logo { background: rgba(255, 255, 255, .14); color: #fff; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .14); }
.side-brand-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.side-brand-text b { color: var(--side-text-strong); font-size: 15px; }
.side-brand-text span { color: var(--side-text); font-size: 12px; letter-spacing: .08em; }
.side-foot { margin-top: auto; padding-top: 10px; border-top: 1px solid var(--side-border); }
.side-theme {
  display: flex; align-items: center; gap: 9px; width: 100%; cursor: pointer;
  font: inherit; font-size: 13px; font-weight: 600; color: var(--side-text);
  background: transparent; border: 1px solid var(--side-border); border-radius: 10px; padding: 9px 12px;
}
.side-theme:hover { background: var(--side-hover); color: var(--side-text-strong); }
.side-theme .ico { font-size: 15px; }

.nav-backdrop { position: fixed; inset: 0; z-index: 35; background: rgba(8, 14, 26, .5); backdrop-filter: blur(2px); }

.shell { min-width: 0; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  padding: 12px 22px; background: var(--topbar-bg); backdrop-filter: saturate(140%) blur(12px);
  border-bottom: 1px solid var(--border); flex-wrap: nowrap;
}
.page-head { min-width: 0; margin-inline-end: auto; display: flex; flex-direction: column; gap: 1px; }
.page-head h1 { font-size: 18px; color: var(--text); font-weight: 700; }
.page-head p { margin: 0; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.topbar .top-logo { display: none; }
.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px; flex: none; cursor: pointer;
  font: inherit; font-size: 17px; line-height: 1; color: var(--muted);
  background: var(--surface); border: 1px solid var(--border); border-radius: 11px;
  transition: color .15s, border-color .15s, background .15s, transform .1s;
}
.icon-btn:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.icon-btn:active { transform: translateY(1px); }
.icon-btn svg { width: 20px; height: 20px; fill: currentColor; }
.nav-toggle { display: grid; }

.logo {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center;
  background: var(--brand); color: #fff; font-weight: 700; font-size: 20px; flex: none;
}

/* navigation: a vertical rail in the sidebar, a bottom bar on phones */
.tabs { display: flex; flex-direction: column; gap: 3px; overflow-y: auto; padding: 2px; }
.tabs a {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px;
  color: var(--side-text); font-weight: 600; font-size: 14px; position: relative;
  transition: background .15s, color .15s;
}
.tabs a:hover { background: var(--side-hover); color: var(--side-text-strong); }
.tabs a.active { background: var(--side-active); color: var(--side-text-strong); }
.tabs a.active::before {
  content: ''; position: absolute; inset-inline-start: 0; top: 9px; bottom: 9px; width: 3px;
  border-radius: 3px; background: var(--side-accent);
}
.tabs svg { width: 18px; height: 18px; fill: currentColor; flex: none; opacity: .95; }
.tabs a span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabs .short { display: none; }

.btn {
  font: inherit; font-weight: 600; border: 0; border-radius: 10px; padding: 8px 16px; cursor: pointer;
  background: linear-gradient(180deg, var(--accent), var(--accent-2)); color: #fff;
  box-shadow: 0 1px 2px rgba(16, 32, 64, .18), inset 0 1px 0 rgba(255, 255, 255, .16);
  transition: filter .15s, transform .1s, box-shadow .15s;
}
.btn:hover { filter: brightness(1.07); }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: var(--surface); color: var(--text); border: 1px solid var(--border); box-shadow: var(--shadow-sm); }
.btn.ghost:hover { border-color: var(--border-strong); background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: default; transform: none; }

.status { margin: 12px 24px 0; padding: 10px 14px; border-radius: 10px; font-size: 14px; }
.status.info { background: var(--accent-soft); color: var(--accent); }
.status.error { background: var(--crit-soft); color: var(--crit); }
.status.warn { background: var(--mid-soft); color: var(--text); }

main { padding: 20px 22px 44px; width: 100%; }
.view { display: flex; flex-direction: column; gap: 16px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); min-width: 0;
}
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: 1fr 1fr; }
.grid.three { grid-template-columns: 1fr 1fr 1fr; }
.span2 { grid-column: span 2; }
@media (max-width: 1000px) {
  .grid.two, .grid.three { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
}

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.kpi {
  position: relative; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 15px 16px 15px 16px; box-shadow: var(--shadow);
  transition: transform .15s, box-shadow .15s, border-color .15s;
}
.kpi::after {
  content: ''; position: absolute; inset-inline-start: 0; top: 0; bottom: 0; width: 3px;
  background: linear-gradient(180deg, var(--accent), transparent); opacity: .8;
}
.kpi:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); border-color: var(--border-strong); }
.kpi .label { color: var(--muted); font-size: 13px; font-weight: 600; }
.kpi .value { font-size: 24px; font-weight: 700; margin-top: 2px; color: var(--text); }
.kpi .sub { font-size: 12px; color: var(--muted); }
.kpi.warn .value { color: var(--crit); }
.kpi.warn::after { background: linear-gradient(180deg, var(--crit), transparent); }
.kpi.link { cursor: pointer; }
.kpi.link:hover { border-color: var(--accent); }

.chart-box { position: relative; height: 290px; }
.chart-box.small { height: 200px; }

/* bars */
.bars { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 110px 1fr 120px 52px; align-items: center; gap: 10px; font-size: 14px; }
.bar-track { height: 14px; background: var(--surface-2); border-radius: 7px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 7px; }
.bar-row .pct { color: var(--muted); font-size: 12px; text-align: left; }
@media (max-width: 560px) { .bar-row { grid-template-columns: 90px 1fr 90px; } .bar-row .pct { display: none; } }

/* tables */
.table-wrap { overflow-x: auto; border-radius: var(--radius-sm); }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14px; }
.table th, .table td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
.table th {
  position: sticky; top: 0; z-index: 1; background: var(--surface-3); color: var(--muted);
  font-weight: 700; font-size: 12px; letter-spacing: .01em; cursor: default; user-select: none;
}
.table th:first-child { border-start-start-radius: var(--radius-sm); }
.table th:last-child { border-start-end-radius: var(--radius-sm); }
.table tbody tr:last-child td { border-bottom: 0; }
.table th.sortable { cursor: pointer; }
.table th.sortable:hover { color: var(--accent); }
.table th .arrow { font-size: 10px; margin-inline-start: 4px; }
.table td.name { white-space: normal; min-width: 180px; font-weight: 600; }
.table td.wrap { white-space: normal; min-width: 160px; }
.table.clickable tbody tr { cursor: pointer; }
.table tbody tr { transition: background .12s; }
.table tbody tr:hover { background: var(--accent-soft); }
.table tfoot td { font-weight: 700; background: var(--surface-3); }
.table-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; align-items: center; }
.table-wrap.has-copy { position: relative; }
.table-copy {
  position: absolute; top: 6px; inset-inline-start: 6px; z-index: 3;
  display: inline-flex; align-items: center; gap: 4px;
  font: inherit; font-size: 12px; font-weight: 600; line-height: 1;
  padding: 5px 10px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--muted);
  opacity: 0; transition: opacity .15s ease, color .15s ease, border-color .15s ease;
}
.table-copy-all { inset-inline-start: auto; inset-inline-end: 6px; }
.table-wrap:hover .table-copy, .table-copy:focus-visible { opacity: 1; }
.table-copy:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.table-copy:active { transform: translateY(1px); }
.table-copy-all { color: var(--accent); border-color: var(--accent); }
@media (hover: none) { .table-copy { opacity: 1; } }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
.table th { position: sticky; top: 0; background: var(--surface-2); color: var(--muted); font-weight: 600; font-size: 13px; cursor: default; user-select: none; }
.table th.sortable { cursor: pointer; }
.table th.sortable:hover { color: var(--text); }
.table th .arrow { font-size: 10px; margin-inline-start: 4px; }
.table td.name { white-space: normal; min-width: 180px; font-weight: 600; }
.table td.wrap { white-space: normal; min-width: 160px; }
.table.clickable tbody tr { cursor: pointer; }
.table tbody tr:hover { background: var(--surface-2); }
.table tfoot td { font-weight: 700; background: var(--surface-2); }
.table-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }

.badge { display: inline-block; padding: 1px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.r-حرج { background: var(--crit-soft); color: var(--crit-ink); }
.r-مرتفع { background: var(--high-soft); color: var(--high-ink); }
.r-متوسط { background: var(--mid-soft); color: var(--mid-ink); }
.r-منخفض { background: var(--good-soft); color: var(--good-ink); }
.r-none { background: var(--none-soft); color: var(--none-ink); }

/* filters */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.filters input[type=search] { flex: 1 1 260px; }
input, select {
  font: inherit; font-size: 14px; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.filters select { flex: 0 1 190px; }
.date-range { display: flex; align-items: center; gap: 6px; flex: 1 1 auto; flex-wrap: wrap; }
.date-range label { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.date-range input[type=date] { padding: 6px 8px; }
.date-range.is-set label { color: var(--accent); font-weight: 600; }
.date-range.is-set input[type=date] { border-color: var(--accent); background: var(--accent-soft); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  font: inherit; font-size: 13px; padding: 4px 14px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer;
}
.chip.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.chip .count { opacity: .7; margin-inline-start: 4px; }

.pager { display: flex; gap: 6px; justify-content: center; align-items: center; margin-top: 12px; flex-wrap: wrap; }
.pager button { font: inherit; font-size: 13px; padding: 4px 10px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; }
.pager button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.pager button:disabled { opacity: .4; cursor: default; }

/* ranking lists */
.rank-list { list-style: none; margin: 0; padding: 0; counter-reset: r; }
.rank-list li { counter-increment: r; display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px dashed var(--border); cursor: pointer; }
.rank-list li:last-child { border-bottom: 0; }
.rank-list li::before { content: counter(r); width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 700; flex: none; }
.rank-list .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-list li:hover .nm { color: var(--accent); }

/* customer detail */
.back { font-weight: 600; cursor: pointer; }
.profile { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.profile .title { flex: 1 1 320px; }
.profile h2 { font-size: 22px; color: var(--text); margin-bottom: 4px; }
.meta { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px 16px; margin-top: 12px; font-size: 14px; }
.meta div span { display: block; color: var(--muted); font-size: 12px; }
.score { text-align: center; min-width: 120px; }
.score .ring { font-size: 30px; font-weight: 700; }
.reco { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.reco > div { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.reco span { display: block; color: var(--muted); font-size: 12px; }
.reco b { font-size: 16px; }
.alert { padding: 10px 14px; border-radius: 10px; background: var(--crit-soft); color: var(--crit); font-size: 14px; }
.stmt-tools { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; align-items: center; }
.stmt-tools select { flex: 0 1 180px; }
.stmt-tools .stmt-kind-share { margin-inline-start: auto; }
/* the balance with open checks: the statement's headline numbers */
.stmt-balance { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 10px; }
.stmt-balance > div { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; min-width: 0; }
.stmt-balance span { display: block; color: var(--muted); font-size: 12px; }
.stmt-balance b { font-size: 17px; }
.stmt-balance .hi { background: var(--high-soft); border-color: var(--high); }
.stmt-balance .hi b { color: var(--high-ink); }

/* settings */
.settings { display: flex; flex-direction: column; gap: 12px; max-width: 860px; }
.settings label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 14px; flex: 1; }
.settings .row { display: flex; gap: 12px; flex-wrap: wrap; }
.help { margin: 0; padding-inline-start: 20px; font-size: 14px; display: flex; flex-direction: column; gap: 4px; }
.file-drop { border: 2px dashed var(--border); border-radius: 12px; padding: 28px; text-align: center; cursor: pointer; color: var(--muted); }
.file-drop.over, .file-drop:hover { border-color: var(--accent); color: var(--accent); }
.file-drop input { display: none; }

.empty { text-align: center; padding: 40px 16px; color: var(--muted); }

/* loader */
.loader { position: fixed; inset: 0; z-index: 50; background: rgba(15, 20, 35, .35); display: grid; place-content: center; justify-items: center; gap: 12px; color: #fff; font-weight: 600; }
.spinner { width: 46px; height: 46px; border-radius: 50%; border: 4px solid rgba(255, 255, 255, .3); border-top-color: #fff; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 700px) {
  .topbar { padding: 10px 16px; }
  main { padding: 12px 16px 32px; }
  .status { margin: 12px 16px 0; }
  .kpi .value { font-size: 20px; }
}

@media print {
  .topbar, .filters, .chips, .pager, .stmt-tools, .back, #status, .no-print { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; break-inside: avoid; }
}

/* ------------------------------------------------------------------ *
 * shared pieces used by the phone layout
 * ------------------------------------------------------------------ */
.tabs .short { display: none; }
.tabs svg { display: none; width: 22px; height: 22px; fill: currentColor; }
.mobile-only { display: none !important; }
.search-row { display: flex; gap: 8px; flex: 1 1 260px; }
.search-row input { flex: 1; }
.filter-fields { display: contents; }
.dot { display: inline-grid; place-items: center; min-width: 18px; height: 18px; border-radius: 9px; background: var(--accent); color: #fff; font-size: 11px; padding: 0 5px; margin-inline-start: 4px; }
.dot[hidden] { display: none; }

.cards { display: flex; flex-direction: column; gap: 10px; }
.m-card { display: block; color: inherit; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.m-card:active { background: var(--surface-2); }
.m-top { display: flex; gap: 10px; align-items: flex-start; justify-content: space-between; }
.m-title { min-width: 0; display: flex; flex-direction: column; }
.m-title b { font-size: 15px; line-height: 1.4; }
.m-title .muted { font-size: 12px; }
.m-top .badge { flex: none; }
.m-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--border); }
.m-stats span { display: block; color: var(--muted); font-size: 11px; }
.m-stats b { font-size: 14px; }
.m-foot { display: flex; justify-content: space-between; gap: 10px; margin-top: 8px; font-size: 12px; }
.m-foot > span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-foot > span:last-child { flex: none; }

.stmt-cards { display: flex; flex-direction: column; }
.stmt-sum { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.stmt-sum div { background: var(--surface-2); border-radius: 10px; padding: 8px 12px; }
.stmt-sum span { display: block; color: var(--muted); font-size: 12px; }
.stmt-item { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.stmt-item:last-child { border-bottom: 0; }
.si-main { display: flex; flex-direction: column; min-width: 0; }
.si-main .muted { font-size: 12px; }
.si-desc { white-space: normal; }
.si-amt { display: flex; flex-direction: column; align-items: flex-end; flex: none; text-align: left; }
.si-amt .muted { font-size: 11px; }
.si-amt b.credit { color: var(--good); }

/* ------------------------------------------------------------------ *
 * phones and small tablets
 * ------------------------------------------------------------------ */
@media (max-width: 700px) {
  body { font-size: 14px; padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  .mobile-only { display: revert !important; }
  .cards.mobile-only, .stmt-cards.mobile-only { display: flex !important; }
  .desktop-only { display: none !important; }

  /* compact header: brand + refresh only; tabs move to a bottom bar */
  .topbar { padding: 8px 16px; padding-top: calc(8px + env(safe-area-inset-top)); gap: 10px; flex-wrap: nowrap; }
  .brand { min-width: 0; }
  .brand > div { min-width: 0; }
  .brand h1 { font-size: 16px; }
  .brand p { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 11px; }
  .logo { width: 34px; height: 34px; font-size: 18px; flex: none; }
  #refreshBtn { flex: none; width: 40px; height: 40px; padding: 0; border-radius: 50%; font-size: 18px; }
  #refreshBtn .lbl { display: none; }

  .tabs {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; gap: 0; flex-wrap: nowrap;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
    box-shadow: 0 -2px 12px rgba(20, 30, 60, .06);
  }
  .tabs a { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px; font-size: 11px; border-radius: 10px; }
  .tabs a span { max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .tabs .long { display: none; }
  .tabs .short { display: inline; }
  .tabs svg { display: block; }
  .tabs a.active { background: none; }
  .tabs a.active svg { background: var(--accent-soft); border-radius: 12px; width: 48px; padding: 2px 13px; height: 26px; }

  main { padding: 12px 12px 24px; }
  .view { gap: 12px; }
  .status { margin: 10px 12px 0; }
  .card { padding: 14px; border-radius: 12px; }
  h2 { font-size: 15px; margin-bottom: 10px; }

  /* dashboard */
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kpi { min-width: 0; }
  .kpi .value { white-space: normal; overflow-wrap: anywhere; }
  .kpi:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .kpi { padding: 10px 12px; border-radius: 12px; }
  .kpi .label { font-size: 12px; }
  .kpi .value { font-size: 18px; }
  .kpi .sub { font-size: 11px; line-height: 1.4; }
  .chart-box { height: 240px; }
  .chart-box.small { height: 230px; }
  .bar-row { grid-template-columns: 78px minmax(0, 1fr) auto; gap: 8px; font-size: 13px; }
  .table th, .table td { padding: 7px 8px; font-size: 13px; }
  .rank-list li { font-size: 14px; }

  /* customer list: search + filter button; fields collapse */
  .filters { flex-direction: column; align-items: stretch; gap: 8px; }
  .search-row { flex: none; }
  .search-row input { font-size: 16px; } /* 16px stops iOS zoom-on-focus */
  .filter-fields { display: none; }
  .filters.open .filter-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .filter-fields select, .filter-fields .btn { width: 100%; font-size: 14px; }
  .filter-fields .date-range { grid-column: 1 / -1; }
  .filter-fields .date-range label { flex: 1 1 120px; }
  .filter-fields .date-range input[type=date] { flex: 1 1 auto; width: 100%; }
  .filter-fields #fSort { grid-column: 1 / -1; }
  .filter-fields #exportBtn { grid-column: 1 / -1; }
  input, select { min-height: 40px; }

  .chips { flex-wrap: nowrap; overflow-x: auto; margin: 0 -12px; padding: 0 12px 2px; scrollbar-width: none; }
  .chips::-webkit-scrollbar { display: none; }
  .chip { flex: none; padding: 6px 14px; }

  .list-card { background: none; border: 0; box-shadow: none; padding: 0; }
  .table-head { flex-direction: column; gap: 2px; margin-bottom: 10px; padding: 0 2px; }
  .pager { gap: 4px; }
  .pager button { min-width: 36px; min-height: 36px; }

  /* customer detail */
  .profile { flex-direction: column; gap: 10px; }
  .profile .title { flex: none; width: 100%; }
  .profile h2 { font-size: 18px; }
  .meta { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 12px; font-size: 13px; }
  .score { display: flex; align-items: center; gap: 12px; text-align: start; min-width: 0; width: 100%; padding: 10px 14px; }
  .score .ring { font-size: 24px; }
  .reco { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .reco b { font-size: 14px; }
  .stmt-tools select { flex: 1; }
  .meta > div, .reco > div { min-width: 0; overflow-wrap: anywhere; }
  .m-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .m-stats > div { min-width: 0; }
  .m-stats b { font-size: 13px; white-space: normal; overflow-wrap: anywhere; }
  .stmt-sum { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stmt-sum > div { min-width: 0; }
  .stmt-sum b { white-space: normal; overflow-wrap: anywhere; }
  .stmt-balance { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stmt-balance > div { min-width: 0; }
  .stmt-balance .hi { grid-column: 1 / -1; }
  .stmt-balance b { white-space: normal; overflow-wrap: anywhere; }
  .search-row input { min-width: 0; }
  .search-row .btn { flex: none; white-space: nowrap; }
  .si-amt { max-width: 50%; }
  .si-amt b { white-space: normal; overflow-wrap: anywhere; }
  .m-title b, .si-main, .rank-list .nm { overflow-wrap: anywhere; }
}

@media (max-width: 360px) {
  .kpi .value { font-size: 16px; }
  .meta, .reco { grid-template-columns: 1fr; }
}

@media print {
  .mobile-only { display: none !important; }
  .desktop-only { display: block !important; }
}

/* ------------------------------------------------------------------ *
 * screen-height tables: the table scrolls inside itself, the header
 * stays on top and the totals row stays at the bottom.
 * ------------------------------------------------------------------ */
:root { --top-h: 62px; --bottom-h: 0px; }
.fill {
  max-height: calc(100vh - var(--top-h) - var(--bottom-h) - 184px);
  max-height: calc(100dvh - var(--top-h) - var(--bottom-h) - 184px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}
.table-wrap.fill { border: 1px solid var(--border); border-radius: 10px; }
.fill .table thead th { position: sticky; top: 0; z-index: 2; box-shadow: inset 0 -1px 0 var(--border); }
.fill .table tfoot td {
  position: sticky; bottom: 0; z-index: 2;
  background: var(--accent-soft); color: var(--text);
  box-shadow: inset 0 1px 0 var(--border);
  border-bottom: 0;
}
.fill .table tbody tr:last-child td { border-bottom: 0; }

/* phone card lists: totals bar pinned to the bottom of the list */
.m-totals {
  position: sticky; bottom: 0; z-index: 2; margin-top: 2px;
  background: var(--brand); color: #fff; border-radius: 12px; padding: 8px 14px;
  box-shadow: 0 -4px 14px rgba(20, 30, 60, .12);
}
.mt-label { font-size: 12px; opacity: .85; }
.mt-items { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.mt-items span { display: block; font-size: 11px; opacity: .8; }
.mt-items b { font-size: 13px; white-space: normal; overflow-wrap: anywhere; }
.mt-items b.neg { color: #ffb4b4; }
.cards.fill { padding-bottom: 0; }

/* phone statement: debit / credit / net pinned on top while scrolling */
.stmt-cards.fill .stmt-sum {
  position: sticky; top: 0; z-index: 2; background: var(--surface);
  grid-template-columns: repeat(3, minmax(0, 1fr)); padding-bottom: 8px; margin-bottom: 0;
}

@media (max-width: 700px) {
  :root { --top-h: 57px; --bottom-h: calc(64px + env(safe-area-inset-bottom)); }
  .stmt-sum div { padding: 6px 10px; }
}

@media print {
  .fill { max-height: none !important; overflow: visible !important; border: 0; }
  .fill .table thead th, .fill .table tfoot td, .m-totals, .stmt-sum { position: static !important; }
}

/* large screens: the page (and its tables) use the full screen width */
@media (min-width: 1400px) {
  main { padding-inline: 32px; }
}

/* warehouses table: the governorates each warehouse covers */
.table td.govs { white-space: normal; min-width: 360px; line-height: 2; }
.gov-chip.more { background: var(--accent-soft); color: var(--accent); border-color: transparent; cursor: help; }
.gov-chip {
  display: inline-block; margin: 0 0 0 4px; padding: 0 8px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border); font-size: 12px; white-space: nowrap;
}
.gov-chip b { color: var(--muted); font-weight: 600; margin-inline-start: 2px; }

/* card heading with a view switch on the side */
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head h2 { margin-bottom: 0; }
.segmented { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; }
.seg { font: inherit; font-size: 13px; font-weight: 600; border: 0; background: none; color: var(--muted); padding: 5px 14px; border-radius: 8px; cursor: pointer; }
.seg:hover { color: var(--text); }
.seg.active { background: var(--surface); color: var(--accent); box-shadow: 0 1px 3px rgba(20, 30, 60, .12); }
@media (max-width: 700px) {
  .segmented { width: 100%; }
  .seg { flex: 1; padding: 6px 4px; }
}

.toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); cursor: pointer; user-select: none; }
.toggle input { width: 16px; height: 16px; min-height: 0; accent-color: var(--accent); margin: 0; }
.chart-note { margin: -6px 0 8px; }

/* linked filters: a list with a value picked stands out */
.filters select.is-set { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.clear-btn { color: var(--crit); }
@media (max-width: 700px) { .filter-fields .clear-btn { grid-column: 1 / -1; } }

/* global filter bar under the header */
.scopebar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 8px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.scopebar.active { background: var(--accent-soft); border-bottom-color: var(--accent); }
.scope-label { font-weight: 700; color: var(--navy); font-size: 14px; }
.scopebar select { flex: 0 1 200px; }
.scopebar select.is-set { border-color: var(--accent); color: var(--accent); font-weight: 600; background: var(--surface); }
.scope-info { margin-inline-start: auto; }
.scopebar #scopeClear { color: var(--crit); padding: 5px 12px; }
@media (max-width: 700px) {
  .scopebar { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; padding: 8px 12px; }
  .scopebar[hidden] { display: none; }
  .scope-label { display: none; }
  .scopebar select { min-height: 36px; font-size: 13px; padding: 4px 6px; }
  .scope-info { grid-column: 1 / -1; margin: 0; font-size: 12px; }
  .scopebar #scopeClear { grid-column: 1 / -1; order: 5; }
}
@media print { .scopebar { display: none !important; } }

/* ------------------------------------------------------------------ *
 * collections follow-up page
 * ------------------------------------------------------------------ */
.collect-filters select { flex: 0 1 260px; }
.collect-filters input[type=search] { flex: 1 1 200px; }
.msg-tpl summary { cursor: pointer; font-weight: 600; color: var(--navy); }
.msg-tpl[open] summary { margin-bottom: 10px; }
.msg-tpl textarea {
  width: 100%; font: inherit; font-size: 14px; padding: 10px; border-radius: 8px; resize: vertical;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.collect-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 12px; }
.c-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px;
  border-inline-start: 4px solid var(--border); display: flex; flex-direction: column; gap: 10px; min-width: 0;
}
.c-card.t-urgent { border-inline-start-color: var(--crit); }
.c-card.t-important { border-inline-start-color: var(--high); }
.c-card.t-follow { border-inline-start-color: var(--mid); }
.c-card.done { opacity: .6; }
.c-top { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.c-name { font-weight: 700; font-size: 15px; color: var(--text); overflow-wrap: anywhere; }
.c-name:hover { color: var(--accent); }
.c-sub { font-size: 12px; }
.tier-badge { align-self: flex-start; font-size: 12px; font-weight: 700; padding: 1px 10px; border-radius: 999px; }
.tier-badge.t-urgent { background: var(--crit-soft); color: var(--crit-ink); }
.tier-badge.t-important { background: var(--high-soft); color: var(--high-ink); }
.tier-badge.t-follow { background: var(--mid-soft); color: var(--mid-ink); }
.c-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.c-stats > div { min-width: 0; }
.c-stats span { display: block; font-size: 11px; color: var(--muted); }
.c-stats b { font-size: 14px; overflow-wrap: anywhere; }
.c-stats small { display: block; font-size: 11px; }
.aging-strip { display: flex; height: 8px; border-radius: 4px; overflow: hidden; background: var(--surface-2); }
.aging-strip i { display: block; height: 100%; }
.c-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.c-actions .btn { padding: 6px 12px; font-size: 13px; text-decoration: none; white-space: nowrap; }
.btn-sm { padding: 1px 10px; font-size: 12px; margin-inline-start: 6px; }
.btn.wa { background: var(--wa); color: #fff; }
.follow-btn { margin-inline-start: auto; }
.c-card.done .follow-btn { color: var(--good); border-color: var(--good); }
@media (max-width: 700px) {
  .collect-grid { grid-template-columns: 1fr; }
  .collect-filters { display: grid; grid-template-columns: 1fr; }
  .collect-filters select, .collect-filters input[type=search] { width: 100%; }
  .c-actions .btn { flex: 1; text-align: center; padding: 8px 6px; }
  .follow-btn { margin-inline-start: 0; }
}
@media print {
  .collect-filters, .msg-tpl, .c-actions { display: none !important; }
  .collect-grid { grid-template-columns: 1fr 1fr; }
  .c-card { break-inside: avoid; opacity: 1 !important; }
}

/* ------------------------------------------------------------------ *
 * send statements to reps
 * ------------------------------------------------------------------ */
.send-intro p { margin: 0 0 12px; font-size: 13px; line-height: 1.8; }
.send-filters { padding: 0; border: 0; box-shadow: none; }
.send-filters select { flex: 0 1 300px; }
.send-list { display: flex; flex-direction: column; gap: 12px; }
.s-card { display: flex; flex-direction: column; gap: 12px; border-inline-start: 4px solid var(--accent); }
.s-card.sent { border-inline-start-color: var(--good); }
.s-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: flex-start; }
.s-title { display: flex; flex-direction: column; min-width: 0; }
.s-title b { font-size: 16px; overflow-wrap: anywhere; }
.s-title .muted { font-size: 12px; }
.s-nums { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.s-nums > span:not(.tier-badge) { display: flex; flex-direction: column; align-items: center; line-height: 1.2; }
.s-nums b { font-size: 17px; }
.s-nums small { font-size: 11px; color: var(--muted); }
.s-nums .chk b { color: var(--high-ink); }
.s-phone { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.s-phone label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); font-weight: 600; }
.s-phone input { width: 190px; font-size: 15px; letter-spacing: .5px; }
.s-phone input.bad { border-color: var(--crit); background: var(--crit-soft); }
.s-from { font-size: 12px; padding-bottom: 8px; }
.s-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.s-actions .btn { text-decoration: none; white-space: nowrap; }
.s-sent { font-size: 12px; margin-inline-start: auto; color: var(--good); }
.s-preview { border-top: 1px dashed var(--border); padding-top: 10px; }
.s-table tr.row-urgent td:first-child { box-shadow: inset -4px 0 0 #d23c3c; }
.s-table tr.row-important td:first-child { box-shadow: inset -4px 0 0 #e07b17; }
.s-table tr.row-follow td:first-child { box-shadow: inset -4px 0 0 #c99a06; }
.s-table small { font-size: 11px; }
.desktop-tab { }
@media (max-width: 700px) {
  .desktop-tab { display: none !important; }
  .send-filters { display: grid; grid-template-columns: 1fr; }
  .s-phone input { width: 100%; }
  .s-phone label { flex: 1; }
  .s-actions .btn { flex: 1 1 45%; text-align: center; }
  .s-sent { margin: 0; flex-basis: 100%; }
}

/* "منتظم": has a balance, nothing overdue */
.tier-badge.t-ok { background: var(--good-soft); color: var(--good-ink); }
.s-table tr.row-ok td:first-child { box-shadow: inset -4px 0 0 #1e9e63; }

/* ------------------------------------------------------------------ *
 * dashboard: clickable aging rows and their details
 * ------------------------------------------------------------------ */
button.aging-row {
  font: inherit; color: inherit; text-align: inherit; width: calc(100% + 12px);
  background: none; border: 0; border-radius: 8px; padding: 4px 6px; margin: -4px -6px; cursor: pointer;
}
button.aging-row:hover { background: var(--surface-2); }
button.aging-row.selected { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
button.aging-row:focus-visible { outline: 2px solid var(--accent); }
.aging-detail {
  margin-top: 14px; padding: 14px; border-radius: 12px; background: var(--surface-2);
  border: 1px solid var(--border); border-top: 4px solid var(--age-color, var(--accent));
}
.ad-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 10px; }
.ad-head b { display: block; font-size: 16px; color: var(--text); }
.ad-head .muted { font-size: 13px; }
.ad-close { font: inherit; border: 0; background: var(--surface); color: var(--muted); width: 30px; height: 30px; border-radius: 50%; cursor: pointer; flex: none; }
.ad-close:hover { color: var(--crit); }
.ad-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.ad-grid h3 { font-size: 13px; color: var(--muted); margin: 0 0 6px; font-weight: 600; }
.ad-branches { display: flex; flex-direction: column; gap: 6px; }
.ad-branch { display: grid; grid-template-columns: minmax(0, 110px) minmax(0, 1fr) auto; gap: 8px; align-items: center; color: var(--text); font-size: 13px; padding: 2px 4px; border-radius: 6px; }
.ad-branch:hover { background: var(--surface); }
.ad-bname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ad-branch .bar-track { height: 10px; display: block; }
.ad-branch .bar-fill { display: block; }
.aging-detail .rank-list li { padding: 5px 0; font-size: 13px; }
.aging-detail .rank-list .nm { display: flex; flex-direction: column; line-height: 1.3; }
.ad-rep { font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ad-all { display: inline-block; margin-top: 12px; text-decoration: none; }
.age-chip { background: var(--crit) !important; border-color: var(--crit) !important; }
td.age-col { font-weight: 700; color: var(--crit); }
@media (max-width: 700px) {
  .ad-grid { grid-template-columns: 1fr; }
  .ad-all { display: block; text-align: center; }
}

/* ------------------------------------------------------------------ *
 * dashboard: details of the clicked month
 * ------------------------------------------------------------------ */
.month-detail { border-top: 4px solid var(--accent); }
.month-detail .ad-head b { color: var(--accent); font-size: 17px; }
.md-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin-bottom: 12px; }
.md-tile { background: var(--surface-2); border-radius: 10px; padding: 8px 12px; border-inline-start: 4px solid var(--border); min-width: 0; }
.md-tile span { display: block; font-size: 12px; color: var(--muted); }
.md-tile b { font-size: 18px; }
.md-tile.c-sales { border-inline-start-color: #2f6fde; }
.md-tile.c-ret { border-inline-start-color: #e07b17; }
.md-tile.c-coll { border-inline-start-color: #1e9e63; }
.md-tile.c-bad { border-inline-start-color: var(--crit); }
.md-tile.c-bad b { color: var(--crit); }
.delta { display: block; font-size: 11px; font-weight: 600; }
.delta.up { color: var(--good); }
.delta.down { color: var(--crit); }
.month-detail .alert { margin-bottom: 12px; }
.md-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.md-grid h3 { font-size: 13px; color: var(--muted); margin: 0 0 6px; font-weight: 600; }
.md-table td.name { position: relative; min-width: 120px; }
.md-bar { position: absolute; inset-block: 6px; right: 0; background: #2f6fde22; border-radius: 4px; z-index: 0; }
.md-bname { position: relative; }
.month-detail .rank-list li { padding: 5px 0; font-size: 13px; }
.month-detail .rank-list .nm { display: flex; flex-direction: column; line-height: 1.3; }
@media (max-width: 700px) { .md-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.data-warn { line-height: 1.8; }

/* dashboard: clickable risk categories */
.risk-table tbody tr[data-risk] { cursor: pointer; }
.risk-table tbody tr.selected { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.risk-table tbody tr[data-risk]:focus-visible { outline: 2px solid var(--accent); }
.risk-hint { margin: 6px 0 0; font-size: 12px; }
.risk-detail { border-top-color: var(--age-color, var(--accent)); }
.risk-detail .ad-head b { color: var(--text); }
.risk-reason { border-inline-start-color: var(--age-color, var(--border)); }
.risk-reason small { display: block; font-size: 11px; }
.risk-detail .rank-list li .badge { flex: none; }
/* risk details: a full row under risk + groups; on one-column screens, right under the risk card */
.grid.three > .risk-detail { grid-column: 1 / -1; }
@media (max-width: 1000px) {
  .grid.three > .risk-detail { order: 1; }
  .grid.three > .span2 { order: 2; }
}
/* month details: full row under the two charts; on one-column screens, right under the monthly chart */
.grid.two > .month-detail { grid-column: 1 / -1; }
@media (max-width: 1000px) {
  .grid.two > .month-detail { order: 1; }
  .grid.two > .aging-card { order: 2; }
}

/* ------------------------------------------------------------------ *
 * dashboard: clickable group / warehouse rows and their details
 * ------------------------------------------------------------------ */
#groupsTable tbody tr[data-group], #whTable tbody tr[data-whkey] { cursor: pointer; }
.table tbody tr.selected { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.table tbody tr[role=button]:focus-visible { outline: 2px solid var(--accent); }
.grid.three > .set-detail { grid-column: 1 / -1; }
@media (max-width: 1000px) { .grid.three > .set-detail { order: 3; } }
.sd-aging { margin-bottom: 14px; }
.aging-strip.big { height: 14px; border-radius: 7px; }
.sd-aging-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 6px; font-size: 12px; color: var(--muted); }
.sd-aging-legend i { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-inline-end: 4px; }
.sd-aging-legend b { color: var(--text); font-weight: 600; }
.sd-row .num small { display: block; font-size: 11px; text-align: left; }
.sd-chart .chart-box.small { height: 210px; }
.md-tile small { display: block; font-size: 11px; line-height: 1.4; }

/* collections page: summary tiles act as filters */
button.ckpi { font: inherit; color: inherit; text-align: start; cursor: pointer; width: 100%; border-inline-start: 4px solid var(--border); }
button.ckpi:hover { border-color: var(--accent); }
button.ckpi.t-urgent { border-inline-start-color: var(--crit); }
button.ckpi.t-important { border-inline-start-color: var(--high); }
button.ckpi.t-follow { border-inline-start-color: var(--mid); }
button.ckpi.t-done { border-inline-start-color: var(--good); }
button.ckpi.on { background: var(--accent-soft); border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
button.ckpi:focus-visible { outline: 2px solid var(--accent); }
.ckpis { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.c-shown { margin: -4px 2px 0; font-size: 13px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.c-shown .chip { padding: 2px 12px; }
@media (max-width: 700px) { .ckpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* ------------------------------------------------------------------ *
 * preview before sending
 * ------------------------------------------------------------------ */
body.modal-open { overflow: hidden; }
.modal {
  position: fixed; inset: 0; z-index: 60; background: rgba(15, 20, 35, .55);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal[hidden] { display: none; }
.modal-box {
  background: var(--surface); color: var(--text); border-radius: 14px; width: min(980px, 100%);
  max-height: calc(100dvh - 40px); display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-head b { display: block; font-size: 17px; color: var(--navy); }
.modal-head .muted { font-size: 12px; }
.modal-body { flex: 1; overflow: auto; padding: 16px; background: var(--surface-2); display: flex; flex-direction: column; gap: 14px; align-items: center; }
.pv-page { margin: 0; width: 100%; max-width: 880px; }
.pv-page img { width: 100%; height: auto; display: block; border-radius: 6px; box-shadow: 0 2px 10px rgba(20, 30, 60, .15); background: #fff; }
.pv-page figcaption { text-align: center; font-size: 12px; margin-top: 4px; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 10px; }
.pv-fields { display: grid; grid-template-columns: 220px 1fr; gap: 10px; }
.pv-fields label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; font-weight: 600; color: var(--muted); }
.pv-fields input { font-size: 15px; }
.pv-fields input.bad { border-color: var(--crit); background: var(--crit-soft); }
.pv-fields textarea { font: inherit; font-size: 14px; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); resize: vertical; }
.pv-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.pv-actions .btn { white-space: nowrap; }
@media (max-width: 700px) {
  .modal { padding: 0; align-items: stretch; }
  .modal-box { max-height: 100dvh; height: 100dvh; border-radius: 0; }
  .modal-body { padding: 10px; }
  .pv-fields { grid-template-columns: 1fr; }
  .pv-actions .btn { flex: 1; }
}
@media print { .modal { display: none !important; } }

/* collections: "show more" */
.c-more { grid-column: 1 / -1; justify-self: center; padding: 10px 24px; }

/* ------------------------------------------------------------------ *
 * Due report
 * ------------------------------------------------------------------ */
.due-ref { font-size: 12px; }
#dueSummary .ckpi.t-done { border-inline-start-color: #2f6fde; }
.due-reps tbody tr[data-drep] { cursor: pointer; }
.due-list { display: flex; flex-direction: column; gap: 8px; }
.due-row { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.due-row.open { border-color: var(--accent); }
.due-head {
  font: inherit; color: inherit; text-align: start; width: 100%; background: none; border: 0; cursor: pointer;
  display: grid; grid-template-columns: minmax(0, 2.2fr) repeat(5, minmax(0, 1fr)); gap: 10px; align-items: center; padding: 10px 14px;
}
.due-head:hover { background: var(--surface-2); }
.dh-name { display: flex; flex-direction: column; min-width: 0; }
.dh-name b { overflow-wrap: anywhere; }
.dh-name small { font-size: 12px; }
.dh-cell { display: flex; flex-direction: column; min-width: 0; }
.dh-cell small { font-size: 11px; color: var(--muted); }
.dh-cell b { font-size: 14px; overflow-wrap: anywhere; }
.due-items { padding: 0 14px 12px; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.due-items .table-wrap { width: 100%; }
.due-st { font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 999px; white-space: nowrap; }
.due-st.late { background: var(--crit-soft); color: var(--crit-ink); }
.due-st.soon { background: var(--high-soft); color: var(--high-ink); }
.due-st.later { background: var(--good-soft); color: var(--good-ink); }
.due-st.credit { background: var(--none-soft); color: var(--none-ink); }
.due-table tr.ds-late td:first-child { box-shadow: inset -3px 0 0 var(--crit); }
.due-table tr.ds-soon td:first-child { box-shadow: inset -3px 0 0 var(--high); }
.due-table tr.ds-later td:first-child { box-shadow: inset -3px 0 0 var(--good); }
@media (max-width: 700px) {
  .due-head { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dh-name { grid-column: 1 / -1; }
}
.due-fill { max-height: min(60vh, 520px); }

/* ------------------------------------------------------------------ *
 * Due vs transactions comparison
 * ------------------------------------------------------------------ */
.due-views { margin-bottom: 0; }
.view-part { display: flex; flex-direction: column; gap: 16px; }
.view-part[hidden] { display: none; }
.cmp-grid { display: grid; grid-template-columns: auto repeat(3, minmax(0, 1fr)); gap: 8px 16px; align-items: baseline; }
.cmp-head { font-size: 12px; color: var(--muted); font-weight: 600; }
.cmp-label { font-weight: 600; }
.cmp-grid b { font-size: 18px; }
.cmp-note { margin: 10px 0 0; font-size: 12px; line-height: 1.8; }
.cmp-tile .value small { font-size: 12px; color: var(--muted); font-weight: 400; }
.cmp-tile .sub b { color: var(--text); }
.cmp-tile.r-bal { border-inline-start-color: var(--crit); }
.cmp-tile.r-cred { border-inline-start-color: var(--high); }
.cmp-tile.r-dates { border-inline-start-color: var(--accent); }
.cmp-tile.r-only { border-inline-start-color: var(--none); }
.cmp-tile.r-ok { border-inline-start-color: var(--good); }
.cmp-badge { font-size: 12px; font-weight: 600; padding: 1px 9px; border-radius: 999px; white-space: nowrap; }
.cmp-badge.r-ok { background: var(--good-soft); color: var(--good-ink); }
.cmp-badge.r-bal { background: var(--crit-soft); color: var(--crit-ink); }
.cmp-badge.r-cred { background: var(--high-soft); color: var(--high-ink); }
.cmp-badge.r-dates { background: var(--accent-soft); color: var(--accent); }
.cmp-badge.r-only { background: var(--none-soft); color: var(--none-ink); }
.cmp-table tbody tr[data-copen] { cursor: pointer; }
.cmp-acc { display: block; font-size: 11px; font-weight: 400; }
td.pos { color: var(--good-ink); }
tr.cmp-detail > td { background: var(--surface-2); white-space: normal; padding: 12px; }
.cmp-explain { font-size: 14px; line-height: 1.8; margin-bottom: 10px; }
.cmp-aging { font-size: 13px; background: var(--surface); }
.cmp-aging tr.cmp-diffrow td { font-weight: 700; border-top: 2px solid var(--border); }
tr.cmp-detail .btn { margin-top: 10px; display: inline-block; text-decoration: none; }
@media (max-width: 700px) {
  .cmp-grid { grid-template-columns: auto repeat(3, minmax(0, 1fr)); gap: 6px 8px; }
  .cmp-grid b { font-size: 13px; }
}

/* ------------------------------------------------------------------ *
 * login
 * ------------------------------------------------------------------ */
body.locked > .shell, body.locked > .sidebar, body.locked > .nav-backdrop { display: none !important; }
.login { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; padding: 20px; background: var(--bg); }
.login[hidden] { display: none; }
.login-box {
  width: min(380px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 28px 24px;
  display: flex; flex-direction: column; gap: 12px; box-shadow: 0 10px 40px rgba(20, 30, 60, .12);
}
.login-box .logo { align-self: center; width: 52px; height: 52px; font-size: 26px; border-radius: 14px; }
.login-box h1 { text-align: center; color: var(--navy); font-size: 20px; }
.login-box > p.muted { text-align: center; margin: -6px 0 6px; }
.login-box label:not(.toggle) { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 13px; }
.login-box input:not([type=checkbox]) { font-size: 16px; padding: 10px 12px; }
.login-box .btn { padding: 11px; font-size: 16px; margin-top: 4px; }
.login-err { margin: 0; color: var(--crit-ink); background: var(--crit-soft); border-radius: 8px; padding: 8px 12px; font-size: 14px; }
.user-chip { font-size: 12px; color: var(--muted); background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 3px 10px; white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.logout-btn { padding: 6px 12px; }
body.scoped-user #tabs a[data-view=settings], body.no-settings #tabs a[data-view=settings] { display: none !important; }
.scopebar.locked select, .scopebar.locked .scope-label { display: none; }
.scopebar.locked { background: var(--accent-soft); }
.scopebar.locked .scope-info { margin: 0; font-weight: 600; color: var(--navy); font-size: 13px; }
@media (max-width: 700px) {
  .user-chip { display: none; }
  .logout-btn { width: 40px; height: 40px; padding: 0; border-radius: 50%; flex: none; }
  .logout-btn .lbl { display: none; }
  .scopebar.locked { display: block; }
}

/* ------------------------------------------------------------------ *
 * users screen (admin)
 * ------------------------------------------------------------------ */
.admin-tab { display: none !important; }
body.role-admin .admin-tab { display: flex !important; }
@media (max-width: 700px) { body.role-admin .admin-tab { display: none !important; } }
#usersBody { display: flex; flex-direction: column; gap: 16px; }
.u-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.u-card { display: flex; flex-direction: column; gap: 8px; border-inline-start: 4px solid var(--accent); }
.u-card.empty-wh { border-inline-start-color: var(--high); }
.u-general { border-inline-start-color: var(--brand); }
.u-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px; }
.u-head b { font-size: 15px; }
.u-head small { flex-basis: 100%; }
.u-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.u-item { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; background: var(--surface-2); }
.u-main { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; min-width: 0; }
.u-main small { flex-basis: 100%; }
.u-actions { display: flex; gap: 4px; flex: none; }
.u-actions .btn { padding: 4px 8px; }
.btn.danger { color: var(--crit-ink); }
.role { font-size: 11px; font-weight: 700; padding: 0 8px; border-radius: 999px; }
.role.role-admin { background: var(--crit-soft); color: var(--crit-ink); }
.role.role-viewer { background: var(--accent-soft); color: var(--accent); }
.role.role-stopped { background: var(--surface); color: var(--muted); }
.settings label.toggle { flex-direction: row; flex: none; font-weight: 400; }
.u-item.stopped .u-main b { text-decoration: line-through; color: var(--muted); }
.u-add { align-self: flex-start; }
.u-save p { margin: 0 0 10px; }
.u-save .msg { margin-top: 10px; padding: 8px 12px; border-radius: 8px; background: var(--surface-2); }
/* until the login check is done, show nothing */
body.booting > .shell, body.booting > .sidebar { visibility: hidden; }

/* customers: share the filtered list as PDF */
.table-head { align-items: center; }
.list-pdf { padding: 6px 14px; font-size: 13px; white-space: nowrap; }
@media (max-width: 700px) { .list-pdf { width: 100%; margin-top: 6px; } }

/* guarantee note */
.g-note { padding: 10px 14px; border-radius: 10px; font-size: 14px; line-height: 1.7; }
.g-note.g-covered { background: var(--good-soft); color: var(--good-ink); }
.g-note.g-over { background: var(--high-soft); color: var(--high-ink); }
.g-note.g-overdue { background: var(--crit-soft); color: var(--crit-ink); }
.g-note.g-none { background: var(--mid-soft); color: var(--mid-ink); }
.c-guar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 12px; }

/* legal affairs: a customer referred to the legal department */
.legal-badge { background: var(--legal-soft); color: var(--legal-ink); white-space: nowrap; max-width: 22ch; overflow: hidden; text-overflow: ellipsis; vertical-align: middle; }
.legal-note { padding: 10px 14px; border-radius: 10px; font-size: 14px; line-height: 1.7; background: var(--legal-soft); color: var(--legal-ink); border-right: 4px solid var(--legal); }
.legal-note a { color: inherit; text-decoration: underline; }
.dh-name .legal-badge, .c-name + .legal-badge { margin-inline-start: 6px; font-size: 11px; }

/* notes on the customer base (admin) */
.notes-table td { white-space: nowrap; }
.notes-table td:nth-child(4), .notes-table td:last-child { white-space: normal; min-width: 160px; }
#notesHint { margin: 4px 0 10px; }
#notesMore { margin-top: 10px; }

/* checks report */
.checks-tab { display: none !important; }
body.has-checks .checks-tab { display: flex !important; }

/* legal-affairs cases */
.cases-tab { display: none !important; }
body.has-cases .cases-tab { display: flex !important; }
.cases-tabs { margin-bottom: 12px; }
.cases-kpis { margin-bottom: 12px; }
.case-table td.name { white-space: normal; min-width: 160px; }
.case-table td.wrap { white-space: normal; min-width: 180px; }
#casesMore { margin-top: 10px; }
.q-table td.wrap { white-space: normal; min-width: 200px; }
.chk-table td.name { min-width: 180px; }
.chk-cust td.wrap { min-width: 160px; }
.chk-kpis { margin-bottom: 12px; }
.badge.r-none { background: var(--surface-2); color: var(--text); }
#chkMore { margin-top: 10px; }

/* customer checks filters */
.cc-filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.cc-fields { display: flex; gap: 8px; flex-wrap: wrap; }
.cc-fields select { flex: 0 1 160px; }
.cc-fields input { flex: 0 1 220px; }
.chk-kpis .kpi.active { outline: 2px solid var(--accent); outline-offset: -2px; }

/* ------------------------------------------------------------------ *
 * responsive dashboard layout
 *   >=1024px : fixed sidebar on the right
 *   700-1023 : sidebar becomes an off-canvas drawer
 *   <700px   : sidebar hidden, navigation moves to the bottom bar
 * ------------------------------------------------------------------ */
@media (min-width: 1024px) {
  body { display: grid; grid-template-columns: 268px minmax(0, 1fr); align-items: start; }
  .sidebar { grid-column: 1; position: sticky; top: 0; height: 100vh; transform: none; box-shadow: none; }
  .shell { grid-column: 2; }
  :root.side-hidden body { grid-template-columns: minmax(0, 1fr); }
  :root.side-hidden .sidebar { display: none; }
  :root.side-hidden .shell { grid-column: 1; }
  :root.side-hidden .topbar .top-logo { display: grid; }
  #themeBtn { display: none; }
  .nav-backdrop { display: none !important; }
}
@media (min-width: 700px) and (max-width: 1023.98px) {
  .topbar .top-logo { display: grid; }
}
@media (max-width: 699.98px) {
  .sidebar { display: contents; }
  .side-brand, .side-foot { display: none; }
  .nav-toggle { display: none; }
  .nav-backdrop { display: none !important; }
  .topbar .top-logo { display: grid; }
  body { padding-bottom: calc(70px + env(safe-area-inset-bottom)); }
  body.nav-open { overflow: hidden; }
  /* the rail turns back into the phone bottom bar */
  .tabs { position: fixed; inset-inline: 0; bottom: 0; z-index: 30; flex-direction: row; flex-wrap: nowrap;
    gap: 0; padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); overflow: visible;
    background: var(--surface); border-top: 1px solid var(--border); border-inline-end: 0;
    box-shadow: 0 -8px 24px -18px rgba(8, 14, 26, .45); }
  .tabs a { flex: 1 1 0; min-width: 0; flex-direction: column; gap: 2px; padding: 6px 2px; font-size: 11px; border-radius: 10px; }
  .tabs a.active::before { display: none; }
  .tabs a.active { background: none; }
  .tabs svg { width: 22px; height: 22px; }
  .tabs .short { display: inline; }
  .tabs .long { display: none; }
  .page-head p { display: none; }
  /* the filter row becomes a column here: a row flex-basis would turn into height */
  .filters input[type=search], .filters select,
  .collect-filters input[type=search], .collect-filters select,
  .send-filters input[type=search], .send-filters select,
  .stmt-tools input[type=search], .stmt-tools select { flex: 0 0 auto; width: 100%; }
}

/* ------------------------------------------------------------------ *
 * finishing touches
 * ------------------------------------------------------------------ */
input, select, textarea { transition: border-color .15s, box-shadow .15s, background .15s; }
input:hover, select:hover { border-color: var(--border-strong); }
input[type=search] { background: var(--surface); }

.filters { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow-sm); }
.chip { border-radius: 999px; background: var(--surface); box-shadow: var(--shadow-sm); transition: color .15s, border-color .15s, background .15s; }
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.active { background: linear-gradient(180deg, var(--accent), var(--accent-2)); border-color: transparent; color: #fff; box-shadow: 0 2px 8px -2px rgba(37, 99, 235, .5); }
.pager button { border-radius: 9px; background: var(--surface); }
.pager button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.pager button.active { background: linear-gradient(180deg, var(--accent), var(--accent-2)); border-color: transparent; color: #fff; }

.status { border-radius: 12px; box-shadow: var(--shadow-sm); margin: 12px 22px 0; }
.data-warn { margin-top: 8px; }

.segmented { background: var(--surface-2); border-radius: 11px; }
.segmented button { border-radius: 8px; }

.table-copy { border-radius: 8px; box-shadow: var(--shadow-sm); background: var(--surface); }

/* thin, theme-aware scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); background-clip: content-box; }

::selection { background: var(--accent-soft); color: var(--text); }

/* login screen */
.login { background: var(--bg); background-image: var(--bg-grad); }
.login-box { border-radius: 20px; box-shadow: var(--shadow-lg); border-color: var(--border); }
.login-box h1 { color: var(--text); }
.login-box .logo { background: linear-gradient(180deg, var(--accent), var(--accent-2)); box-shadow: 0 8px 20px -8px rgba(37, 99, 235, .7); }

/* charts and empty states read better on the new surfaces */
.chart-box { padding: 2px; }
.empty { border: 1px dashed var(--border); border-radius: var(--radius); background: var(--surface-2); }

/* keep the drawer above the phone bottom bar */
@media (max-width: 1023.98px) {
  .sidebar { box-shadow: var(--shadow-lg); }
}
@media print {
  .sidebar, .nav-backdrop, .top-actions { display: none !important; }
  body { display: block; background: #fff; }
}

/* ------------------------------------------------------------------ *
 * rep performance analysis (reps.js)
 * ------------------------------------------------------------------ */
.perf-note { margin: 2px 0 0; }
.perf-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; margin-bottom: 14px; }
.perf-stat {
  display: flex; flex-direction: column; gap: 2px; min-width: 0;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px;
}
.perf-stat .lbl { font-size: 12px; color: var(--muted); font-weight: 600; }
.perf-stat .val { font-size: 19px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.perf-stat .sub { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.perf-stat.hi .val { color: var(--accent); }

.perf-table { font-size: 12.5px; }
.perf-table th, .perf-table td { padding: 8px 7px; }
.perf-table th.sorted { color: var(--accent); }
.perf-table td.name { min-width: 132px; }
.perf-name { display: block; max-width: 175px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.perf-table .perf-delta { font-weight: 700; }
.perf-table .perf-delta.up, .perf-cmp .perf-delta.up { color: var(--good-ink); }
.perf-table .perf-delta.down, .perf-cmp .perf-delta.down { color: var(--crit-ink); }
.perf-table .perf-delta.same, .perf-cmp .perf-delta.same { color: var(--muted); }
.perf-empty { text-align: center; color: var(--muted); padding: 18px; }

.perf-badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; white-space: nowrap; }
.perf-badge.g-excellent { background: var(--good-soft); color: var(--good-ink); }
.perf-badge.g-good { background: var(--accent-soft); color: var(--accent-ink); }
.perf-badge.g-ok { background: var(--mid-soft); color: var(--mid-ink); }
.perf-badge.g-weak { background: var(--high-soft); color: var(--high-ink); }
.perf-badge.g-bad { background: var(--crit-soft); color: var(--crit-ink); }
.perf-legend { margin: 10px 0 0; font-size: 12px; }

.perf-card { display: flex; flex-direction: column; gap: 6px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); }
.perf-card + .perf-card { margin-top: 8px; }
.perf-card-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.perf-card-top b { font-size: 14.5px; }
.perf-card-sub { font-size: 12px; }
.perf-cmp { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.perf-cmp > div { background: var(--surface-2); border-radius: 9px; padding: 7px 9px; display: flex; flex-direction: column; gap: 1px; }
.perf-cmp .lbl { font-size: 11px; color: var(--muted); }
.perf-cmp b { font-size: 13px; }
.perf-cmp .perf-delta { font-size: 12px; font-weight: 700; }

@media (max-width: 699.98px) {
  .perf-stats { grid-template-columns: 1fr 1fr; }
  .perf-stat .val { font-size: 16px; }
  .perf-stat .sub { font-size: 11px; }
}

/* ------------------------------------------------------------------ *
 * installable app (pwa.js)
 * ------------------------------------------------------------------ */
.install-top { display: none; }
@media (max-width: 1023.98px) { .install-top { display: inline-grid; } }
.install-btn { margin-bottom: 8px; }

.pwa-modal {
  position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; padding: 18px;
  background: rgba(8, 14, 26, .55);
}
.pwa-modal-card {
  width: min(430px, 100%); background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 16px; padding: 20px;
  box-shadow: 0 24px 60px -24px rgba(8, 14, 26, .55);
}
.pwa-modal-card h3 { margin: 0 0 10px; font-size: 17px; }
.pwa-steps { margin: 0 0 16px; padding-inline-start: 20px; display: flex; flex-direction: column; gap: 8px; font-size: 14px; line-height: 1.7; }
.pwa-modal-card .btn { width: 100%; }

.pwa-toast {
  position: fixed; inset-inline: 0; bottom: calc(24px + env(safe-area-inset-bottom)); margin: 0 auto;
  width: fit-content; max-width: calc(100vw - 32px); z-index: 210;
  background: #14315e; color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 13px; font-weight: 600; box-shadow: 0 12px 30px -12px rgba(0, 0, 0, .5);
  opacity: 0; transform: translateY(10px); pointer-events: none; transition: opacity .2s, transform .2s;
}
.pwa-toast.is-on { opacity: 1; transform: none; }
@media (max-width: 699.98px) { .pwa-toast { bottom: calc(84px + env(safe-area-inset-bottom)); } }

/* unified names: one customer under several accounts */
.u-acc { margin-top: 8px; border-top: 1px dashed var(--border); padding-top: 6px; }
.u-acc summary { cursor: pointer; font-size: 12px; color: var(--accent); font-weight: 600; }
.u-acc ul { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 4px; }
.u-acc li { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; font-size: 12px; }
.u-acc li a { color: inherit; text-decoration: none; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.u-acc li a:hover { color: var(--accent); }
.u-acc li .num { flex: none; }

/* targets page: sub menu, one group at a time, short scrollable tables */
.tg-filters { align-items: flex-end; }
.tg-groups { display: flex; gap: 6px; flex-wrap: wrap; flex: 1 1 100%; }
.tg-group-btn {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--muted);
  border-radius: 999px; padding: 5px 12px; font-size: 12px; font-weight: 600; cursor: pointer;
}
.tg-group-btn:hover { color: var(--accent); border-color: var(--accent); }
.tg-group-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.tg-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 12px 0; }
.tg-tab, .tg-branch-btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--muted);
  border-radius: 999px; padding: 7px 15px; font-size: 13px; font-weight: 700; cursor: pointer;
}
.tg-tab:hover, .tg-branch-btn:hover { color: var(--accent); border-color: var(--accent); }
.tg-tab.active, .tg-branch-btn.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.tg-tab:focus-visible, .tg-branch-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tg-panel[hidden] { display: none; }
.tg-branches { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.tg-count { opacity: .75; margin-inline-start: 4px; font-size: 11px; }

.tg-scroll {
  max-height: 340px; overflow: auto; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--surface);
}
.tg-scroll .table { min-width: 720px; border-collapse: separate; border-spacing: 0; }
.tg-scroll th { z-index: 2; }
.tg-scroll tfoot td {
  position: sticky; bottom: 0; z-index: 2; background: var(--surface-2);
  border-top: 1px solid var(--border);
}
.tg-rep-branch + .tg-rep-branch { border-top: 1px solid var(--border); margin-top: 12px; padding-top: 12px; }
.tg-branch-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.tg-branch-head h3 { margin: 0; font-size: 15px; }

.tg-num { direction: ltr; unicode-bidi: isolate; }
.tg-pct { font-weight: 700; }
.tg-good { color: #1e9e63; }
.tg-low { color: #d23c3c; }
.tg-empty { text-align: center; color: var(--muted); padding: 14px; }
@media (max-width: 699.98px) {
  .tg-filters select, .tg-filters input[type=search] { flex: 1 1 100%; }
  .tg-scroll { max-height: 300px; }
  .tg-tabs, .tg-branches { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; }
  .tg-tab, .tg-branch-btn { flex: 0 0 auto; }
}
