/* TriEmp Incentive Admin — single stylesheet, no frameworks. */

:root {
  --bg: #f3f5f8;
  --panel: #ffffff;
  --ink: #1b2430;
  --muted: #647181;
  --line: #e1e5eb;
  --sidebar: #15202b;
  --sidebar-ink: #c9d2dc;
  --sidebar-muted: #7c8a99;
  --accent: #e0700f;
  --accent-ink: #ffffff;
  --accent-soft: #fdf0e4;
  --accent-strong: #b85600; /* button background: white text on it is 4.8:1 (the plain accent is only 3.2:1) */
  --accent-text: #a64f00; /* accent used as text on the page / panel background (5.1:1 on the page grey) */
  --accent-badge: #8f4300; /* accent text on the soft accent background */
  --danger-btn: #c4352d;
  --success: #136a3c;
  --success-soft: #e5f4ec;
  --danger: #c4352d;
  --danger-soft: #fbeaea;
  --info: #2f5f9e;
  --info-soft: #e8eff8;
  --head-bg: #f6f7f9;
  --row-hover: #f8fafc;
  --focus: 0 0 0 3px rgba(224, 112, 15, 0.35);
  --radius: 8px;
  --font: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Consolas, monospace;
  --sidebar-w: 248px;
  --group-row-h: 30px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f151c;
    --panel: #18212b;
    --ink: #e6ebf1;
    --muted: #93a1b0;
    --line: #2a3542;
    --sidebar: #0b1117;
    --accent-soft: #3a2614;
    --accent-text: #f08a2c;
    --accent-badge: #f59a4a;
    --success: #3cb877;
    --success-soft: #16301f;
    --danger: #ef6a62;
    --danger-soft: #3a1c1b;
    --info: #79a6e0;
    --info-soft: #1a2a40;
    --head-bg: #1d2732;
    --row-hover: #1c2631;
  }
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
}

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

h1, h2, h3 { line-height: 1.25; margin: 0; }

:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 4px; }

.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.small { font-size: 12px; }
.center { text-align: center; }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- layout */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--sidebar);
  color: var(--sidebar-ink);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  gap: 6px;
  align-items: baseline;
  padding: 20px 20px 16px;
  color: #ffffff;
  font-weight: 600;
  font-size: 16px;
  text-decoration: none;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.brand-mark { letter-spacing: 0.14em; color: var(--accent); font-weight: 700; }
.brand-sep { color: var(--sidebar-muted); }

.sidebar-nav { padding: 12px 10px; flex: 1; display: flex; flex-direction: column; gap: 2px; }

.nav-link {
  display: block;
  padding: 8px 12px;
  border-radius: 6px;
  color: var(--sidebar-ink);
  text-decoration: none;
  font-size: 13.5px;
  border-left: 3px solid transparent;
}
.nav-link:hover { background: rgba(255, 255, 255, 0.06); color: #ffffff; }
.nav-link.is-active { background: rgba(224, 112, 15, 0.16); color: #ffffff; border-left-color: var(--accent); }
.nav-sub { padding-left: 22px; font-size: 13px; }

.nav-group { margin-top: 12px; }
.nav-group-title {
  padding: 4px 12px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--sidebar-muted);
  font-weight: 600;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 13px;
}
.user-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user .link-button { color: var(--accent); }

.content { flex: 1; min-width: 0; padding: 24px 28px 48px; }

.page-title { font-size: 22px; font-weight: 600; margin-bottom: 18px; }

.breadcrumb { color: var(--muted); font-size: 12.5px; margin-bottom: 4px; }

/* ---------------------------------------------------------------- cards */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.card-title { font-size: 15px; font-weight: 600; margin-bottom: 12px; }
.card + .card { margin-top: 16px; }

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 0 16px;
  border-radius: 6px;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 500;
  font-size: 13.5px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  line-height: 1;
}
.btn-primary { background: var(--accent-strong); color: var(--accent-ink); border-color: var(--accent-strong); }
.btn-primary:hover { filter: brightness(0.94); }
.btn-secondary { background: var(--panel); color: var(--ink); border-color: var(--line); }
.btn-secondary:hover { background: var(--head-bg); }
.btn-outline-accent { background: transparent; color: var(--accent-text); border-color: var(--accent-text); }
.btn-outline-accent:hover { background: var(--accent-soft); }
.btn-danger { background: var(--danger-btn); color: #ffffff; border-color: var(--danger-btn); }
.btn-sm { min-height: 30px; padding: 0 10px; font-size: 12.5px; }
.btn-block { width: 100%; }
.btn.is-current { background: var(--accent-strong); color: var(--accent-ink); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.link-button {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: var(--info);
  cursor: pointer;
  text-decoration: underline;
}
.inline-form { display: inline; margin: 0; }

/* ---------------------------------------------------------------- forms */
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label, .field-label { font-weight: 500; font-size: 13px; }

input[type="text"], input[type="password"], input[type="month"], input[type="number"],
input[type="email"], input[type="date"], input[type="search"],
input[type="file"], input[inputmode="numeric"], select {
  min-height: 38px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
  width: 100%;
}
input[type="file"] { padding: 6px 8px; }
input:focus-visible, select:focus-visible { border-color: var(--accent); box-shadow: var(--focus); outline: none; }

.check { display: flex; align-items: center; gap: 8px; font-size: 13.5px; }
.hint { color: var(--muted); font-size: 12.5px; margin: 0; }
.field-error { color: var(--danger); font-size: 12.5px; margin: 0; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.form-actions.center { justify-content: center; }

/* ---------------------------------------------------------------- flashes */
.flashes { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.flash {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel);
  border-left-width: 4px;
}
.flash-text { flex: 1; }
.flash-success { border-left-color: var(--success); background: var(--success-soft); }
.flash-error { border-left-color: var(--danger); background: var(--danger-soft); }
.flash-info { border-left-color: var(--info); background: var(--info-soft); }
.flash-warning { border-left-color: var(--accent); background: var(--accent-soft); }
.flash-close {
  background: none; border: 0; font-size: 20px; line-height: 1; cursor: pointer; color: var(--muted); padding: 0 2px;
}

/* ---------------------------------------------------------------- pills & chips */
.pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}
.pill-sent { background: var(--success-soft); color: var(--success); }
.pill-not_sent, .pill-failed { background: var(--danger-soft); color: var(--danger); }
.pill-queued { background: var(--info-soft); color: var(--info); }
.pill-failed { cursor: help; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-block;
  padding: 3px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  color: var(--ink);
  text-decoration: none;
  background: var(--panel);
}
.chip:hover { border-color: var(--accent); color: var(--accent); }

/* ---------------------------------------------------------------- dashboard */
.dash-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; margin-bottom: 18px; }
.dash-head .page-title { margin-bottom: 0; }
.dash-month { display: flex; align-items: center; gap: 8px; }
.dash-month label { font-weight: 500; font-size: 13px; color: var(--muted); }
.dash-month select { width: auto; min-width: 140px; }
.dash-empty { margin-bottom: 16px; color: var(--muted); }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; min-width: 0; }
.kpi-label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.kpi-value { margin: 6px 0 4px; font-size: 24px; font-weight: 600; font-family: var(--mono); overflow-wrap: anywhere; }
.kpi-delta { margin: 0; font-size: 12.5px; font-weight: 500; }
.kpi-good { color: var(--success); }
.kpi-bad { color: var(--danger); }
.kpi-neutral { color: var(--muted); }
.kpi-note { margin: 4px 0 0; font-size: 12px; color: var(--muted); }

.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; margin-bottom: 16px; }
.chart-grid .card + .card { margin-top: 0; }
.chart { width: 100%; min-height: 240px; }
.chart svg { display: block; max-width: 100%; }
.chart-empty { margin: 0; padding: 90px 10px; text-align: center; color: var(--muted); }
.ch-text { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.ch-value { fill: var(--ink); font-size: 11px; font-family: var(--mono); }
.ch-grid { stroke: var(--line); stroke-width: 1; }
.ch-bar { fill: var(--accent); }
.ch-bar:hover { filter: brightness(0.92); }
.ch-line { fill: none; stroke: var(--info); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.ch-area { fill: var(--info-soft); stroke: none; }
.ch-dot { fill: var(--panel); stroke: var(--info); stroke-width: 2; }
.ch-dot.is-current { fill: var(--info); }

.grid-wrap { overflow-x: auto; }
.status-grid { border-collapse: separate; border-spacing: 0; width: 100%; min-width: 640px; font-size: 13px; }
.status-grid th, .status-grid td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; }
.status-grid thead th { color: var(--muted); font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.status-grid tbody th { font-weight: 500; white-space: nowrap; }
.grid-group { display: block; font-size: 11px; font-weight: 400; color: var(--muted); }
.cell {
  display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 6px 10px;
  border-radius: 6px; border: 1px solid transparent; text-decoration: none; font-weight: 500; white-space: nowrap;
}
.cell-count { font-weight: 400; font-size: 11.5px; opacity: 0.85; }
.cell-pending { background: var(--head-bg); color: var(--muted); border-color: var(--line); }
.cell-uploaded { background: var(--info-soft); color: var(--info); }
.cell-sent { background: var(--success-soft); color: var(--success); }
.cell:hover { border-color: currentColor; }

.activity { list-style: none; margin: 0; padding: 0; }
.activity-item { display: flex; align-items: flex-start; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.activity-item:first-child { border-top: 0; padding-top: 0; }
.activity-icon {
  flex: none; min-width: 34px; padding: 3px 0; text-align: center; border-radius: 6px;
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.04em;
}
.activity-upload { background: var(--info-soft); color: var(--info); }
.activity-sms { background: var(--accent-soft); color: var(--accent-badge); }
.activity-body { flex: 1; min-width: 0; }
.activity-title { margin: 0; font-weight: 500; overflow-wrap: anywhere; }
.activity-title a { color: var(--ink); }
.activity-detail { margin: 0; font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }
.activity-meta { flex: none; display: flex; flex-direction: column; align-items: flex-end; font-size: 12px; color: var(--muted); text-align: right; }

@media (max-width: 767px) {
  .activity-item { flex-wrap: wrap; }
  .activity-meta { flex-direction: row; gap: 8px; width: 100%; align-items: baseline; justify-content: flex-start; padding-left: 46px; text-align: left; }
  .kpi-value { font-size: 21px; }
}
/* ---------------------------------------------------------------- upload cards */
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; align-items: start; }
.two-col .card + .card { margin-top: 0; }
.narrow { max-width: 640px; }

/* ---------------------------------------------------------------- incentive page */
.page-head { margin-bottom: 14px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tab {
  padding: 9px 16px;
  color: var(--muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  font-weight: 500;
  white-space: nowrap;
}
.tab:hover { color: var(--ink); }
.tab.is-active { color: var(--accent-text); border-bottom-color: var(--accent); }

.action-bar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 16px 24px; }
.sms-form { display: flex; align-items: flex-end; gap: 10px; }
.sms-form .field { min-width: 170px; }
.sms-ids { flex-basis: 100%; margin: 0; }
.sms-banner { padding: 12px 16px; margin-bottom: 16px; border-radius: 8px; border-left: 4px solid; font-size: 14px; }
.sms-banner-dry { border-left-color: var(--accent); background: var(--accent-soft); }
.sms-banner-block { border-left-color: var(--danger); background: var(--danger-soft); }
.summary { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; flex: 1; min-width: 220px; font-size: 13px; }
.summary-months { color: var(--muted); width: 100%; font-size: 12.5px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }

.table-card { padding: 0; overflow: hidden; }
.table-wrap { overflow: auto; max-height: 70vh; }

.data-table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13px; }
.data-table th, .data-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
  background: var(--panel);
}
.data-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--head-bg);
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.data-table.has-groups .col-head th { top: var(--group-row-h); }
.data-table .group-head th { height: var(--group-row-h); padding-top: 4px; padding-bottom: 4px; text-align: center; }
.data-table .group-head th.grp { color: var(--ink); border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
.data-table tbody tr:hover td { background: var(--row-hover); }
.data-table td.num, .data-table th.num { text-align: right; font-family: var(--mono); }
.data-table td.amount-final { font-weight: 700; color: var(--success); }
.data-table .sticky-1 { position: sticky; left: 0; z-index: 1; width: 52px; min-width: 52px; }
.data-table .sticky-2 { position: sticky; left: 52px; z-index: 1; box-shadow: 1px 0 0 var(--line); }
.data-table thead .sticky-1, .data-table thead .sticky-2 { z-index: 3; }
.link-cell { max-width: 260px; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }

.empty-state { padding: 48px 20px; text-align: center; color: var(--muted); }

.pagination {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px;
  padding: 12px 16px; border-top: 1px solid var(--line);
}
.pagination-links { display: flex; gap: 4px; flex-wrap: wrap; }
.pagination-gap { padding: 0 6px; color: var(--muted); }
.pagination-info { color: var(--muted); font-size: 12.5px; }

/* ---------------------------------------------------------------- modal */
.modal {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0;
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100vh - 40px);
  background: var(--panel);
  color: var(--ink);
}
.modal.modal-wide { width: min(720px, calc(100vw - 24px)); }
.modal::backdrop { background: rgba(15, 21, 28, 0.55); }
.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
}
.modal-title { font-size: 16px; font-weight: 600; }
.modal-x { background: none; border: 0; font-size: 24px; line-height: 1; cursor: pointer; color: var(--muted); }
.modal-body { padding: 18px; overflow: auto; }
.confirm-text { font-size: 15px; font-weight: 500; margin: 0 0 6px; }

/* ---------------------------------------------------------------- auth & error */
.layout-plain { min-height: 100vh; }
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 400px; padding: 28px; }
.auth-brand { text-align: center; margin-bottom: 16px; }
.auth-logo { display: block; width: 140px; max-width: 100%; height: auto; margin: 0 auto; }
@media (prefers-color-scheme: dark) { .auth-logo { filter: invert(1); } }
.auth-title { font-size: 20px; margin-bottom: 18px; }
.auth-card-wide { max-width: 480px; }
.auth-link { margin: 16px 0 0; text-align: center; font-size: 13.5px; }
.form .auth-link { margin-top: 2px; }
.auth-secondary { display: flex; justify-content: center; gap: 8px; margin-top: 12px; font-size: 13.5px; color: var(--muted); }
.otp-input { font-family: var(--mono); font-size: 20px; letter-spacing: 0.4em; text-align: center; }
/* Show/hide password toggle (js/password-toggle.js) */
.pw-wrap { position: relative; display: flex; align-items: center; }
.pw-wrap input { padding-right: 42px; }
.pw-toggle {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; padding: 0; border: 0; border-radius: 6px;
  background: transparent; color: var(--muted); cursor: pointer;
}
.pw-toggle:hover { color: var(--ink); }
.pw-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Forgot-password stepper */
.stepper { display: flex; gap: 8px; list-style: none; margin: 0 0 20px; padding: 0; }
.step { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; position: relative; color: var(--muted); }
.step + .step::before { content: ""; position: absolute; top: 13px; right: 50%; width: 100%; height: 2px; background: var(--line); }
.step.is-done + .step::before, .step.is-active::before { background: var(--accent-strong); }
.step-dot {
  position: relative; z-index: 1; width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600; background: var(--panel); border: 2px solid var(--line); color: var(--muted);
}
.step.is-active .step-dot { background: var(--accent-strong); border-color: var(--accent-strong); color: var(--accent-ink); }
.step.is-done .step-dot { background: var(--accent-soft); border-color: var(--accent-strong); color: var(--accent-badge); }
.step.is-active, .step.is-done { color: var(--ink); }
.step-label { font-size: 12px; font-weight: 500; line-height: 1.3; }
@media (max-width: 420px) { .step-label { font-size: 11px; } }
.error-code { font-family: var(--mono); font-size: 40px; font-weight: 600; color: var(--accent); }

/* ---------------------------------------------------------------- statement */
.statement-page { max-width: 560px; margin: 0 auto; padding: 24px 16px 48px; }
.statement { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.statement-band {
  background: var(--sidebar); color: #ffffff; padding: 14px 18px; font-weight: 600; letter-spacing: 0.08em; font-size: 13px;
}
.statement-band .brand-mark { margin-right: 4px; }
.statement-month { padding: 14px 18px 0; margin: 0; }
.statement-meta { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 16px; padding: 14px 18px; margin: 0; }
.statement-meta dt { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em; }
.statement-meta dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }
.statement-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.statement-table th, .statement-table td { padding: 9px 18px; border-top: 1px solid var(--line); text-align: left; }
.statement-table thead th {
  background: var(--head-bg); color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em;
}
.statement-table td.amount { text-align: right; font-family: var(--mono); white-space: nowrap; }
.statement-table thead th.amount { text-align: right; }
.statement-table tr.section th { background: var(--head-bg); color: var(--ink); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.statement-table tr.final td { background: var(--success-soft); color: var(--success); font-weight: 700; }
.statement-foot { padding: 12px 18px; color: var(--muted); font-size: 12px; border-top: 1px solid var(--line); }
.verify-card { max-width: 400px; margin: 40px auto 0; }
.digits-input { font-family: var(--mono); font-size: 20px; letter-spacing: 0.4em; text-align: center; }

/* ---------------------------------------------------------------- responsive */
/* Tablets in portrait (820px) get the top navigation too: beside a 248px sidebar the admin tables lose their action buttons off-screen. */
@media (max-width: 900px) {
  .shell { flex-direction: column; }
  .sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
    width: 100%;
    flex: none;
    height: auto;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
  }
  .sidebar-brand { border-bottom: 0; padding: 12px 14px; flex: none; }
  .sidebar-nav { flex-direction: row; align-items: center; padding: 6px; gap: 2px; flex: none; }
  .nav-group { display: flex; align-items: center; margin-top: 0; }
  .nav-group-title { display: none; }
  .nav-link, .nav-sub { padding: 8px 10px; border-left: 0; border-bottom: 2px solid transparent; border-radius: 4px; }
  .nav-link.is-active { border-bottom-color: var(--accent); }
  .sidebar-user { border-top: 0; padding: 8px 14px; flex: none; }
  .content { padding: 16px 12px 40px; }
  .action-bar { flex-direction: column; align-items: stretch; }
  .sms-form { flex-direction: column; align-items: stretch; }
  .actions { flex-direction: column; }
  .actions .btn, .sms-form .btn { width: 100%; }
  .statement-meta { grid-template-columns: 1fr 1fr; }
}

/* ---------------------------------------------------------------- top bar & profile menu */
.topbar { display: flex; justify-content: flex-end; margin: -8px 0 12px; }
.profile { position: relative; }
.profile-toggle {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 4px 10px 4px 4px;
  background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 999px;
  font: inherit; cursor: pointer; max-width: 100%;
}
.profile-toggle:hover { border-color: var(--accent); }
.profile-avatar { flex: none; }
.avatar-bg { fill: var(--accent-soft); }
.avatar-fg { fill: var(--accent); }
.profile-name { font-weight: 500; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.role-badge {
  font-size: 11px; font-weight: 700; letter-spacing: 0.04em; color: var(--accent-badge); background: var(--accent-soft);
  padding: 2px 8px; border-radius: 999px; white-space: nowrap;
}
.profile-caret { flex: none; color: var(--muted); transition: transform 0.15s; }
.profile-toggle[aria-expanded="true"] .profile-caret { transform: rotate(180deg); }
.profile-menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; min-width: 220px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18); padding: 6px; display: flex; flex-direction: column;
}
.profile-menu-head { display: flex; flex-direction: column; padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; overflow-wrap: anywhere; }
.profile-logout { margin: 0; }
.profile-item {
  display: block; width: 100%; padding: 9px 10px; border: 0; border-radius: 6px; background: none; color: var(--ink);
  font: inherit; text-align: left; text-decoration: none; cursor: pointer;
}
.profile-item:hover, .profile-item:focus-visible { background: var(--head-bg); }

/* ---------------------------------------------------------------- admin pages */
.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.pill-active { background: var(--success-soft); color: var(--success); }
.pill-inactive { background: var(--head-bg); color: var(--muted); border: 1px solid var(--line); }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.search-form { display: flex; flex-wrap: wrap; gap: 8px; flex: 1; min-width: 240px; max-width: 520px; }
.search-form input[type="search"] { flex: 1; min-width: 160px; width: auto; }
.toolbar-actions { display: flex; align-items: center; gap: 10px; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px;
  border: 1px solid var(--line); border-radius: 6px; background: var(--panel); color: var(--ink); text-decoration: none;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }

.users-table td.row-actions { display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; }
@media (max-width: 1180px) {
  .users-table { font-size: 12.5px; }
  .users-table th, .users-table td { padding: 6px 6px; }
}
.users-table th, .users-table td { padding: 8px 8px; }
.users-table td:nth-child(4) { white-space: normal; overflow-wrap: anywhere; min-width: 140px; }
.data-table td.wrap { white-space: normal; min-width: 220px; overflow-wrap: anywhere; }
.btn.is-disabled, .btn:disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; }

.filter-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 16px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.filter-form .field { min-width: 150px; }
.filter-form .field-grow { flex: 1; min-width: 200px; }
.filter-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.filter-note { margin: 0; padding: 10px 16px; color: var(--danger); background: var(--danger-soft); font-size: 13px; }

.pager { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--line); }
.pager-buttons { display: flex; gap: 6px; }

.credentials { border-left: 4px solid var(--accent); margin-bottom: 16px; }
.credentials-list { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 12px 0 0; }
.credentials-list dt { color: var(--muted); }
.credentials-list dd { margin: 0; }
.one-time-password { font-family: var(--mono); font-size: 18px; font-weight: 600; letter-spacing: 0.06em; user-select: all; }

@media (max-width: 767px) {
  .topbar { margin: 0 0 10px; }
  .profile-name, .role-badge { display: none; }
  .profile-toggle { padding: 2px 8px 2px 2px; }
  .toolbar-actions { width: 100%; justify-content: flex-end; }
  .search-form { max-width: none; }
}

.sidebar .back-link { margin: 12px 10px 0; color: var(--sidebar-muted); font-size: 13px; }
.sidebar .back-link:hover { color: #ffffff; }
a.profile-menu-head { text-decoration: none; color: var(--ink); border-radius: 6px 6px 0 0; }
a.profile-menu-head:hover, a.profile-menu-head:focus-visible { background: var(--head-bg); }
@media (max-width: 900px) {
  .sidebar .back-link { margin: 0; padding: 8px 10px; flex: none; }
}

/* ---------------------------------------------------------------- print */
@media print {
  :root { --bg: #ffffff; --panel: #ffffff; --ink: #000000; --muted: #444444; --line: #cccccc; }
  body { background: #ffffff; }
  .sidebar, .flashes, .no-print, .modal { display: none !important; }
  .statement-page { padding: 0; max-width: none; }
  .statement { border-color: #999999; }
  .statement-band { background: #ffffff; color: #000000; border-bottom: 2px solid #000000; }
  .statement-table tr.final td { background: #ffffff; color: #000000; border-top: 2px solid #000000; }
}

/* Roles: permission matrix */
.perm-matrix th, .perm-matrix td { text-align: center; white-space: nowrap; }
.perm-matrix th[scope="row"], .perm-matrix thead th:first-child { text-align: left; }
.perm-matrix .perm-group th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted, inherit); }
.perm-matrix input[type="checkbox"] { width: 16px; height: 16px; }
.perm-matrix .check { justify-content: center; }

/* One-time credentials card (new user / reset password) */
.credentials { border: 2px solid var(--accent-strong, var(--accent)); border-left-width: 6px; padding: 18px 20px; }
.credentials:focus { outline: none; }
.credentials-note { font-size: 15px; margin: 4px 0 0; }
.credentials .form-actions { justify-content: flex-start; margin-top: 14px; }
.visually-hidden-form { display: none; }
.btn-left { margin-right: auto; }

/* Roles & Permissions screen */
.page-head-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.role-picker { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.role-select { min-width: min(360px, 100%); }
.role-picker-side { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.tag-system { background: var(--accent-soft); color: var(--accent-badge); }
.role-note { background: var(--accent-soft); border-left: 4px solid var(--accent); padding: 10px 14px; margin: 0 0 14px; border-radius: 4px; }
.role-description { max-width: 520px; margin-bottom: 14px; }
.perm-tabs { margin-bottom: 0; }
.perm-tabs .tab { display: inline-flex; align-items: center; gap: 8px; background: none; border-top: 0; border-left: 0; border-right: 0; cursor: pointer; font: inherit; }
.tab-count { min-width: 22px; padding: 1px 7px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-badge); font-size: 12px; font-weight: 700; text-align: center; }
.tab-count.is-zero { background: var(--line); color: var(--muted); }
.perm-panel { border-top-left-radius: 0; border-top-right-radius: 0; padding: 0; margin-top: 0; }
.perm-bar { padding: 12px 18px; background: var(--accent-soft); border-bottom: 1px solid var(--line); }
.perm-bar-title { font-size: 15px; font-weight: 600; margin: 0; color: var(--accent-badge); }
.perm-list { list-style: none; margin: 0; padding: 0; }
.perm-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.perm-row:last-child { border-bottom: 0; }
.perm-page { font-weight: 500; }
.perm-toggles { display: flex; gap: 22px; flex-wrap: wrap; }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13.5px; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track { position: relative; width: 38px; height: 22px; border-radius: 999px; background: var(--line); border: 1px solid var(--muted); transition: background .15s; flex: none; }
.switch-track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #ffffff; box-shadow: 0 1px 2px rgba(0,0,0,.35); transition: transform .15s; }
.switch input:checked + .switch-track { background: var(--accent-strong); border-color: var(--accent-strong); }
.switch input:checked + .switch-track::after { transform: translateX(16px); }
.switch input:focus-visible + .switch-track { box-shadow: var(--focus); }
.switch input:disabled + .switch-track { opacity: .65; }
.switch input:disabled ~ .switch-label { color: var(--muted); }
.switch:has(input:disabled) { cursor: not-allowed; }
.save-fab { position: fixed; right: 24px; bottom: 24px; z-index: 20; padding: 12px 22px; box-shadow: 0 6px 18px rgba(0,0,0,.28); }
.save-fab:disabled { opacity: .55; box-shadow: none; cursor: not-allowed; }
