:root {
  color-scheme: light dark;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1b1f24;
  --muted: #5d6673;
  --border: #d9dde3;
  --accent: #1f5fbf;
  --accent-text: #ffffff;
  --row-alt: #f8f9fb;
  --row-hover: #eef3fb;
  --info-bg: #e8f0fc;
  --info-text: #17407f;
  --warn-bg: #fff1d6;
  --warn-text: #7a4b00;
  --error-bg: #fde7e7;
  --error-text: #8f1d1d;
  --radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171b;
    --surface: #1d2127;
    --text: #e6e9ee;
    --muted: #9aa4b2;
    --border: #323841;
    --accent: #6ea3f5;
    --accent-text: #0e1420;
    --row-alt: #20252c;
    --row-hover: #283140;
    --info-bg: #1c2b45;
    --info-text: #b9d2fb;
    --warn-bg: #43330f;
    --warn-text: #ffd98a;
    --error-bg: #4a1c1c;
    --error-text: #ffc0c0;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 650;
}

.muted {
  color: var(--muted);
}

code {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.92em;
}

/* ---- top bar ---- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.88rem;
}

main {
  max-width: 1500px;
  margin: 0 auto;
  padding: 16px 20px 40px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* ---- filters ---- */

#filters {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px 14px;
  padding: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.field-zone {
  grid-column: span 2;
}

.field-presets {
  grid-column: span 2;
}

.field-wide {
  grid-column: span 2;
}

.field-check {
  justify-content: flex-end;
  padding-bottom: 8px;
}

.field-check label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.95rem;
  color: var(--text);
}

label,
.label {
  font-size: 0.8rem;
  color: var(--muted);
}

input,
select {
  width: 100%;
  min-height: 36px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

input[type="checkbox"] {
  width: 16px;
  min-height: 16px;
  height: 16px;
  padding: 0;
  accent-color: var(--accent);
}

input:focus-visible,
select:focus-visible,
button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.field-note {
  margin: 2px 0 0;
  font-size: 0.8rem;
  color: var(--warn-text);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  cursor: pointer;
}

.chip:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.actions {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding-top: 4px;
}

.tz-note {
  margin-left: auto;
  font-size: 0.85rem;
}

.btn {
  min-height: 36px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 550;
  cursor: pointer;
}

.btn:hover:not(:disabled) {
  border-color: var(--accent);
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.btn-primary {
  min-width: 120px;
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-text);
}

.btn-quiet {
  min-height: 30px;
  padding: 0 10px;
  font-weight: 450;
}

/* ---- status ---- */

.status {
  margin: 14px 0 0;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 0.95rem;
}

.status-info {
  background: var(--info-bg);
  color: var(--info-text);
}

.status-warn {
  background: var(--warn-bg);
  color: var(--warn-text);
  font-weight: 550;
}

.status-error {
  background: var(--error-bg);
  color: var(--error-text);
  font-weight: 550;
}

/* ---- result ---- */

.result {
  margin-top: 14px;
}

.result-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}

.summary {
  font-size: 0.9rem;
  color: var(--muted);
}

.pager {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.88rem;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

th,
td {
  padding: 7px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  padding: 0;
  background: var(--surface);
  font-size: 0.82rem;
}

.num {
  text-align: right;
}

.sort {
  width: 100%;
  padding: 9px 12px;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  text-align: inherit;
  cursor: pointer;
}

.sort:hover,
.sort.is-active {
  color: var(--text);
}

.sort-arrow {
  color: var(--accent);
}

tbody tr:nth-child(even) {
  background: var(--row-alt);
}

tbody tr:hover {
  background: var(--row-hover);
}

.strong {
  font-weight: 600;
}

.pct {
  color: var(--muted);
}

.subid-cell {
  max-width: 420px;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.9em;
}

.subid {
  color: var(--accent);
  text-decoration: none;
}

.subid:hover {
  text-decoration: underline;
}

tfoot td {
  border-top: 2px solid var(--border);
  border-bottom: 0;
  font-weight: 650;
}

tfoot .pct {
  color: var(--text);
}

/* ---- login ---- */

.login-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 20px;
}

.login-card {
  width: min(440px, 100%);
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.login-msg {
  margin: 14px 0 0;
}

.login-msg.is-error {
  color: var(--error-text);
  font-weight: 550;
}

.login-help {
  margin: 12px 0 0;
  font-size: 0.9rem;
  color: var(--muted);
}

@media (max-width: 1000px) {
  #filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .field-zone,
  .field-presets,
  .field-wide {
    grid-column: 1 / -1;
  }

  .tz-note {
    margin-left: 0;
  }
}
