/* ---- Palette ----------------------------------------------------
 *
 * Two complete palettes (light / dark). The "active" variables at the
 * bottom of :root point at one or the other and get re-pointed by:
 *   - @media (prefers-color-scheme: dark)          — automatic
 *   - html[data-theme="dark"]                      — manual override
 *   - html[data-theme="light"]                     — manual override
 *
 * Reports are excluded from dark mode because PDF/HTML exports are
 * meant to be printed and shared on unknown backgrounds — the
 * body.report selector at the bottom locks them back to the light
 * palette regardless of the active theme.
 * ---------------------------------------------------------------- */
:root {
  /* light palette */
  --l-fg: #1b1d22;
  --l-bg: #f7f7f9;
  --l-surface: #ffffff;
  --l-surface-alt: #eef0f4;
  --l-border: #dcdde3;
  --l-muted: #6a707b;
  --l-accent: #1f5fb0;
  --l-state: #3e885b;
  --l-key: #9a6b1a;
  --l-syslog: #7a3a9f;
  --l-dns: #0d6c8a;
  --l-named: #b03b00;
  --l-rndc: #a62e4f;

  /* dark palette */
  --d-fg: #e5e7ed;
  --d-bg: #0f1116;
  --d-surface: #181b22;
  --d-surface-alt: #22262f;
  --d-border: #2a2f3a;
  --d-muted: #8a909c;
  --d-accent: #6aa6ff;
  --d-state: #5ec07e;
  --d-key: #e0b060;
  --d-syslog: #c482e6;
  --d-dns: #4dc6e6;
  --d-named: #ff9060;
  --d-rndc: #f08099;

  /* active palette — defaults to light */
  --fg: var(--l-fg);
  --bg: var(--l-bg);
  --surface: var(--l-surface);
  --surface-alt: var(--l-surface-alt);
  --border: var(--l-border);
  --muted: var(--l-muted);
  --accent: var(--l-accent);
  --state: var(--l-state);
  --key: var(--l-key);
  --syslog: var(--l-syslog);
  --dns: var(--l-dns);
  --named: var(--l-named);
  --rndc: var(--l-rndc);

  color-scheme: light;
}

/* Auto dark via system preference, unless the user has explicitly
 * locked light mode via the toggle. */
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) {
    --fg: var(--d-fg);
    --bg: var(--d-bg);
    --surface: var(--d-surface);
    --surface-alt: var(--d-surface-alt);
    --border: var(--d-border);
    --muted: var(--d-muted);
    --accent: var(--d-accent);
    --state: var(--d-state);
    --key: var(--d-key);
    --syslog: var(--d-syslog);
    --dns: var(--d-dns);
    --named: var(--d-named);
    --rndc: var(--d-rndc);
    color-scheme: dark;
  }
}

/* Manual dark override — wins over the media query. */
html[data-theme="dark"] {
  --fg: var(--d-fg);
  --bg: var(--d-bg);
  --surface: var(--d-surface);
  --surface-alt: var(--d-surface-alt);
  --border: var(--d-border);
  --muted: var(--d-muted);
  --accent: var(--d-accent);
  --state: var(--d-state);
  --key: var(--d-key);
  --syslog: var(--d-syslog);
  --dns: var(--d-dns);
  --named: var(--d-named);
  --rndc: var(--d-rndc);
  color-scheme: dark;
}

/* Manual light override — defaults already match, but the explicit
 * rule makes sure the media query above never flips us back. */
html[data-theme="light"] {
  color-scheme: light;
}

/* ---- Base -------------------------------------------------------- */
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  color: var(--fg);
  background: var(--bg);
}
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.8rem 1.4rem;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.8rem;
}
header h1 { margin: 0; font-size: 1.2rem; }
header h1 a { text-decoration: none; color: var(--fg); }
header nav { display: flex; align-items: baseline; gap: 1rem; }
header nav a { color: var(--accent); text-decoration: none; }

#theme-toggle {
  font: inherit;
  font-size: 0.78rem;
  color: var(--muted);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.15rem 0.55rem;
  cursor: pointer;
}
#theme-toggle:hover { color: var(--fg); border-color: var(--accent); }

main { padding: 1.2rem 1.4rem 3rem; max-width: 1200px; margin: 0 auto; }

h2 { margin-top: 1.6rem; }
a { color: var(--accent); }
code {
  background: var(--surface-alt);
  color: var(--fg);
  padding: 0.05rem 0.3rem;
  border-radius: 3px;
}

/* ---- Tables ------------------------------------------------------ */
table { border-collapse: collapse; width: 100%; background: var(--surface); }
table th, table td {
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: 0.88rem;
  vertical-align: top;
}
table th { background: var(--surface-alt); font-weight: 600; }
.ts {
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 0.82rem;
  color: var(--muted);
  white-space: nowrap;
}

/* ---- Badges (source pill) --------------------------------------- */
.badge {
  display: inline-block;
  font-size: 0.72rem;
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  background: var(--surface-alt);
  color: var(--muted);
}
.src-state  .badge { background: color-mix(in srgb, var(--state)  18%, var(--surface)); color: var(--state); }
.src-key    .badge { background: color-mix(in srgb, var(--key)    18%, var(--surface)); color: var(--key); }
.src-syslog .badge { background: color-mix(in srgb, var(--syslog) 18%, var(--surface)); color: var(--syslog); }
.src-dns    .badge { background: color-mix(in srgb, var(--dns)    18%, var(--surface)); color: var(--dns); }
.src-named  .badge { background: color-mix(in srgb, var(--named)  18%, var(--surface)); color: var(--named); }
.src-rndc   .badge { background: color-mix(in srgb, var(--rndc)   18%, var(--surface)); color: var(--rndc); }

/* ---- Controls --------------------------------------------------- */
.action {
  display: inline-block;
  margin-right: 0.6rem;
  color: var(--accent);
  text-decoration: none;
  border: 1px solid var(--accent);
  padding: 0.15rem 0.5rem;
  border-radius: 3px;
  font-size: 0.82rem;
}
.action:hover { background: var(--accent); color: #fff; }

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.6rem 0.8rem;
  margin-bottom: 0.8rem;
}
.filters label {
  font-size: 0.82rem;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  position: relative;
}
.filters input[type="text"],
.filters input:not([type]),
.filters input[type="date"] {
  padding: 0.28rem 0.45rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--surface);
  color: var(--fg);
  font: inherit;
  font-size: 0.9rem;
  min-width: 180px;
}
.filters input[type="date"] {
  min-width: 150px;
  color-scheme: inherit;
}
.filters .hint {
  position: absolute;
  right: 0.35rem;
  bottom: 0.3rem;
  font-size: 0.65rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--surface-alt);
  padding: 0.05rem 0.3rem;
  border-radius: 2px;
  pointer-events: none;
}
.filters button {
  padding: 0.35rem 0.9rem;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 3px;
  cursor: pointer;
  font: inherit;
}
.filters .clear {
  font-size: 0.8rem;
  color: var(--muted);
  text-decoration: none;
  padding: 0.35rem 0.2rem;
}
.filters .clear:hover { color: var(--fg); }
.filter-note { margin: 0 0 1rem; font-size: 0.82rem; }

/* The "DNSKEY focus" preset checkbox lives alongside the regular
 * stacked labels, but its own label flows horizontally so the
 * checkbox sits next to the text. */
.filters label.preset-check {
  flex-direction: row;
  align-items: center;
  gap: 0.35rem;
  padding-bottom: 0.3rem;
  color: var(--fg);
  font-size: 0.9rem;
}
.filters select {
  padding: 0.28rem 0.45rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--surface);
  color: var(--fg);
  font: inherit;
  font-size: 0.9rem;
}

/* Filter-summary banner used on the report when a FilterSet is
 * active. Scoped inside body.report so the active variables are
 * always the light palette. */
.report .filter-summary {
  margin: 1rem 0;
  padding: 0.6rem 0.9rem;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 3px;
  font-size: 0.9rem;
  color: var(--fg);
}

.meta { color: var(--muted); font-size: 0.9rem; }
.refresh-hint {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  padding: 0.55rem 0.8rem;
  margin: 0 0 1rem;
  border-radius: 3px;
}

/* Warning banner for overdue keys (past scheduled Delete but still
 * published at the zone or DS still at the parent). Hard-coded red
 * variants because the palette has no dedicated "warning" colour and
 * this needs to read *alarming* on every background — dark UI, light
 * UI, and the always-light report body. */
.warning-banner {
  background: color-mix(in srgb, #c43030 12%, var(--surface));
  border: 1px solid #c43030;
  border-left: 4px solid #c43030;
  padding: 0.6rem 0.9rem;
  margin: 0 0 1rem;
  border-radius: 3px;
  color: var(--fg);
}
.warning-banner strong { color: #c43030; }
.warning-banner ul { margin: 0.35rem 0 0.35rem; padding-left: 1.2rem; }
.warning-banner li { margin: 0.1rem 0; font-size: 0.9rem; }
.warning-banner a { color: #c43030; font-weight: 600; }
.warning-banner p.meta { margin: 0.35rem 0 0; font-size: 0.82rem; color: var(--muted); }
/* Pin the report variant to a light-palette-safe form since the
 * report body (.report) forces color-scheme: light regardless of
 * the UI theme. */
.report .warning-banner { color: #1b1d22; background: #fbe8e8; }
.report .warning-banner p.meta { color: #6a707b; }
.timeline {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 0.6rem;
}

/* ---- Calendar scroll nav --------------------------------------- */
.cal-nav {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin: 0.2rem 0 0.6rem;
}
.cal-nav-btn {
  padding: 0.3rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--accent);
  text-decoration: none;
  font-size: 0.85rem;
  background: var(--surface);
}
.cal-nav-btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.cal-nav-current {
  font-size: 0.88rem;
  color: var(--muted);
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
}

/* ---- Calendar view --------------------------------------------- */
.calendar-view { color: var(--fg); }
.cal-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.9rem;
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 0.6rem;
}
.cal-legend-item { display: inline-flex; align-items: center; gap: 0.3rem; }
.cal-dot {
  display: inline-block;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--muted);
}
.cal-dot.src-state  { background: var(--state); }
.cal-dot.src-key    { background: var(--key); }
.cal-dot.src-syslog { background: var(--syslog); }
.cal-dot.src-dns    { background: var(--dns); }
.cal-dot.src-named  { background: var(--named); }
.cal-dot.src-rndc   { background: var(--rndc); }
.cal-dot.cal-today-dot {
  background: transparent;
  border: 2px solid var(--accent);
  width: 8px; height: 8px;
}

.cal-month {
  width: auto;
  display: inline-table;
  margin: 0 1.2rem 1.2rem 0;
  vertical-align: top;
  table-layout: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
}
.cal-month caption {
  text-align: left;
  font-weight: 600;
  padding: 0.3rem 0.5rem;
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
  caption-side: top;
}
.cal-month th {
  width: 38px;
  padding: 0.25rem 0;
  text-align: center;
  font-size: 0.72rem;
  color: var(--muted);
  background: var(--surface-alt);
}
.cal-month td.cal-cell {
  width: 38px;
  height: 44px;
  padding: 2px 3px;
  text-align: right;
  vertical-align: top;
  position: relative;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  background: var(--surface);
  color: var(--fg);
  font-size: 0.78rem;
}
.cal-month td.cal-out {
  color: var(--muted);
  opacity: 0.4;
  background: var(--bg);
}
.cal-month td.cal-today .cal-day {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-radius: 2px;
  padding: 0 2px;
}
.cal-month td.has-events { cursor: help; }
.cal-month td.count-s { background: color-mix(in srgb, var(--accent) 6%, var(--surface)); }
.cal-month td.count-m { background: color-mix(in srgb, var(--accent) 14%, var(--surface)); }
.cal-month td.count-l { background: color-mix(in srgb, var(--accent) 24%, var(--surface)); }
.cal-month td.count-xl { background: color-mix(in srgb, var(--accent) 36%, var(--surface)); }
.cal-dots {
  display: flex;
  gap: 2px;
  justify-content: flex-start;
  align-items: center;
  position: absolute;
  left: 3px;
  bottom: 2px;
}
.cal-dots .cal-dot { width: 6px; height: 6px; }
/* Scheduled marker: hollow outlined square so it reads as "this
 * hasn't happened yet, it's on the calendar" next to the solid
 * source dots for observed events. */
.cal-scheduled-marker {
  display: inline-block;
  width: 6px;
  height: 6px;
  border: 1.5px solid var(--accent);
  border-radius: 1px;
  background: transparent;
  box-sizing: border-box;
}
.cal-legend-item .cal-scheduled-marker { width: 8px; height: 8px; }
.cal-month td.has-scheduled.cal-cell:not(.has-events) {
  background: color-mix(in srgb, var(--accent) 4%, var(--surface));
}

/* ---- Event timeline chart -------------------------------------- */
.event-timeline {
  width: 100%;
  max-width: 100%;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 0.3rem;
}

/* ---- Rollover view ------------------------------------------------ */
.rollover-view {
  color: var(--fg);
}
.rollover-view svg {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
}

/* ---- Per-key timings grid -------------------------------------- */
.key-block { margin-top: 1.6rem; }
.timings-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin: 0.6rem 0 1.2rem;
}
.timings {
  width: auto;
  min-width: 260px;
  flex: 0 1 auto;
}
.timings caption {
  caption-side: top;
  text-align: left;
  font-weight: 600;
  padding: 0.3rem 0.5rem;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-bottom: 0;
}
.timings th { font-size: 0.78rem; }
.timings td { font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; font-size: 0.78rem; }

/* ---- Report (HTML + PDF export) --------------------------------
 *
 * Always use the light palette, no matter what the active UI theme is.
 * PDFs and shared HTML files need to be printable on any background,
 * so the report re-pins every active variable to its light value and
 * forces color-scheme: light.
 */
body.report {
  --fg: var(--l-fg);
  --bg: var(--l-bg);
  --surface: var(--l-surface);
  --surface-alt: var(--l-surface-alt);
  --border: var(--l-border);
  --muted: var(--l-muted);
  --accent: var(--l-accent);
  --state: var(--l-state);
  --key: var(--l-key);
  --syslog: var(--l-syslog);
  --dns: var(--l-dns);
  --named: var(--l-named);
  --rndc: var(--l-rndc);
  color-scheme: light;
  color: var(--l-fg);
  background: #fff;
}
.report { max-width: none; padding: 2.5rem 2.5rem 3rem; }
.report .cover { page-break-after: always; }
.report .cover h1 { font-size: 2rem; margin-bottom: 0.2rem; }
.report .cover h2 { font-size: 1.3rem; font-weight: 500; color: var(--muted); margin-top: 0; }
.report section { page-break-inside: avoid; margin-top: 2rem; }
.report .note { color: var(--muted); font-size: 0.88rem; }
.report pre {
  background: var(--surface-alt);
  padding: 0.7rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  overflow-x: auto;
  font-size: 0.78rem;
}
