/* Visitor Management – corporate UI */
:root {
  --brand: #0b4f8a;
  --brand-600: #0a4477;
  --brand-50: #eaf2fa;
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #dde3ea;
  --border-strong: #c7d0da;
  --text: #1b2530;
  --text-2: #4e5b68;
  --text-3: #7a8693;
  --ok: #0b7a4f; --ok-bg: #e5f5ee;
  --warn: #8a5a00; --warn-bg: #fff4d6;
  --bad: #b42318; --bad-bg: #fdecea;
  --info: #0b4f8a; --info-bg: #e7f0fa;
  --muted-bg: #eef1f4;
  --purple: #6941c6; --purple-bg: #f1ecfc;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .18);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: Consolas, "SF Mono", Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1419; --surface: #171e26; --surface-2: #1c242e; --border: #2a3440; --border-strong: #3a4654;
    --text: #e6ebf0; --text-2: #b3bec9; --text-3: #8592a0; --brand-50: #13263a;
    --ok: #4cc38a; --ok-bg: #11291f; --warn: #f0b429; --warn-bg: #2d2412; --bad: #f97066; --bad-bg: #3a1714;
    --info: #6aa9e6; --info-bg: #13263a; --muted-bg: #222b35; --purple: #b692f6; --purple-bg: #2a2140;
    --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
a { color: var(--link, var(--brand)); text-decoration: none; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --link: var(--info); } }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; font-weight: 600; }
h1 { font-size: 22px; } h2 { font-size: 17px; } h3 { font-size: 15px; }
p { margin: 0 0 10px; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
[hidden] { display: none !important; }

/* ---------- Layout ---------- */
.shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar { background: #0c2238; color: #cdd8e4; padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; color: #fff; font-weight: 600; font-size: 15px; }
.brand-mark { width: 32px; height: 32px; border-radius: 8px; background: var(--brand); display: grid; place-items: center; color: #fff; flex: none; }
.brand small { display: block; font-weight: 400; color: #8fa3b8; font-size: 11.5px; }
.nav-group { margin: 10px 0 4px; padding: 0 10px; font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: #7f93a8; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 7px; color: #cdd8e4; font-weight: 500; }
.nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.nav a.active { background: rgba(255,255,255,.12); color: #fff; }
.nav svg { width: 18px; height: 18px; flex: none; opacity: .9; }
.nav .count { margin-left: auto; background: #e0a100; color: #1b1300; border-radius: 10px; font-size: 11px; padding: 0 7px; font-weight: 700; }
.brand.has-logo { flex-direction: column; align-items: flex-start; gap: 8px; }
.logo-chip { display: inline-flex; align-items: center; background: #fff; border-radius: 8px; padding: 6px 10px; max-width: 100%; }
.logo-chip img { display: block; max-height: 40px; max-width: 200px; width: auto; height: auto; object-fit: contain; }
.logo-chip.sm { padding: 4px 8px; border-radius: 6px; }
.logo-chip.sm img { max-height: 28px; max-width: 140px; }
.auth-brand .brand { color: var(--text); padding: 0 0 18px; }
.auth-brand .brand small { color: var(--text-3); }
.auth-brand .logo-chip { padding: 0; }
.auth-brand .logo-chip img { max-height: 56px; max-width: 240px; }
.sidebar-foot { margin-top: auto; padding: 12px 10px 0; font-size: 12px; color: #8fa3b8; }
.main { min-width: 0; }
.topbar { height: 60px; display: flex; align-items: center; gap: 12px; padding: 0 24px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar .title { font-weight: 600; font-size: 15px; }
.topbar .spacer { flex: 1; }
.btn.menu-btn { display: none; }
.content { padding: 24px; max-width: 1320px; }
.page-head { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .sub { color: var(--text-2); margin-top: 4px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 50; left: 0; top: 0; width: 264px; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow-lg); }
  .shell.nav-open .sidebar { transform: none; }
  .shell.nav-open::after { content: ""; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; }
  .btn.menu-btn { display: inline-flex; }
  .content { padding: 16px; }
  .topbar { padding: 0 16px; }
}

/* ---------- Components ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-h h2, .card-h h3 { flex: 1; }
.card-b { padding: 18px; }
.card-b.tight { padding: 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid > * { min-width: 0; }
@media (max-width: 1150px) { .g2 { grid-template-columns: minmax(0, 1fr); } .g3, .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 1000px) { .g3 { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 700px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } }
.stack > * + * { margin-top: 16px; }

.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
@media (max-width: 1200px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 560px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kpi { padding: 14px 16px; display: block; color: inherit; }
.kpi:hover { text-decoration: none; border-color: var(--border-strong); }
.kpi .v { font-size: 26px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--text-2); font-size: 12.5px; margin-top: 4px; }
.kpi.ok .v { color: var(--ok); } .kpi.warn .v { color: var(--warn); } .kpi.bad .v { color: var(--bad); } .kpi.info .v { color: var(--info); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: 7px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; text-decoration: none !important; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand, #fff); }
label.btn.disabled { opacity: .55; pointer-events: none; }
.btn.primary:hover { background: var(--brand-600); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--border)); }
.btn.danger:hover { background: var(--bad-bg); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--muted-bg); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn svg { width: 16px; height: 16px; }
.icon-btn { width: 36px; padding: 0; position: relative; }
.icon-btn .dot { position: absolute; top: 4px; right: 4px; min-width: 16px; height: 16px; border-radius: 8px; background: var(--bad); color: #fff; font-size: 10px; display: grid; place-items: center; padding: 0 4px; font-weight: 700; }

.badge { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: 11px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--muted-bg); color: var(--text-2); }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 3px; background: currentColor; opacity: .9; }
.badge.plain::before { display: none; }
.s-pending_approval { background: var(--warn-bg); color: var(--warn); }
.s-pending_verification { background: var(--purple-bg); color: var(--purple); }
.s-invited { background: var(--info-bg); color: var(--info); }
.s-checked_in { background: var(--ok-bg); color: var(--ok); }
.s-checked_out { background: var(--muted-bg); color: var(--text); }
.s-cancelled { background: var(--bad-bg); color: var(--bad); }
.s-expired { background: var(--muted-bg); color: var(--text-3); }
.e-accepted { background: var(--ok-bg); color: var(--ok); }
.e-queued, .e-sending { background: var(--warn-bg); color: var(--warn); }
.e-failed, .e-not_configured { background: var(--bad-bg); color: var(--bad); }
.tag-demo { background: var(--purple-bg); color: var(--purple); }

table.t { width: 100%; border-collapse: collapse; }
table.t th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--text-3); font-weight: 600; padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
table.t td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.t tr:last-child td { border-bottom: 0; }
table.t tr.click { cursor: pointer; }
table.t tr.click:hover td { background: var(--surface-2); }
.t .sub { color: var(--text-3); font-size: 12.5px; }
.table-wrap { overflow-x: auto; }
.nowrap { white-space: nowrap; }
.t td.col-visitor { min-width: 170px; }
@media (max-width: 640px) {
  table.t.cards-sm thead { display: none; }
  table.t.cards-sm, table.t.cards-sm tbody { display: block; }
  table.t.cards-sm tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 14px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
  table.t.cards-sm tr:last-child { border-bottom: 0; }
  table.t.cards-sm td { display: block; padding: 0; border: 0; min-width: 0; }
  table.t.cards-sm td.col-visitor { grid-column: 1 / -1; }
  table.t.cards-sm td[data-label]::before { content: attr(data-label); display: block; font-size: 11px; font-weight: 600; letter-spacing: .4px; text-transform: uppercase; color: var(--text-3); }
}
.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 28px 18px; text-align: center; color: var(--text-3); }

.field { display: flex; flex-direction: column; gap: 5px; }
.field > span, .label { font-weight: 600; font-size: 13px; color: var(--text-2); }
.field .hint { font-size: 12px; color: var(--text-3); }
.req::after { content: " *"; color: var(--bad); }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: 7px; padding: 8px 10px; min-height: 36px; width: 100%; }
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 40%, transparent); outline-offset: 0; border-color: var(--brand); }
input[type=checkbox], input[type=radio] { width: auto; min-height: 0; accent-color: var(--brand); }
.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 500; }
.check input { margin-top: 3px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 700px) { .form-grid { grid-template-columns: 1fr; } }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--text-3); font-weight: 700; margin: 6px 0 -4px; grid-column: 1 / -1; }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.filters .field { min-width: 140px; flex: 1 1 140px; }
.filters .field.grow { flex: 2 1 220px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { padding: 9px 14px; color: var(--text-2); font-weight: 600; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--brand); border-color: var(--brand); text-decoration: none; }

.alert { padding: 12px 14px; border-radius: 8px; border: 1px solid; display: flex; gap: 10px; align-items: flex-start; }
.alert.info { background: var(--info-bg); border-color: color-mix(in srgb, var(--info) 30%, transparent); color: var(--text); }
.alert.warn { background: var(--warn-bg); border-color: color-mix(in srgb, var(--warn) 35%, transparent); color: var(--text); }
.alert.bad { background: var(--bad-bg); border-color: color-mix(in srgb, var(--bad) 35%, transparent); color: var(--text); }
.alert.ok { background: var(--ok-bg); border-color: color-mix(in srgb, var(--ok) 35%, transparent); color: var(--text); }
.alert b { display: block; }

dl.kv { display: grid; grid-template-columns: 170px 1fr; gap: 8px 14px; margin: 0; }
dl.kv dt { color: var(--text-3); }
dl.kv dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }
@media (max-width: 560px) { dl.kv { grid-template-columns: 1fr; gap: 2px; } dl.kv dd { margin-bottom: 8px; } }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 14px 22px; }
.timeline li::before { content: ""; position: absolute; left: 5px; top: 6px; width: 8px; height: 8px; border-radius: 4px; background: var(--brand); }
.timeline li::after { content: ""; position: absolute; left: 8.5px; top: 16px; bottom: 0; width: 1px; background: var(--border); }
.timeline li:last-child::after { display: none; }
.timeline .when { color: var(--text-3); font-size: 12.5px; }

.bar { height: 8px; background: var(--muted-bg); border-radius: 4px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--brand); }

.copy-field { display: flex; gap: 6px; }
.code-box { margin: 8px 0 0; padding: 10px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 7px; font-family: var(--mono); font-size: 12.5px; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 320px; overflow: auto; }
textarea.mono { font-family: var(--mono); font-size: 12.5px; }

/* ---------- Two-factor authentication ---------- */
.tf-steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 10px; }
.tf-qr { margin: 10px 0 6px; display: block; width: max-content; padding: 10px; background: #fff; border-radius: 10px; border: 1px solid var(--border); }
.tf-qr img { display: block; }
.tf-code-input { font-family: var(--mono); font-size: 20px; letter-spacing: 4px; text-align: center; }
.recovery-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; padding: 12px; border: 1px dashed var(--border-strong); border-radius: 8px; background: var(--surface-2); font-size: 15px; text-align: center; }
.setup-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: var(--bg); }
.setup-card { width: min(520px, 100%); }
.copy-field input { font-family: var(--mono); font-size: 12.5px; }

.pager { display: flex; align-items: center; gap: 8px; justify-content: flex-end; padding: 12px 18px; border-top: 1px solid var(--border); color: var(--text-2); }

/* ---------- Toasts & modal ---------- */
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: #1b2530; color: #fff; padding: 12px 14px; border-radius: 8px; box-shadow: var(--shadow-lg); font-weight: 500; }
.toast.bad { background: #8f1d14; } .toast.ok { background: #0b5e3d; }
.modal-back { position: fixed; inset: 0; background: rgba(12, 20, 30, .5); display: grid; place-items: center; z-index: 90; padding: 16px; }
.modal { background: var(--surface); border-radius: 12px; width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto; box-shadow: var(--shadow-lg); }
.modal.wide { width: min(820px, 100%); }
.modal .card-h { position: sticky; top: 0; background: var(--surface); z-index: 1; }

.dropdown { position: absolute; right: 16px; top: 56px; width: min(380px, calc(100vw - 32px)); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-lg); z-index: 60; max-height: 70vh; overflow: auto; }
.notif { display: block; padding: 12px 14px; border-bottom: 1px solid var(--border); color: inherit; }
.notif:hover { background: var(--surface-2); text-decoration: none; }
.notif.unread { background: var(--brand-50); }
.notif .when { color: var(--text-3); font-size: 12px; }

/* ---------- Auth / public pages ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: linear-gradient(160deg, #0c2238 0%, var(--brand) 100%); }
.auth-card { width: min(420px, 100%); padding: 28px; }
.public-wrap { min-height: 100vh; background: var(--bg); }
.public-head { background: var(--brand); color: var(--on-brand, #fff); padding: 14px 16px; min-height: 60px; display: flex; align-items: center; }
.public-head .in { max-width: 760px; width: 100%; margin: 0 auto; display: flex; align-items: center; gap: 12px; font-weight: 600; font-size: 16px; }
.public-body { max-width: 760px; margin: 0 auto; padding: 20px 16px 24px; }
.public-head .logo-chip.sm img { max-height: 36px; max-width: 180px; }
.public-foot { max-width: 760px; margin: 0 auto; padding: 0 16px 40px; color: var(--text-3); font-size: 12.5px; line-height: 1.6; }
.public-foot strong { color: var(--text-2); }

/* ---------- Organisation settings ---------- */
.org-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
.org-preview { position: sticky; top: 76px; }
@media (max-width: 1150px) { .org-layout { grid-template-columns: minmax(0, 1fr); } .org-preview { position: static; } }
.logo-edit { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.logo-box { width: 240px; height: 110px; border: 1px dashed var(--border-strong); border-radius: 10px; display: grid; place-items: center; padding: 12px; flex: none;
  background: #fff repeating-conic-gradient(#f1f3f6 0 25%, #fff 0 50%) 0 0 / 16px 16px; }
.logo-box img { max-width: 100%; max-height: 86px; object-fit: contain; }
.pv-sidebar { background: #0c2238; color: #fff; border-radius: 8px; padding: 12px; display: flex; flex-direction: column; align-items: flex-start; gap: 8px; font-weight: 600; }
.pv-name small { display: block; font-weight: 400; color: #8fa3b8; font-size: 11.5px; }
.pv-mail { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.pv-mail-white { background: #fff; color: #5b6875; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; font-size: 12px; }
.pv-logo img { display: block; max-height: 32px; max-width: 150px; }
.pv-mail-color { padding: 12px; font-weight: 600; }
.pv-public { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.pv-pub-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px; font-weight: 600; }
.muted { color: var(--text-2); }
.small { font-size: 12.5px; }
.right { text-align: right; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--border-strong); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { padding: 40px; text-align: center; color: var(--text-3); }
.ref { font-family: var(--mono); font-weight: 700; letter-spacing: 1px; }
