:root {
    color-scheme: light;
    --bg: #f6f6f4;
    --surface: #ffffff;
    --surface-2: #f0efec;
    --surface-3: #e8e7e3;
    --border: #e2e1dc;
    --text: #0b0b0b;
    --text-2: #52514e;
    --muted: #7a7974;
    --accent: #2a78d6;
    --accent-wash: rgba(42, 120, 214, 0.1);
    --accent-ink: #1c5cab;
    --grid: #ebeae6;
    --good: #0f7b3f;
    --good-wash: #e3f3e8;
    --warn: #8f5a00;
    --warn-wash: #fbf0d9;
    --bad: #b8302f;
    --bad-wash: #fbe5e4;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.06);
    --radius: 12px;
    --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
    background: var(--bg);
    color: var(--text);
    font: 14px/1.45 var(--font);
    -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* ---- top bar ---- */
.top {
    position: sticky; top: 0; z-index: 5;
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    padding: 12px 24px;
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: saturate(1.4) blur(10px);
    border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 15px; letter-spacing: -0.01em; }
.top-actions { display: flex; align-items: center; gap: 10px; min-width: 0; }
.who { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }

main { max-width: 1320px; margin: 0 auto; padding: 24px 24px 64px; outline: none; }
.loading { color: var(--muted); padding: 48px 0; text-align: center; }

/* ---- controls ---- */
select, input[type='text'], input[type='number'] {
    height: 34px; padding: 0 10px;
    background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
}
select { padding-right: 28px; }
input[type='number'] { width: 110px; text-align: right; font-variant-numeric: tabular-nums; }
input:hover, select:hover { border-color: var(--muted); }
.btn {
    display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px;
    border-radius: 8px; border: 1px solid var(--border); background: var(--surface);
    font-weight: 500; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--bad); }
.btn.small { height: 28px; padding: 0 10px; font-size: 13px; }
.link { background: none; border: 0; padding: 0; color: var(--accent-ink); cursor: pointer; font-weight: 500; text-align: left; }
.link:hover { text-decoration: underline; }

.switch { position: relative; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 36px; height: 20px; margin: 0; cursor: pointer; }
.switch .track { width: 36px; height: 20px; border-radius: 10px; background: var(--surface-3); position: relative; transition: background 0.15s; flex: none; }
.switch .track::after { content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform 0.15s; }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- figures ---- */
.figures { display: grid; grid-template-columns: 1.4fr repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }
.figure { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; min-width: 0; }
.figure .label { color: var(--text-2); font-size: 13px; }
.figure .value { font-size: 26px; font-weight: 600; letter-spacing: -0.02em; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.figure.hero .value { font-size: 40px; line-height: 1.1; }
.figure .sub { color: var(--muted); font-size: 12px; margin-top: 4px; }

/* ---- attention ---- */
.attention { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }
.notice {
    display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 10px;
    border: 1px solid var(--border); background: var(--surface); font-size: 13px; cursor: pointer;
}
.notice:hover { background: var(--surface-2); }
.notice .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.notice.warn .dot { background: var(--warn); }
.notice.bad .dot { background: var(--bad); }
.notice.info .dot { background: var(--accent); }

/* ---- needs follow-up ---- */
.followup { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 10px; margin-bottom: 20px; }
.followup h2 { margin: 0 6px 6px; font-size: 14px; font-weight: 600; }
.followup ul { list-style: none; margin: 0; padding: 0; }
.followup-item {
    display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 10px; width: 100%; padding: 8px 6px;
    border: 0; border-radius: 8px; background: none; text-align: left; font-size: 13px; cursor: pointer;
}
.followup-item:hover { background: var(--surface-2); }
.followup-item .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--bad); flex: none; align-self: center; }
.followup-note { color: var(--bad); font-size: 13px; margin: -4px 0 12px; }

/* ---- panel, tabs, toolbar ---- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.toolbar { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.tabs { display: inline-flex; background: var(--surface-2); padding: 3px; border-radius: 9px; gap: 2px; }
.tabs button { border: 0; background: transparent; height: 28px; padding: 0 14px; border-radius: 7px; cursor: pointer; font-weight: 500; color: var(--text-2); }
.tabs button[aria-selected='true'] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.toolbar .spacer { flex: 1; }
.search { width: 220px; }

/* ---- tables ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 12px; font-weight: 500; color: var(--muted); background: var(--surface); position: sticky; top: 0; }
th.num, td.num { text-align: right; }
tbody tr.row { cursor: pointer; }
tbody tr.row:hover td { background: var(--surface-2); }
tr.child td { background: color-mix(in srgb, var(--surface-2) 55%, var(--surface)); font-size: 13px; }
tr.child td:first-child { padding-left: 44px; }
tr.total td { font-weight: 600; border-bottom: 0; background: var(--surface); }
tr:last-child td { border-bottom: 0; }
.chev { display: inline-block; width: 16px; color: var(--muted); transition: transform 0.15s; }
.chev.open { transform: rotate(90deg); }
.name { font-weight: 500; }
.sub-name { color: var(--muted); font-size: 12px; margin-left: 6px; }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }
.dim { color: var(--muted); }
.chip { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: var(--surface-2); color: var(--text-2); margin-right: 4px; }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.status::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status.ok { color: var(--good); }
.status.late { color: var(--warn); }
.status.silent { color: var(--bad); }
.status.waiting { color: var(--muted); }
.status span { color: var(--text-2); }
.spark { display: block; }
.spark path { fill: none; stroke: var(--accent); stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; }
.spark circle { fill: var(--accent); }

/* ---- drawer & modal ---- */
dialog { color: var(--text); background: var(--surface); border: 1px solid var(--border); padding: 0; }
dialog::backdrop { background: rgba(10, 10, 10, 0.35); backdrop-filter: blur(1px); }
.drawer {
    margin: 0 0 0 auto; height: 100vh; max-height: 100vh; width: min(640px, 100vw);
    border-radius: 0; border-width: 0 0 0 1px; box-shadow: var(--shadow);
}
.drawer[open] { animation: slide 0.18s ease-out; }
@keyframes slide { from { transform: translateX(24px); opacity: 0.6; } }
.drawer-head { position: sticky; top: 0; z-index: 2; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 20px 24px 16px; background: var(--surface); border-bottom: 1px solid var(--border); }
.drawer-head h2 { margin: 0; font-size: 18px; letter-spacing: -0.01em; }
.drawer-head .kicker { color: var(--muted); font-size: 12px; margin-bottom: 2px; }
.drawer-body { padding: 8px 24px 32px; }
.section { padding: 18px 0; border-bottom: 1px solid var(--border); }
.section:last-child { border-bottom: 0; }
.section h3 { margin: 0 0 12px; font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.kv .k { color: var(--muted); font-size: 12px; }
.kv .v { font-size: 15px; font-weight: 500; font-variant-numeric: tabular-nums; }
.form-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.form-row label.lbl { min-width: 130px; color: var(--text-2); font-size: 13px; }
.hint { color: var(--muted); font-size: 12px; margin: -4px 0 12px 142px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.modal { width: min(520px, calc(100vw - 32px)); border-radius: var(--radius); box-shadow: var(--shadow); }
.modal form, .modal .modal-body { padding: 20px 22px; }
.modal h2 { margin: 0 0 16px; font-size: 17px; }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.modal .form-row label.lbl { min-width: 140px; }

/* ---- chart ---- */
.chart { position: relative; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .axis-text { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--accent); opacity: 0.1; }
.chart .end { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart .cross { stroke: var(--muted); stroke-width: 1; }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; }
.week-table { margin-top: 10px; max-height: 260px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; }
.week-table th, .week-table td { padding: 6px 12px; }

.tip {
    position: absolute; z-index: 50; pointer-events: none; opacity: 0;
    background: var(--text); color: var(--bg); padding: 6px 10px; border-radius: 8px; font-size: 12px;
    transform: translate(-50%, calc(-100% - 10px)); white-space: nowrap; transition: opacity 0.08s;
}
.tip.show { opacity: 1; }
.tip b { font-weight: 600; font-variant-numeric: tabular-nums; }

.toast {
    position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(16px);
    background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 13px;
    opacity: 0; pointer-events: none; transition: opacity 0.15s, transform 0.15s; z-index: 60;
}
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.error { background: var(--bad); color: #fff; }

@media (max-width: 960px) {
    .figures { grid-template-columns: repeat(2, 1fr); }
    .figure.hero { grid-column: 1 / -1; }
}
@media (max-width: 600px) {
    .top { padding: 10px 16px; }
    .who { display: none; }
    main { padding: 16px 16px 48px; }
    .search { width: 100%; }
    .grid2 { grid-template-columns: 1fr; }
    .hint { margin-left: 0; }
    th, td { padding: 8px 10px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

.gap { height: 16px; }
.gap-below { margin-bottom: 16px; }
.gap-around { margin: 8px 0 16px; }
.kv .v.small { font-size: 13px; }
.hint.flush, .dim.flush { margin: 8px 0 0; }
.grow { flex: 1; min-width: 0; }
.push-left { margin-right: auto; }

.link.edit { margin-left: 10px; font-size: 12px; color: var(--accent-ink); }
.btn.set-client { margin-left: 12px; height: 26px; }
.toolbar .btn + .btn { margin-left: -4px; }
th:first-child, td:first-child { padding-left: 16px; }
th:last-child, td:last-child { padding-right: 16px; }

/* The sign-out button in the top bar posts a form. */
form.signout { display: inline; margin: 0; }

/* ---- client contracts ---- */
input[type='date'], input[type='email'], textarea {
    height: 34px; padding: 0 10px;
    background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
}
textarea { height: auto; padding: 8px 10px; resize: vertical; font: inherit; line-height: 1.4; }
.modal.wide { width: min(640px, calc(100vw - 32px)); }
.modal .group { border: 1px solid var(--border); border-radius: 10px; padding: 12px 16px 14px; margin: 0 0 16px; min-width: 0; }
.modal .group legend { padding: 0 6px; font-weight: 600; font-size: 13px; }
.form-grid { display: grid; grid-template-columns: 150px minmax(0, 1fr); align-items: center; gap: 10px 12px; }
.form-grid .lbl { color: var(--text-2); font-size: 13px; }
.form-grid .wide { width: 100%; box-sizing: border-box; }
.chip.warn { background: var(--warn-wash); color: var(--warn); }
.chip.bad { background: var(--bad-wash); color: var(--bad); }
@media (max-width: 600px) {
    .form-grid { grid-template-columns: 1fr; gap: 4px; }
    .form-grid > div { margin-bottom: 8px; }
}
