:root[data-theme="light"] {
  --bg: #FAF8F5;
  --surface: #F2EDE5;
  --surface-alt: #ECE6DD;
  --text: #1A1815;
  --muted: #6B6259;
  --border: #E0D9CD;
  --accent: #C44A3A;
  --accent-hover: #B43E2F;
  --up: #2D5F3F;
  --down: #8B2A2A;
  --warn: #B8841C;
  --inconclusive: #5A6470;
}
:root[data-theme="dark"] {
  --bg: #14110D;
  --surface: #1F1A14;
  --surface-alt: #29231B;
  --text: #F5F1EA;
  --muted: #A8A096;
  --border: #2E281F;
  --accent: #D86B5C;
  --accent-hover: #E27E70;
  --up: #5BA378;
  --down: #D87878;
  --warn: #E0B05C;
  --inconclusive: #9CA3AF;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html, body {
  font-family: 'Geist', system-ui, sans-serif;
  font-feature-settings: "ss01", "cv01";
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
.mono { font-family: 'Geist Mono', monospace; font-variant-numeric: tabular-nums; }

a {
  color: var(--accent);
  text-decoration: none;
  transition: color 150ms ease-out;
}
a:hover { color: var(--accent-hover); }

/* Keyboard-only focus ring. Mouse + autofocus don't trigger this — they
   trigger :focus, which we leave un-styled so an autofocused email field
   doesn't read as a red error border on initial page load. Linear-tier
   accent outline with 2px offset, drawn outside the element so existing
   border-radius / box-shadow stay intact. */
button:focus-visible,
a:focus-visible,
[role="button"]:focus-visible,
input[type="checkbox"]:focus-visible,
input[type="radio"]:focus-visible,
select:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Toolbar */
.toolbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 32px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.toolbar-left { color: var(--muted); }
.toolbar-right { display: flex; gap: 18px; align-items: center; }
.toolbar-user {
  font-size: 12px;
  color: var(--muted);
  border-right: 1px solid var(--border);
  padding-right: 18px;
}
.toolbar-user:empty { display: none; border: none; padding: 0; }
.toolbar-button {
  color: var(--muted);
  background: none;
  border: none;
  font: inherit;
  cursor: pointer;
}
.toolbar-button:hover { color: var(--text); }

/* Layout */
.frame {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: calc(100vh - 45px);
  max-width: 1200px;
  margin: 0 auto;
}

/* Sidebar */
.sidebar {
  background: var(--surface-alt);
  border-right: 1px solid var(--border);
  padding: 28px 0;
  display: flex;
  flex-direction: column;
}
.brand { padding: 0 24px 32px; }
.wordmark {
  font-family: 'Geist', sans-serif;
  font-weight: 700;
  font-size: 17px;
  color: var(--accent);
  letter-spacing: -0.02em;
}
.nav { display: flex; flex-direction: column; }
.nav a {
  padding: 8px 24px;
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: color 150ms ease-out;
}
.nav a.current {
  color: var(--text);
  background: var(--surface);
  border-right: 2px solid var(--accent);
}
.nav a.disabled { opacity: 0.5; cursor: not-allowed; }
.nav a:hover:not(.disabled):not(.current) { color: var(--text); }
.sidebar .meta {
  margin-top: auto;
  padding: 32px 24px 16px;
  font-size: 11px;
  color: var(--muted);
}

/* Main */
.main {
  padding: 48px 56px;
  background: var(--bg);
}
.main-header {
  margin-bottom: 48px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
}
.main-header h2 {
  font-family: 'Geist', sans-serif;
  font-size: 32px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.02em;
  /* Reserve space when empty (initial render before JS fetches the
     headline text). Prevents both the 'Loading…' flash AND layout
     shift when text arrives. */
  min-height: 1.1em;
}
.timestamp { font-size: 12px; color: var(--muted); }

/* Checks list */
.checks {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.loading {
  padding: 24px;
  color: var(--muted);
  font-size: 13px;
}
/* When .loading is the placeholder for a list that may render an
   .empty-state once data arrives (dashboard checks, /secrets, /domains),
   reserve the empty-state's footprint so the swap doesn't shift the page. */
.checks > .loading,
.domains > .loading,
.account-summary > .loading {
  padding: 64px 24px;
  text-align: center;
}
.empty-state {
  padding: 64px 24px;
  text-align: center;
  color: var(--muted);
}
.empty-state h3 {
  font-family: 'Geist', sans-serif;
  font-weight: 700;
  font-size: 20px;
  color: var(--text);
  margin-bottom: 8px;
  letter-spacing: -0.01em;
}
.empty-state p { font-size: 14px; max-width: 380px; margin: 0 auto; }

.check-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  border-bottom: 1px solid var(--border);
  transition: background 100ms ease-out;
}
.check-row:hover { background: var(--surface-alt); }
.check-row:last-child { border-bottom: none; }
.check {
  display: grid;
  grid-template-columns: 16px 1fr auto auto;
  gap: 16px;
  align-items: center;
  padding: 18px 24px;
  text-decoration: none;
  color: inherit;
}
.check-delete {
  font-family: 'Geist Mono', monospace;
  font-size: 18px;
  line-height: 1;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 6px 10px;
  margin-right: 16px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 150ms ease-out, color 150ms ease-out, border-color 150ms ease-out;
}
.check-row:hover .check-delete { opacity: 1; }
.check-delete:hover, .check-delete:focus-visible {
  opacity: 1;
  color: var(--down);
  border-color: var(--down);
}
.check-delete:disabled { opacity: 0.4; cursor: not-allowed; }

.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.dot.up { background: var(--up); }
.dot.down { background: var(--down); }
.dot.inconclusive { background: var(--inconclusive); }
.dot.unknown { background: var(--muted); }
.dot.running { background: var(--up); animation: pulse 2s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.85); }
}

.check .info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.check .info .name {
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
  letter-spacing: -0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.check .info .url {
  font-family: 'Geist Mono', monospace;
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.check .info .url.down-text { color: var(--down); }

.check .sparkline { width: 96px; height: 28px; flex-shrink: 0; }

.check .response {
  font-family: 'Geist Mono', monospace;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  color: var(--text);
  width: 80px;
  text-align: right;
}
.check .response.muted { color: var(--muted); }
.check .response.down-text { color: var(--down); }

.check .uptime {
  font-family: 'Geist Mono', monospace;
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  color: var(--muted);
  width: 60px;
  text-align: right;
}

/* Flow editor (in the Add-check dialog) */
.flow-disclosure {
  margin-top: -8px;
  border-top: 1px dashed var(--border);
  padding-top: 16px;
}
.flow-disclosure summary {
  font-family: 'Geist', sans-serif;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  list-style: none;
}
.flow-disclosure summary::before {
  content: "▸ ";
  font-size: 10px;
}
.flow-disclosure[open] summary::before { content: "▾ "; }
.flow-disclosure summary:hover { color: var(--text); }
.flow-hint {
  margin: 12px 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}
.flow-steps {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}
/* Starter templates — shown only when flowSteps is empty. Click a chip to
   pre-fill the step list with a working example the user can edit. */
.flow-templates {
  margin-bottom: 16px;
  padding: 16px;
  background: var(--surface-alt);
  border: 1px dashed var(--border);
  border-radius: 6px;
}
.flow-templates-lead {
  font-family: 'Geist', sans-serif;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 10px;
  letter-spacing: -0.005em;
}
.flow-templates-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.flow-template-chip {
  display: grid;
  grid-template-columns: minmax(110px, auto) 1fr;
  align-items: baseline;
  gap: 14px;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  text-align: left;
  transition: border-color 150ms ease-out, background 150ms ease-out;
}
.flow-template-chip:hover {
  border-color: var(--accent);
  background: var(--surface);
}
.flow-template-label {
  font-family: 'Geist', sans-serif;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.flow-template-hint {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
  font-family: 'Geist', sans-serif;
}
.flow-step {
  display: grid;
  grid-template-columns: 30px 90px 1fr auto;
  gap: 8px;
  align-items: start;
  padding: 8px 10px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 4px;
}
.flow-step-pos {
  font-family: 'Geist Mono', monospace;
  font-size: 11px;
  color: var(--muted);
  padding-top: 6px;
}
.flow-step-kind {
  font-family: 'Geist Mono', monospace;
  font-size: 11px;
  color: var(--accent);
  font-weight: 600;
  padding-top: 6px;
}
.flow-step-fields {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.flow-step-fields input {
  padding: 6px 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  font-family: 'Geist Mono', monospace;
  font-size: 12px;
  color: var(--text);
}
.flow-step-fields input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.flow-step-remove {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
  padding: 0 6px;
  align-self: start;
  margin-top: 2px;
}
.flow-step-remove:hover { color: var(--down); }
.flow-add-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.flow-add-row select {
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: 'Geist', sans-serif;
  font-size: 13px;
  color: var(--text);
}
.flow-add-row .btn-ghost { padding: 8px 14px; }

/* /domains page */
.domains-intro {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 24px;
  max-width: 620px;
  line-height: 1.55;
}
.domains {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.domain-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px 24px;
  display: grid;
  grid-template-columns: 16px 1fr auto auto auto;
  gap: 16px;
  align-items: center;
}
.domain-row.pending { grid-template-rows: auto 1fr; }
.domain-remove {
  font-family: 'Geist Mono', monospace;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  transition: color 150ms ease-out, border-color 150ms ease-out;
}
.domain-remove:hover {
  color: var(--down);
  border-color: var(--down);
}
.domain-remove:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.remove-state {
  font-size: 12px;
  color: var(--muted);
  min-width: 0;
}
.remove-state.error { color: var(--down); }
.remove-state:empty { display: none; }
.domain-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.domain-name {
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
  letter-spacing: -0.01em;
}
.domain-sub {
  font-size: 12px;
  color: var(--muted);
}
.domain-status {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 4px 10px;
  border-radius: 4px;
}
.domain-status.verified { color: var(--up); background: rgba(45, 95, 63, 0.08); }
.domain-status.pending { color: var(--warn); background: rgba(184, 132, 28, 0.08); }
.domain-instructions {
  grid-column: 1 / -1;
  border-top: 1px solid var(--border);
  margin-top: 12px;
  padding-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.instructions-lead {
  font-size: 13px;
  color: var(--text);
  margin: 0;
}
.record {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.record-row {
  display: grid;
  grid-template-columns: 70px 1fr auto;
  gap: 12px;
  align-items: center;
}
.record-label {
  font-family: 'Geist Mono', monospace;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.record-value {
  font-size: 12px;
  color: var(--text);
  word-break: break-all;
  background: transparent;
}
.record-copy {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  font: 500 11px 'Geist Mono', monospace;
  padding: 3px 10px;
  border-radius: 3px;
  cursor: pointer;
}
.record-copy:hover { border-color: var(--text); color: var(--text); }
.verify-now { align-self: flex-start; }
.verify-state {
  font-size: 12px;
  color: var(--muted);
}
.verify-state.error { color: var(--down); }
.domains-footnote {
  margin-top: 32px;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* Pending-verification badge on dashboard rows */
.dot.pending { background: var(--warn); }
.check .info .url.pending-text { color: var(--warn); }

/* Verify-email banner */
.verify-banner {
  margin: 0 0 24px;
  padding: 12px 16px;
  background: rgba(184, 132, 28, 0.08);
  border: 1px solid var(--warn);
  border-radius: 4px;
  color: var(--warn);
  font-size: 13px;
  display: flex;
  gap: 12px;
  align-items: center;
}
.verify-banner button { color: var(--warn); }
.verify-banner button:hover { color: var(--text); }

/* Footer meta */
.main-footer {
  margin-top: 32px;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* Add-check button + dialog */
.add-check-row {
  margin-top: 24px;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 16px;
}
.plan-usage {
  font-size: 12px;
  color: var(--muted);
}
.plan-usage.at-limit { color: var(--down); }
.btn-primary {
  padding: 11px 18px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 4px;
  font: 600 14px 'Geist', sans-serif;
  letter-spacing: -0.01em;
  cursor: pointer;
  transition: background 150ms ease-out;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-ghost {
  padding: 11px 18px;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  font: 500 14px 'Geist', sans-serif;
  letter-spacing: -0.01em;
  cursor: pointer;
  transition: border-color 150ms ease-out;
}
.btn-ghost:hover { border-color: var(--text); }
.btn-ghost.danger { color: var(--down); border-color: var(--down); }
.btn-ghost.danger:hover { background: var(--down); color: #fff; }
.btn-primary.danger { background: var(--down); }
.btn-primary.danger:hover { background: #6f1f1f; }
.section-h {
  font-family: 'Geist', sans-serif;
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.02em;
  color: var(--down);
  margin-top: 48px;
  margin-bottom: 8px;
}
.account-summary { margin-bottom: 24px; }

.add-dialog {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 40px;
  max-width: 520px;
  width: 90vw;
  color: var(--text);
  /* The universal `* { margin: 0 }` reset zeros out the dialog's auto-
     centering margins. Restore them explicitly so showModal() centers
     in the viewport instead of pinning to the top-left. */
  margin: auto;
}
.add-dialog::backdrop {
  background: rgba(26, 24, 21, 0.4);
  backdrop-filter: blur(2px);
}
.add-dialog form { display: flex; flex-direction: column; gap: 32px; }
/* The .field elements live inside #add-check-form-fields, NOT as direct
   children of the form. The form's gap doesn't reach them, so set up
   the same flex-column gap on the wrapper. Without this, fields stack
   with zero visible spacing between hint and next label. */
#add-check-form-fields { display: flex; flex-direction: column; gap: 28px; }
.add-dialog .flow-disclosure {
  margin-top: 4px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}
.add-title {
  font-family: 'Geist', sans-serif;
  font-weight: 700;
  font-size: 22px;
  letter-spacing: -0.02em;
  color: var(--text);
}
.add-sub {
  font-family: 'Geist', sans-serif;
  font-size: 14px;
  color: var(--muted);
  margin-top: -16px; /* tighten under .add-title */
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label {
  font-family: 'Geist', sans-serif;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.005em;
}
.field-optional {
  font-family: 'Geist Mono', monospace;
  font-size: 11px;
  font-weight: 400;
  color: var(--muted);
  margin-left: 4px;
}
.field input {
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: 'Geist', sans-serif;
  font-size: 14px;
  color: var(--text);
  transition: border-color 150ms ease-out;
}
.field input.mono { font-family: 'Geist Mono', monospace; }
/* Use an outline RING instead of changing the border color. Chromium treats
   autofocus as :focus-visible (correct a11y behavior), and a coral border
   on an empty required field reads as "error red" to users. The ring is
   drawn outside the input so the border stays neutral. */
.field input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.field-hint {
  font-family: 'Geist Mono', monospace;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.4;
}
.add-error {
  padding: 10px 12px;
  background: rgba(139, 42, 42, 0.08);
  border: 1px solid var(--down);
  border-radius: 4px;
  color: var(--down);
  font-size: 12px;
}
.add-ok {
  padding: 10px 12px;
  background: rgba(45, 95, 63, 0.08);
  border: 1px solid var(--up);
  border-radius: 4px;
  color: var(--up);
  font-size: 12px;
}
.add-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* Mobile */
@media (max-width: 768px) {
  /* Desktop's frame min-height: calc(100vh - 45px) makes sidebar fill the
     viewport — perfect for the two-column layout. On single-column mobile/
     tablet, that same min-height spreads across the now-stacked rows, so
     the horizontal-nav sidebar inflates from ~80px content to ~260px of
     mostly empty space. Reset to auto. */
  .frame { grid-template-columns: 1fr; min-height: auto; }
  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 16px 0;
    flex-direction: row;
    align-items: center;
    gap: 16px;
  }
  .sidebar .brand { padding: 0 16px; }
  .sidebar .nav { flex-direction: row; gap: 8px; flex: 1; padding: 0 16px; }
  .sidebar .nav a { padding: 8px 12px; }
  .sidebar .nav a.current { border-right: none; border-bottom: 2px solid var(--accent); }
  .sidebar .meta { display: none; }
  .main { padding: 24px 16px; }
  .check .sparkline { display: none; }

  /* Mobile touch targets (Apple HIG / Material recommend ≥44px). Desktop
     keeps the dense slim look — we only inflate hit areas for fingers. */
  .toolbar-button { min-height: 44px; padding: 10px 12px; }
  .toolbar .wordmark, .sidebar .wordmark { padding: 12px 0; }

  /* Toolbar layout on narrow viewports — keep everything on one row.
     Hide the email pill (not critical UX info on mobile), truncate the
     breadcrumb if it gets long, tighten side padding. */
  .toolbar { padding: 8px 16px; gap: 12px; }
  .toolbar-left {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
  }
  .toolbar-user { display: none; }
  .toolbar-right { gap: 8px; flex-shrink: 0; }
  .toolbar-button { padding: 8px 10px; font-size: 12px; }
}
