:root {
  color-scheme: light;
  --gold: #be9235;
  --gold-hover: #a97f2a;
  --gold-soft: #e7cf96;
  --ink: #141519;
  --bg: #f5f3ee;
  --card: #ffffff;
  --surface-2: #fcfbf8;
  --surface-3: #efece4;
  --chip: #eeeae0;
  --input: #ffffff;
  --text: #22242a;
  --muted: #6b6f78;
  --faint: #b3ada0;
  --line: #e4e0d6;
  --link: #8a6720;
  --danger: #b4423a;
  --danger-bg: #fbecea;
  --ok: #2f7d4f;
  --ok-bg: #e8f4ec;
  --gold-bg: #f6ecd6;
  --good-text: #006300;
  --good-bg: #e6f4e6;
  --warn-text: #7a5200;
  --warn-bg: #fdf1d6;
  --crit-text: #a12a2a;
  --crit-bg: #fbe4e4;
  --crit: #d03b3b;
  --overdue-line: #e9b8b5;
  --chart-ink: #0b0b0b;
  --chart-ink-2: #52514e;
  --chart-muted: #898781;
  --chart-grid: #e1e0d9;
  --chart-axis: #c3c2b7;
  --chart-surface: #ffffff;
  --positive: #2a78d6;
  --negative: #e34948;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #6250d6;
  --series-8: #e34948;
  --series-other: #898781;
  --event-meeting: #eef4fc;
  --event-delivery: #fdf0ea;
  --event-follow: #e8f7f1;
  --event-other: #f1f0ec;
  --radius: 10px;
  font-family: "Titillium Web", system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1012;
    --card: #17181c;
    --surface-2: #1c1d22;
    --surface-3: #131417;
    --chip: #26282e;
    --input: #121316;
    --text: #ebe6dc;
    --muted: #9c978c;
    --faint: #5c5a55;
    --line: #2a2c32;
    --link: #d9b766;
    --danger: #ef8a83;
    --danger-bg: #3a1d1c;
    --ok: #7fcf9a;
    --ok-bg: #16301f;
    --gold-bg: #33291a;
    --good-text: #6fd06f;
    --good-bg: #15301a;
    --warn-text: #f3c45c;
    --warn-bg: #3a2e12;
    --crit-text: #f19a9a;
    --crit-bg: #3d1c1c;
    --overdue-line: #6b2f2c;
    --chart-ink: #f0efec;
    --chart-ink-2: #c3c2b7;
    --chart-muted: #898781;
    --chart-grid: #2c2c2a;
    --chart-axis: #383835;
    --chart-surface: #17181c;
    --positive: #3987e5;
    --negative: #e66767;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
    --event-meeting: #172536;
    --event-delivery: #36211a;
    --event-follow: #12302a;
    --event-other: #24252a;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1012;
  --card: #17181c;
  --surface-2: #1c1d22;
  --surface-3: #131417;
  --chip: #26282e;
  --input: #121316;
  --text: #ebe6dc;
  --muted: #9c978c;
  --faint: #5c5a55;
  --line: #2a2c32;
  --link: #d9b766;
  --danger: #ef8a83;
  --danger-bg: #3a1d1c;
  --ok: #7fcf9a;
  --ok-bg: #16301f;
  --gold-bg: #33291a;
  --good-text: #6fd06f;
  --good-bg: #15301a;
  --warn-text: #f3c45c;
  --warn-bg: #3a2e12;
  --crit-text: #f19a9a;
  --crit-bg: #3d1c1c;
  --overdue-line: #6b2f2c;
  --chart-ink: #f0efec;
  --chart-ink-2: #c3c2b7;
  --chart-muted: #898781;
  --chart-grid: #2c2c2a;
  --chart-axis: #383835;
  --chart-surface: #17181c;
  --positive: #3987e5;
  --negative: #e66767;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;
  --event-meeting: #172536;
  --event-delivery: #36211a;
  --event-follow: #12302a;
  --event-other: #24252a;
}

* { box-sizing: border-box; }

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

a { color: var(--link); }

h1, h2, h3, h4 { margin: 0 0 12px; font-weight: 700; letter-spacing: -.005em; }
h1 { font-size: 26px; }
h2 { font-size: 19px; }
h3 { font-size: 16px; }

td.num, th.num { font-variant-numeric: tabular-nums; }

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 24px;
  height: 56px;
  background: var(--ink);
  color: #f3eee3;
}

.topbar a { color: #f3eee3; text-decoration: none; }
.topbar a:hover, .topbar a.active { color: var(--gold-soft); }

.brand {
  font-weight: 700;
  letter-spacing: .16em;
  text-transform: uppercase;
  font-size: 14px;
  color: var(--gold) !important;
  white-space: nowrap;
}

.topbar nav { display: flex; gap: 18px; flex: 1; }
.topbar .user { display: flex; align-items: center; gap: 14px; font-size: 13px; color: #c9b892; }

.container { max-width: 1360px; margin: 0 auto; padding: 24px clamp(16px, 2.5vw, 32px); }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.page-header h1 { margin: 0; }
.page-header .subtitle { color: var(--muted); font-size: 14px; }

.card {
  container-type: inline-size;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}

.grid { display: grid; gap: 20px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); align-items: start; }

.stats { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 140px), 1fr)); }
.stat {
  display: block;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  text-decoration: none;
  color: var(--text);
  background: var(--surface-2);
}
.stat:hover { border-color: var(--gold); }
.stat strong { display: block; font-size: 22px; }
.stat span { color: var(--muted); font-size: 13px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; }
td.num, th.num { text-align: right; white-space: nowrap; }
td.actions { text-align: right; white-space: nowrap; }
td.actions > * { margin: 2px 0 2px 6px; }
.grid td.actions { white-space: normal; }
.grid td.actions > * { display: inline-block; }
.card > .toolbar:last-child { margin-bottom: 0; }
tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }

.btn, button, input[type=submit] {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.2;
}
.btn:hover, button:hover { border-color: var(--gold); }
.btn-primary, input[type=submit] { background: var(--gold); border-color: var(--gold); color: var(--ink); }
.btn-primary:hover, input[type=submit]:hover { background: var(--gold-hover); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-link { border: 0; background: none; padding: 0; color: var(--link); font-weight: 600; }
form.inline { display: inline; }

.form { max-width: 640px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 700; font-size: 14px; margin-bottom: 4px; }
.field .hint { color: var(--muted); font-size: 13px; margin-top: 4px; }
.field.checkbox label { display: inline-flex; align-items: center; gap: 8px; font-weight: 400; }

input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=datetime-local], input[type=search], input[type=file], select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  background: var(--input);
  color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold-soft); border-color: var(--gold); }
input:disabled { opacity: .7; }
input[type=file] { min-width: 0; max-width: 100%; }
textarea { min-height: 80px; }
.form-actions { display: flex; gap: 10px; align-items: center; margin-top: 18px; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; }
.flash.notice { background: var(--ok-bg); color: var(--ok); }
.flash.alert { background: var(--danger-bg); color: var(--danger); }
.flash.alert a { color: inherit; }

.errors { background: var(--danger-bg); color: var(--danger); padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; }
.errors ul { margin: 6px 0 0; padding-left: 18px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 700; background: var(--chip); color: var(--muted); }
.badge.on { background: var(--ok-bg); color: var(--ok); }
.badge.gold { background: var(--gold-bg); color: var(--link); }

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

.tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.tabs a { padding: 8px 12px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--text); border-bottom-color: var(--gold); font-weight: 700; }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar form { display: flex; gap: 8px; align-items: center; }
.toolbar input, .toolbar select { width: auto; }

.pagination { display: flex; gap: 8px; justify-content: center; align-items: center; margin-top: 14px; }

.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: radial-gradient(120% 90% at 50% 14%, #1b1c1f 0%, #0a0a0b 48%, #000 100%);
  color-scheme: dark;
}
.auth-card {
  width: min(380px, calc(100vw - 32px));
  background: #16171b;
  border: 1px solid rgba(190, 146, 53, .35);
  border-radius: 14px;
  padding: 32px;
  color: #f3eee3;
}
.auth-logo { display: block; width: 200px; max-width: 70%; height: auto; margin: 0 auto; }
.auth-card .divider { width: 74px; height: 1px; background: var(--gold); margin: 16px auto 22px; }
.auth-card label { color: #c9b892; }
.auth-card input[type=email], .auth-card input[type=password] { background: #0f1013; border-color: #33343a; color: #f3eee3; }
.auth-card input[type=submit] { width: 100%; justify-content: center; padding: 11px; }
.auth-card a { color: var(--gold-soft); font-size: 14px; }
.auth-card .footer { text-align: center; margin-top: 16px; }
.auth-card .muted { color: #a59e8f; }

.viewer-body { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
.viewer-body .topbar { height: 46px; flex: none; }
.viewer-logo { height: 30px; width: auto; display: block; }
.viewer-frame { flex: 1; width: 100%; border: 0; background: #0a0a0b; }
.save-status { font-size: 13px; color: #c9b892; }
.save-status[data-status=error] { color: #e39b95; }
.save-status[data-status=readonly] { color: var(--gold-soft); }
.viewer-empty { flex: 1; display: grid; place-items: center; color: #c9b892; background: #0a0a0b; text-align: center; padding: 24px; }

.app-body { display: flex; min-height: 100vh; }

.sidebar {
  position: sticky;
  top: 0;
  flex: none;
  width: 248px;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--ink);
  color: #f3eee3;
  padding: 18px 14px 16px;
  overflow-y: auto;
  border-right: 1px solid #222329;
}

.sidebar-brand { display: block; text-decoration: none; padding: 4px 10px 18px; border-bottom: 1px solid #2a2b30; margin-bottom: 10px; }
.sidebar-logo { display: block; width: 100%; max-width: 180px; height: auto; margin: 0 auto; }

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-section { color: #77705f; font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; padding: 14px 10px 6px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 9px 10px;
  border-radius: 8px;
  color: #d8d1c2;
  text-decoration: none;
  font-size: 15px;
  font-weight: 600;
  border: 0;
  background: none;
  cursor: pointer;
  text-align: left;
}
.nav-item:hover { background: #1f2126; color: #fff; border: 0; }
.nav-item.active { background: rgba(190, 146, 53, .16); color: var(--gold-soft); }
.nav-item.active .nav-icon { color: var(--gold); }
.nav-icon { width: 18px; height: 18px; flex: none; color: #9a927f; }
.nav-count { margin-left: auto; min-width: 20px; padding: 1px 7px; border-radius: 99px; background: #2f3138; color: #f3eee3; font-size: 12px; font-weight: 700; text-align: center; }
.nav-count.alert { background: var(--crit); color: #fff; }

.theme-dark-label, .theme-sun { display: none; }
:root[data-theme="dark"] .theme-dark-label, :root[data-theme="dark"] .theme-sun { display: inline; }
:root[data-theme="dark"] .theme-light-label, :root[data-theme="dark"] .theme-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-dark-label, :root:not([data-theme="light"]) .theme-sun { display: inline; }
  :root:not([data-theme="light"]) .theme-light-label, :root:not([data-theme="light"]) .theme-moon { display: none; }
}

.sidebar-footer { border-top: 1px solid #2a2b30; padding-top: 12px; display: flex; flex-direction: column; gap: 2px; }
.sidebar-footer form { margin: 0; }
.sidebar-user { padding: 4px 10px 10px; overflow: hidden; }
.sidebar-user strong { display: block; font-size: 14px; }
.sidebar-user small { display: block; color: #8d8577; font-size: 13px; text-overflow: ellipsis; overflow: hidden; white-space: nowrap; }

.main { flex: 1; min-width: 0; }

.kpis { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr)); margin-bottom: 20px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; text-decoration: none; color: var(--text); display: block; }
a.kpi:hover { border-color: var(--gold); }
.kpi-label { color: var(--muted); font-size: 13px; font-weight: 700; }
.kpi-value { font-size: 28px; font-weight: 700; margin: 2px 0 0; letter-spacing: -.01em; line-height: 1.25; }
.kpi-meta { color: var(--muted); font-size: 13px; }
.delta-up { color: var(--good-text); font-weight: 700; }
.delta-down { color: var(--danger); font-weight: 700; }

.hero { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 22px; margin-bottom: 20px; display: flex; flex-wrap: wrap; gap: 20px 28px; align-items: center; }
.hero-figure { font-size: clamp(38px, 6vw, 50px); font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.hero-split { display: grid; gap: 12px; grid-template-columns: repeat(3, minmax(0, 1fr)); flex: 1 1 420px; max-width: 760px; margin-left: auto; }
.hero-split.kpi-row { grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr)); }
.kpi-row .kpi-value { white-space: nowrap; font-size: clamp(20px, 5.4vw, 28px); }

.health-pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 8px; border-radius: 99px; font-size: 13px; font-weight: 700; white-space: nowrap; }
.health-pill svg { width: 14px; height: 14px; flex: none; }
.health-pill.healthy { background: var(--good-bg); color: var(--good-text); }
.health-pill.attention { background: var(--warn-bg); color: var(--warn-text); }
.health-pill.critical { background: var(--crit-bg); color: var(--crit-text); }

.health-tile { display: flex; align-items: center; justify-content: flex-start; flex-wrap: wrap; gap: 8px 12px; min-width: 0; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); }
.health-tile strong { font-size: 26px; }

.chart-card { position: relative; }
.chart-box { position: relative; height: 300px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.card-head .muted { font-size: 13px; }

.segmented { display: inline-flex; padding: 3px; border-radius: 9px; background: var(--chip); gap: 2px; }
.segmented button { border: 0; background: none; padding: 6px 12px; font-size: 13px; color: var(--muted); border-radius: 7px; }
.segmented button:hover { color: var(--text); border: 0; }
.segmented button[aria-pressed="true"] { background: var(--card); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }

.client-key { display: inline-flex; align-items: center; gap: 8px; }
.client-swatch { width: 10px; height: 10px; border-radius: 99px; flex: none; background: var(--series-other); box-shadow: 0 0 0 2px var(--card); }
.client-swatch.s1 { background: var(--series-1); }
.client-swatch.s2 { background: var(--series-2); }
.client-swatch.s3 { background: var(--series-3); }
.client-swatch.s4 { background: var(--series-4); }
.client-swatch.s5 { background: var(--series-5); }
.client-swatch.s6 { background: var(--series-6); }
.client-swatch.s7 { background: var(--series-7); }
.client-swatch.s8 { background: var(--series-8); }

.legend { display: flex; flex-wrap: wrap; gap: 8px 18px; margin: 0 0 10px; padding: 0; list-style: none; font-size: 14px; color: var(--muted); }

.client-cards { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); margin-bottom: 20px; }
.client-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; position: relative; overflow: hidden; }
.client-card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--card-color, var(--series-other)); }
.client-card header { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.client-card header a { color: var(--text); font-weight: 700; text-decoration: none; font-size: 16px; }
.client-card header a:hover { color: var(--link); }
.client-figures { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.client-figures dt { color: var(--muted); font-size: 12px; font-weight: 700; }
.client-figures dd { margin: 0; font-size: clamp(15px, 4.2vw, 18px); font-weight: 700; white-space: nowrap; }
.client-figures dd.neg { color: var(--danger); }
.spend { margin-top: 14px; }
.spend-track { height: 8px; border-radius: 99px; background: var(--chip); overflow: hidden; }
.spend-fill { height: 100%; border-radius: 99px; background: var(--card-color, var(--series-other)); }
.spend-fill.over { background: var(--negative); }
.spend small { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 13px; margin-top: 4px; }
.spend small strong { color: var(--text); }
.client-card.c1 { --card-color: var(--series-1); }
.client-card.c2 { --card-color: var(--series-2); }
.client-card.c3 { --card-color: var(--series-3); }
.client-card.c4 { --card-color: var(--series-4); }
.client-card.c5 { --card-color: var(--series-5); }
.client-card.c6 { --card-color: var(--series-6); }
.client-card.c7 { --card-color: var(--series-7); }
.client-card.c8 { --card-color: var(--series-8); }

.reasons { margin: 4px 0 0; padding: 0; list-style: none; font-size: 13px; color: var(--muted); }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list .when { flex: none; width: 54px; text-align: center; border: 1px solid var(--line); border-radius: 8px; padding: 4px 0; background: var(--surface-2); }
.list .when strong { display: block; font-size: 18px; line-height: 1.1; }
.list .when small { display: block; font-size: 11px; text-transform: uppercase; color: var(--muted); }
.list .body { flex: 1; min-width: 0; }
.list .body small { color: var(--muted); display: block; font-size: 13px; }

.calendar { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.calendar .dow { padding: 8px; font-size: 12px; font-weight: 700; text-transform: uppercase; color: var(--muted); border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); background: var(--surface-2); }
.calendar .day { min-height: 108px; padding: 6px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 4px; }
.calendar .day.other { background: var(--surface-3); color: var(--faint); }
.calendar .day.today .num { background: var(--gold); color: var(--ink); }
.calendar .num { align-self: flex-start; font-size: 13px; font-weight: 700; padding: 1px 7px; border-radius: 99px; text-decoration: none; color: inherit; }
.calendar .num:hover { background: var(--chip); }
.event { display: block; font-size: 13px; padding: 3px 6px; border-radius: 6px; background: var(--event-meeting); border-left: 3px solid var(--series-1); color: var(--text); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.event.delivery { background: var(--event-delivery); border-left-color: var(--series-2); }
.event.follow_up { background: var(--event-follow); border-left-color: var(--series-3); }
.event.other { background: var(--event-other); border-left-color: var(--series-other); }
.event.done { opacity: .55; text-decoration: line-through; }
.event.cancelled { opacity: .45; text-decoration: line-through; }

.board { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 290px), 1fr)); align-items: start; }
.column { background: var(--surface-3); border-radius: var(--radius); padding: 12px; }
.column h3 { display: flex; justify-content: space-between; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 10px; }
.point { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin-bottom: 10px; }
.point:last-child { margin-bottom: 0; }
.point h4 { margin: 0 0 4px; font-size: 15px; }
.point p { margin: 6px 0; color: var(--muted); font-size: 14px; }
.point .meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 13px; color: var(--muted); }
.point .actions { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.point.overdue { border-color: var(--overdue-line); }
.badge.high { background: var(--crit-bg); color: var(--crit-text); }
.badge.medium { background: var(--warn-bg); color: var(--warn-text); }
.badge.low { background: var(--chip); color: var(--muted); }
.badge.late { background: var(--crit); color: #fff; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
details.table-view summary { cursor: pointer; color: var(--muted); font-size: 13px; margin-top: 10px; }

.mobile-bar, .drawer-backdrop { display: none; }

.stack-table td::before { content: none; }

@container (max-width: 760px) {
  .stack-table thead { display: none; }
  .stack-table, .stack-table tbody, .stack-table tr, .stack-table td { display: block; width: 100%; }
  .stack-table tr { padding: 12px 0; border-bottom: 1px solid var(--line); }
  .stack-table tr:last-child { border-bottom: 0; }
  .stack-table td { padding: 3px 0; border: 0; text-align: right; white-space: normal; overflow-wrap: anywhere; }
  .stack-table td::before { content: attr(data-label); float: left; margin-right: 12px; color: var(--muted); font-size: 13px; font-weight: 600; text-align: left; }
  .stack-table td.primary { display: block; text-align: left; padding-bottom: 6px; }
  .stack-table td.primary::before, .stack-table td.actions::before { content: none; }
  .stack-table td.actions { display: flex; justify-content: flex-start; flex-wrap: wrap; gap: 6px; padding-top: 8px; }
  .stack-table td.actions > * { margin: 0; }
  .stack-table td:empty { display: none; }
}

@container (max-width: 1040px) {
  .stack-wide thead { display: none; }
  .stack-wide, .stack-wide tbody, .stack-wide tr, .stack-wide td { display: block; width: 100%; }
  .stack-wide tbody { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); }
  .stack-wide tr { padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); }
  .stack-wide td { padding: 4px 0; border: 0; text-align: right; }
  .stack-wide td::before { content: attr(data-label); float: left; margin-right: 12px; color: var(--muted); font-size: 13px; font-weight: 600; text-align: left; }
  .stack-wide td.primary { display: block; text-align: left; padding-bottom: 8px; margin-bottom: 4px; border-bottom: 1px solid var(--line); }
  .stack-wide td.primary::before { content: none; }
  .stack-wide td.num .muted { display: inline; margin-left: 6px; }
  .stack-wide td::after, .stack-table td::after { content: ""; display: table; clear: both; }
}

@media (max-width: 1099px) {
  .app-body { display: block; }
  .mobile-bar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 12px;
    height: 56px;
    padding: 0 12px;
    background: var(--ink);
    color: #f3eee3;
    border-bottom: 1px solid #222329;
  }
  .menu-button { display: grid; place-items: center; width: 40px; height: 40px; padding: 0; border: 0; border-radius: 8px; background: none; color: #f3eee3; }
  .menu-button:hover { background: #1f2126; border: 0; }
  .menu-button svg { width: 22px; height: 22px; }
  .mobile-brand { display: flex; }
  .mobile-logo { height: 40px; width: auto; }
  .mobile-title { font-weight: 700; font-size: 15px; color: #d8d1c2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 50;
    width: min(290px, 86vw);
    height: 100dvh;
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: none;
  }
  .drawer-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .45); }
  .drawer-backdrop { display: block; position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .5); opacity: 0; pointer-events: none; transition: opacity .22s ease; }
  .drawer-open .drawer-backdrop { opacity: 1; pointer-events: auto; }
  .drawer-open { overflow: hidden; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar, .drawer-backdrop { transition: none; }
}

@media (min-width: 721px) and (max-width: 900px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .container { padding: 16px; }
  .page-header { align-items: flex-start; }
  .page-header .toolbar { width: 100%; }
  .card { padding: 16px; }
  .hero { padding: 16px; }
  .hero-split { flex-basis: 100%; gap: 8px; max-width: none; margin-left: 0; }
  .health-tile { flex-direction: column; align-items: flex-start; padding: 10px; }
  .health-tile strong { font-size: 22px; }
  .chart-box { height: 240px; }
  .tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .tabs a { white-space: nowrap; }
  .toolbar input[type=search] { flex: 1; min-width: 0; }
  .toolbar form { flex-wrap: wrap; max-width: 100%; }
  .toolbar input[type=file] { width: 100%; }
  .calendar .day { min-height: 52px; padding: 4px; flex-direction: row; flex-wrap: wrap; align-content: flex-start; gap: 3px; }
  .calendar .num { flex-basis: 100%; padding: 0 5px; }
  .calendar .dow { padding: 6px 2px; text-align: center; font-size: 10px; }
  .calendar .event { width: 8px; height: 8px; padding: 0; border: 0; border-radius: 99px; font-size: 0; background: var(--series-1); }
  .calendar .event.delivery { background: var(--series-2); }
  .calendar .event.follow_up { background: var(--series-3); }
  .calendar .event.other { background: var(--series-other); }
  .client-figures { gap: 6px; }
  .list li { flex-wrap: wrap; }
  .list li:has(.when) .body { flex: 1 1 calc(100% - 66px); }
  .list li:has(.when) > form { margin-left: 66px; }
  h1 { font-size: 23px; }
}

@media (max-width: 720px) {
  .viewer-body .topbar { gap: 12px; padding: 0 12px; overflow-x: auto; }
  .viewer-body .topbar .user > :not(.save-status):not(form) { display: none; }
}
