:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --text: #14161a;
  --muted: #6b7280;
  --border: #e2e5ea;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --ok: #15803d;
  --ok-bg: #dcfce7;
  --warn: #a16207;
  --warn-bg: #fef3c7;
  --danger: #b91c1c;
  --danger-bg: #fee2e2;
  --info: #1d4ed8;
  --info-bg: #dbeafe;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 3px rgba(16, 24, 40, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a20;
    --surface-2: #1d2128;
    --text: #e8eaed;
    --muted: #98a0ac;
    --border: #272c35;
    --accent: #5b8cff;
    --accent-text: #0b1020;
    --ok: #86efac;
    --ok-bg: #14321f;
    --warn: #fcd34d;
    --warn-bg: #3a2c0a;
    --danger: #fca5a5;
    --danger-bg: #3b1616;
    --info: #93b4ff;
    --info-bg: #16244a;
    --shadow: none;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

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

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

h1,
h2 {
  margin: 0;
  font-weight: 600;
}

h1 {
  font-size: 22px;
}

h2 {
  font-size: 15px;
  letter-spacing: 0.01em;
}

/* ---- auth ------------------------------------------------------------- */

.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 30px;
  width: min(420px, 100%);
  display: grid;
  gap: 18px;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.auth-brand div {
  display: flex;
  flex-direction: column;
  line-height: 1.35;
}

.auth-brand strong {
  font-size: 18px;
}

.auth-brand .muted {
  font-size: 13px;
}

.auth-card form {
  display: grid;
  gap: 14px;
}

.segmented {
  display: flex;
  gap: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 3px;
}

.seg {
  flex: 1;
  background: none;
  border: 0;
  padding: 7px;
  border-radius: 7px;
  color: var(--muted);
  font-size: 14px;
}

.seg.active {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: var(--shadow);
}

.wide {
  width: 100%;
}

.input-prefix {
  display: flex;
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.input-prefix input {
  border: 0;
  background: none;
  border-radius: 0;
  text-align: center;
}

.affix {
  padding: 0 10px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  white-space: nowrap;
}

.preview-line {
  margin: 0;
  font-size: 13px;
  color: var(--accent);
  min-height: 1.2em;
}

/* ---- chrome ----------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand div {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.logo {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: var(--accent-text);
  border-radius: 8px;
  font-size: 16px;
}

.tabs {
  display: flex;
  gap: 4px;
  margin-left: auto;
  flex-wrap: wrap;
}

.tab {
  background: none;
  border: 0;
  padding: 7px 13px;
  border-radius: 8px;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

.tab:hover {
  background: var(--surface-2);
  color: var(--text);
}

.tab.active {
  background: var(--accent);
  color: var(--accent-text);
}

.badge {
  display: inline-block;
  min-width: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 11px;
  font-weight: 700;
  text-align: center;
}

.tab.active .badge {
  background: rgba(255, 255, 255, 0.25);
  color: inherit;
}

main {
  max-width: 1000px;
  margin: 0 auto;
  padding: 20px;
  display: grid;
  gap: 16px;
}

.panel,
.stack {
  display: grid;
  gap: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  display: grid;
  gap: 14px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.banner {
  max-width: 1000px;
  margin: 16px auto -4px;
  padding: 11px 14px;
  border-radius: var(--radius);
  background: var(--warn-bg);
  color: var(--warn);
  font-size: 14px;
  border: 1px solid transparent;
}

/* ---- forms ------------------------------------------------------------ */

.field {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.field.grow {
  flex: 1 1 180px;
}

label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

input,
select,
textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 11px;
  width: 100%;
  min-width: 0;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.input-suffix {
  display: flex;
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.input-suffix input {
  border: 0;
  background: none;
  border-radius: 0;
}

.input-suffix .suffix {
  padding: 0 11px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  white-space: nowrap;
}

.row-form {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.search {
  max-width: 220px;
}

.hint {
  margin: 0;
  font-size: 12.5px;
  color: var(--muted);
}

.error {
  margin: 0;
  color: var(--danger);
  font-size: 13.5px;
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

button {
  font: inherit;
  cursor: pointer;
  border-radius: 8px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  white-space: nowrap;
}

button:hover {
  border-color: var(--muted);
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

button.primary:hover {
  filter: brightness(1.07);
}

button.ghost {
  background: none;
}

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

button.small {
  padding: 5px 10px;
  font-size: 13px;
}

/* ---- lists ------------------------------------------------------------ */

.list {
  display: grid;
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.list:empty::after {
  content: "Nothing here yet.";
  display: block;
  background: var(--surface);
  padding: 28px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

.item {
  background: var(--surface);
  padding: 13px 15px;
  display: grid;
  gap: 8px;
}

.item-main {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}

.address {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13.5px;
  font-weight: 600;
  background: none;
  border: 0;
  padding: 0;
  color: var(--text);
  cursor: pointer;
}

.address:hover {
  color: var(--accent);
  text-decoration: underline;
}

.item-meta {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 12.5px;
  color: var(--muted);
}

.item-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.subject {
  font-weight: 600;
  font-size: 14px;
}

.preview {
  font-size: 13px;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
}

.pill.ok {
  background: var(--ok-bg);
  color: var(--ok);
  border-color: transparent;
}

.pill.warn {
  background: var(--warn-bg);
  color: var(--warn);
  border-color: transparent;
}

.pill.danger {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: transparent;
}

.pill.info {
  background: var(--info-bg);
  color: var(--info);
  border-color: transparent;
}

.reason {
  font-size: 12.5px;
  color: var(--warn);
}

/* ---- DNS records table ------------------------------------------------ */

.records-toggle summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 0;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  user-select: none;
}

.records-toggle summary::-webkit-details-marker {
  display: none;
}

/* Rotates to point down when open. */
.records-toggle summary::before {
  content: "›";
  display: inline-block;
  font-size: 16px;
  line-height: 1;
  color: var(--muted);
  transition: transform 0.12s ease;
}

.records-toggle[open] summary::before {
  transform: rotate(90deg);
}

.records-toggle summary .muted {
  font-weight: 400;
  font-size: 12.5px;
}

.records-toggle summary:hover {
  color: var(--accent);
}

/* The scroll lives on a wrapper, not the table. `display: block` on a table
   defeats table-layout, which is what actually keeps a 400-character DKIM key
   inside its column instead of pushing the whole page sideways. */
.records-scroll {
  overflow-x: auto;
  min-width: 0;
}

/* A grid item will not shrink below its content unless told to, so without
   this the table's min-width drags the panel — and the whole page — wider
   than the viewport instead of scrolling inside the wrapper above. */
.panel,
.records-toggle {
  min-width: 0;
}

.records {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  table-layout: fixed;
  /* Below this the value column is squeezed to a few characters wide and a
     DKIM key becomes a tall unreadable ribbon. Past it the wrapper scrolls
     instead, which is the lesser evil on a narrow screen. */
  min-width: 640px;
}

.records .c-type {
  width: 68px;
}

.records .c-host {
  width: 23%;
}

.records .c-why {
  width: 24%;
}

.records th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.records td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

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

.records .hint {
  max-width: 34ch;
}

.records .host-cell {
  overflow-wrap: anywhere;
}

.value-cell {
  overflow-wrap: anywhere;
}

.value-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.value-row + .value-row {
  margin-top: 6px;
}

.value-text {
  /* min-width: 0 is what allows a flex child to shrink below its content and
     wrap. Without it the key sets the column width and the page scrolls. */
  min-width: 0;
  flex: 1;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  color: var(--accent);
  overflow-wrap: anywhere;
  line-height: 1.5;
}

.copy {
  flex: none;
  padding: 3px 9px;
  font-size: 11.5px;
  line-height: 1.4;
  border-radius: 5px;
  cursor: pointer;
}

.chunks {
  margin-top: 8px;
}

.chunks summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

.linkish {
  background: none;
  border: 0;
  padding: 0;
  color: var(--accent);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
  word-break: break-all;
}

.linkish:hover {
  text-decoration: underline;
}

/* ---- toast ------------------------------------------------------------ */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 14px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  z-index: 50;
}

@media (max-width: 640px) {
  .topbar {
    gap: 12px;
  }

  .tabs {
    order: 3;
    width: 100%;
    margin-left: 0;
  }

  main {
    padding: 14px;
  }
}

/* ---- two-factor setup -------------------------------------------------- */
/* .card lays its own children out on a grid with a gap. These are wrappers
   inside one of those children, so they got no gap at all and everything
   inside them sat flush. Giving them the same treatment is the fix; adding
   margins on top of a grid gap only produces the opposite problem. */

#mfa-setup,
#mfa-codes,
#mfa-on,
#mfa-off,
#mfa-reset-form {
  display: grid;
  gap: 18px;
}

#mfa-reset-form {
  padding-top: 4px;
  border-top: 1px solid var(--border);
}


/* A button needs more air above it than two paragraphs need between them. At
   the container's own gap it read as attached to the sentence above it. */
#mfa-card .actions,
#credentials-card .actions,
#password-card .actions,
#sessions-card .actions {
  margin-top: 6px;
}

.mfa-grid {
  display: flex;
  gap: 22px;
  align-items: flex-start;
  flex-wrap: wrap;
  margin: 4px 0 18px;
}

/* White always, whatever the page theme. A scanner reads dark modules on a
   light field, and inverting that stops most cameras working. */
.mfa-qr {
  flex: none;
  padding: 10px;
  background: #fff;
  border-radius: 10px;
  line-height: 0;
}

.mfa-qr svg {
  display: block;
}

/* A grid, not a plain block: its children are a labelled field and a line of
   help, and stacked block elements sit flush against one another. */
.mfa-manual {
  display: grid;
  gap: 12px;
  align-content: start;
  flex: 1;
  min-width: 240px;
}

#mfa-secret {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  letter-spacing: 0.04em;
}

.mfa-confirm {
  max-width: 220px;
}

#mfa-codes-list {
  margin: 12px 0;
  padding: 14px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.9;
  letter-spacing: 0.06em;
  white-space: pre;
  overflow-x: auto;
}

@media (max-width: 560px) {
  .mfa-grid {
    gap: 16px;
  }

  .mfa-confirm {
    max-width: none;
  }
}