/* Kittle Eye dashboard. Palette: a night game under the lights:
   dark turf, chalk-white lines, gold for caution, scarlet for blocks. */

:root {
  color-scheme: dark;
  --bg: #1b1f1c;
  --panel: #222723;
  --raise: #2a302b;
  --line: #343b35;
  --text: #edf0eb;
  --muted: #9ba49c;
  --faint: #6e776f;
  --pass: #6cbf7c;
  --chal: #d9b45f;
  --block: #e5584f;
  --focus: #d9b45f;
  --on-accent: #1b1f1c;
  --display: "Avenir Next Condensed", "Roboto Condensed", "Arial Narrow", "Helvetica Neue", Arial, sans-serif;
  --body: "Avenir Next", "Segoe UI", Roboto, system-ui, -apple-system, sans-serif;
  --data: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --radius: 6px;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #eef1ec;
    --panel: #fbfcfa;
    --raise: #f2f4f0;
    --line: #d6dbd3;
    --text: #1c211d;
    --muted: #5a635b;
    --faint: #8a938b;
    --pass: #2e7a42;
    --chal: #8f6d1f;
    --block: #b42318;
    --focus: #8f6d1f;
    --on-accent: #ffffff;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--body);
}

h1, h2 { margin: 0; font-weight: 650; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: var(--data); font-size: 13px; }

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

/* --------------------------------------------------------------- shell */
.shell { max-width: 1280px; margin: 0 auto; padding: 20px 24px 40px; }

.wordmark {
  font-family: var(--display);
  font-stretch: condensed;
  font-weight: 700;
  font-size: 30px;
  line-height: 1;
  letter-spacing: 0.01em;
}

.top {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; flex-direction: column; gap: 6px; }
.status-line { color: var(--muted); display: flex; align-items: center; gap: 8px; }
.status-line::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--faint);
  flex: none;
}
.status-line[data-state="on"]::before { background: var(--pass); animation: pulse 2.4s ease-in-out infinite; }
.status-line[data-state="partial"]::before { background: var(--chal); }
.status-line[data-state="off"]::before { background: var(--block); }
@keyframes pulse { 50% { opacity: 0.35; } }

.top-actions { display: flex; align-items: center; gap: 16px; }

/* ------------------------------------------------------------ overview */
.overview {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr);
  gap: 20px;
  margin: 22px 0 26px;
}
.chart-card, .tally-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.tally-card { padding: 16px 18px; }
.tally-card h2 { font-size: 15px; margin-bottom: 12px; }
.chart-card { padding: 16px 18px 12px; }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.chart-head h2 { font-size: 15px; }
#chart { display: block; width: 100%; height: 150px; }
#chart .bar.pass { fill: var(--pass); }
#chart .bar.chal { fill: var(--chal); }
#chart .bar.block { fill: var(--block); }
#chart .bar.idle { fill: var(--line); }
.chart-axis { display: flex; justify-content: space-between; color: var(--faint); font-size: 12px; margin-top: 6px; }

.tally {
  margin: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 18px;
  align-content: start;
}
.tally div { min-width: 0; }
.tally dt { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 6px; }
.tally dt[data-swatch]::before { content: ""; width: 9px; height: 9px; border-radius: 2px; flex: none; }
.tally dt[data-swatch="pass"]::before { background: var(--pass); }
.tally dt[data-swatch="chal"]::before { background: var(--chal); }
.tally dt[data-swatch="block"]::before { background: var(--block); }
.tally dd {
  margin: 2px 0 0;
  font-family: var(--display);
  font-stretch: condensed;
  font-weight: 700;
  font-size: 30px;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------- tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button {
  appearance: none;
  background: none;
  border: 0;
  border-bottom: 3px solid transparent;
  margin-bottom: -1px;
  padding: 10px 14px 9px;
  color: var(--muted);
  font: 600 14px/1.2 var(--body);
  cursor: pointer;
  white-space: nowrap;
}
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--chal); }

/* -------------------------------------------------------- panel/toolbar */
.panel { padding-top: 16px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.toolbar:empty { display: none; }
.toolbar .grow { flex: 1 1 220px; }
.toolbar .note { color: var(--muted); font-size: 13px; }

input[type="text"], input[type="search"], input[type="password"], input[type="number"], select {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 7px 10px;
  min-height: 36px;
}
input[type="search"] { width: 100%; max-width: 360px; }
input[type="number"] { width: 110px; font-variant-numeric: tabular-nums; }
input::placeholder { color: var(--faint); }

/* ------------------------------------------------------------- buttons */
.btn {
  appearance: none;
  font: 600 13px/1 var(--body);
  color: var(--text);
  background: var(--raise);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 13px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--faint); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.primary { background: var(--chal); border-color: var(--chal); color: var(--on-accent); }
.btn.danger { color: var(--block); border-color: color-mix(in srgb, var(--block) 45%, var(--line)); background: transparent; }
.btn.danger:hover { background: color-mix(in srgb, var(--block) 12%, transparent); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 12px; }

/* -------------------------------------------------------------- switch */
.switch { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; font-weight: 600; font-size: 14px; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track {
  position: relative;
  width: 36px;
  height: 20px;
  border-radius: 10px;
  background: var(--line);
  transition: background 0.15s;
  flex: none;
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text);
  transition: transform 0.15s;
}
.switch input:checked + .switch-track { background: var(--pass); }
.switch input:checked + .switch-track::after { transform: translateX(16px); background: var(--on-accent); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--focus); outline-offset: 2px; }

/* -------------------------------------------------------------- tables */
.table-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left;
  font-weight: 600;
  font-size: 13px;
  color: var(--muted);
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: sticky;
  top: 0;
  white-space: nowrap;
}
td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--raise); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.wrap { max-width: 340px; overflow-wrap: anywhere; }
td.nowrap { white-space: nowrap; }
td.actions { white-space: nowrap; text-align: right; }
td.actions .btn + .btn { margin-left: 6px; }
.sub { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }

.chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  background: color-mix(in srgb, var(--faint) 18%, transparent);
  color: var(--muted);
}
.chip.pass { background: color-mix(in srgb, var(--pass) 16%, transparent); color: var(--pass); }
.chip.chal { background: color-mix(in srgb, var(--chal) 16%, transparent); color: var(--chal); }
.chip.block { background: color-mix(in srgb, var(--block) 16%, transparent); color: var(--block); }

.link {
  appearance: none;
  background: none;
  border: 0;
  padding: 0;
  color: inherit;
  font: inherit;
  text-decoration: underline;
  text-decoration-color: var(--faint);
  text-underline-offset: 3px;
  cursor: pointer;
}
.link:hover { text-decoration-color: var(--text); }

.empty {
  padding: 36px 18px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

/* -------------------------------------------------------- forms/settings */
.ban-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.field input, .field select { color: var(--text); }

.settings { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 18px; }
.group { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.group h3 { margin: 0 0 10px; font-size: 15px; font-weight: 650; }
.setting { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 10px 0; border-top: 1px solid var(--line); }
.setting:first-of-type { border-top: 0; }
.setting-label { min-width: 0; }
.setting-label span { display: block; font-weight: 600; font-size: 14px; }
.setting-label small { display: block; color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.setting-label .changed { color: var(--chal); }
.settings-note { color: var(--muted); font-size: 13px; margin-bottom: 14px; }
.settings-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }

/* --------------------------------------------------------------- login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 26px 24px;
}
.login-card .wordmark { margin-bottom: 8px; }
.login-card h1 { font-size: 18px; }
.login-card label { font-weight: 600; font-size: 13px; margin-top: 8px; }
.login-card .btn { margin-top: 6px; padding: 11px 14px; font-size: 14px; }
.form-error { color: var(--block); font-size: 13px; min-height: 1em; }

/* -------------------------------------------------------------- drawer */
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(560px, 100%);
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: -12px 0 32px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  z-index: 20;
}
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { font-size: 17px; }
.drawer-body { padding: 16px 20px 28px; overflow-y: auto; }
.drawer-body h3 { font-size: 14px; margin: 20px 0 8px; }
.kv { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 6px 14px; margin: 0; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.reasons { margin: 0; padding-left: 18px; font-size: 13.5px; }

/* -------------------------------------------------------------- toasts */
.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 30; max-width: min(420px, calc(100% - 40px)); }
.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--raise);
  border: 1px solid var(--line);
  border-left: 3px solid var(--pass);
  border-radius: var(--radius);
  padding: 10px 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  font-size: 14px;
}
.toast.error { border-left-color: var(--block); }
.toast span { flex: 1; }

.foot { margin-top: 28px; color: var(--faint); font-size: 12px; }

/* ---------------------------------------------------------- responsive */
@media (max-width: 880px) {
  .shell { padding: 16px 14px 32px; }
  .overview { grid-template-columns: 1fr; }
  .top { align-items: flex-start; }
}

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