/*
 * CrtUP — one hand-written stylesheet, no build step, no framework.
 *
 * Mostly white, black and grey, with a single purple carrying every accent. Theme follows
 * the OS via prefers-color-scheme; the tokens are also keyed off a `data-theme` attribute
 * on <html> so a saved override later is a form and a session field, not a restructure.
 *
 * Nothing here is ported from Certmand.
 */

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

:root {
  color-scheme: light dark;

  --bg: #fbfbfd;
  --surface: #ffffff;
  --sunken: #f4f4f7;
  --border: #e2e2e8;
  --border-strong: #c9c9d3;
  --text: #16161a;
  --muted: #5c5c6b;

  /* Hue 282°. 7.06:1 on white; the dark counterpart below is the same hue, lighter. */
  --accent: #8a21b6;
  --accent-hover: #73178f;
  --accent-soft: #f6eafb;
  --accent-border: #e3c4f0;
  --accent-text: #ffffff;

  --danger: #a91b13;
  --danger-soft: #fdeceb;
  --danger-border: #f3c9c6;
  --warn: #7a5100;
  --warn-soft: #fff6e0;
  --warn-border: #ecd9a8;
  --ok: #10633b;
  --ok-soft: #e7f6ee;
  --ok-border: #b9e0cb;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgb(16 16 26 / 6%), 0 1px 3px rgb(16 16 26 / 4%);

  --content: 74rem;
  --content-narrow: 26rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1116;
    --surface: #171a21;
    --sunken: #1e222b;
    --border: #2a2f3a;
    --border-strong: #3f4655;
    --text: #e8eaef;
    --muted: #9aa2b1;

    --accent: #d494f0;
    --accent-hover: #e4b6f6;
    --accent-soft: #2a1733;
    --accent-border: #4a2b58;
    --accent-text: #0f1116;

    --danger: #ff9a90;
    --danger-soft: #2e1613;
    --danger-border: #5b2a24;
    --warn: #f0c264;
    --warn-soft: #2b2311;
    --warn-border: #55431c;
    --ok: #63d69c;
    --ok-soft: #10291d;
    --ok-border: #21503a;

    --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 1px 3px rgb(0 0 0 / 30%);
  }
}

/* The same values again, so an explicit choice wins over the OS in both directions. */
:root[data-theme="light"] {
  color-scheme: light;
}

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

  --bg: #0f1116;
  --surface: #171a21;
  --sunken: #1e222b;
  --border: #2a2f3a;
  --border-strong: #3f4655;
  --text: #e8eaef;
  --muted: #9aa2b1;

  --accent: #d494f0;
  --accent-hover: #e4b6f6;
  --accent-soft: #2a1733;
  --accent-border: #4a2b58;
  --accent-text: #0f1116;

  --danger: #ff9a90;
  --danger-soft: #2e1613;
  --danger-border: #5b2a24;
  --warn: #f0c264;
  --warn-soft: #2b2311;
  --warn-border: #55431c;
  --ok: #63d69c;
  --ok-soft: #10291d;
  --ok-border: #21503a;
}

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

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

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

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-feature-settings: "tnum" 1;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: -0.014em;
  line-height: 1.25;
}

h1 {
  font-size: 1.4rem;
}

h2 {
  font-size: 1.05rem;
}

h3 {
  font-size: 0.95rem;
}

p {
  margin: 0;
}

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

a:hover {
  color: var(--accent-hover);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

code,
.mono {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.92em;
}

/* ── Layout ───────────────────────────────────────────────────────────────── */

.masthead {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.masthead > .inner {
  width: min(var(--content), 100% - 2rem);
  margin-inline: auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.5rem;
  padding-block: 0.85rem;
}

.wordmark {
  font-size: 1.1rem;
  font-weight: 640;
  letter-spacing: -0.02em;
  text-decoration: none;
  color: var(--text);
  margin-right: auto;
}

.wordmark em {
  font-style: normal;
  color: var(--accent);
}

.masthead nav {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.masthead nav a {
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius-sm);
  color: var(--muted);
  text-decoration: none;
  font-weight: 500;
}

.masthead nav a:hover {
  background: var(--sunken);
  color: var(--text);
}

.masthead nav a[aria-current="page"] {
  color: var(--accent);
  background: var(--accent-soft);
}

.masthead .account {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding-left: 0.75rem;
  border-left: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.88rem;
}

main {
  flex: 1;
  width: min(var(--content), 100% - 2rem);
  margin: 1.75rem auto 3rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

main.narrow {
  width: min(var(--content-narrow), 100% - 2rem);
  margin-top: clamp(2rem, 8vh, 5rem);
}

footer {
  border-top: 1px solid var(--border);
  padding: 1.25rem 0;
  color: var(--muted);
  font-size: 0.82rem;
}

footer > .inner {
  width: min(var(--content), 100% - 2rem);
  margin-inline: auto;
}

/* ── Panels ───────────────────────────────────────────────────────────────── */

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

.panel > header {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  align-items: baseline;
  justify-content: space-between;
  padding: 1.05rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.panel > header.plain {
  border-bottom: 0;
  padding-bottom: 0;
}

.panel > .body {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.subtitle {
  color: var(--muted);
  font-size: 0.88rem;
}

.page-head {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.5rem;
  align-items: flex-end;
  justify-content: space-between;
}

.page-head p {
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 0.3rem;
}

/* ── Messages ─────────────────────────────────────────────────────────────── */

.flash,
.error,
.notice,
.alert {
  padding: 0.7rem 0.95rem;
  border: 1px solid;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
}

.flash {
  border-color: var(--ok-border);
  background: var(--ok-soft);
  color: var(--ok);
}

.error {
  border-color: var(--danger-border);
  background: var(--danger-soft);
  color: var(--danger);
}

.notice {
  border-color: var(--warn-border);
  background: var(--warn-soft);
  color: var(--warn);
}

/* The lapsed-domain banner: the most serious thing whois can tell us. */
.alert {
  border-color: var(--danger-border);
  background: var(--danger-soft);
  color: var(--danger);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.alert strong {
  font-weight: 620;
}

.alert a {
  color: inherit;
}

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

.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.field + .field {
  margin-top: 0.9rem;
}

label {
  font-size: 0.86rem;
  font-weight: 560;
}

.hint {
  color: var(--muted);
  font-size: 0.82rem;
}

input,
select {
  width: 100%;
  padding: 0.5rem 0.65rem;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
}

input:disabled {
  color: var(--muted);
  background: var(--sunken);
}

input::placeholder {
  color: var(--muted);
  opacity: 0.75;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
  margin-top: 1.1rem;
}

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: flex-end;
}

.inline-form .field {
  flex: 1 1 14rem;
  margin: 0;
}

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

button,
.button {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.9rem;
  font: inherit;
  font-weight: 560;
  line-height: 1.3;
  color: var(--accent-text);
  background: var(--accent);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  text-decoration: none;
  cursor: pointer;
}

button:hover,
.button:hover {
  background: var(--accent-hover);
  color: var(--accent-text);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button.secondary,
.button.secondary {
  color: var(--text);
  background: var(--surface);
  border-color: var(--border-strong);
}

button.secondary:hover,
.button.secondary:hover {
  background: var(--sunken);
  color: var(--text);
}

button.link {
  padding: 0;
  font-weight: inherit;
  color: var(--accent);
  background: none;
  border: 0;
  text-decoration: underline;
  text-underline-offset: 2px;
}

button.link:hover {
  color: var(--accent-hover);
  background: none;
}

button.link.danger {
  color: var(--danger);
}

/* ── Status ───────────────────────────────────────────────────────────────── */

/*
 * Driven by ExpiryStatus. Colour is never the message: the text inside always says what
 * the state is, so the badge still reads correctly in monochrome or to a screen reader.
 */
.status {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border: 1px solid;
  border-radius: 999px;
  font-size: 0.79rem;
  font-weight: 560;
  white-space: nowrap;
}

.status-expired,
.status-critical,
.status-missing,
.status-lapsed {
  border-color: var(--danger-border);
  background: var(--danger-soft);
  color: var(--danger);
}

.status-warning,
.status-caution {
  border-color: var(--warn-border);
  background: var(--warn-soft);
  color: var(--warn);
}

.status-healthy {
  border-color: var(--ok-border);
  background: var(--ok-soft);
  color: var(--ok);
}

.status-muted,
.status-neutral {
  border-color: var(--border-strong);
  background: var(--sunken);
  color: var(--muted);
}

.tag {
  display: inline-block;
  padding: 0.1rem 0.4rem;
  border: 1px solid var(--accent-border);
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 560;
}

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

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

thead th {
  padding: 0.5rem 1.25rem;
  text-align: left;
  font-size: 0.74rem;
  font-weight: 620;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--sunken);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 0.6rem 1.25rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr:last-child td {
  border-bottom: 0;
}

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

td.numeric,
th.numeric {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

td.shrink,
th.shrink {
  width: 1%;
  white-space: nowrap;
}

.name-cell {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.88rem;
  word-break: break-all;
}

.muted-row td {
  opacity: 0.6;
}

/*
 * Below this width a five-column table is unreadable, so each row becomes a stacked block
 * labelled from `data-label`. No JavaScript, and the markup stays a real table for
 * assistive technology on wider screens.
 */
@media (max-width: 46rem) {
  .stacked thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .stacked tbody tr {
    display: block;
    padding: 0.85rem 1.25rem;
    border-bottom: 1px solid var(--border);
  }

  .stacked tbody tr:last-child {
    border-bottom: 0;
  }

  .stacked tbody td {
    display: flex;
    gap: 1rem;
    align-items: baseline;
    justify-content: space-between;
    padding: 0.15rem 0;
    border: 0;
  }

  .stacked tbody td::before {
    content: attr(data-label);
    flex: none;
    font-size: 0.74rem;
    font-weight: 620;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--muted);
  }

  .stacked tbody td:empty {
    display: none;
  }

  .stacked td.numeric {
    text-align: left;
  }
}

/* ── Definition lists ─────────────────────────────────────────────────────── */

.facts {
  display: grid;
  grid-template-columns: minmax(9rem, auto) 1fr;
  gap: 0.55rem 1.5rem;
  margin: 0;
  font-size: 0.9rem;
}

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

.facts dd {
  margin: 0;
  word-break: break-word;
}

@media (max-width: 34rem) {
  .facts {
    grid-template-columns: 1fr;
    gap: 0.15rem;
  }

  .facts dd {
    margin-bottom: 0.6rem;
  }
}

/* ── Blocks of text ───────────────────────────────────────────────────────── */

pre {
  margin: 0;
  padding: 0.9rem 1rem;
  overflow-x: auto;
  background: var(--sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.8rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-all;
}

.empty {
  padding: 2rem 1.25rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.92rem;
}

.aside {
  color: var(--muted);
  font-size: 0.88rem;
}

.list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

/* ── Filter bar ───────────────────────────────────────────────────────────── */

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: flex-end;
  padding: 0.9rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.filters .field {
  flex: 0 1 15rem;
  margin: 0;
}

.filters .field label {
  font-size: 0.74rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ── Summary strip ────────────────────────────────────────────────────────── */

.summary {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 2rem;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.86rem;
  color: var(--muted);
}

.summary b {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* ── Error pages ──────────────────────────────────────────────────────────── */

.error-page {
  text-align: center;
  padding: clamp(2rem, 10vh, 5rem) 1.25rem;
}

.error-page .code {
  font-size: 3rem;
  font-weight: 660;
  letter-spacing: -0.03em;
  color: var(--accent);
  line-height: 1;
}

.error-page h1 {
  margin: 0.75rem 0 0.4rem;
}

.error-page p {
  color: var(--muted);
}

.error-page .actions {
  justify-content: center;
}

@media (prefers-reduced-motion: no-preference) {
  a,
  button,
  .button {
    transition: background-color 120ms ease, color 120ms ease;
  }
}
