/* Layout: one column. Summary + filters on top, a dense status grid below, problems first.
   Color: cool slate neutrals, one teal accent for actions, and four status colors that carry meaning.
   Type: the OS UI face (SF Pro on a Mac), tabular numbers, mono only for keys. No web fonts. */
:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --sunken: #eef2f7;
  --text: #0f172a;
  --muted: #5b6577;
  --line: #e2e7ef;
  --accent: #0f766e;
  --on-accent: #ffffff;
  --ok: #15803d;
  --suspicious: #b45309;
  --missed: #dc2626;
  --pending: #94a3b8;
  --error: #7c3aed;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --radius: 8px;
  color-scheme: light;
}

/* Set by public/js/theme.js from the saved choice or the OS setting. */
:root[data-theme="dark"] {
  --bg: #0b1016;
  --surface: #121922;
  --sunken: #18212c;
  --text: #e6edf5;
  --muted: #8d9aab;
  --line: #233040;
  --accent: #2dd4bf;
  --on-accent: #062a26;
  --ok: #34d399;
  --suspicious: #fbbf24;
  --missed: #f87171;
  --pending: #4b5868;
  --error: #a78bfa;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

.page {
  max-width: 1280px;
  margin: 0 auto;
  padding-block: 32px 48px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: grid;
  gap: 16px;
}

h1 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -0.02em; text-wrap: balance; }
h3 { margin: 14px 0 6px; font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.muted { color: var(--muted); margin: 2px 0 0; }
.empty { text-align: center; padding-block: 24px; }

/* Controls */
.masthead, .toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.actions, .chips { display: flex; flex-wrap: wrap; gap: 8px; }

button, input { font: inherit; color: var(--text); }
button, .button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text);
  text-decoration: none;
  font: inherit;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 7px 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 120ms, border-color 120ms;
}
button:hover, .button:hover { background: var(--sunken); }
button:disabled { opacity: 0.6; cursor: progress; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
button.primary:hover { background: color-mix(in srgb, var(--accent) 88%, var(--text)); }
button.icon-button { display: inline-grid; place-items: center; width: 38px; padding: 0; color: var(--muted); }
button.icon-button:hover { color: var(--text); }

/* Lucide SVGs used as masks, so they take the text color in both themes. */
.icon { width: 18px; height: 18px; background: currentColor; mask: var(--icon) center / contain no-repeat; }
.icon-sun { --icon: url("/icons/sun.svg"); }
.icon-moon { --icon: url("/icons/moon.svg"); }
.icon-file-spreadsheet { --icon: url("/icons/file-spreadsheet.svg"); }
.icon-arrow-up-narrow-wide { --icon: url("/icons/arrow-up-narrow-wide.svg"); }
.icon-arrow-down-wide-narrow { --icon: url("/icons/arrow-down-wide-narrow.svg"); }
.icon-arrow-down-up { --icon: url("/icons/arrow-down-up.svg"); }
.icon-eye { --icon: url("/icons/eye.svg"); }
.icon-eye-off { --icon: url("/icons/eye-off.svg"); }

#search {
  flex: 1 1 280px;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 12px;
}
#search:focus { border-color: var(--accent); }

.chip { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 5px 12px; }
.chip:not(.all)::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--status); }
.chip[aria-pressed="true"] { border-color: var(--status, var(--accent)); background: color-mix(in srgb, var(--status, var(--accent)) 12%, var(--surface)); }
.chip-count { color: var(--muted); font-variant-numeric: tabular-nums; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.notice { margin: 0; border-radius: var(--radius); padding: 10px 14px; }
.notice { border: 1px solid var(--missed); color: var(--missed); background: color-mix(in srgb, var(--missed) 6%, var(--surface)); }

/* Grid */
.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 1px 2px color-mix(in srgb, var(--text) 6%, transparent);
}

table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
tbody tr:last-child > td { border-bottom: none; }
th { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; background: var(--sunken); }
.num { font-variant-numeric: tabular-nums; }
#grid th:first-child, td.serial { width: 3.5rem; max-width: 3.5rem; }
td.serial { color: var(--muted); }

/* Sortable headers: the whole cell is the button; arrows show the direction, the badge the priority. */
#grid th[data-key] { padding: 0; }
.sort-button { all: unset; box-sizing: border-box; display: inline-flex; align-items: center; gap: 4px; width: 100%; padding: 10px 14px; cursor: pointer; }
.sort-button:hover { background: none; color: var(--text); }
.sort-button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
th[aria-sort="ascending"] .sort-button, th[aria-sort="descending"] .sort-button { color: var(--text); }
.sort-button .icon { width: 13px; height: 13px; flex: none; }
.sort-button .idle { opacity: 0; transition: opacity 150ms; }
.sort-button:hover .idle, .sort-button:focus-visible .idle { opacity: 0.6; }
.sort-priority { min-width: 15px; padding: 0 4px; border-radius: 999px; background: var(--accent); color: var(--on-accent); font-size: 10px; text-align: center; letter-spacing: 0; }

/* Severity stripe + a faint tint: problem rows read at a glance. */
tr.client { --stripe: transparent; }
tr.client[data-status="missed"] { --stripe: var(--missed); }
tr.client[data-status="suspicious"] { --stripe: var(--suspicious); }
tr.client[data-status="error"] { --stripe: var(--error); }
tr.client > td { background: color-mix(in srgb, var(--stripe) 5%, transparent); }
tr.client > td:first-child { box-shadow: inset 3px 0 0 var(--stripe); }
tr.client[tabindex] { cursor: pointer; }
tr.client:hover > td { background: color-mix(in srgb, var(--stripe) 5%, var(--sunken)); }

.name { display: block; font-weight: 600; }
.bucket { display: block; color: var(--muted); font: 12px var(--mono); }
.error-text { color: var(--error); white-space: normal; }

.pill {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 999px;
  color: var(--status);
  background: color-mix(in srgb, var(--status) 13%, transparent);
}

.dots { display: inline-flex; gap: 4px; vertical-align: middle; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--status); }
.dot.pending { background: transparent; box-shadow: inset 0 0 0 1.5px var(--status); }
.day-count { margin-left: 6px; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

.ok { --status: var(--ok); }
.suspicious { --status: var(--suspicious); }
.missed { --status: var(--missed); }
.pending { --status: var(--pending); }
.error { --status: var(--error); }

/* Row detail */
tr.detail > td { background: var(--bg); white-space: normal; padding: 14px 18px 18px; }
.mini th { background: transparent; }
.mini th, .mini td { padding: 5px 10px; border-bottom: none; font-size: 12px; }
.key { display: inline-flex; flex-direction: column; font-family: var(--mono); }
.key-name { white-space: nowrap; }
.key-folder { color: var(--muted); font-size: 11px; overflow-wrap: anywhere; }

.legend { display: flex; flex-wrap: wrap; gap: 16px; color: var(--muted); font-size: 12px; }
.legend .dot { margin-right: 6px; vertical-align: -1px; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* Login page: one centered card, same tokens as the dashboard. */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(380px, 100%);
  display: grid;
  gap: 10px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.login-card h1, .login-card > .muted { text-align: center; }
.field-label { margin-top: 8px; font-size: 12px; font-weight: 600; color: var(--muted); }
.password-field { position: relative; display: grid; }
.login-card input {
  padding: 9px 44px 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
}
.login-card input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.login-card button { justify-content: center; }
.login-card button.reveal { position: absolute; inset: 2px 2px 2px auto; width: 38px; border: none; background: transparent; }
.login-card button.reveal:hover { color: var(--text); }
