:root {
  --bg: #f6f7f9; --surface: #ffffff; --text: #16181d; --muted: #667085; --border: #dde1e7;
  --primary: #2457d6; --primary-text: #ffffff; --danger: #c62828; --ok: #1b7f3b;
  --warn: #9a6700; --info: #0b6b9a; --accent: #6d3fc4;
  --b-ok: #dff5e6; --b-warn: #fff1cc; --b-info: #dcf0fb; --b-accent: #ece3fb;
  --b-danger: #fde2e2; --b-muted: #e8eaee;
  --radius: 10px; --gutter: 16px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101216; --surface: #181b21; --text: #e8eaee; --muted: #9aa3b2; --border: #2b303a;
    --primary: #6d93f5; --primary-text: #0b0f1a; --danger: #ff7b72; --ok: #5fd07f;
    --warn: #e3b341; --info: #6cc3f0; --accent: #b79af0;
    --b-ok: #123222; --b-warn: #3a2d0c; --b-info: #0f2a3a; --b-accent: #2a2142;
    --b-danger: #3d1717; --b-muted: #262a33;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--primary); }
h1 { font-size: 1.5rem; margin: 0.4em 0; }
h2 { font-size: 1.1rem; margin: 1.2em 0 0.5em; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.92em; }
.mono { overflow-wrap: anywhere; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.container { max-width: 1100px; margin: 0 auto; padding: 0 var(--gutter) 24px; }

.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px;
  padding: 10px var(--gutter); background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; text-decoration: none; color: var(--text); }
.nav { display: flex; flex-wrap: wrap; gap: 4px; flex: 1; }
.nav a { padding: 6px 10px; border-radius: 8px; text-decoration: none; color: var(--text); }
.nav a[aria-current="page"] { background: var(--b-info); color: var(--info); font-weight: 600; }
.logout { margin: 0; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px var(--gutter); margin: 12px 0;
}
.card h2:first-child { margin-top: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.row.between { justify-content: space-between; }
.row.nowrap { flex-wrap: nowrap; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 0 16px; }
.grid2 > .card, .grid2 > section.card { margin: 12px 0; }

label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 0.92rem; }
label.check { flex-direction: row; align-items: center; font-weight: 400; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 9px 10px; width: 100%; min-height: 42px;
}
input[type="checkbox"] { width: auto; min-height: 0; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 1px;
}
textarea { resize: vertical; }
.field-error { color: var(--danger); margin: 0; font-weight: 600; font-size: 0.88rem; }
.has-error input, .has-error select, .has-error textarea { border-color: var(--danger); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  padding: 9px 14px; min-height: 42px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
}
.btn.small { padding: 4px 10px; min-height: 34px; font-size: 0.9rem; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.ghost { background: transparent; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
form.inline { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: 8px 0; }

.badge {
  display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 0.82rem;
  font-weight: 600; white-space: nowrap; background: var(--b-muted); color: var(--muted);
}
.badge.ok { background: var(--b-ok); color: var(--ok); }
.badge.warn { background: var(--b-warn); color: var(--warn); }
.badge.info { background: var(--b-info); color: var(--info); }
.badge.accent { background: var(--b-accent); color: var(--accent); }
.badge.danger { background: var(--b-danger); color: var(--danger); }

.flash { padding: 10px 14px; border-radius: var(--radius); margin: 12px 0; border: 1px solid var(--border); background: var(--b-ok); color: var(--ok); font-weight: 600; }
.flash.error { background: var(--b-danger); color: var(--danger); }
.flash.warning { background: var(--b-warn); color: var(--warn); }
.flash.info { background: var(--b-info); color: var(--info); }
.empty { padding: 20px; text-align: center; color: var(--muted); border: 1px dashed var(--border); border-radius: var(--radius); }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); white-space: nowrap; }
th.num { text-align: right; }
tr:last-child td { border-bottom: 0; }
tr.dim td { opacity: 0.6; }
.actions-cell { display: flex; gap: 6px; justify-content: flex-end; }
.actions-cell form { margin: 0; }

.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; align-items: end; }
.pager { display: flex; justify-content: space-between; align-items: center; margin: 14px 0; gap: 8px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.tile { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); text-decoration: none; color: var(--text); }
.tile-n { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.store { display: flex; align-items: center; gap: 10px; margin: 0; }

dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; }
dt { color: var(--muted); }
dd { margin: 0; overflow-wrap: anywhere; }
dl.meta { grid-template-columns: repeat(auto-fit, minmax(150px, max-content)); }
dl.meta dt { grid-column: auto; }
.timeline { list-style: none; margin: 12px 0; padding: 0 0 0 14px; border-left: 2px solid var(--border); }
.timeline li { margin: 0 0 14px; padding-left: 10px; }

.code { font-size: 1.3rem; font-weight: 700; padding: 12px; background: var(--b-warn); border-radius: 8px; user-select: all; }
.preview { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 12px; font: inherit; }
.login { max-width: 380px; margin: 8vh auto 0; }
footer { padding-top: 8px; }

/* Phones: tables become stacked cards so nothing scrolls sideways. */
@media (max-width: 640px) {
  .table-wrap { overflow: visible; border: 0; background: transparent; }
  table, thead, tbody, tr, td { display: block; width: 100%; }
  thead { position: absolute; left: -9999px; }
  tr { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin: 0 0 10px; padding: 4px 0; }
  td { display: flex; justify-content: space-between; gap: 12px; border: 0; padding: 5px 12px; text-align: right; }
  td::before { content: attr(data-label); color: var(--muted); font-weight: 600; text-align: left; flex: none; }
  td:not([data-label])::before { content: none; }
  td.num { text-align: right; }
  .actions-cell { justify-content: flex-end; }
  h1 { font-size: 1.3rem; }
}
