/*
 * Design tokens & components — see design-system/dmarc-analyzer/MASTER.md
 * for the rationale (palette, type, spacing). Applied here; do not
 * hand-tune colors ad hoc elsewhere — add a token if one is missing.
 */

:root {
  color-scheme: light;

  --color-bg: #F8FAFC;
  --color-surface: #FFFFFF;
  --color-surface-muted: #F1F5F9;
  --color-fg: #0F172A;
  --color-fg-muted: #64748B;
  --color-border: #E2E8F0;
  --color-primary: #0F172A;
  --color-on-primary: #F8FAFC;
  --color-accent: #0369A1;
  --color-accent-muted: #E0F2FE;

  --status-success-fg: #15803D;
  --status-success-bg: #F0FDF4;
  --status-warning-fg: #B45309;
  --status-warning-bg: #FFFBEB;
  --status-danger-fg: #DC2626;
  --status-danger-bg: #FEF2F2;
  --status-neutral-fg: #475569;
  --status-neutral-bg: #F1F5F9;
  --status-unknown-fg: #7C3AED;
  --status-unknown-bg: #F5F3FF;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.12);
  --shadow-lg: 0 16px 40px rgba(15, 23, 42, 0.20);

  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", monospace;
}

/*
 * DARK PALETTE — this block and the :root[data-theme="dark"] block below it
 * must be kept identical. The first applies dark-by-default when the OS
 * prefers dark and the user hasn't explicitly picked light; the second
 * applies when the user explicitly picked dark regardless of OS. CSS can't
 * express "OS-preference OR explicit-attribute" in one rule, and this
 * project has no build step to generate both from one source, so the
 * values are hand-duplicated — update both together.
 */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;

    --color-bg: #0B1220;
    --color-surface: #111A2E;
    --color-surface-muted: #182238;
    --color-fg: #E2E8F0;
    --color-fg-muted: #94A3B8;
    --color-border: #243149;
    --color-primary: #E2E8F0;
    --color-on-primary: #0B1220;
    --color-accent: #38BDF8;
    --color-accent-muted: #0C2942;

    --status-success-fg: #4ADE80;
    --status-success-bg: #0F2A1A;
    --status-warning-fg: #FBBF24;
    --status-warning-bg: #2E2205;
    --status-danger-fg: #F87171;
    --status-danger-bg: #2E1215;
    --status-neutral-fg: #94A3B8;
    --status-neutral-bg: #182238;
    --status-unknown-fg: #A78BFA;
    --status-unknown-bg: #211B3D;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.5);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --color-bg: #0B1220;
  --color-surface: #111A2E;
  --color-surface-muted: #182238;
  --color-fg: #E2E8F0;
  --color-fg-muted: #94A3B8;
  --color-border: #243149;
  --color-primary: #E2E8F0;
  --color-on-primary: #0B1220;
  --color-accent: #38BDF8;
  --color-accent-muted: #0C2942;

  --status-success-fg: #4ADE80;
  --status-success-bg: #0F2A1A;
  --status-warning-fg: #FBBF24;
  --status-warning-bg: #2E2205;
  --status-danger-fg: #F87171;
  --status-danger-bg: #2E1215;
  --status-neutral-fg: #94A3B8;
  --status-neutral-bg: #182238;
  --status-unknown-fg: #A78BFA;
  --status-unknown-bg: #211B3D;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-fg);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--color-accent); }
button { font-family: inherit; }

svg.icon {
  width: 1em; height: 1em;
  vertical-align: -0.15em;
}

/* ---- shell ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; height: 56px; border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
}
.brand {
  display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px;
  color: var(--color-fg); text-decoration: none;
}
.brand svg.icon { width: 20px; height: 20px; color: var(--color-accent); }
.topnav { display: flex; align-items: center; gap: 4px; }
.topnav a {
  color: var(--color-fg-muted); text-decoration: none; font-size: 13px; font-weight: 500;
  padding: 6px 10px; border-radius: 6px; transition: background-color 150ms ease, color 150ms ease;
}
.topnav a:hover { background: var(--color-surface-muted); color: var(--color-fg); }
/* admin-only nav items, visually offset from the everyone-sees-these group */
.topnav-admin {
  display: flex; align-items: center; gap: 4px; margin-left: 8px; padding-left: 12px;
  border-left: 1px solid var(--color-border);
}
.who {
  display: flex; align-items: center; gap: 12px; margin-left: 8px; padding-left: 12px;
  border-left: 1px solid var(--color-border);
}
.who .id { font-size: 13px; line-height: 1.3; color: inherit; text-decoration: none; }
.who .id .email { font-weight: 600; transition: color 150ms ease; }
.who .id .role { display: block; color: var(--color-fg-muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }
.who .id:hover .email { color: var(--color-accent); }
.logout-btn {
  background: none; border: none; color: var(--color-fg-muted); cursor: pointer; padding: 6px;
  border-radius: 6px; display: flex;
}
.logout-btn:hover { color: var(--status-danger-fg); background: var(--color-surface-muted); }
.logout-btn svg.icon { width: 17px; height: 17px; }

.theme-toggle {
  background: none; border: none; color: var(--color-fg-muted); cursor: pointer; padding: 6px;
  border-radius: 6px; display: flex;
}
.theme-toggle:hover { color: var(--color-fg); background: var(--color-surface-muted); }
.theme-toggle svg.icon { width: 17px; height: 17px; }
.theme-toggle .icon.i-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .icon.i-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon.i-moon { display: inline; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon.i-sun { display: none; }
  :root:not([data-theme="light"]) .theme-toggle .icon.i-moon { display: inline; }
}

main { max-width: 1120px; margin: 0 auto; padding: 24px; }

.page-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 20px; gap: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; font-weight: 700; margin: 0 0 2px; letter-spacing: -0.01em; }
.page-head .sub { font-size: 13px; color: var(--color-fg-muted); }

/* ---- stat tiles ---- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat-tile { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 8px; padding: 16px; }
.stat-tile .label { font-size: 11px; font-weight: 600; color: var(--color-fg-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 6px; }
.stat-tile .value { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.stat-tile .value.warn { color: var(--status-warning-fg); }
.stat-tile .value.sm { font-size: 14px; }
.stat-tile .delta { font-size: 12px; color: var(--color-fg-muted); margin-top: 4px; }

/* ---- table ---- */
.table-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 8px; overflow: hidden; }
.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
thead th {
  background: var(--color-surface-muted); text-align: left; font-weight: 600; font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.04em; color: var(--color-fg-muted);
  padding: 10px 14px; border-bottom: 1px solid var(--color-border); white-space: nowrap;
}
tbody td { padding: 11px 14px; border-bottom: 1px solid var(--color-border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--color-surface-muted); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.domain-cell { font-weight: 600; }
.mono { font-family: var(--font-mono); font-size: 12.5px; }
.policy-pill { display: inline-block; font-family: var(--font-mono); font-size: 11.5px; background: var(--color-surface-muted); padding: 2px 6px; border-radius: 4px; color: var(--color-fg-muted); }

/* ---- badges ---- */
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px 2px 6px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
.badge svg.icon { width: 12px; height: 12px; }
.badge.success { background: var(--status-success-bg); color: var(--status-success-fg); }
.badge.warning { background: var(--status-warning-bg); color: var(--status-warning-fg); }
.badge.danger  { background: var(--status-danger-bg);  color: var(--status-danger-fg); }
.badge.neutral { background: var(--status-neutral-bg); color: var(--status-neutral-fg); }
.badge.unknown { background: var(--status-unknown-bg); color: var(--status-unknown-fg); }

/* ---- narrow card layout (auth / settings) ---- */
.narrow { max-width: 480px; margin: 32px auto; display: flex; flex-direction: column; gap: 16px; }
.narrow-tight { margin-bottom: 0; }
.narrow-sm    { max-width: 400px; }
.narrow-notop { margin-top: 0; }
.login-mark { text-align: center; }
.login-mark svg.icon { width: 28px; height: 28px; color: var(--color-accent); }
.card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 8px; padding: 20px; }
.card h2 { font-size: 15px; font-weight: 700; margin: 0 0 4px; }
.card .card-sub { font-size: 12.5px; color: var(--color-fg-muted); margin: 0 0 16px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field:last-of-type { margin-bottom: 0; }
.field label { font-size: 12.5px; font-weight: 600; }
.field input, .field select {
  font: inherit; font-size: 14px; padding: 8px 10px; border: 1px solid var(--color-border);
  border-radius: 6px; background: var(--color-surface); color: var(--color-fg); width: 100%;
}
.field input:focus, .field select:focus, .input:focus {
  outline: 2px solid var(--color-accent); outline-offset: 1px; border-color: var(--color-accent);
}
.field .hint { font-size: 12px; color: var(--color-fg-muted); }
/* checkboxes/radios must not inherit the block-level input reset above (width:100%,
   padding, border) — that turns a native checkbox into a large empty box */
.field input[type="checkbox"], .field input[type="radio"] {
  width: auto; padding: 0; border: 0; background: none; margin: 0;
}
.checkbox-label { display: flex; align-items: center; gap: 6px; font-weight: 400; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; font-size: 13.5px; font-weight: 600;
  padding: 8px 16px; border-radius: 6px; cursor: pointer; border: 1px solid transparent;
  transition: background-color 150ms ease, border-color 150ms ease, opacity 150ms ease;
}
.btn:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--color-primary); color: var(--color-on-primary); }
.btn-primary:hover:not(:disabled) { opacity: 0.88; }
.btn-secondary { background: var(--color-surface); border-color: var(--color-border); color: var(--color-fg); }
.btn-secondary:hover:not(:disabled) { background: var(--color-surface-muted); }
.btn-danger { background: none; border-color: var(--status-danger-fg); color: var(--status-danger-fg); }
.btn-danger:hover:not(:disabled) { background: var(--status-danger-bg); }
.btn-block { width: 100%; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn svg.icon { width: 14px; height: 14px; }

.divider-label { display: flex; align-items: center; gap: 10px; color: var(--color-fg-muted); font-size: 12px; margin: 4px 0; }
.divider-label::before, .divider-label::after { content: ""; flex: 1; height: 1px; background: var(--color-border); }
.helper-link { text-align: center; font-size: 12.5px; }

.text-center { text-align: center; }
.mt-sm { margin-top: 6px; }
.mt-md { margin-top: 14px; }
.mt-lg { margin-top: 16px; }
.input-inline {
  font-size: 12px; padding: 4px 6px; border: 1px solid var(--color-border); border-radius: 4px; margin-right: 6px;
}
.inline-check-label {
  font-size: 11px; display: inline-flex; align-items: center; gap: 4px; margin-right: 6px;
}

/* ---- help system (docs/feature-helpsystem.md) ---- */
.help-index-card { padding: 4px 14px; }
.help-trigger {
  display: inline-flex; align-items: center; justify-content: center; vertical-align: middle;
  width: 18px; height: 18px; padding: 0; margin-left: 4px; background: none; border: none;
  border-radius: 50%; cursor: pointer; color: var(--color-fg-muted);
}
.help-trigger:hover, .help-trigger:focus-visible { color: var(--color-accent); background: var(--color-surface-muted); }
.help-trigger svg.icon { width: 14px; height: 14px; }
/* position:fixed + JS-computed coordinates (help.js) — floats above the
   page entirely, so it can never affect the layout of whatever grid/flex
   container the trigger happens to live in. */
.help-popover {
  position: fixed; z-index: 30; max-width: 320px; white-space: normal;
  background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 8px;
  padding: 10px 12px; box-shadow: var(--shadow-md); font-size: 12.5px; color: var(--color-fg);
}
.help-popover p { margin: 0 0 8px; }
.help-popover a { font-size: 12px; font-weight: 600; }

.list-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--color-border); gap: 12px; flex-wrap: wrap; }
.list-row:last-child { border-bottom: none; }
.list-row .meta { display: flex; align-items: center; gap: 10px; min-width: 0; }
.list-row .meta svg.icon { width: 17px; height: 17px; color: var(--color-fg-muted); flex-shrink: 0; }
.list-row .name { font-size: 13.5px; font-weight: 600; }
.list-row .detail { font-size: 12px; color: var(--color-fg-muted); }

select.role-select {
  font: inherit; font-size: 12.5px; padding: 5px 8px; border: 1px solid var(--color-border); border-radius: 6px;
  background: var(--color-surface); color: var(--color-fg);
}
select.role-select.block { width: 100%; padding: 8px 10px; }
.actions-cell { display: flex; gap: 6px; flex-wrap: wrap; }

.flash { background: var(--status-success-bg); color: var(--status-success-fg); border: 1px solid var(--status-success-fg); border-radius: 8px; padding: 10px 14px; font-size: 13px; font-weight: 500; margin: 0 0 16px; }
.error { background: var(--status-danger-bg); color: var(--status-danger-fg); border: 1px solid var(--status-danger-fg); border-radius: 8px; padding: 10px 14px; font-size: 13px; font-weight: 500; margin: 0 0 16px; }
.error:empty { display: none; margin: 0; padding: 0; border: 0; } /* JS-filled slots (e.g. #webauthn-error) before any error occurs */
.secret { font-family: var(--font-mono); font-size: 13px; background: var(--color-surface-muted); padding: 2px 6px; border-radius: 4px; letter-spacing: 0.02em; }
.secret-block { display: block; text-align: center; padding: 10px; margin-bottom: 12px; }
ul.secret-list { list-style: none; margin: 0 0 16px; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
ul.secret-list li.secret { text-align: center; padding: 8px; }

code { font-family: var(--font-mono); background: var(--color-surface-muted); padding: 1px 5px; border-radius: 4px; font-size: 0.9em; }

/* ---- domain drill-down (spec §7.2) ---- */
.overview-grid { display: grid; grid-template-columns: minmax(220px, 320px) 1fr; gap: 16px; margin-bottom: 20px; }
.policy-row { display: flex; align-items: center; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid var(--color-border); gap: 12px; }
.policy-row:last-child { border-bottom: none; }
.policy-label { font-size: 12.5px; color: var(--color-fg-muted); flex-shrink: 0; }
.inline-form { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0; }
/* step-up note/password prompt inside an .inline-form (e.g. Deactivate) must not
   be squeezed into a flex row next to the button — force it onto its own line */
.step-up-field {
  flex-basis: 100%; margin: 0; display: flex; flex-wrap: wrap; align-items: center;
  gap: 8px; font-size: 12px; color: var(--color-fg-muted);
}
.step-up-field label { display: flex; align-items: center; gap: 6px; font-weight: 400; color: var(--color-fg); font-size: 13px; }
.step-up-field input[type="password"] { flex: 1 1 auto; min-width: 0; }
.step-up-error { flex-basis: 100%; }
.overview-col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.chart-card .trend-chart { width: 100%; height: 160px; display: block; }
.chart-card .chart-empty { font-size: 12.5px; color: var(--color-fg-muted); }
.chart-label { font-size: 9px; fill: var(--color-fg-muted); }

.section-head { display: flex; align-items: baseline; justify-content: space-between; margin: 24px 0 8px; gap: 12px; flex-wrap: wrap; }
.section-head h2 { font-size: 15px; font-weight: 700; margin: 0; }
.section-head .sub { font-size: 12.5px; color: var(--color-fg-muted); }
.section-head-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.table-filters { display: flex; gap: 4px; flex-wrap: wrap; }
.table-filters a {
  color: var(--color-fg-muted); text-decoration: none; font-size: 12px; font-weight: 500;
  padding: 4px 8px; border-radius: 999px; transition: background-color 150ms ease, color 150ms ease;
}
.table-filters a:hover { background: var(--color-surface-muted); color: var(--color-fg); }
.table-filters a.active { background: var(--color-accent-muted); color: var(--color-accent); }
th a { color: inherit; text-decoration: none; }
th a:hover { color: var(--color-accent); }
th a.active { color: var(--color-accent); }
td.empty { text-align: center; color: var(--color-fg-muted); padding: 24px 14px; }

.health-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; margin-top: 12px; }
/* min-width: 0 overrides the grid item's default min-width: auto (sized to
   its content's min-content) — without it, a long unbroken evidence string
   can force this cell, and the whole grid row/track, wider than the card. */
.health-item { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 7px 10px; background: var(--color-surface-muted); border-radius: 6px; min-width: 0; }
.health-category { font-size: 10.5px; color: var(--color-fg-muted); text-transform: uppercase; letter-spacing: 0.04em; margin-left: auto; }
.health-reason { flex-basis: 100%; font-size: 11px; color: var(--color-fg-muted); }
.health-evidence {
  flex-basis: 100%; max-width: 100%; display: block; font-family: var(--font-mono); font-size: 11px;
  color: var(--color-fg-muted); white-space: pre-wrap; word-break: break-all; overflow-wrap: anywhere;
}
/* .fix-trigger opens a floating .fix-popover (help.js) — the fix content
   itself lives in a <template>, never rendered in-flow, so it can't
   inflate a .health-grid row the way an always-visible block would. */
.fix-trigger { flex-basis: 100%; margin-top: 2px; align-self: flex-start; }
.fix-popover { max-width: 420px; }
.fix-block + .fix-block { margin-top: 10px; }
.fix-block {
  padding: 10px; border: 1px solid var(--color-border);
  border-radius: 6px; background: var(--color-surface-muted);
}
.fix-label { font-size: 11px; font-weight: 600; margin-bottom: 4px; }
.fix-block .rec-evidence { display: block; margin: 6px 0; }
.fix-block .card-sub { margin: 0 0 8px; }
.copy-btn { min-width: 64px; }

.posture-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; margin-top: 12px; }
.posture-card { display: flex; flex-direction: column; gap: 8px; }
.posture-card .posture-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.posture-card .posture-head h2 { font-size: 14px; margin: 0; }
.posture-card .posture-sparkline { width: 100%; height: 28px; display: block; }
.posture-card .posture-recs { display: flex; gap: 6px; flex-wrap: wrap; }

.rec-list { display: flex; flex-direction: column; gap: 8px; }
.rec-item { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 8px; padding: 12px 14px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.rec-rule { font-weight: 700; font-size: 13px; }
.rec-meta { font-size: 11.5px; color: var(--color-fg-muted); margin-left: auto; }
.rec-evidence { flex-basis: 100%; font-size: 11.5px; white-space: pre-wrap; word-break: break-all; }

tr.auth-details td { background: var(--color-surface-muted); padding: 8px 14px; border-bottom: 1px solid var(--color-border); }
.auth-row { font-size: 12px; color: var(--color-fg-muted); }
.auth-row + .auth-row { margin-top: 3px; }

/* ---- public landing page (docs/feature-landing-page.md) ---- */
.landing-hero { text-align: center; padding: 48px 0 32px; }
.landing-hero h1 { font-size: 28px; font-weight: 700; margin: 0 0 8px; letter-spacing: -0.01em; display: flex; align-items: center; justify-content: center; gap: 10px; }
.landing-hero h1 svg.icon { width: 26px; height: 26px; color: var(--color-accent); }
.landing-hero .lead { font-size: 15px; color: var(--color-fg-muted); max-width: 560px; margin: 0 auto 20px; }
.landing-cta { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; }
.landing-about { max-width: 720px; margin: 0 auto 32px; font-size: 14px; }
.landing-about p { margin: 0 0 14px; }
.landing-capabilities { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 32px; }
.landing-capabilities .card h3 { font-size: 14px; margin: 0 0 4px; }
.landing-help-cta { text-align: center; padding: 24px; margin-bottom: 24px; }
.landing-help-cta h2 { font-size: 16px; margin: 0 0 6px; }
.landing-help-cta .card-sub { max-width: 480px; margin: 0 auto 14px; }
.landing-footer { text-align: center; padding: 16px 0 32px; font-size: 12.5px; color: var(--color-fg-muted); }

@media (max-width: 760px) {
  .who .id { display: none; }
  ul.secret-list { grid-template-columns: 1fr; }
  .overview-grid { grid-template-columns: 1fr; }
}
