/* DMARC Observer — application stylesheet.
 *
 * Compiled into the binary (routes/assets.rs) and served at /static/app.css;
 * no external CSS. A compact layout for scanning reports: 14px text, tight
 * tables, a slim top bar, full-width content. Styles plain HTML elements plus
 * a few conventions the templates use: role="group" for inline rows,
 * role="button" for link-buttons, .secondary / .outline / .small buttons,
 * details.dropdown for the account menu, and .page-head / .narrow / .muted.
 * The current page's nav link is highlighted by matching <body data-section>
 * against the link's data-nav (templates/base.html).
 */

/* ── Tokens ──────────────────────────────────────────────────────────────── */

:root {
  --bg:          #f5f6f8;
  --surface:     #ffffff;
  --surface-2:   #eceff3;
  --text:        #1c222d;
  --muted:       #5c6677;
  --border:      #dce0e6;
  --accent:      #2f5fd0;
  --accent-text: #ffffff;
  --ok:          #1a7f45;
  --bad:         #c0362c;
  --warn:        #9a6400;
  --focus:       rgb(47 95 208 / 0.35);

  --font:  system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono:  ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --radius: 5px;
  --gap:    12px;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:          #12151b;
    --surface:     #1a1f27;
    --surface-2:   #252b35;
    --text:        #e3e7ee;
    --muted:       #98a2b3;
    --border:      #2f3642;
    --accent:      #6b93ff;
    --accent-text: #0d1220;
    --ok:          #45b36d;
    --bad:         #ef6b5f;
    --warn:        #d9a33a;
    --focus:       rgb(107 147 255 / 0.4);
    color-scheme: dark;
  }
}

/* ── Base ────────────────────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; }

html { font-size: 14px; -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
}

h1, h2, h3, h4 { margin: 0 0 0.5rem; line-height: 1.25; font-weight: 600; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.25rem; margin-top: 0.25rem; }
h3 { font-size: 1.05rem; margin-top: 1.25rem; }
h4 { font-size: 1rem; }

p, ul, ol, dl { margin: 0 0 0.75rem; }
small { font-size: 0.857rem; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1rem 0; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

code, kbd, pre { font-family: var(--mono); font-size: 0.9em; }
code { background: var(--surface-2); padding: 0.05em 0.35em; border-radius: 3px; }
kbd {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 3px; padding: 0.05em 0.35em;
}
pre {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0.6rem 0.75rem;
  overflow-x: auto; margin: 0 0 0.75rem;
}
pre code { background: none; padding: 0; }

hgroup { margin-bottom: 1rem; }
hgroup > :first-child { margin-bottom: 0.15rem; }
hgroup > p { color: var(--muted); margin: 0; }

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

/* ── Page shell ──────────────────────────────────────────────────────────── */

.container { max-width: 1400px; margin: 0 auto; padding: 0 20px; }

body > header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}

header nav {
  display: flex; align-items: center; justify-content: space-between;
  min-height: 44px; gap: 1rem;
}
header nav ul {
  display: flex; align-items: center; gap: 1.1rem;
  list-style: none; margin: 0; padding: 0;
}
header nav strong { font-size: 1.05rem; }
header nav a { color: var(--text); }
header nav a:hover { color: var(--accent); text-decoration: none; }
header nav ul:first-child { flex-wrap: wrap; row-gap: 0; }
header nav ul:first-child a[data-nav] {
  display: block; padding: 0.7rem 0 calc(0.7rem - 2px);
  border-bottom: 2px solid transparent;
}

/* Current page: one selector per section named in templates/base.html. */
body[data-section="dashboard"] [data-nav="dashboard"],
body[data-section="domains"] [data-nav="domains"],
body[data-section="reports"] [data-nav="reports"],
body[data-section="sources"] [data-nav="sources"],
body[data-section="messages"] [data-nav="messages"],
body[data-section="admin-domains"] [data-nav="admin-domains"],
body[data-section="admin-users"] [data-nav="admin-users"],
body[data-section="admin-sso"] [data-nav="admin-sso"],
body[data-section="admin-tenants"] [data-nav="admin-tenants"] {
  color: var(--accent); border-bottom-color: var(--accent);
}

main.container { padding-top: 1.25rem; padding-bottom: 2.5rem; }

.page-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; margin-bottom: 0.75rem;
}
.page-head > * { margin-bottom: 0; }

/* ── Account dropdown (details.dropdown) ─────────────────────────────────── */

details.dropdown { position: relative; }
details.dropdown > summary {
  list-style: none; cursor: pointer; color: var(--text);
  padding: 0.2rem 0.6rem; border: 1px solid var(--border); border-radius: var(--radius);
}
details.dropdown > summary::-webkit-details-marker { display: none; }
details.dropdown > summary::after { content: " ▾"; color: var(--muted); }
details.dropdown[open] > summary { background: var(--surface-2); }
details.dropdown > ul {
  position: absolute; right: 0; top: calc(100% + 4px); min-width: 180px;
  display: block; padding: 0.3rem; margin: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.12);
}
details.dropdown > ul li { list-style: none; }
details.dropdown > ul a, details.dropdown > ul button {
  display: block; width: 100%; text-align: left;
  padding: 0.35rem 0.6rem; border-radius: 3px;
}
details.dropdown > ul a:hover { background: var(--surface-2); text-decoration: none; }
details.dropdown > ul form { margin: 0; }
details.dropdown .menu-label {
  padding: 0.3rem 0.6rem 0.15rem; font-size: 0.8rem; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
details.dropdown .menu-group { border-top: 1px solid var(--border); margin-top: 0.3rem; padding-top: 0.45rem; }
details.dropdown li.menu-group:not(.menu-label) { padding-top: 0.3rem; }

/* ── Cards ───────────────────────────────────────────────────────────────── */

article {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  margin: 0 0 var(--gap);
}
article > :last-child { margin-bottom: 0; }
.narrow { max-width: 520px; }

/* ── Tables ──────────────────────────────────────────────────────────────── */

figure {
  margin: 0 0 1rem;
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
th, td {
  padding: 0.4rem 0.65rem;
  text-align: left; vertical-align: middle;
  border-bottom: 1px solid var(--border);
}
thead th {
  font-weight: 600; font-size: 0.85rem; color: var(--muted);
  background: var(--surface-2); white-space: nowrap;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
td form { margin: 0; }

/* ── Forms ───────────────────────────────────────────────────────────────── */

form { margin: 0 0 1rem; }
label { display: block; font-weight: 500; margin: 0 0 0.25rem; }
label + input, label + select, label + textarea { margin-top: 0; }

input:not([type="checkbox"], [type="radio"], [type="submit"]), select, textarea {
  display: block; width: 100%;
  font: inherit; color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.4rem 0.6rem;
  margin: 0 0 0.75rem;
}
input:focus, select:focus, textarea:focus, button:focus-visible, [role="button"]:focus-visible {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus);
}
input[type="checkbox"], input[type="radio"] { margin: 0 0.4rem 0 0; vertical-align: -1px; }
label:has(> input[type="checkbox"]) { display: flex; align-items: center; font-weight: 400; }

/* Inline rows: a form or div whose children sit side by side. */
[role="group"] { display: flex; align-items: center; gap: 0.5rem; }
[role="group"] > input:not([type="checkbox"], [type="radio"]),
[role="group"] > select { margin: 0; flex: 1 1 10rem; width: auto; }
td [role="group"] { display: inline-flex; flex-wrap: nowrap; }
/* A one-field row (e.g. "Add a domain") doesn't need the full page width. */
form[role="group"]:not(:has(> :is(input, select) ~ :is(input, select))) { max-width: 560px; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */

button, [role="button"], input[type="submit"] {
  display: inline-block;
  font: inherit; font-weight: 500; line-height: 1.3;
  color: var(--accent-text); background: var(--accent);
  border: 1px solid var(--accent); border-radius: var(--radius);
  padding: 0.4rem 0.85rem;
  cursor: pointer; white-space: nowrap; text-align: center;
}
button:hover, [role="button"]:hover, input[type="submit"]:hover { filter: brightness(1.08); text-decoration: none; }
.secondary {
  color: var(--text); background: var(--surface-2); border-color: var(--border);
}
.outline { background: transparent; color: var(--accent); }
.secondary.outline { background: transparent; color: var(--text); border-color: var(--border); }
.small { padding: 0.15rem 0.55rem; font-size: 0.857rem; }

/* ── Progress ────────────────────────────────────────────────────────────── */

progress {
  appearance: none; width: 110px; height: 7px; vertical-align: middle;
  border: 0; border-radius: 4px; overflow: hidden; background: var(--surface-2);
  margin-right: 0.4rem;
}
progress::-webkit-progress-bar { background: var(--surface-2); }
progress::-webkit-progress-value { background: var(--ok); }
progress::-moz-progress-bar { background: var(--ok); }

/* ── Status colours and dashboard ────────────────────────────────────────── */

.pass { color: var(--ok); }
.fail { color: var(--bad); }
.rate { font-variant-numeric: tabular-nums; }
.error { color: var(--bad); }
.tenant-badge { font-size: 0.75rem; color: var(--muted); }
.progress-cell { min-width: 160px; white-space: nowrap; }

.summary-cards {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--gap); margin-bottom: 1rem;
}
.summary-card { padding: 0.7rem 0.9rem; margin: 0; }
.summary-card .value { font-size: 1.6rem; font-weight: 600; margin: 0; font-variant-numeric: tabular-nums; }
.summary-card .label { font-size: 0.85rem; color: var(--muted); margin: 0; }

.bar-chart { display: flex; align-items: flex-end; gap: 2px; height: 60px; margin: 0.5rem 0 1rem; }
.bar-chart .bar-total { background: var(--surface-2); }
.bar-chart .bar-pass  { background: var(--ok); }

/* Alerts (dashboard banners and similar). */
[role="alert"], .dns-banner {
  border-left: 4px solid var(--bad);
}

/* Reports parked for an unregistered domain (_parked.html): needs a decision,
   but nothing is broken. */
.parked-banner { border-left-color: var(--warn); }
ul.parked-list { list-style: none; padding: 0; }
ul.parked-list li {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 0.4rem 1rem; padding: 0.35rem 0; border-top: 1px solid var(--border);
}
ul.parked-list form { margin: 0; }

/* ── Messages and report detail ──────────────────────────────────────────── */

.badge, .status-processed { color: var(--ok); }
.status-error     { color: var(--bad); }
.status-parked    { color: var(--warn); }
.status-pending, .status-discarded { color: var(--muted); }

/* Filter links above a list; the current one is marked aria-current. */
nav.tabs { display: flex; flex-wrap: wrap; gap: 0.35rem; margin: 0 0 0.75rem; }
nav.tabs a {
  padding: 0.15rem 0.65rem; border: 1px solid var(--border); border-radius: 1rem;
  color: var(--text); background: var(--surface);
}
nav.tabs a:hover { text-decoration: none; border-color: var(--accent); }
nav.tabs a[aria-current] { color: var(--accent-text); background: var(--accent); border-color: var(--accent); }

/* Label/value pairs, two columns where there's room. */
dl.facts {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 0.6rem 2rem; margin: 0;
}
dl.facts dt { font-size: 0.85rem; color: var(--muted); }
dl.facts dd { margin: 0; overflow-wrap: anywhere; }
article > h3:first-child { margin-top: 0; }
td small.auth { margin-left: 0.25rem; }
td small.override { color: var(--warn); }

pre.headers { max-height: 26rem; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; }

/* ── DNS checks (admin/_domain_dns.html) ─────────────────────────────────── */

details { margin: 0 0 0.5rem; }
details:not(.dropdown) > summary { cursor: pointer; padding: 0.3rem 0; font-weight: 500; }
details:not(.dropdown)[open] > summary { margin-bottom: 0.4rem; }

pre.dns-records { white-space: pre; }
.dns-badge {
  display: inline-block; font-size: 0.8rem; line-height: 1.4;
  padding: 0 0.5rem; border-radius: 1rem; white-space: nowrap;
  border: 1px solid currentColor;
}
.dns-ok      { color: var(--ok); }
.dns-error   { color: var(--bad); }
.dns-warning { color: var(--warn); }
.dns-unknown, .dns-unchecked, .dns-info { color: var(--muted); }
ul.dns-results { list-style: none; padding-left: 0; }
ul.dns-results li {
  color: var(--text); border-left: 3px solid var(--border);
  padding-left: 0.7rem; margin-bottom: 0.45rem;
}
ul.dns-results li.dns-ok      { border-color: var(--ok); }
ul.dns-results li.dns-error   { border-color: var(--bad); }
ul.dns-results li.dns-warning { border-color: var(--warn); }

/* ── Sign-in pages ───────────────────────────────────────────────────────── */

main.auth { max-width: 380px; margin: 4rem auto; padding: 0 16px; }
main.auth button[type="submit"] { width: 100%; }
.center { text-align: center; }

/* Space between a DNS record's copy button and the check results below it. */
[data-copy-target] { margin-bottom: 0.6rem; }
