/* ===========================================================================
   idmanager design system.
   Tokens live here; every other rule consumes them via var(). No raw hex
   outside :root and the dark-mode blocks — that is what makes dark mode flow
   everywhere without per-component work.
   =========================================================================== */

:root {
  color-scheme: light;

  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-raised: #ffffff;

  --text: #1d1d1f;
  --text-secondary: #6e6e73;
  --text-tertiary: #86868b;

  --separator: rgba(0, 0, 0, 0.10);
  --separator-opaque: #d2d2d7;
  --fill-secondary: rgba(120, 120, 128, 0.12);
  --fill-tertiary: rgba(120, 120, 128, 0.08);

  --accent: #0071e3;
  --accent-hover: #0077ed;
  --accent-contrast: #ffffff;
  --accent-tint: rgba(0, 113, 227, 0.10);

  --success-fg: #1d7a3a;
  --success-bg: rgba(52, 199, 89, 0.14);
  --warning-fg: #9a5b00;
  --warning-bg: rgba(255, 149, 0, 0.16);
  --danger-fg: #c4291e;
  --danger-bg: rgba(255, 59, 48, 0.14);

  --focus-ring: 0 0 0 4px rgba(0, 113, 227, 0.35);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.08);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-pill: 980px;

  --text-xs: 12px;
  --text-sm: 13px;
  --text-base: 15px;
  --text-md: 17px;
  --text-lg: 21px;
  --text-2xl: 28px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
}

/* Two mechanisms on purpose: the media query honours the OS setting for a
   first-time visitor, and the attribute lets an explicit in-app choice win. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #000000;
    --surface: #1c1c1e;
    --surface-raised: #2c2c2e;
    --text: #f5f5f7;
    --text-secondary: #aeaeb2;
    --text-tertiary: #8e8e93;
    --separator: rgba(255, 255, 255, 0.12);
    --separator-opaque: #38383a;
    --fill-secondary: rgba(120, 120, 128, 0.24);
    --fill-tertiary: rgba(120, 120, 128, 0.18);
    --accent: #0a84ff;
    --accent-hover: #3d9bff;
    --accent-tint: rgba(10, 132, 255, 0.18);
    --success-fg: #4cd964;
    --success-bg: rgba(52, 199, 89, 0.20);
    --warning-fg: #ffb340;
    --warning-bg: rgba(255, 149, 0, 0.22);
    --danger-fg: #ff6961;
    --danger-bg: rgba(255, 59, 48, 0.22);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.5);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #000000;
  --surface: #1c1c1e;
  --surface-raised: #2c2c2e;
  --text: #f5f5f7;
  --text-secondary: #aeaeb2;
  --text-tertiary: #8e8e93;
  --separator: rgba(255, 255, 255, 0.12);
  --separator-opaque: #38383a;
  --fill-secondary: rgba(120, 120, 128, 0.24);
  --fill-tertiary: rgba(120, 120, 128, 0.18);
  --accent: #0a84ff;
  --accent-hover: #3d9bff;
  --accent-tint: rgba(10, 132, 255, 0.18);
  --success-fg: #4cd964;
  --success-bg: rgba(52, 199, 89, 0.20);
  --warning-fg: #ffb340;
  --warning-bg: rgba(255, 149, 0, 0.22);
  --danger-fg: #ff6961;
  --danger-bg: rgba(255, 59, 48, 0.22);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.5);
}

/* ── Base ─────────────────────────────────────────────────────────────── */

* { box-sizing: border-box; }

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

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.muted { color: var(--text-secondary); }
.hidden { display: none !important; }

/* ── Layout ───────────────────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-5);
  background: var(--surface);
  border-bottom: 1px solid var(--separator);
}

.topbar .brand {
  font-size: var(--text-md);
  font-weight: 600;
  color: var(--text);
}
.topbar .brand:hover { text-decoration: none; }

.shell {
  max-width: 760px;
  margin: 0 auto;
  padding: var(--space-6) var(--space-4);
}

.card {
  background: var(--surface);
  border: 1px solid var(--separator);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-5);
}

.card + .card { margin-top: var(--space-4); }

.narrow { max-width: 420px; margin: 0 auto; }

h1 { font-size: var(--text-2xl); margin: 0 0 var(--space-2); letter-spacing: -0.02em; }
h2 { font-size: var(--text-lg); margin: 0 0 var(--space-3); letter-spacing: -0.01em; }
.subtitle { color: var(--text-secondary); margin: 0 0 var(--space-5); }

/* ── Forms ────────────────────────────────────────────────────────────── */

.field { margin-bottom: var(--space-4); }
.field label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: var(--space-1);
}

.field input {
  width: 100%;
  padding: 10px var(--space-3);
  font-size: var(--text-base);
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--separator-opaque);
  border-radius: var(--radius-sm);
}
.field input:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus-ring); }

.row { display: flex; gap: var(--space-3); }
.row .field { flex: 1; }

.errors { list-style: none; margin: var(--space-1) 0 0; padding: 0; }
.errors li { color: var(--danger-fg); font-size: var(--text-sm); }

/* ── Buttons ──────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 10px var(--space-5);
  font-size: var(--text-base);
  font-family: inherit;
  font-weight: 500;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  cursor: pointer;
  background: var(--fill-secondary);
  color: var(--text);
}
.btn:hover { text-decoration: none; background: var(--fill-tertiary); }
.btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }

.btn-primary { background: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover { background: var(--accent-hover); }

.btn-block { width: 100%; }

.btn-quiet { background: transparent; border-color: var(--separator-opaque); }
.btn-danger { background: transparent; color: var(--danger-fg); border-color: var(--separator-opaque); }
.btn-danger:hover { background: var(--danger-bg); }

.btn[disabled] { opacity: 0.45; cursor: not-allowed; }

/* ── Messages ─────────────────────────────────────────────────────────── */

.messages { list-style: none; margin: 0 0 var(--space-4); padding: 0; }
.messages li {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-2);
  font-size: var(--text-sm);
}
.messages .success { background: var(--success-bg); color: var(--success-fg); }
.messages .error   { background: var(--danger-bg);  color: var(--danger-fg); }
.messages .warning { background: var(--warning-bg); color: var(--warning-fg); }
.messages .info    { background: var(--fill-secondary); color: var(--text-secondary); }

/* ── Identity list ────────────────────────────────────────────────────── */

.identity {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--separator);
}
.identity:last-child { border-bottom: none; }

.identity .meta { min-width: 0; }
.identity .name { font-weight: 500; }
.identity .detail { font-size: var(--text-sm); color: var(--text-secondary); }

.divider {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin: var(--space-5) 0;
  color: var(--text-tertiary);
  font-size: var(--text-sm);
}
.divider::before, .divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--separator);
}

.stack > * + * { margin-top: var(--space-3); }
.footnote { margin-top: var(--space-5); text-align: center; font-size: var(--text-sm); }

/* ── Badges ───────────────────────────────────────────────────────────── */

.badges { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-2); }
.badge {
  display: inline-block;
  padding: 2px var(--space-3);
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: 500;
}
.badge-ok { background: var(--success-bg); color: var(--success-fg); }
.badge-warn { background: var(--warning-bg); color: var(--warning-fg); }

/* ── National ID card (face + demographics) ───────────────────────────── */

.face-photo {
  width: 96px;
  height: 96px;
  object-fit: cover;
  border-radius: var(--radius-md);
  border: 1px solid var(--separator);
  flex: none;
}
.detail-table { border-collapse: collapse; width: 100%; font-size: var(--text-sm); }
.detail-table th {
  text-align: left;
  color: var(--text-secondary);
  font-weight: 500;
  padding: var(--space-1) var(--space-3) var(--space-1) 0;
  vertical-align: top;
  white-space: nowrap;
}
.detail-table td { padding: var(--space-1) 0; color: var(--text); }

@media (max-width: 560px) {
  .shell { padding: var(--space-4) var(--space-3); }
  .row { flex-direction: column; gap: 0; }
}
