/* The admin console (Phase 36). Colours follow hatch-website's site.css and the app's Theme.swift:
   accent #13a06a (light), #3ddc97 on #0b0f14 (dark). Phone first. No inline styles anywhere: the
   Content-Security-Policy allows only this file. */
:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --text: #11161c;
  --muted: #5b6878;
  --accent: #13a06a;
  --on-accent: #ffffff;
  --rule: #e2e6ea;
  --danger: #c43c3c;
  --warn: #9a6400;
  --warn-bg: #fff4dc;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f14;
    --surface: #151b23;
    --text: #e8edf2;
    --muted: #9aa7b6;
    --accent: #3ddc97;
    --on-accent: #0b0f14;
    --rule: #222b36;
    --danger: #ff6b6b;
    --warn: #f3c164;
    --warn-bg: #2a2212;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

a { color: var(--accent); }
h1 { font-size: 1.6rem; line-height: 1.2; letter-spacing: -0.02em; margin: 0; }
h2 { font-size: 1rem; margin: 24px 0 8px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.muted { color: var(--muted); }
.center { text-align: center; }
.error { color: var(--danger); }
.warn { color: var(--warn); background: var(--warn-bg); border-radius: 10px; padding: 10px 12px; font-size: 0.95rem; }

/* ── The bar ─────────────────────────────────────────────────────────────── */
.bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px; border-bottom: 1px solid var(--rule); background: var(--surface);
  position: sticky; top: 0; z-index: 2;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; white-space: nowrap; color: inherit; text-decoration: none; }
.mark { display: inline-block; width: 22px; height: 22px; border-radius: 50%; border: 5px solid var(--accent); flex: none; }
.mark.big { width: 56px; height: 56px; border-width: 12px; }
.stage { font-size: 0.75rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--warn-bg); color: var(--warn); text-transform: uppercase; letter-spacing: 0.04em; }
.who { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; min-width: 0; }
.who #who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.who .link { white-space: nowrap; flex: none; }
/* Phones: the handle drops under the brand's row rather than squeezing "Sign out". */
@media (max-width: 480px) {
  .bar { flex-wrap: wrap; row-gap: 2px; padding: 10px 14px; }
  .brand { flex: 1; }
  .who { order: 3; flex-basis: 100%; justify-content: space-between; }
}

main { max-width: 640px; margin: 0 auto; padding: 16px 16px 48px; }
.view > * + * { margin-top: 14px; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
button, .button {
  font: inherit; font-weight: 600; border-radius: 12px; border: 1px solid var(--rule);
  background: var(--surface); color: var(--text); padding: 10px 16px; min-height: 44px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none;
}
button:disabled { opacity: 0.5; cursor: default; }
.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.link { background: none; border: none; color: var(--accent); padding: 6px 4px; min-height: 0; font-weight: 500; }
.wide { width: 100%; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.back { margin-left: -4px; }

/* ── Sign-in ─────────────────────────────────────────────────────────────── */
.signin { text-align: center; padding: 48px 8px 0; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.signin p { max-width: 360px; margin: 0; }
.signin .wide { max-width: 360px; }

/* ── The list ────────────────────────────────────────────────────────────── */
.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.banner { background: var(--surface); border: 1px solid var(--accent); border-radius: 14px; padding: 12px 14px; }
.banner p { margin: 0 0 10px; }
.filters, .segmented { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.filters button, .segmented button { flex: none; min-height: 36px; padding: 6px 14px; border-radius: 999px; font-weight: 500; }
.segmented button { flex: 1; }
.filters button[aria-pressed="true"], .segmented button[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
input {
  font: inherit; width: 100%; padding: 10px 12px; min-height: 44px; border-radius: 12px;
  border: 1px solid var(--rule); background: var(--surface); color: var(--text);
}
input:focus, button:focus-visible, .button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.keys, .devices, .results { list-style: none; margin: 0; padding: 0; }
.keys { background: var(--surface); border: 1px solid var(--rule); border-radius: 14px; overflow: hidden; }
.keys li + li { border-top: 1px solid var(--rule); }
.keys button {
  width: 100%; border: none; border-radius: 0; background: none; justify-content: space-between;
  padding: 12px 14px; text-align: left; font-weight: 400; min-height: 56px;
}
.keys .label { font-weight: 600; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.95rem; }
.keys .right { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 0.9rem; white-space: nowrap; }
.keys .chev { color: var(--muted); font-size: 1.2rem; }

.badge { font-size: 0.75rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; border: 1px solid currentColor; white-space: nowrap; }
.badge.active { color: var(--accent); }
.badge.unused, .badge.expired { color: var(--muted); }
.badge.full { color: var(--warn); }
.badge.revoked { color: var(--danger); }
.foot { text-align: center; font-size: 0.9rem; }

/* ── The owner's account picker (Phase 36, iteration) ───────────────────── */
.picker { position: relative; }
#account-button { width: 100%; justify-content: flex-start; gap: 10px; text-align: left; }
.picker-label { color: var(--muted); font-weight: 500; font-size: 0.85rem; }
#account-current { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.caret { color: var(--muted); }
.menu {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 3; list-style: none; margin: 0; padding: 6px;
  background: var(--surface); border: 1px solid var(--rule); border-radius: 14px; box-shadow: 0 12px 32px rgba(5, 8, 12, 0.18);
  max-height: 60vh; overflow-y: auto;
}
.menu button { width: 100%; border: none; justify-content: space-between; font-weight: 500; border-radius: 10px; }
.menu button[aria-selected="true"] { background: var(--bg); font-weight: 700; }
.menu .count { color: var(--muted); font-weight: 500; }
.menu .stray { color: var(--warn); font-weight: 500; font-size: 0.85rem; }
.menu li.sep { border-top: 1px solid var(--rule); margin: 4px 6px; }
select {
  font: inherit; width: 100%; padding: 10px 12px; min-height: 44px; border-radius: 12px;
  border: 1px solid var(--rule); background: var(--surface); color: var(--text);
}
.facts .span { grid-column: 1 / -1; }
.actions > * + * { margin-top: 10px; }

/* ── One key ─────────────────────────────────────────────────────────────── */
#key-label { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; overflow-wrap: anywhere; }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 0; }
.facts div { background: var(--surface); border: 1px solid var(--rule); border-radius: 12px; padding: 10px 12px; }
.facts dt { font-size: 0.8rem; color: var(--muted); }
.facts dd { margin: 2px 0 0; font-weight: 600; }
.devices li {
  background: var(--surface); border: 1px solid var(--rule); border-radius: 12px; padding: 10px 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.devices li + li { margin-top: 8px; }
.devices .platform { font-weight: 600; text-transform: capitalize; }
.devices .meta { font-size: 0.85rem; color: var(--muted); }
.devices code { font-size: 0.85rem; }
.devices button { min-height: 36px; padding: 6px 12px; }
.actions { margin-top: 24px; }

/* ── New ─────────────────────────────────────────────────────────────────── */
form > * + * { margin-top: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span:first-child { font-weight: 600; }
.field small { font-size: 0.85rem; }
.joined { display: flex; align-items: stretch; }
.joined .fixed {
  display: flex; align-items: center; padding: 0 10px; border: 1px solid var(--rule); border-right: none;
  border-radius: 12px 0 0 12px; background: var(--bg); color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.joined .fixed + input { border-radius: 0 12px 12px 0; }

/* ── The result ──────────────────────────────────────────────────────────── */
.results li { background: var(--surface); border: 1px solid var(--rule); border-radius: 14px; padding: 14px; }
.results li + li { margin-top: 10px; }
.results .label { font-weight: 600; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.results .link-text {
  display: block; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85rem;
  overflow-wrap: anywhere; user-select: all; -webkit-user-select: all; margin: 6px 0 10px; color: var(--text);
}
.results .row button { flex: 1; white-space: nowrap; padding: 10px 10px; }
/* A QR code is dark on light whatever the theme, with its quiet zone drawn on the canvas. */
.qr { display: block; margin: 12px auto 0; width: 220px; height: 220px; border-radius: 10px; image-rendering: pixelated; }
.results.many .qr { width: 180px; height: 180px; }

/* ── Dialog and toast ────────────────────────────────────────────────────── */
dialog {
  border: 1px solid var(--rule); border-radius: 16px; background: var(--surface); color: var(--text);
  padding: 18px; width: min(92vw, 420px);
}
dialog::backdrop { background: rgba(5, 8, 12, 0.55); }
dialog h2 { margin: 0 0 8px; text-transform: none; letter-spacing: 0; color: var(--text); font-size: 1.15rem; }
dialog p { margin: 0 0 16px; }
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-weight: 600; z-index: 5;
}
