:root {
  color-scheme: light;
  --ink: #30416a;
  --muted: #57585a;
  --line: #d4dfef;
  --panel: #ffffff;
  --page: #f4f7fb;
  --accent: #2061af;
  --accent-dark: #1558aa;
  --accent-soft: #eaf2fb;
  --danger: #a73232;
  font-family: "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--page); color: var(--ink); font-size: 15px; }
a { color: var(--accent-dark); }
.topbar { min-height: 66px; display: flex; align-items: center; gap: 28px; padding: 0 28px; background: #fff; color: var(--ink); border-bottom: 1px solid var(--line); box-shadow: 0 2px 9px rgba(48, 65, 106, .07); }
.topbar a { color: var(--ink); text-decoration: none; }
.topbar nav > a:hover { color: var(--accent); }
.topbar nav > a.active, .topbar .identity.active { font-weight: 700; }
.topbar .brand { display: flex; align-items: center; gap: 13px; font-size: 15px; font-weight: 650; margin-right: 8px; }
.topbar .brand img { width: 174px; height: auto; display: block; }
.topbar .brand img[src$="support-metrics-icon.svg"] { width: 48px; height: 48px; }
.topbar .brand span { border-left: 1px solid var(--line); padding-left: 13px; white-space: nowrap; color: var(--accent); }
.topbar nav { display: flex; align-items: center; gap: 20px; flex: 1; }
.topbar .identity { color: var(--muted); }
.topbar .identity:hover { color: var(--accent); text-decoration: underline; }
.container { max-width: 1440px; margin: 0 auto; padding: 28px; }
h1 { margin: 0 0 6px; font-size: 28px; }
h2 { margin: 0 0 16px; font-size: 19px; }
p { color: var(--muted); margin-top: 0; }
.heading-row { display: flex; justify-content: space-between; align-items: center; gap: 20px; margin-bottom: 20px; }
.panel, .auth-card, .secret-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 2px 8px rgba(48, 65, 106, .05); padding: 20px; margin-bottom: 20px; }
.auth-card { max-width: 430px; margin: 10vh auto; padding: 32px; }
.login-logo { display: block; width: min(100%, 263px); height: auto; margin: 0 0 24px; }
.stack { display: grid; gap: 18px; }
label { display: grid; gap: 6px; color: #39465a; font-size: 13px; font-weight: 650; }
input, select, textarea { width: 100%; min-height: 40px; border: 1px solid #bfc9d6; border-radius: 7px; padding: 8px 10px; background: white; color: var(--ink); font: inherit; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(21, 122, 110, .16); border-color: var(--accent); }
button, .button { display: inline-flex; align-items: center; justify-content: center; min-height: 40px; border: 1px solid var(--accent); border-radius: 7px; background: var(--accent); color: white; padding: 8px 15px; font: inherit; font-weight: 700; text-decoration: none; cursor: pointer; }
button:hover, .button:hover { background: var(--accent-dark); }
.secondary { background: white; color: var(--accent-dark); }
.secondary:hover { background: var(--accent-soft); color: var(--accent-dark); }
.danger { border-color: #d6a4a4; background: white; color: var(--danger); }
.danger:hover { border-color: var(--danger); background: #fae8e8; color: var(--danger); }
.danger-solid { border-color: var(--danger); background: var(--danger); }
.danger-solid:hover { border-color: #842626; background: #842626; }
.small { min-height: 32px; padding: 5px 10px; font-size: 13px; }
.inline, .inline-form { display: inline-flex; align-items: end; gap: 12px; margin: 0; }
.inline-form { flex-wrap: wrap; }
.inline-form label { min-width: 190px; }
.inline-form.wide label { min-width: 210px; }
.link-button { border: 0; min-height: auto; padding: 0; background: transparent; color: var(--ink); font-weight: 400; }
.link-button:hover { background: transparent; text-decoration: underline; }
.filter-grid { display: grid; grid-template-columns: repeat(6, minmax(130px, 1fr)); gap: 12px; align-items: end; }
.filter-actions { display: flex; gap: 8px; grid-column: 1 / -1; }
.table-wrap { overflow-x: auto; padding: 0; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); padding: 13px 14px; }
th { background: #f8fafc; color: #536176; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
td small { display: block; color: var(--muted); margin-top: 4px; }
time[data-local-datetime] { white-space: nowrap; font-variant-numeric: tabular-nums; }
tbody tr.is-today td { background: #edf5ff; }
tbody tr.is-today td:first-child { box-shadow: inset 3px 0 0 #7ca7d7; font-weight: 650; }
.badge { display: inline-block; border-radius: 999px; background: var(--accent-soft); color: var(--accent-dark); padding: 3px 8px; font-size: 12px; text-transform: capitalize; }
.empty { padding: 42px; text-align: center; color: var(--muted); }
.pagination { display: flex; justify-content: flex-end; align-items: center; gap: 14px; padding: 14px; }
.flash { padding: 12px 14px; border-radius: 8px; margin-bottom: 18px; background: var(--accent-soft); color: var(--accent-dark); }
.flash.error { background: #fae8e8; color: var(--danger); }
.flash.warning { background: #fff3d8; color: #74500a; }
.secret-card { border-color: #dfb750; background: #fff9e9; }
.secret-card code { user-select: all; word-break: break-all; }
.secret-card dl { display: grid; grid-template-columns: 120px 1fr; gap: 8px 15px; }
.secret-card dt { font-weight: 700; }
.secret-card dd { margin: 0; }
.checkbox { display: flex; align-items: center; flex-direction: row; min-height: 40px; }
.checkbox input { width: auto; min-height: auto; }
.action-cell { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; min-width: 220px; }
.row-actions, .form-actions { display: flex; align-items: center; gap: 8px; }
.row-actions { min-width: 132px; flex-wrap: wrap; }
.company-name-form { display: flex; align-items: center; gap: 8px; min-width: 300px; }
.company-name-form input[name="name"] { min-width: 190px; }
.edit-panel { max-width: 980px; }
.edit-grid { display: grid; grid-template-columns: repeat(2, minmax(220px, 1fr)); gap: 16px; }
.form-help { margin: -4px 0 0; font-size: 13px; }
.optional { color: var(--muted); font-size: 12px; font-weight: 400; }
.confirm-dialog { width: min(92vw, 520px); max-width: none; border: 0; border-radius: 12px; padding: 0; background: transparent; box-shadow: 0 20px 55px rgba(24, 35, 58, .28); }
.confirm-dialog::backdrop { background: rgba(26, 38, 62, .48); }
.dialog-card { margin: 0; border: 1px solid var(--line); border-radius: 12px; padding: 24px; background: #fff; }
.dialog-card h2 { margin-bottom: 8px; }
.dialog-card .interaction-summary { border-radius: 8px; padding: 11px 12px; background: var(--page); color: var(--ink); font-weight: 650; overflow-wrap: anywhere; }
.dialog-actions { justify-content: flex-end; margin-top: 22px; }
.delete-confirm { max-width: 700px; }
.delete-confirm dl { display: grid; grid-template-columns: 130px 1fr; gap: 10px 18px; margin: 0 0 24px; }
.delete-confirm dt { font-weight: 700; }
.delete-confirm dd { margin: 0; overflow-wrap: anywhere; }
.status-active { color: #237447; font-weight: 650; }
.status-inactive { color: var(--muted); }
.status-locked { color: var(--danger); font-weight: 700; }
.mfa-setup-panel { max-width: 980px; border-color: #7ca7d7; background: #f8fbff; }
.mfa-setup-grid { display: grid; grid-template-columns: minmax(220px, 280px) 1fr; align-items: center; gap: 24px; }
.mfa-qr { min-height: 220px; padding: 12px; border: 1px solid var(--line); border-radius: 9px; background: #fff; }
.mfa-qr svg { display: block; width: 100%; height: auto; }
.mfa-secret-label { display: block; margin: 14px 0 6px; font-weight: 700; }
.mfa-secret-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 9px; }
.mfa-secret { width: 100%; margin: 0; background: #eaf2fb; color: var(--ink); font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace; font-size: 15px; font-weight: 700; letter-spacing: .06em; }
.mfa-copy-status { min-height: 1.35em; margin: 7px 0 0; color: var(--accent-dark); }
.mfa-self-form { max-width: 720px; margin-top: 16px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.stats-heading { margin-bottom: 18px; }
.range-badge { flex: none; border: 1px solid var(--line); border-radius: 999px; padding: 7px 12px; background: #fff; color: var(--muted); font-size: 13px; font-weight: 650; }
.stats-controls, .filter-panel { padding: 18px 20px; }
.filter-control-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 16px; }
.filter-control-heading h2 { margin-bottom: 4px; }
.chart-heading h2 { margin-bottom: 0; }
.filter-control-heading p, .chart-heading p { margin: 0; font-size: 13px; }
.stats-presets { display: flex; flex-wrap: wrap; gap: 7px; }
.stats-preset.active, .stats-preset.active:hover { border-color: var(--accent); background: var(--accent); color: #fff; }
.stats-filter { grid-template-columns: repeat(3, minmax(160px, 1fr)); gap: 10px; }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 20px; }
.metric-card { display: grid; align-content: start; gap: 8px; min-height: 136px; padding: 19px; background: #fff; border: 1px solid var(--line); border-radius: 11px; box-shadow: 0 3px 12px rgba(48, 65, 106, .06); }
.metric-card span { color: var(--muted); font-size: 12px; font-weight: 750; letter-spacing: .035em; text-transform: uppercase; }
.metric-card strong { color: var(--ink); font-size: 34px; line-height: 1.05; }
.metric-card strong.metric-delta { color: var(--accent-dark); }
.metric-card small { color: var(--muted); line-height: 1.35; }
.trend-panel { padding: 22px 24px 18px; }
.chart-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 14px; }
.volume-figure { margin: 0; }
.volume-chart-wrap { width: 100%; overflow-x: auto; }
.volume-chart { display: block; width: 100%; min-width: 700px; height: auto; }
.chart-weekend-band { fill: #f1f3f6; }
.chart-gridline { stroke: #dfe6f0; stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart-axis-label { fill: #68758a; font-family: "Segoe UI", system-ui, sans-serif; font-size: 12px; }
.chart-date-label { font-size: 11px; }
.chart-bar { fill: var(--accent); cursor: help; outline: none; }
.chart-bar:hover { fill: var(--accent-dark); }
.chart-bar:focus { fill: var(--accent-dark); stroke: #fff; stroke-width: 2px; }
.chart-tooltip-layer { pointer-events: none; }
.chart-tooltip-layer[hidden] { display: none; }
.chart-tooltip-layer rect { fill: #243755; stroke: rgba(255, 255, 255, .75); stroke-width: 1px; }
.chart-tooltip-layer text { fill: #fff; font-family: "Segoe UI", system-ui, sans-serif; font-size: 11px; font-weight: 650; }
.chart-data { margin-top: 10px; color: var(--muted); font-size: 13px; }
.chart-data summary { width: max-content; color: var(--accent-dark); cursor: pointer; font-weight: 650; }
.chart-data-table { max-height: 260px; margin-top: 10px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.chart-data-table th, .chart-data-table td { padding: 8px 10px; }
.stats-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
.stats-grid .panel { margin-bottom: 0; }
.stats-panel { min-width: 0; }
.rank-list { display: grid; gap: 15px; }
.rank-label { display: flex; justify-content: space-between; gap: 14px; margin-bottom: 6px; }
.rank-label span { min-width: 0; overflow: hidden; color: var(--ink); text-overflow: ellipsis; white-space: nowrap; }
.rank-label strong { flex: none; color: var(--accent-dark); }
.rank-track { display: block; width: 100%; height: 8px; }
.rank-track-bg { fill: #e7edf7; }
.rank-fill { fill: var(--accent); }
.companies-panel .rank-fill { fill: #5a7fae; }
.leader-list { display: grid; gap: 0; margin: 0; padding: 0; list-style: none; }
.leader-list li { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 43px; border-bottom: 1px solid #e6ebf3; }
.leader-list li:last-child { border-bottom: 0; }
.leader-list li > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leader-list strong { color: var(--accent-dark); }
.leader-rank { display: inline-flex; align-items: center; justify-content: center; width: 25px; height: 25px; margin-right: 9px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-dark); font-size: 12px; font-weight: 750; }
.empty.compact { padding: 18px 0; }
.error-page { max-width: 650px; margin: 10vh auto; text-align: center; }
button:disabled { opacity: .45; cursor: not-allowed; }

@media (max-width: 900px) {
  .topbar { align-items: flex-start; flex-wrap: wrap; padding: 15px 18px; gap: 12px; }
  .topbar nav { order: 3; flex-basis: 100%; overflow-x: auto; }
  .container { padding: 18px; }
  .filter-grid { grid-template-columns: repeat(2, minmax(130px, 1fr)); }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats-grid { grid-template-columns: 1fr; }
  .stats-filter { grid-template-columns: repeat(2, minmax(140px, 1fr)); }
  .filter-control-heading { flex-direction: column; }
  .heading-row { align-items: flex-start; }
  .edit-grid { grid-template-columns: 1fr; }
  .mfa-setup-grid { grid-template-columns: 1fr; }
  .mfa-secret-row { grid-template-columns: 1fr; }
  .mfa-qr { max-width: 320px; }
}

@media (max-width: 560px) {
  .topbar .brand span { display: none; }
  .topbar .brand img { width: 150px; }
  .metric-grid { grid-template-columns: 1fr; }
  .delete-confirm dl { grid-template-columns: 1fr; gap: 4px; }
  .delete-confirm dd { margin-bottom: 10px; }
}
