:root {
  --bg: #f2f2f7;
  --surface: #ffffff;
  --ink: #1c1c1e;
  --ink-secondary: #6c6c70;
  --ink-muted: #8e8e93;
  --line: #e3e3e8;
  --in: #16794a;
  --out: #b3261e;
  --pending: #8a5a00;
  --accent: #16794a;
  --radius: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --ink: #f2f2f7;
    --ink-secondary: #a1a1a6;
    --ink-muted: #8e8e93;
    --line: #2c2c2e;
    --in: #40c463;
    --out: #f85149;
    --pending: #e3a008;
    --accent: #40c463;
  }
}

* { box-sizing: border-box; }

/* An author `display` rule beats the UA stylesheet's [hidden] { display: none },
   so anything toggled via the hidden attribute needs this to actually hide. */
[hidden] { display: none !important; }

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

main { max-width: 640px; margin: 0 auto; }
main.wide { max-width: 900px; }

h1 { font-size: 1.9rem; margin: 0; letter-spacing: -0.02em; }
h2 { font-size: 1rem; margin: 0 0 2px; color: var(--ink-secondary); font-weight: 600; }

.muted { color: var(--ink-muted); font-size: 0.85rem; margin: 2px 0 0; }
.error { color: var(--out); font-size: 0.85rem; }
.success { color: var(--in); font-size: 0.85rem; }

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.head-actions { display: flex; gap: 0.5rem; align-items: center; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

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

hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }

button {
  font: inherit;
  font-weight: 600;
  padding: 10px 18px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
button:hover { opacity: 0.9; }
button:disabled { opacity: 0.5; cursor: default; }

button.ghost {
  background: transparent;
  color: var(--ink-secondary);
  border: 1px solid var(--line);
  padding: 7px 14px;
  font-size: 0.85rem;
}

button.danger { color: var(--out); }
button.small { padding: 6px 12px; font-size: 0.8rem; }

.gate { min-height: 80vh; display: grid; place-items: center; }

.gate-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 32px;
  width: min(400px, 100%);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field { display: flex; flex-direction: column; gap: 5px; }
.field span { font-size: 0.8rem; font-weight: 600; color: var(--ink-secondary); }

.gate-card input, .card input {
  font: inherit;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
  width: 100%;
}

input:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.link-button {
  background: none;
  border: none;
  color: var(--accent);
  font-weight: 600;
  font-size: 0.85rem;
  padding: 0;
  cursor: pointer;
  text-align: left;
}

.otp-input { letter-spacing: 0.4em; font-size: 1.3rem; text-align: center; font-variant-numeric: tabular-nums; }

.qr-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 0;
}
.qr-box img { width: 200px; height: 200px; border-radius: 8px; background: #fff; padding: 8px; }
.qr-secret {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85rem;
  letter-spacing: 0.05em;
  word-break: break-all;
  text-align: center;
  color: var(--ink-secondary);
  user-select: all;
}

/* --------------------------------------------------------------- plates */

.plate-list { display: flex; flex-direction: column; gap: 0; }

.plate-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
}
.plate-row:last-child { border-bottom: 0; }

.plate-flag {
  width: 46px;
  height: 46px;
  flex: 0 0 auto;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 1.5rem;
  background: var(--bg);
}

.plate-main { flex: 1 1 auto; min-width: 0; }

.plate-country {
  font-size: 0.78rem;
  color: var(--ink-muted);
  margin-bottom: 4px;
}

/* Real photos (or, for a few countries, the vector diagram Wikipedia's own
   editors use) of each country's actual current plate — see
   public/plates/ATTRIBUTION.md. Fixed *width*, proportional height: a couple
   of source photos (Hungary's new-template reference, notably) are a boxier
   crop than the standard ~4.5:1 plate, and sizing by height alone made those
   render tiny next to everyone else's. Sizing by width keeps every row
   occupying the same footprint; a stubbier plate just comes out a bit
   taller, which reads as "that plate is shaped differently" rather than
   "that image is broken". */

.plate-graphic {
  display: block;
  width: 165px;
  height: auto;
  max-height: 76px;
  max-width: 100%;
  border-radius: 4px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  background: #fff; /* lets an SVG/PNG with transparent corners still read as a plate */
}

.plate-checked-at {
  font-size: 0.72rem;
  color: var(--ink-muted);
  margin-top: 5px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.plate-others {
  font-size: 0.68rem;
  color: var(--ink-muted);
  margin-top: 2px;
}

.plate-check {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 2px solid var(--line);
  background: transparent;
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
}
.plate-check.checked { border-color: var(--in); background: color-mix(in srgb, var(--in) 15%, transparent); color: var(--in); font-weight: 800; }

.progress-line { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
.progress-bar { flex: 1; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); }

/* The plate-check button and, for area-code countries, its counter — kept as
   one column so the row layout doesn't jump between the two kinds. */
.plate-check-wrap { display: flex; flex-direction: column; align-items: center; gap: 4px; flex: 0 0 auto; }
.plate-area-counter { font-size: 0.68rem; color: var(--ink-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* --------------------------------------------------------------- area codes */

#area-dialog { width: min(30rem, 92vw); max-height: 85vh; display: flex; flex-direction: column; }
#area-dialog[open] { display: flex; }

.area-dialog-advisory {
  margin: 6px 0 0;
  padding: 8px 10px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--pending) 16%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--pending) 35%, transparent);
  color: var(--ink);
  font-size: 0.82rem;
  line-height: 1.35;
}

.area-none-button {
  width: 100%;
  margin: 10px 0;
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--line);
  text-align: left;
  font-weight: 600;
}
.area-none-button:hover { opacity: 1; background: var(--line); }

.area-code-list {
  overflow-y: auto;
  border-top: 1px solid var(--line);
  margin-top: 4px;
}

.area-code-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  padding: 9px 2px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  font-weight: 400;
  text-align: left;
  cursor: pointer;
}
.area-code-row:hover { background: var(--bg); }

.area-code-main { display: flex; gap: 8px; min-width: 0; }
.area-code-code { font-weight: 700; font-variant-numeric: tabular-nums; flex: 0 0 auto; }
.area-code-name { color: var(--ink-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.area-code-row.logged .area-code-code,
.area-code-row.logged .area-code-name { color: var(--in); }

.area-code-meta { font-size: 0.72rem; color: var(--ink-muted); white-space: nowrap; flex: 0 0 auto; }

.area-code-empty { padding: 16px 2px; color: var(--ink-muted); font-size: 0.9rem; text-align: center; }

/* --------------------------------------------------------------- admin */

.table-scroll { overflow-x: auto; margin-top: 12px; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 9px 12px 9px 0; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--ink-muted); font-weight: 600; font-size: 0.8rem; }
tbody tr:last-child td { border-bottom: 0; }

.status { font-variant-caps: all-small-caps; letter-spacing: 0.04em; font-weight: 600; }
.status-active { color: var(--in); }
.status-used, .status-none { color: var(--ink-muted); }
.status-expired { color: var(--pending); }
.status-disabled { color: var(--out); }

.card.highlight { border: 1px solid var(--pending); }

.code-display {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1.6rem;
  letter-spacing: 0.08em;
  margin: 0.4rem 0 0.8rem;
  user-select: all;
}

dialog { border: none; border-radius: 16px; padding: 1.4rem; max-width: min(28rem, 92vw); background: var(--surface); color: var(--ink); }
dialog::backdrop { background: rgb(0 0 0 / 0.45); }
dialog h2 { margin-top: 0; }

.dialog-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1rem; }

.row-actions { display: flex; gap: 0.35rem; flex-wrap: wrap; }

.pager { display: flex; align-items: center; gap: 0.75rem; margin-top: 0.75rem; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}
