:root {
  --bg: #1c1350;
  --bg-2: #2a1d78;
  --panel: rgba(28, 19, 80, 0.72);
  --stroke: rgba(255, 255, 255, 0.14);
  --text: #ffffff;
  --muted: #c9c0e8;
  --gold: #e8c15a;
  --on-gold: #241a5c;
  --error: #ff8a80;
  --ok: #8fd9a8;
  --radius: 16px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font: 15px/1.5 system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--text);
  background: radial-gradient(1200px 600px at 80% -10%, #5a2db5 0%, transparent 60%),
    linear-gradient(180deg, var(--bg-2), var(--bg));
  background-attachment: fixed;
}

[hidden] { display: none !important; }

.wordmark {
  font-family: 'Reem Kufi', serif;
  color: var(--gold);
  letter-spacing: 0.04em;
  font-size: 22px;
  margin: 0;
}
.wordmark span { color: var(--muted); font-family: system-ui, sans-serif; font-size: 14px; font-weight: 500; }

.card {
  background: var(--panel);
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  padding: 20px;
  backdrop-filter: blur(16px);
}

.login { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { width: min(380px, 100%); display: grid; gap: 14px; }

label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid var(--stroke);
  border-radius: 10px;
  padding: 9px 12px;
  min-width: 0;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }

button {
  font: inherit;
  cursor: pointer;
  border-radius: 999px;
  padding: 7px 14px;
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  white-space: nowrap;
}
button:hover { background: rgba(255, 255, 255, 0.12); }
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: var(--gold); color: var(--on-gold); border-color: var(--gold); font-weight: 600; }
button.danger { color: var(--error); border-color: rgba(255, 138, 128, 0.4); }
button.ghost { background: none; }

.error { color: var(--error); margin: 0; min-height: 1.2em; font-size: 13px; }

.shell { max-width: 1180px; margin: 0 auto; padding: 0 16px 48px; }

.topbar {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 14px 0;
  background: linear-gradient(180deg, var(--bg-2) 70%, transparent);
}
#tabs { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
#tabs button[aria-current='page'] { background: var(--gold); color: var(--on-gold); border-color: var(--gold); }

.view { display: grid; gap: 16px; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar input[type='search'] { flex: 1; min-width: 180px; }
.toolbar h2 { margin: 0 auto 0 0; font-size: 20px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat strong { display: block; font-size: 30px; color: var(--gold); font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 13px; }

.list { display: grid; gap: 10px; }
.row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px;
  align-items: center;
}
.row img, .thumb {
  width: 64px; height: 80px; object-fit: cover;
  border-radius: 10px; background: rgba(0, 0, 0, 0.3);
}
.row.plain { grid-template-columns: 1fr auto; }
.thumb { display: grid; place-items: center; font: 600 26px 'Reem Kufi', serif; color: var(--gold); }
.row .main { min-width: 0; }
.row .title { font-weight: 600; overflow-wrap: anywhere; }
.row .meta { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.row .actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

.badge {
  display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px;
  border: 1px solid var(--stroke); color: var(--muted); margin-inline-start: 6px; vertical-align: 1px;
}
.badge.gold { color: var(--gold); border-color: rgba(232, 193, 90, 0.5); }
.badge.bad { color: var(--error); border-color: rgba(255, 138, 128, 0.5); }
.badge.ok { color: var(--ok); border-color: rgba(143, 217, 168, 0.5); }

.empty { color: var(--muted); text-align: center; padding: 32px; }

dialog {
  color: var(--text); background: var(--bg-2);
  border: 1px solid var(--stroke); border-radius: var(--radius);
  width: min(440px, calc(100vw - 32px)); padding: 20px;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.55); }
dialog form { display: grid; gap: 12px; }
dialog h3 { margin: 0; }
dialog .buttons { display: flex; gap: 8px; justify-content: flex-end; }

.toast {
  position: fixed; inset-inline: 16px; bottom: 20px; margin: 0 auto; width: fit-content; max-width: calc(100% - 32px);
  background: var(--gold); color: var(--on-gold); font-weight: 600;
  padding: 10px 18px; border-radius: 999px; opacity: 0; transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s; pointer-events: none;
}
.toast.show { opacity: 1; transform: none; }
.toast.bad { background: var(--error); }

@media (max-width: 640px) {
  .topbar { position: static; justify-content: space-between; }
  #tabs { order: 3; flex: 1 0 100%; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .row { grid-template-columns: auto 1fr; }
  .row.plain { grid-template-columns: 1fr; }
  .row .actions { grid-column: 1 / -1; justify-content: flex-start; }
}

/* ------------------------------------------------------------------ */
/* Analytics tab (2026-10-12). Charts are inline SVG; marks carry the */
/* series colour, every piece of text stays on the ink tokens.        */
/* ------------------------------------------------------------------ */
.analytics-section { margin: 0 0 28px; }
.section-head { margin: 0 0 10px; }
.section-head h3 { margin: 0 0 2px; font-size: 17px; }
.section-head p { margin: 0; font-size: 13px; max-width: 80ch; line-height: 1.45; }
.muted { color: var(--muted); }
.footnote { font-size: 13px; max-width: 80ch; }

.tiles { margin-bottom: 0; }
.tile { display: grid; gap: 2px; padding: 14px 16px; }
.tile-label { color: var(--muted); font-size: 13px; }
.tile-value { font-size: 24px; line-height: 1.1; }
.tile-sub { color: var(--muted); font-size: 12px; }

.chart-wrap { position: relative; }
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid { stroke: rgba(255, 255, 255, 0.1); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .cursor { stroke: rgba(255, 255, 255, 0.35); stroke-width: 1; stroke-dasharray: 3 3; }

.tip {
  position: absolute; top: 4px; z-index: 2; pointer-events: none;
  background: var(--bg); border: 1px solid var(--stroke); border-radius: 10px;
  padding: 8px 10px; font-size: 12px; display: grid; gap: 2px; white-space: nowrap;
}
.tip svg { vertical-align: -1px; }

.legend { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 8px; font-size: 13px; color: var(--muted); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }

.funnel { display: grid; gap: 8px; }
.funnel-row { display: grid; grid-template-columns: 90px 1fr 70px 150px; align-items: center; gap: 10px; font-size: 14px; }
.funnel-name { text-transform: capitalize; color: var(--muted); }
.funnel-bar { background: rgba(255, 255, 255, 0.07); border-radius: 4px; height: 18px; }
.funnel-fill { display: block; height: 100%; border-radius: 4px; background: #b28d2e; }
.funnel-n { text-align: right; font-variant-numeric: tabular-nums; }
.funnel-rate { color: var(--muted); font-size: 13px; }

.table-wrap { overflow-x: auto; padding: 0; }
table.data { border-collapse: collapse; width: 100%; font-size: 13px; }
table.data th, table.data td { padding: 8px 10px; text-align: left; white-space: nowrap; }
table.data th { color: var(--muted); font-weight: 600; cursor: pointer; user-select: none; position: sticky; top: 0; background: var(--bg-2); }
table.data th[aria-sort]::after { content: ' \25BC'; font-size: 9px; }
table.data th[aria-sort="ascending"]::after { content: ' \25B2'; }
table.data td.n, table.data th.n { text-align: right; font-variant-numeric: tabular-nums; }
table.data tbody tr:nth-child(odd) { background: rgba(255, 255, 255, 0.03); }

.cell-bar { display: inline-grid; grid-template-columns: 1fr auto; align-items: center; gap: 6px; min-width: 110px; }
.cell-fill { height: 8px; border-radius: 4px; min-width: 2px; }
.cell-n { font-variant-numeric: tabular-nums; }

.two-col { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.stack { display: grid; gap: 16px; }
.analytics-section h4 { margin: 14px 0 6px; font-size: 14px; color: var(--muted); }
.numbers { margin-top: 12px; }
.numbers summary { cursor: pointer; color: var(--muted); font-size: 13px; }

@media (max-width: 640px) {
  .funnel-row { grid-template-columns: 72px 1fr 56px; }
  .funnel-rate { grid-column: 2 / -1; }
}

/* Two-step sign-in */
.login-card .meta { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
#mfa-qr { justify-self: center; background: #fff; border-radius: 8px; padding: 8px; }
