/* ==========================================================================
   Echoes Intranet – design system
   ========================================================================== */
:root {
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --line: #e7ebee;
  --line-strong: #d6dde2;
  --ink: #0f1a1f;
  --ink-2: #3c4a52;
  --muted: #6b7a83;
  --faint: #9aa7af;

  --brand: #119470;
  --brand-600: #0d7f60;
  --brand-50: #e7f6f0;
  --dark: #111b20;

  --b1: #11946f;  --b1-bg: #e4f5ee;   /* 1–30  */
  --b2: #1574b5;  --b2-bg: #e3f0fa;   /* 31–60 */
  --b3: #c46a0a;  --b3-bg: #fdf0dc;   /* 61–90 */
  --b4: #d0213f;  --b4-bg: #fde6ea;   /* 91+   */

  --danger: #d0213f;
  --danger-bg: #fde8eb;
  --warn-bg: #fff4e0;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(15, 26, 31, .04);
  --shadow: 0 1px 2px rgba(15, 26, 31, .04), 0 4px 16px rgba(15, 26, 31, .05);
  --shadow-lg: 0 12px 40px rgba(15, 26, 31, .16);
  --sidebar-w: 248px;
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.icon { width: 18px; height: 18px; flex: none; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ------------------------------------------------------------------ Shell */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w);
  background: var(--dark); color: #c9d4d9;
  display: flex; flex-direction: column; padding: 18px 14px; z-index: 40;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 22px; color: #fff; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center;
  background: linear-gradient(135deg, #19b386, #0b7a5b); font-weight: 700; font-size: 18px; color: #fff;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.15);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 16px; letter-spacing: -.01em; }
.brand-text small { color: #7f9099; font-size: 12px; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #66777f; padding: 14px 10px 6px; font-weight: 600; }
.nav-link {
  display: flex; align-items: center; gap: 11px; padding: 9px 10px; border-radius: 9px;
  font-weight: 500; color: #b9c6cc; transition: background .15s, color .15s;
}
.nav-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-link.active { background: rgba(25,179,134,.16); color: #fff; }
.nav-link.active .icon { color: #3fd4a5; }
.sidebar-foot { display: flex; align-items: center; gap: 6px; border-top: 1px solid rgba(255,255,255,.08); padding-top: 14px; }
.sidebar-foot form { margin: 0; }
.sidebar-foot .icon-btn { color: #8fa0a8; }
.sidebar-foot .icon-btn:hover { background: rgba(255,255,255,.08); color: #fff; }
.me { flex: 1; display: flex; align-items: center; gap: 10px; padding: 6px; border-radius: 10px; min-width: 0; }
.me:hover, .me.active { background: rgba(255,255,255,.06); }
.me-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.me-text strong { color: #fff; font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-text small { color: #7f9099; font-size: 12px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: #23343c; color: #dfe9ed; font-weight: 600; font-size: 12px;
}
.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 60px; display: flex; align-items: center; gap: 12px; padding: 0 28px;
  border-bottom: 1px solid var(--line); background: rgba(245,247,248,.85); backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 20;
}
.topbar-spacer { flex: 1; }
.menu-btn { display: none; }
.content { padding: 28px; max-width: 1600px; width: 100%; }
.sidebar-scrim { display: none; }

.env-pill {
  display: inline-flex; align-items: center; gap: 8px; padding: 5px 12px; border-radius: 999px;
  font-size: 12.5px; font-weight: 600; border: 1px solid var(--line); background: var(--surface);
}
.env-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 20%, transparent); }
.env-live { color: #b4122e; border-color: #f5c6cf; background: #fff5f6; }
.env-staging { color: #a35a00; border-color: #f4dcb5; background: #fffaf1; }
.env-none { color: var(--muted); }

/* ------------------------------------------------------------ Page header */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 28px; letter-spacing: -.025em; font-weight: 700; line-height: 1.15; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.page-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.back-link { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-weight: 500; margin-bottom: 10px; }
.back-link:hover { color: var(--ink); }
.back-link .icon { width: 16px; height: 16px; }

/* ---------------------------------------------------------------- Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 42px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line-strong);
  background: var(--surface); font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, box-shadow .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); border-color: #c3ccd2; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .icon-btn:focus-visible, .seg button:focus-visible, .chip:focus-visible, .switch input:focus-visible + .slider {
  outline: 3px solid color-mix(in srgb, var(--brand) 35%, transparent); outline-offset: 2px;
}
.btn .icon { width: 17px; height: 17px; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-600); border-color: var(--brand-600); }
.btn-dark { background: var(--dark); border-color: var(--dark); color: #fff; }
.btn-dark:hover { background: #22323a; border-color: #22323a; }
.btn-danger { background: var(--surface); border-color: #f2c2cb; color: var(--danger); }
.btn-danger:hover { background: var(--danger-bg); border-color: #eaa3b0; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { height: 34px; padding: 0 12px; font-size: 13px; border-radius: 9px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn .badge-count { background: #fff; color: var(--dark); border-radius: 999px; font-size: 11px; padding: 0 7px; line-height: 18px; }
.icon-btn {
  width: 36px; height: 36px; display: inline-grid; place-items: center; border-radius: 9px;
  border: 0; background: transparent; cursor: pointer; color: var(--muted);
}
.icon-btn:hover { background: #eef2f4; color: var(--ink); }
.spin { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------------ Cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 22px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.card-head h2, .card-head h3 { margin: 0; font-size: 16px; letter-spacing: -.01em; }

/* -------------------------------------------------------------------- KPI */
.kpis { display: grid; grid-template-columns: 1.15fr repeat(4, 1fr); gap: 16px; margin-bottom: 22px; }
.kpi {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; min-height: 136px; position: relative;
  text-align: left; display: flex; flex-direction: column;
}
button.kpi { cursor: pointer; transition: border-color .15s, box-shadow .15s, transform .15s; }
button.kpi:hover { border-color: var(--line-strong); transform: translateY(-1px); }
button.kpi.selected { border-color: currentColor; box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 15%, transparent), var(--shadow); }
.kpi-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.kpi-label { color: var(--ink-2); font-size: 14px; }
.kpi-value { font-size: 21px; font-weight: 700; letter-spacing: -.01em; margin-top: 16px; font-variant-numeric: tabular-nums; }
.kpi-sub { color: var(--muted); font-size: 12px; margin-top: 4px; }
.kpi-total .kpi-value { color: var(--ink); font-size: 22px; margin-top: auto; }
.kpi-total .kpi-icon { width: 36px; height: 36px; border-radius: 10px; background: var(--dark); color: #fff; display: grid; place-items: center; }
.kpi-total .kpi-icon .icon { width: 17px; height: 17px; }
.pct { font-size: 11px; font-weight: 700; border-radius: 999px; padding: 2px 8px; }
.bar { height: 6px; border-radius: 6px; background: #edf1f3; margin-top: 12px; overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 6px; background: currentColor; width: 0; transition: width .6s cubic-bezier(.2,.8,.2,1); }
.b1 { color: var(--b1); } .b1 .pct { background: var(--b1-bg); }
.b2 { color: var(--b2); } .b2 .pct { background: var(--b2-bg); }
.b3 { color: var(--b3); } .b3 .pct { background: var(--b3-bg); }
.b4 { color: var(--b4); } .b4 .pct { background: var(--b4-bg); }
.kpi .kpi-label { color: var(--ink-2); }

/* ---------------------------------------------------------------- Toolbar */
.toolbar { display: flex; align-items: center; gap: 12px; padding: 16px; flex-wrap: wrap; }
.search { position: relative; flex: 1 1 280px; min-width: 200px; }
.search .icon { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--faint); width: 17px; height: 17px; }
.search input {
  width: 100%; height: 42px; padding: 0 14px 0 38px; border: 1px solid var(--line-strong);
  border-radius: 10px; background: var(--surface); outline: none; transition: border-color .15s, box-shadow .15s;
}
.search input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-50); }
.seg { display: inline-flex; padding: 4px; border-radius: 999px; background: #eef2f4; border: 1px solid var(--line); }
.seg button {
  border: 0; background: transparent; padding: 0 14px; height: 32px; border-radius: 999px;
  font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer; transition: background .15s, color .15s;
}
.seg button:hover { color: var(--ink); }
.seg button.on { background: var(--brand); color: #fff; box-shadow: var(--shadow-sm); }
.seg.seg-dark button.on { background: var(--dark); }

.active-filters { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 0 16px 14px; }
.active-filters:empty { display: none; }
.active-filters .label { color: var(--muted); font-size: 12.5px; font-weight: 500; margin-right: 2px; }

/* ------------------------------------------------------------------ Chips */
.chip {
  display: inline-flex; align-items: center; gap: 7px; height: 32px; padding: 0 13px; border-radius: 999px;
  border: 1px solid var(--line-strong); background: var(--surface); font-size: 13px; font-weight: 600;
  color: var(--ink-2); cursor: pointer; transition: all .15s; user-select: none;
}
.chip:hover { border-color: #b8c3ca; background: var(--surface-2); }
.chip .swatch { width: 9px; height: 9px; border-radius: 50%; background: var(--c, var(--faint)); }
.chip.on { background: color-mix(in srgb, var(--c, var(--brand)) 12%, white); border-color: color-mix(in srgb, var(--c, var(--brand)) 55%, white); color: var(--ink); }
.chip.on .check { display: inline-block; }
.chip .check, .chip .x { width: 14px; height: 14px; }
.chip .check { display: none; color: var(--c, var(--brand)); }
.chip-removable { height: 28px; padding: 0 6px 0 11px; font-size: 12.5px; }
.chip-removable .x { color: var(--muted); border-radius: 50%; padding: 1px; }
.chip-removable:hover .x { color: var(--ink); background: rgba(0,0,0,.06); }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.link-btn { border: 0; background: none; color: var(--brand); font-weight: 600; font-size: 12.5px; cursor: pointer; padding: 4px; }
.link-btn:hover { text-decoration: underline; }

/* -------------------------------------------------------- Filter popover */
.filter-wrap { position: relative; }
.popover {
  position: absolute; right: 0; top: calc(100% + 8px); width: min(420px, calc(100vw - 32px));
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); z-index: 30; display: none;
}
.popover.open { display: block; animation: pop .14s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.popover-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.popover-head h3 { margin: 0; font-size: 15px; }
.popover-body { padding: 16px 18px; display: grid; gap: 18px; max-height: 60vh; overflow: auto; }
.popover-section h4 { margin: 0 0 10px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; display: flex; align-items: center; gap: 6px; }
.popover-section h4 .icon { width: 14px; height: 14px; }
.popover-foot { display: flex; justify-content: space-between; gap: 10px; padding: 12px 18px; border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 var(--radius) var(--radius); }

/* ------------------------------------------------------------------ Table */
.table-card { overflow: hidden; }
.table-scroll { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; }
table.data th {
  text-align: left; font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
  color: var(--ink-2); padding: 14px 16px; border-bottom: 1px solid var(--line); white-space: nowrap;
  background: var(--surface); position: sticky; top: 0;
}
table.data td { padding: 11px 16px; border-bottom: 1px solid #eff2f4; vertical-align: middle; }
table.data tbody tr:hover td { background: #fafcfc; }
table.data .r { text-align: right; }
table.data .amt { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.age { color: var(--faint); font-size: 12px; margin-left: 4px; }
.cust-name { font-weight: 600; }
tr.subtotal td { background: var(--surface-2); font-size: 12.5px; padding-top: 9px; padding-bottom: 9px; }
tr.subtotal:hover td { background: var(--surface-2) !important; }
tr.subtotal .sub-label { color: var(--ink-2); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
tr.subtotal .sub-label .muted-cap { color: var(--muted); }
tr.subtotal .amt { color: var(--ink); font-weight: 700; }
tr.grand td { background: #eef3f2; font-weight: 700; border-top: 2px solid var(--line-strong); }
.pdf-chip {
  display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: 6px; margin-left: 8px;
  border: 1px solid #bfe5d6; color: var(--brand); background: #fff; font-size: 11.5px; font-weight: 600; vertical-align: middle; text-transform: none; letter-spacing: 0;
}
.pdf-chip:hover { background: var(--brand-50); }
.pdf-chip .icon { width: 12px; height: 12px; }
.refund-tag { font-size: 10.5px; font-weight: 700; color: #6d4bd1; background: #efe9ff; padding: 1px 6px; border-radius: 5px; margin-left: 6px; }
.table-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; color: var(--muted); font-size: 12.5px; border-top: 1px solid var(--line); flex-wrap: wrap; }

.state { padding: 64px 20px; text-align: center; color: var(--muted); }
.state .icon { width: 30px; height: 30px; color: var(--faint); margin-bottom: 10px; }
.state h3 { color: var(--ink); margin: 0 0 4px; font-size: 16px; }
.state p { margin: 0 auto; max-width: 440px; }
.skeleton { height: 14px; border-radius: 6px; background: linear-gradient(90deg, #eef2f4 0%, #f7f9fa 50%, #eef2f4 100%); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ------------------------------------------------------------------ Forms */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.form-grid .full { grid-column: 1 / -1; }
.field label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 7px; color: var(--ink-2); }
.field .hint { color: var(--muted); font-size: 12px; margin-top: 6px; }
.input, select.input {
  width: 100%; height: 44px; padding: 0 14px; border: 1px solid var(--line-strong); border-radius: 10px;
  background: var(--surface); outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-50); }
.input-wrap { position: relative; }
.input-wrap .icon-lead { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--faint); width: 17px; height: 17px; }
.input-wrap .input.has-lead { padding-left: 40px; }
.input-wrap .reveal { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); }
.input-wrap .input.has-trail { padding-right: 44px; }
.input.mono { font-family: ui-monospace, 'Cascadia Code', Consolas, monospace; font-size: 13px; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; flex-wrap: wrap; }
.radio-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.radio-card { position: relative; border: 1px solid var(--line-strong); border-radius: 11px; padding: 12px 14px; cursor: pointer; display: flex; gap: 10px; align-items: flex-start; }
.radio-card input { margin: 3px 0 0; accent-color: var(--brand); }
.radio-card strong { display: block; font-size: 13.5px; }
.radio-card small { color: var(--muted); font-size: 12px; }
.radio-card:has(input:checked) { border-color: var(--brand); background: var(--brand-50); }

/* ----------------------------------------------------------------- Switch */
.switch { position: relative; display: inline-block; width: 46px; height: 26px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch .slider { position: absolute; inset: 0; border-radius: 999px; background: #cfd8dd; cursor: pointer; transition: background .2s; }
.switch .slider::before { content: ''; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s; }
.switch input:checked + .slider { background: var(--brand); }
.switch input:checked + .slider::before { transform: translateX(20px); }
.switch input:disabled + .slider { cursor: not-allowed; opacity: .6; }

/* Environment slider (Staging ⟷ Live) */
.env-slider { position: relative; display: inline-grid; grid-template-columns: 1fr 1fr; padding: 5px; border-radius: 999px; background: #eef2f4; border: 1px solid var(--line); min-width: 300px; }
.env-slider input { position: absolute; opacity: 0; pointer-events: none; }
.env-slider label { position: relative; z-index: 1; display: flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 22px; border-radius: 999px; font-weight: 600; color: var(--muted); cursor: pointer; transition: color .2s; }
.env-slider label .icon { width: 16px; height: 16px; }
.env-slider .thumb { position: absolute; top: 5px; bottom: 5px; left: 5px; width: calc(50% - 5px); border-radius: 999px; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.12), 0 4px 12px rgba(0,0,0,.06); transition: transform .28s cubic-bezier(.3,.9,.3,1), background .2s; }
.env-slider #env-live:checked ~ .thumb { transform: translateX(100%); background: #d0213f; }
.env-slider #env-staging:checked ~ .thumb { background: #e08a00; }
.env-slider #env-live:checked ~ label[for="env-live"],
.env-slider #env-staging:checked ~ label[for="env-staging"] { color: #fff; }
.env-slider input:focus-visible ~ .thumb { outline: 3px solid color-mix(in srgb, var(--brand) 35%, transparent); outline-offset: 2px; }

.env-banner { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 20px 22px; flex-wrap: wrap; margin-bottom: 20px; }
.env-banner h2 { margin: 0; font-size: 16px; }
.env-banner p { margin: 3px 0 0; color: var(--muted); }
.conn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.conn-card.is-active { border-color: color-mix(in srgb, var(--accent) 45%, white); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 12%, transparent), var(--shadow); }
.conn-card[data-env="live"] { --accent: #d0213f; }
.conn-card[data-env="staging"] { --accent: #e08a00; }
.conn-title { display: flex; align-items: center; gap: 12px; }
.conn-icon { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; background: color-mix(in srgb, var(--accent) 12%, white); color: var(--accent); }
.conn-title small { display: block; color: var(--muted); font-weight: 500; font-size: 12px; }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px; }
.status .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status-on { color: var(--brand); background: var(--brand-50); }
.status-off { color: var(--muted); background: #eef2f4; }
.test-result { margin-top: 14px; font-size: 13px; border-radius: 10px; padding: 10px 12px; display: none; align-items: flex-start; gap: 8px; }
.test-result.show { display: flex; }
.test-result.ok { background: var(--brand-50); color: #0b6b50; }
.test-result.err { background: var(--danger-bg); color: #a0142f; }

/* ----------------------------------------------------------------- Alerts */
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 11px; margin-bottom: 16px; font-weight: 500; border: 1px solid; }
.alert .icon { margin-top: 1px; }
.alert-success { background: var(--brand-50); border-color: #bfe5d6; color: #0b6b50; }
.alert-error { background: var(--danger-bg); border-color: #f5c3cc; color: #a0142f; }
.alert-info { background: #eef5fb; border-color: #cfe2f3; color: #1d5784; }

/* ------------------------------------------------------------------ Users */
.user-cell { display: flex; align-items: center; gap: 12px; }
.user-cell .avatar { background: var(--brand-50); color: var(--brand-600); }
.user-cell small { display: block; color: var(--muted); }
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px; }
.badge-admin { background: #eef0ff; color: #4537c4; }
.badge-user { background: #eef2f4; color: var(--ink-2); }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; }
.row-actions form { margin: 0; }
.danger-zone { border-color: #f5ccd4; }
.danger-zone .card-head h3 { color: var(--danger); }
.empty-state { text-align: center; padding: 80px 20px; }
.empty-state .empty-icon { width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center; margin: 0 auto 14px; background: #eef2f4; color: var(--muted); }
.empty-state h2 { margin: 0 0 4px; }
.empty-state p { color: var(--muted); margin: 0; }

/* ------------------------------------------------------------------ Login */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.05fr 1fr; background: var(--surface); }
.auth-art {
  position: relative; overflow: hidden; color: #fff; padding: 44px 48px; display: flex; flex-direction: column; justify-content: space-between;
  background:
    radial-gradient(1200px 600px at -10% 110%, rgba(25,179,134,.55), transparent 60%),
    radial-gradient(800px 500px at 110% -10%, rgba(21,116,181,.45), transparent 60%),
    #0d171c;
}
.auth-art::before {
  content: ''; position: absolute; inset: 0; opacity: .14;
  background-image: linear-gradient(rgba(255,255,255,.5) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.5) 1px, transparent 1px);
  background-size: 44px 44px; mask-image: radial-gradient(ellipse at 30% 60%, #000 20%, transparent 75%);
}
.auth-art > * { position: relative; }
.auth-art .brand { padding: 0; }
.auth-art .brand-text small { color: rgba(255,255,255,.6); }
.auth-pitch h2 { font-size: 38px; line-height: 1.12; letter-spacing: -.03em; margin: 0 0 14px; max-width: 480px; }
.auth-pitch p { color: rgba(255,255,255,.72); max-width: 440px; margin: 0; font-size: 15px; }
.auth-stats { display: flex; gap: 12px; flex-wrap: wrap; }
.auth-stat { background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.12); backdrop-filter: blur(6px); border-radius: 14px; padding: 14px 16px; min-width: 132px; }
.auth-stat small { color: rgba(255,255,255,.6); font-size: 12px; }
.auth-stat strong { display: block; font-size: 15px; margin-top: 2px; }
.auth-stat .bar { background: rgba(255,255,255,.14); height: 5px; margin-top: 10px; }
.auth-foot { color: rgba(255,255,255,.45); font-size: 12.5px; }
.auth-form-wrap { display: grid; place-items: center; padding: 40px 24px; }
.auth-form { width: 100%; max-width: 380px; }
.auth-form h1 { font-size: 26px; letter-spacing: -.025em; margin: 0 0 6px; }
.auth-form > p { color: var(--muted); margin: 0 0 28px; }
.auth-form .field { margin-bottom: 16px; }
.auth-form .btn { width: 100%; height: 46px; margin-top: 6px; }
.auth-help { margin-top: 22px; color: var(--muted); font-size: 12.5px; text-align: center; }
.mobile-brand { display: none; margin-bottom: 28px; }
.mobile-brand .brand-text strong { color: var(--ink); }
.mobile-brand .brand-text small { color: var(--muted); }

/* -------------------------------------------------------------- Statement */
.statement { max-width: 900px; margin: 0 auto; padding: 40px 32px; background: #fff; }
.statement .st-head { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; border-bottom: 2px solid var(--ink); padding-bottom: 18px; }
.statement h1 { margin: 0; font-size: 24px; letter-spacing: -.02em; }
.statement .st-meta { text-align: right; color: var(--ink-2); font-size: 13px; }
.statement .st-to { margin: 22px 0; display: flex; justify-content: space-between; gap: 20px; }
.statement .st-to h4 { margin: 0 0 4px; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.statement .st-aging { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); border: 1px solid var(--line-strong); border-radius: 10px; overflow: hidden; margin: 18px 0 24px; }
.statement .st-aging div { padding: 10px 12px; border-right: 1px solid var(--line-strong); }
.statement .st-aging div:last-child { border-right: 0; }
.statement .st-aging small { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.statement .st-aging strong { font-variant-numeric: tabular-nums; }
.statement table.data th { position: static; }
.statement-bar { position: sticky; top: 0; display: flex; justify-content: center; gap: 10px; padding: 12px; background: var(--bg); border-bottom: 1px solid var(--line); }

/* ------------------------------------------------------------- Responsive */
@media (max-width: 1280px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .kpis .kpi-total { grid-column: 1 / -1; min-height: 0; }
}
@media (max-width: 1024px) {
  .conn-grid { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); transition: transform .25s ease; }
  body.nav-open .sidebar { transform: none; box-shadow: var(--shadow-lg); }
  body.nav-open .sidebar-scrim { display: block; position: fixed; inset: 0; background: rgba(10,18,22,.45); z-index: 35; }
  .main { margin-left: 0; }
  .menu-btn { display: inline-grid; }
  .topbar { padding: 0 16px; }
  .content { padding: 20px 16px; }
  .auth { grid-template-columns: 1fr; }
  .auth-art { display: none; }
  .mobile-brand { display: flex; }
}
@media (max-width: 640px) {
  .kpis { grid-template-columns: 1fr; }
  .form-grid, .radio-cards { grid-template-columns: 1fr; }
  .page-head h1 { font-size: 24px; }
  .toolbar .seg { flex: 1; } .toolbar .seg button { flex: 1; }
  .env-slider { min-width: 0; width: 100%; }
  .statement .st-aging { grid-template-columns: repeat(2, 1fr); }
}

/* ------------------------------------------------------------------ Print */
@media print {
  @page { size: A4 landscape; margin: 12mm; }
  body { background: #fff; font-size: 11px; }
  .sidebar, .topbar, .toolbar, .active-filters, .page-actions, .no-print, .pdf-chip, .statement-bar, .table-foot .no-print { display: none !important; }
  .main { margin: 0; }
  .content { padding: 0; max-width: none; }
  .card, .kpi { box-shadow: none; }
  .kpis { grid-template-columns: repeat(5, 1fr); gap: 8px; }
  .kpis .kpi-total { grid-column: auto; }
  .kpi { min-height: 0; padding: 10px; }
  .kpi-value { font-size: 14px; margin-top: 6px; }
  table.data th { position: static; }
  table.data td, table.data th { padding: 5px 8px; }
  tr { break-inside: avoid; }
  .table-scroll { overflow: visible; }
  .statement { padding: 0; }
  body.statement-page { font-size: 12px; }
}
body.statement-page { background: #fff; }
.icon-xs { width: 13px; height: 13px; }

/* --------------------------------------------------------- Ageing buckets */
.bucket-list { display: grid; }
.bucket-row {
  display: grid; grid-template-columns: 32px minmax(160px, 1.4fr) 150px auto 120px 36px;
  gap: 16px; align-items: end; padding: 16px 22px; border-bottom: 1px solid var(--line);
}
.bucket-row:last-child { border-bottom: 0; }
.bucket-row .field label { font-size: 12px; margin-bottom: 6px; }
.bucket-num { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: #eef2f4; font-weight: 700; font-size: 12px; color: var(--ink-2); margin-bottom: 8px; }
.days-input { display: flex; align-items: center; gap: 8px; }
.days-input .input { width: 90px; }
.days-input span { color: var(--muted); font-size: 13px; }
.input:disabled { background: #f1f4f6; color: var(--muted); cursor: not-allowed; }
.input.is-invalid { border-color: var(--danger); box-shadow: 0 0 0 3px var(--danger-bg); }
.swatches { display: flex; gap: 6px; flex-wrap: wrap; height: 44px; align-items: center; }
.swatch-btn { width: 22px; height: 22px; border-radius: 50%; border: 0; background: var(--c); cursor: pointer; box-shadow: inset 0 0 0 1px rgba(0,0,0,.1); transition: transform .12s; }
.swatch-btn:hover { transform: scale(1.12); }
.swatch-btn.on { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--c); }
.swatch-btn:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 35%, transparent); outline-offset: 3px; }
.range-pill { justify-self: start; margin-bottom: 11px; font-size: 12px; font-weight: 600; color: var(--ink-2); background: #eef2f4; border-radius: 999px; padding: 3px 10px; white-space: nowrap; }
.bucket-row .icon-btn { margin-bottom: 4px; }
.bucket-row .icon-btn:disabled { opacity: .35; cursor: not-allowed; }
.age-bar { display: flex; gap: 3px; height: 12px; }
.age-bar span { background: var(--c); border-radius: 4px; min-width: 6px; }
.age-legend { display: flex; flex-wrap: wrap; gap: 10px 22px; margin-top: 14px; }
.age-legend div { display: flex; align-items: center; gap: 8px; }
.age-legend i { width: 10px; height: 10px; border-radius: 3px; background: var(--c); }
.age-legend small { color: var(--muted); }
@media (max-width: 860px) {
  .bucket-row { grid-template-columns: 32px 1fr 36px; align-items: center; }
  .bucket-row .field { grid-column: 2 / 3; }
  .bucket-row .bucket-num { grid-row: 1; margin: 0; }
  .bucket-row .icon-btn { grid-column: 3; grid-row: 1; margin: 0; }
  .bucket-row .range-pill { grid-column: 2; margin: 0; }
}

/* Dynamic bucket colours (set with --c) */
.bk { color: var(--c); }
.bk .pct { background: color-mix(in srgb, var(--c) 12%, white); }
.kpis { grid-template-columns: minmax(240px, 1.15fr) repeat(var(--n, 4), minmax(0, 1fr)); }
@media (max-width: 1280px) { .kpis { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); } }
@media (max-width: 640px) { .kpis { grid-template-columns: 1fr; } }
@media print { .kpis { grid-template-columns: repeat(calc(var(--n, 4) + 1), 1fr); } }
