/* ---------- Tokens ---------- */
:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #f1f3f9;
  --border: #e3e6ef;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef2ff;
  --on-primary: #ffffff;
  --success: #059669;
  --success-soft: #d1fae5;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --chart-1: #4f46e5;
  --chart-2: #0ea5e9;
  --shadow: 0 1px 2px rgb(15 23 42 / 6%), 0 1px 3px rgb(15 23 42 / 4%);
  --shadow-lg: 0 20px 50px rgb(15 23 42 / 20%);
  --radius: 14px;
  --radius-sm: 10px;
  --sidebar-w: 248px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1020;
    --surface: #131a2e;
    --surface-2: #1b2440;
    --border: #263052;
    --text: #e8ecf6;
    --muted: #94a0bd;
    --primary: #6366f1;
    --primary-hover: #7578f5;
    --primary-soft: #1e2347;
    --success: #34d399;
    --success-soft: #0f3a2e;
    --danger: #f87171;
    --danger-soft: #3b1a1f;
    --chart-1: #818cf8;
    --chart-2: #38bdf8;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%);
    --shadow-lg: 0 20px 50px rgb(0 0 0 / 55%);
  }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p { margin: 0; }
h1 { font-size: 1.5rem; line-height: 1.25; letter-spacing: -0.01em; }
h2 { font-size: 1.1rem; }
h3 { font-size: 0.95rem; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.8125rem; }
.nowrap { white-space: nowrap; }
.center { text-align: center; }
.grow { flex: 1; min-width: 0; }
.icon { flex: none; }

/* ---------- Buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  min-height: 40px; padding: 0 1rem;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font-weight: 550; line-height: 1; white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger); filter: brightness(0.92); }
.btn-danger-outline { color: var(--danger); }
.btn-danger-outline:hover { background: var(--danger-soft); }
.btn-sm { min-height: 34px; padding: 0 0.75rem; font-size: 0.875rem; }
.btn-block { width: 100%; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; padding: 0;
  border: 0; border-radius: 8px; background: transparent; color: var(--muted);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }
.icon-btn.sm { width: 28px; height: 28px; }

input[type="text"], input[type="password"], input[type="search"], input[type="url"], select {
  width: 100%; min-height: 42px; padding: 0 0.75rem;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
}
input::placeholder { color: var(--muted); opacity: 0.75; }
input:focus, select:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }
input[aria-invalid] { border-color: var(--danger); }
select { appearance: none; padding-right: 2rem; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 17px) 18px, calc(100% - 12px) 18px; background-size: 5px 5px; background-repeat: no-repeat; }
input[type="color"] { width: 40px; height: 40px; padding: 2px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); cursor: pointer; flex: none; }

.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field > span, .field > label > span { font-size: 0.8125rem; font-weight: 600; }
.hint { min-height: 1.1em; font-size: 0.78rem; color: var(--muted); }
.hint.ok { color: var(--success); }
.hint.bad, .field-error, .form-error { color: var(--danger); }
.field-error, .form-error { font-size: 0.8125rem; }
.form-error { padding: 0.6rem 0.8rem; border-radius: var(--radius-sm); background: var(--danger-soft); }

.input-group { display: flex; align-items: stretch; }
.input-group .prefix {
  display: flex; align-items: center; flex: none; padding: 0 0.7rem; max-width: 60%;
  border: 1px solid var(--border); border-right: 0; border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  background: var(--surface-2); color: var(--muted); font-size: 0.875rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.input-group input { flex: 1; min-width: 0; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }

/* On/off switch: a <button role=switch> in lists, an <input role=switch> in forms. */
.switch, input[role="switch"] {
  appearance: none; position: relative; flex: none;
  width: 42px; height: 24px; padding: 0; margin: 0;
  border: 0; border-radius: 999px; background: var(--border);
  transition: background 0.2s;
}
.switch-thumb, input[role="switch"]::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 18px; height: 18px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 2px rgb(0 0 0 / 30%); transition: transform 0.2s;
}
.switch[aria-checked="true"], input[role="switch"]:checked { background: var(--success); }
.switch[aria-checked="true"] .switch-thumb, input[role="switch"]:checked::after { transform: translateX(18px); }
.switch:disabled { opacity: 0.6; }

.segmented { display: inline-flex; padding: 3px; gap: 2px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
.segmented button { min-height: 32px; padding: 0 0.8rem; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font-size: 0.875rem; font-weight: 550; }
.segmented button.active { background: var(--primary-soft); color: var(--primary); }

/* ---------- Brand ---------- */
.brand { display: flex; align-items: center; gap: 0.6rem; font-weight: 700; font-size: 1.05rem; letter-spacing: -0.01em; }
.brand-lg { font-size: 1.25rem; margin-bottom: 1.5rem; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: var(--primary) url("/static/favicon.svg") center / cover; }

/* ---------- Shell ---------- */
.shell { min-height: 100vh; min-height: 100dvh; }
.sidebar { display: none; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.6rem 1rem; padding-top: calc(0.6rem + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.content { padding: 1.25rem 1rem calc(5.5rem + env(safe-area-inset-bottom)); max-width: 1200px; margin: 0 auto; outline: none; }
.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 20;
  display: grid; grid-template-columns: repeat(3, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
}
.tabbar .nav-link { flex-direction: column; gap: 2px; padding: 0.55rem 0.25rem; font-size: 0.72rem; border-radius: 0; }

.nav-link {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.6rem 0.8rem; border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--muted); font-weight: 550; text-align: left; width: 100%;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-link.active { background: var(--primary-soft); color: var(--primary); }

@media (min-width: 900px) {
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w);
    display: flex; flex-direction: column; gap: 1.25rem; padding: 1.25rem 1rem;
    background: var(--surface); border-right: 1px solid var(--border);
  }
  .nav { display: flex; flex-direction: column; gap: 2px; }
  .sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 0.5rem; padding-top: 1rem; border-top: 1px solid var(--border); }
  .user { display: flex; align-items: center; gap: 0.6rem; padding: 0 0.8rem; font-weight: 600; }
  .avatar { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); font-size: 0.8rem; }
  .main { margin-left: var(--sidebar-w); }
  .topbar, .tabbar { display: none; }
  .content { padding: 2rem 2rem 3rem; }
}

/* ---------- Page chrome ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 0.75rem 1rem; margin-bottom: 1.25rem; }
.page-head p { margin-top: 0.15rem; }
.page-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.section-title { margin: 1.75rem 0 0.75rem; }
.section-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem; margin: 0.25rem 0 0.75rem; }
.section-head .section-title { margin: 0; }
.back-link { display: inline-flex; align-items: center; gap: 0.35rem; margin-bottom: 0.75rem; color: var(--muted); font-weight: 550; font-size: 0.875rem; }

.card { padding: 1.1rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.9rem; }
.card-head h3 { display: flex; align-items: center; gap: 0.5rem; }
.card-icon { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 7px; background: var(--primary-soft); color: var(--primary); }

.grid { display: grid; gap: 1rem; }
.grid-kpi { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-bottom: 1rem; }
.grid-main { grid-template-columns: minmax(0, 1fr); }
.grid-traffic { grid-template-columns: minmax(0, 1fr); }
@media (min-width: 700px) { .grid-traffic { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1000px) {
  .grid-kpi { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .grid-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
  .grid-traffic { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
.grid-main + .section-title, .card + .section-title { margin-top: 1.75rem; }
.grid-kpi + .card, .grid-kpi + .grid { margin-top: 0; }
.attribution { margin-top: 1rem; }

.kpi { display: flex; gap: 0.8rem; align-items: center; padding: 1rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); min-width: 0; }
.kpi > div { min-width: 0; }
.kpi-icon { display: grid; place-items: center; flex: none; width: 40px; height: 40px; border-radius: 11px; background: var(--primary-soft); color: var(--primary); }
.kpi-label { color: var(--muted); font-size: 0.8125rem; font-weight: 550; }
.kpi-value { font-size: 1.5rem; font-weight: 700; line-height: 1.2; letter-spacing: -0.02em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kpi-value { min-width: 0; }
.kpi-hint { color: var(--muted); font-size: 0.78rem; }

@media (max-width: 479px) {
  .kpi { padding: 0.85rem; }
  .kpi-icon { display: none; }
}
.kpi-text { font-size: 1.1rem; line-height: 1.3; white-space: normal; overflow-wrap: anywhere; }

.chart-box { position: relative; height: 260px; }
.chart-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 0.875rem; pointer-events: none; }

/* Horizontal-bar breakdown lists */
.bars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.35rem; }
.bar-row { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; min-height: 34px; padding: 0 0.6rem; border-radius: 8px; overflow: hidden; }
.bar-fill { position: absolute; inset: 0 auto 0 0; width: var(--w); background: var(--primary-soft); border-radius: 8px; }
.bar-label, .bar-value { position: relative; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.9rem; }
.bar-value { flex: none; font-weight: 650; font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.bar-value small { color: var(--muted); font-weight: 450; }
.empty-note { padding: 1rem 0; text-align: center; }

.top-links { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.top-links li { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; padding: 0.6rem 0; border-bottom: 1px solid var(--border); }
.top-links li:last-child { border-bottom: 0; }
.top-links a { display: flex; flex-direction: column; min-width: 0; color: var(--text); }
.top-links a:hover { text-decoration: none; }
.top-links a:hover strong { color: var(--primary); }
.top-links strong, .top-links span.muted { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-count { flex: none; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- Links list ---------- */
.toolbar { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; margin-bottom: 1rem; }
.toolbar .search { grid-column: 1 / -1; position: relative; display: block; }
.toolbar .search .icon { position: absolute; top: 12px; left: 12px; color: var(--muted); pointer-events: none; }
.toolbar .search input { padding-left: 2.4rem; }
@media (min-width: 900px) {
  .toolbar { grid-template-columns: minmax(220px, 1.6fr) repeat(4, minmax(0, 1fr)); }
  .toolbar .search { grid-column: auto; }
}

.link-list { display: flex; flex-direction: column; gap: 0.75rem; }
.link-row {
  display: grid; gap: 0.75rem 1rem;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "title toggle" "short short" "dest dest" "meta meta" "org org" "stats actions";
  gap: 0.2rem 1rem; align-items: center; padding: 1rem;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow);
}
.cell-toggle { grid-area: toggle; align-self: start; justify-self: end; }
/* Mobile: the main column dissolves into the card grid so each line can span the full width. */
.cell-main { grid-area: main; min-width: 0; flex-direction: column; gap: 0.2rem; display: contents; }
.link-title-line { grid-area: title; }
.short-url { grid-area: short; }
.dest { grid-area: dest; }
.meta { grid-area: meta; }
.cell-org, .cell-stats, .cell-actions { margin-top: 0.55rem; }
.cell-org { grid-area: org; display: flex; flex-wrap: wrap; gap: 0.35rem; }
.cell-stats { grid-area: stats; display: flex; gap: 1.25rem; }
.cell-stats div { display: flex; flex-direction: column; line-height: 1.25; }
.cell-stats strong { font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.cell-stats span { color: var(--muted); font-size: 0.75rem; }
.cell-actions { grid-area: actions; display: flex; justify-content: flex-end; gap: 0.1rem; }
.cell-org:has(> .small:only-child) { display: none; }

.link-title-line { display: flex; align-items: center; gap: 0.5rem; min-width: 0; }
.link-title { overflow-wrap: anywhere; font-weight: 650; color: var(--text); }
.link-title:hover { color: var(--primary); text-decoration: none; }
.link-row .badge-off { display: none; }
.link-row.is-disabled .badge-off { display: inline-flex; }
.link-row.is-disabled .link-title, .link-row.is-disabled .dest { opacity: 0.6; }
.short-url { display: flex; align-items: center; gap: 0.25rem; min-width: 0; font-weight: 600; }
.short-url a { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.short-url.lg { font-size: 1.1rem; }
.dest { display: flex; align-items: center; gap: 0.3rem; min-width: 0; color: var(--muted); font-size: 0.8125rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dest-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dest.wrap { white-space: normal; word-break: break-all; align-items: flex-start; }
.dest.wrap .icon { margin-top: 4px; }
.dest a { color: inherit; }
.meta { color: var(--muted); font-size: 0.75rem; }

@media (min-width: 900px) {
  .link-row {
    grid-template-columns: 46px minmax(0, 1.8fr) minmax(0, 1fr) 150px auto;
    grid-template-areas: "toggle main org stats actions"; padding: 1rem 1.1rem;
  }
  .cell-main { display: flex; }
  .cell-toggle { align-self: center; justify-self: auto; }
  .cell-org, .cell-stats, .cell-actions { margin-top: 0; }
  .cell-actions { gap: 0; }
  .link-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

.chips { display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; }
.chip {
  display: inline-flex; align-items: center; gap: 0.35rem; max-width: 100%;
  padding: 2px 9px; border: 0; border-radius: 999px;
  background: var(--surface-2); color: var(--text); font-size: 0.78rem; font-weight: 550; line-height: 1.6;
}
button.chip:hover { background: var(--primary-soft); color: var(--primary); }
.chip-tag { color: var(--muted); }
.chip .dot, .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c, var(--primary)); flex: none; }
.chip button { display: grid; place-items: center; padding: 0; border: 0; background: none; color: var(--muted); }
.chip button:hover { color: var(--danger); }

.badge { display: inline-flex; align-items: center; padding: 1px 8px; border-radius: 999px; font-size: 0.72rem; font-weight: 650; line-height: 1.6; }
.badge-on { background: var(--success-soft); color: var(--success); }
.badge-off { background: var(--danger-soft); color: var(--danger); }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-top: 1rem; }
.pager-buttons { display: flex; gap: 0.5rem; }

.state { display: flex; flex-direction: column; align-items: center; gap: 0.75rem; padding: 2.5rem 1rem; text-align: center; color: var(--muted); border: 1px dashed var(--border); border-radius: var(--radius); background: var(--surface); }
.state-error { color: var(--danger); }

.skeletons { display: grid; gap: 0.75rem; }
.skeleton { height: 96px; border-radius: var(--radius); background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%) 0 0 / 200% 100%; border: 1px solid var(--border); animation: shimmer 1.3s infinite linear; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- Link detail ---------- */
.detail-head { display: flex; flex-direction: column; gap: 1rem; margin-bottom: 1.25rem; }
.detail-title { min-width: 0; display: flex; flex-direction: column; gap: 0.35rem; }
.detail-title h1 { overflow-wrap: anywhere; }
.detail-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; margin-top: 0.35rem; }
.detail-actions { display: flex; flex-direction: column; gap: 0.75rem; }
.inline-switch { display: inline-flex; align-items: center; gap: 0.6rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: 0.5rem; }
@media (min-width: 900px) {
  .detail-head { flex-direction: row; justify-content: space-between; align-items: flex-start; }
  .detail-actions { align-items: flex-end; flex: none; }
}

/* ---------- Dialogs ---------- */
.dialog {
  width: min(480px, calc(100vw - 2rem)); max-height: calc(100dvh - 2rem); padding: 0; overflow: auto;
  border: 1px solid var(--border); border-radius: 16px; background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
}
.dialog-wide { width: min(640px, calc(100vw - 2rem)); }
.dialog::backdrop { background: rgb(8 12 28 / 55%); backdrop-filter: blur(2px); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.1rem 0.25rem 1.25rem; }
.dialog-body { display: flex; flex-direction: column; gap: 1rem; padding: 0.75rem 1.25rem 1.25rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.25rem; }
.dialog-actions.center { justify-content: center; }
.form-row { display: grid; gap: 1rem; grid-template-columns: 1fr; }
@media (min-width: 560px) { .form-row { grid-template-columns: 1fr 1fr; } }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.75rem 0.9rem; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.switch-row span { display: flex; flex-direction: column; }
.switch-row small { color: var(--muted); font-size: 0.78rem; }

.tag-input { display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; min-height: 42px; padding: 4px 8px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); cursor: text; }
.tag-input:focus-within { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }
.tag-input input { flex: 1; min-width: 90px; min-height: 30px; padding: 0; border: 0; background: transparent; }
.tag-input input:focus { outline: none; }

.qr-body { align-items: center; text-align: center; }
.qr-frame { padding: 12px; border-radius: 14px; background: #fff; border: 1px solid var(--border); }
.qr-frame img { display: block; width: 256px; height: 256px; max-width: 100%; image-rendering: pixelated; }
.qr-url { font-weight: 650; word-break: break-all; }

.category-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.6rem; }
.category-row { display: flex; align-items: center; gap: 0.6rem; }

@media (max-width: 599px) {
  .dialog, .dialog-wide {
    width: 100vw; max-width: none; margin: auto 0 0; max-height: 92dvh;
    border-radius: 18px 18px 0 0; border-bottom: 0; animation: sheet-up 0.22s ease-out;
  }
  .dialog-body { padding-bottom: calc(1.25rem + env(safe-area-inset-bottom)); }
  .dialog-actions .btn { flex: 1; }
  input, select { font-size: 16px; } /* stops iOS zooming into focused inputs */
}
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } }

/* ---------- Toasts ---------- */
.toasts { position: fixed; z-index: 100; right: 1rem; bottom: calc(1rem + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 0.5rem; max-width: calc(100vw - 2rem); }
.toast { padding: 0.65rem 1rem; border-radius: var(--radius-sm); background: var(--text); color: var(--bg); font-size: 0.875rem; font-weight: 550; box-shadow: var(--shadow-lg); animation: toast-in 0.2s ease-out; }
.toast-error { background: var(--danger); color: #fff; }
.toast.leaving { opacity: 0; transform: translateY(6px); transition: 0.25s; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }
@media (max-width: 899px) { .toasts { left: 1rem; right: 1rem; bottom: calc(4.75rem + env(safe-area-inset-bottom)); align-items: center; } }

/* ---------- Login / status pages ---------- */
body.centered { display: grid; place-items: center; min-height: 100vh; min-height: 100dvh; padding: 1rem; }
.login-card, .status-card { width: min(400px, 100%); padding: 2rem; border: 1px solid var(--border); border-radius: 18px; background: var(--surface); box-shadow: var(--shadow-lg); }
.login-card form { display: flex; flex-direction: column; gap: 1rem; margin-top: 1.5rem; }
.login-card h1 { margin-bottom: 0.25rem; }
.status-card { text-align: center; }
.status-code { font-size: 3.5rem; font-weight: 800; letter-spacing: -0.04em; color: var(--primary); line-height: 1; margin-bottom: 0.75rem; }
.status-card h1 { margin-bottom: 0.4rem; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
