/* Palette taken from the Qamani shield: deep navy, gold lettering, brushed silver. */
:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #f6f8fb;
  --text: #0f1b33;
  --muted: #5b6780;
  --border: #dce2ec;
  --brand: #1a4a8f;
  --brand-strong: #133a73;
  --brand-soft: #e7eef9;
  --on-brand: #ffffff;
  --gold-text: #8a6a1f;
  --gold-soft: #f8f1de;
  --gold-line: #c9a24a;
  --navy-1: #0b2350;
  --navy-2: #17447f;
  --navy-deep: #071733;
  --ok: #047857;
  --ok-soft: #e1f5ec;
  --warn: #a16207;
  --warn-soft: #fdf3d8;
  --danger: #b42318;
  --danger-soft: #fdeceb;
  --info-soft: #e8f1fb;
  --info: #1d4f91;
  --shadow: 0 1px 2px rgba(15, 27, 51, .05), 0 4px 16px rgba(15, 27, 51, .06);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #070e1c;
    --surface: #0e1830;
    --surface-2: #0b1428;
    --text: #e6ebf5;
    --muted: #97a3bb;
    --border: #1f2c47;
    --brand: #8ab8f5;
    --brand-strong: #b0cffa;
    --brand-soft: #142a4d;
    --on-brand: #071530;
    --gold-text: #e3c473;
    --gold-soft: #2a2412;
    --gold-line: #d9b65e;
    --navy-1: #081a3d;
    --navy-2: #123769;
    --navy-deep: #050d1f;
    --ok: #4ade9b;
    --ok-soft: #0e2a1f;
    --warn: #f2c14e;
    --warn-soft: #2d2510;
    --danger: #f87171;
    --danger-soft: #331414;
    --info-soft: #10233b;
    --info: #9cc3f5;
    --shadow: 0 1px 2px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2 { line-height: 1.25; margin: 0 0 .4em; letter-spacing: -.01em; }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.15rem; }
.section > h2 { padding-left: 12px; border-left: 3px solid var(--gold-line); }
p { margin: 0 0 .8em; }
code { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: .88em; background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: .05em .35em; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.wrap { width: 100%; max-width: 1080px; margin: 0 auto; padding: 0 16px; }
.main { padding-top: 28px; padding-bottom: 40px; min-height: calc(100vh - 140px); }

/* top bar */
.topbar { background: linear-gradient(100deg, var(--navy-1), var(--navy-2)); border-bottom: 2px solid var(--gold-line); }
.topbar-admin { background: var(--navy-deep); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 62px; flex-wrap: wrap; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.25rem; letter-spacing: .01em; color: #e9c873; }
.brand img { filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .35)); }
.brand:hover { text-decoration: none; }
.badge-admin { font-size: .7rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; background: #d9b65e; color: #0b2350; padding: 2px 8px; border-radius: 999px; }
.nav { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.topbar .nav a { color: #c3cad6; font-weight: 500; }
.topbar .nav a[aria-current="page"], .topbar .nav a:hover { color: #fff; text-decoration: none; }
.topbar .nav a[aria-current="page"] { box-shadow: inset 0 -2px 0 #e9c873; }
.topbar .btn-ghost { color: #eef2f8; border-color: rgba(255, 255, 255, .28); background: transparent; }
.topbar .btn-ghost:hover { background: rgba(255, 255, 255, .08); border-color: rgba(255, 255, 255, .5); }
.topbar .nav a.btn-gold { color: #0b2350; }
.inline { display: inline; margin: 0; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; font-size: .95rem;
  padding: 9px 16px; border-radius: 9px; border: 1px solid var(--brand);
  background: var(--brand); color: var(--on-brand); cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--brand-strong); border-color: var(--brand-strong); text-decoration: none; }
.btn:focus-visible, input:focus-visible, a:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 45%, transparent); outline-offset: 2px; }
.btn-gold { background: linear-gradient(180deg, #e2c16b, #c29a3f); border-color: #b38a33; color: #0b2350; box-shadow: inset 0 1px 0 rgba(255, 255, 255, .35); }
.btn-gold:hover { background: linear-gradient(180deg, #ebcd7c, #c9a24a); border-color: #a07a2b; }
.btn-on-dark { background: transparent; color: #eef2f8; border-color: rgba(255, 255, 255, .35); }
.btn-on-dark:hover { background: rgba(255, 255, 255, .08); border-color: rgba(255, 255, 255, .6); }
.btn-sm { padding: 5px 11px; font-size: .85rem; border-radius: 7px; }
.btn-lg { padding: 12px 22px; font-size: 1rem; }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--muted); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.92); background: var(--danger); border-color: var(--danger); }
.btn-danger-ghost { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn-danger-ghost:hover { background: var(--danger-soft); border-color: var(--danger); }

/* cards and layout */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; margin-bottom: 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
.grid-2 > .card { margin-bottom: 0; }
.grid-2 + * { margin-top: 20px; }
.section { margin: 36px 0 24px; }
.narrow { max-width: 520px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.crumbs { margin-bottom: 8px; }
.pill { background: var(--brand-soft); color: var(--brand); font-weight: 600; font-size: .82rem; padding: 3px 10px; border-radius: 999px; }
.empty { color: var(--muted); background: var(--surface-2); border: 1px dashed var(--border); border-radius: 10px; padding: 18px; text-align: center; margin: 4px 0 0; }

/* hero */
.hero {
  display: grid; grid-template-columns: 1.4fr 1fr; gap: 32px; align-items: center;
  padding: 40px 44px; border-radius: 18px; color: #eef2f8;
  background:
    radial-gradient(120% 140% at 85% 20%, rgba(79, 140, 214, .35), transparent 55%),
    linear-gradient(135deg, var(--navy-1) 0%, var(--navy-2) 60%, #1d5592 100%);
  border: 1px solid rgba(195, 202, 214, .45);
  box-shadow: 0 10px 30px rgba(11, 35, 80, .25);
}
.eyebrow { text-transform: uppercase; letter-spacing: .1em; font-size: .78rem; font-weight: 700; color: var(--gold-text); margin-bottom: 10px; }
.hero .eyebrow { color: #e9c873; }
.hero h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); color: #fff; }
.lead { font-size: 1.08rem; color: var(--muted); max-width: 40em; }
.hero .lead { color: #c3cad6; }
.hero-art { display: flex; justify-content: center; }
.hero-art img { width: 100%; max-width: 272px; height: auto; filter: drop-shadow(0 14px 28px rgba(0, 0, 0, .45)); }
.actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 22px; }
.steps { list-style: none; counter-reset: s; padding: 0; margin: 22px 0 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.steps li { counter-increment: s; position: relative; padding: 18px 18px 18px 64px; margin: 0; display: flex; flex-direction: column; }
.steps li::before { content: counter(s); position: absolute; left: 18px; top: 18px; width: 32px; height: 32px; border-radius: 50%; background: linear-gradient(180deg, #e2c16b, #c29a3f); color: #0b2350; font-weight: 800; display: grid; place-items: center; }
.steps span { color: var(--muted); }

/* downloads */
.downloads { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; margin-top: 14px; }
.dl { display: flex; flex-direction: column; gap: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; color: var(--text); box-shadow: var(--shadow); transition: border-color .15s, transform .15s; }
.dl:hover { text-decoration: none; border-color: var(--gold-line); transform: translateY(-1px); }
.dl-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.dl-title { font-weight: 700; }
.dl-size { color: var(--muted); font-size: .82rem; white-space: nowrap; }
.dl-meta { color: var(--brand); font-weight: 600; font-size: .88rem; }
.dl-note { color: var(--muted); font-size: .88rem; }
.downloads > p { grid-column: 1 / -1; margin: 0; }
.dl-hash { color: var(--muted); font-family: ui-monospace, Consolas, monospace; font-size: .75rem; margin-top: 4px; }

/* forms */
.auth { display: flex; justify-content: center; padding: 20px 0; }
.auth-card { width: 100%; max-width: 440px; padding: 30px; border-top: 3px solid var(--gold-line); }
.auth-logo { display: block; width: 64px; height: 64px; margin: 0 auto 14px; filter: drop-shadow(0 4px 8px rgba(11, 35, 80, .25)); }
.auth-card > h1, .auth-card > h1 + .muted { text-align: center; }
.form { display: flex; flex-direction: column; gap: 14px; margin: 18px 0; }
label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: .9rem; }
label small { font-weight: 400; color: var(--muted); }
input {
  font: inherit; font-weight: 400; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; width: 100%;
}
textarea {
  font: .82rem/1.45 ui-monospace, "Cascadia Mono", Consolas, monospace; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; width: 100%; resize: vertical; word-break: break-all;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); }
select {
  font: inherit; font-weight: 400; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; width: 100%;
}

/* radio / checkbox cards (admin access settings) */
.choices { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.choice { flex-direction: row; align-items: flex-start; gap: 12px; font-weight: 400; padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); cursor: pointer; }
.choice:hover { border-color: var(--muted); }
.choice:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.choice input { width: auto; margin: 3px 0 0; accent-color: var(--brand); flex: none; }
.choice > span { display: flex; flex-direction: column; gap: 2px; }

/* per-device exit options (admin user page) */
.optform { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; margin: 0; }
.optform label { flex-direction: row; align-items: center; gap: 6px; font-weight: 400; font-size: .86rem; white-space: nowrap; cursor: pointer; }
.optform input { width: auto; margin: 0; accent-color: var(--brand); }
.optform .btn { width: auto; }

/* connection state */
.conn { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: .86rem; }
.conn::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.conn-online { color: var(--ok); }
.conn-offline { color: var(--muted); }
.conn-direct { color: var(--brand); margin-top: 2px; }

/* device-to-device identity keys */
.idlist { list-style: none; padding: 0; margin: 14px 0 0; }
.idrow { padding: 12px 0; border-top: 1px solid var(--border); }
.idrow-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.idrow details { margin-top: 6px; }
.table.routes { margin-top: 6px; }
.table.routes td { padding-top: 6px; padding-bottom: 6px; }
.table.routes td:first-child { width: 40%; }
.idrow summary { cursor: pointer; color: var(--brand); font-weight: 600; font-size: .88rem; width: fit-content; }
.idform { margin: 10px 0; }
.idwarn { margin: 8px 0 0; padding: 8px 12px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); }

/* group chips */
.chips { list-style: none; padding: 0; margin: 0 0 4px; display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 2px; background: var(--brand-soft); border-radius: 999px; padding: 3px 4px 3px 12px; font-weight: 600; font-size: .88rem; }
.chip-x { border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 1.05rem; line-height: 1; width: 24px; height: 24px; border-radius: 50%; cursor: pointer; }
.chip-x:hover { background: var(--danger-soft); color: var(--danger); }
.add-device { display: flex; gap: 10px; align-items: flex-end; margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--border); }
.grow { flex: 1; }
.big-icon { width: 56px; height: 56px; margin: 0 auto 12px; border-radius: 50%; background: var(--gold-soft); color: var(--gold-text); display: grid; place-items: center; font-size: 1.6rem; font-weight: 700; }

/* flash */
.flash { border-radius: 10px; padding: 12px 14px; margin-bottom: 18px; border: 1px solid transparent; }
.flash-success { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.flash-error { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.flash-info { background: var(--info-soft); color: var(--info); border-color: color-mix(in srgb, var(--info) 20%, transparent); }

/* key ready */
.keyready { display: flex; align-items: center; justify-content: space-between; gap: 20px; border-color: var(--gold-line); background: linear-gradient(0deg, var(--gold-soft), var(--gold-soft)), var(--surface); }
.keyready h2 { color: var(--gold-text); }

/* tables */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th { text-align: left; font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.table td { padding: 11px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.row-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; align-items: center; }
td.row-actions { display: table-cell; text-align: right; white-space: nowrap; }
td.row-actions > * + * { margin-left: 6px; }
.form .btn:not(.btn-block) { align-self: flex-start; }
.howto { padding-left: 1.2em; margin: 0 0 12px; }
.howto li { margin-bottom: 8px; }

/* admin */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.stat { display: flex; flex-direction: column; gap: 4px; margin: 0; color: var(--text); }
a.stat:hover { text-decoration: none; border-color: var(--brand); }
.stat-label { color: var(--muted); font-size: .85rem; font-weight: 600; }
.stat-value { font-size: 2rem; font-weight: 700; letter-spacing: -.02em; }
.stat-attention { border-color: var(--warn); background: linear-gradient(0deg, var(--warn-soft), var(--warn-soft)), var(--surface); }
.stat-attention .stat-value { color: var(--warn); }
.status { display: inline-block; font-size: .74rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: 3px 9px; border-radius: 999px; }
.status-pending { background: var(--warn-soft); color: var(--warn); }
.status-approved { background: var(--ok-soft); color: var(--ok); }
.status-disabled { background: var(--danger-soft); color: var(--danger); }
.status-rejected { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.tabs a { padding: 7px 14px; border-radius: 999px; color: var(--muted); font-weight: 600; text-transform: capitalize; border: 1px solid var(--border); background: var(--surface); }
.tabs a:hover { text-decoration: none; color: var(--text); }
.tabs a[aria-current="page"] { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.tab-count { opacity: .75; font-weight: 500; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 10px 18px; margin: 0; }
.facts dt { color: var(--muted); font-size: .9rem; }
.facts dd { margin: 0; word-break: break-all; }
.activity { list-style: none; padding: 0; margin: 0; }
.activity li { display: flex; flex-wrap: wrap; gap: 4px 8px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: .9rem; }
.activity li:last-child { border-bottom: 0; }
.act-action { font-family: ui-monospace, Consolas, monospace; font-size: .8rem; background: var(--brand-soft); color: var(--brand); padding: 1px 7px; border-radius: 5px; }
.act-meta { width: 100%; }

.footer { color: var(--muted); font-size: .84rem; padding-top: 18px; padding-bottom: 28px; border-top: 1px solid var(--border); display: flex; flex-wrap: wrap; gap: 6px; }

@media (max-width: 820px) {
  .hero, .grid-2 { grid-template-columns: 1fr; }
  .hero { padding: 28px 24px; }
  .hero-art { order: -1; }
  .hero-art img { max-width: 150px; }
  .steps { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .keyready { flex-direction: column; align-items: stretch; }
}
@media (max-width: 520px) {
  h1 { font-size: 1.4rem; }
  .card, .auth-card { padding: 18px; }
  .hero { padding: 24px 18px; border-radius: 14px; }
  .add-device { flex-direction: column; align-items: stretch; }
  .row-actions { justify-content: flex-start; }
  td.row-actions { white-space: normal; text-align: left; }
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-value { font-size: 1.6rem; }
}
