:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --sunken: #f4f5f7;
  --text: #1a202b;
  --muted: #586174;
  --border: #d5dae2;
  --accent: #0b5cad;
  --accent-text: #ffffff;
  --danger: #b42318;
  --ok: #05603a;
  --warn: #93370d;
  --row-hover: #f0f4fa;
  --shadow: 0 8px 28px rgb(16 24 40 / 18%);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11141a;
    --surface: #1a1f28;
    --sunken: #141820;
    --text: #e6e9ef;
    --muted: #a0a9b8;
    --border: #2f3644;
    --accent: #6aacf5;
    --accent-text: #0b1220;
    --danger: #f97066;
    --ok: #47cd89;
    --warn: #fdb022;
    --row-hover: #212835;
    --shadow: 0 8px 28px rgb(0 0 0 / 55%);
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
main:focus { outline: none; }
.skip { position: absolute; left: -999px; top: 4px; background: var(--surface); padding: 6px 10px; border-radius: 6px; z-index: 30; }
.skip:focus { left: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 13px; }
.muted { color: var(--muted); }
.error-text { color: var(--danger); }
.ok-text { color: var(--ok); }

/* ---------------------------------------------------------------- top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; flex-wrap: wrap; gap: 8px 24px; align-items: center;
  padding: 8px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 650; font-size: 16px; white-space: nowrap; }
nav { display: flex; flex-wrap: wrap; gap: 2px; flex: 1; }
nav a { color: var(--muted); text-decoration: none; padding: 6px 10px; border-radius: 6px; font-weight: 500; }
nav a:hover { color: var(--text); background: var(--sunken); }
nav a[aria-current] { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.who { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; color: var(--muted); margin-left: auto; }
.badge {
  font-size: 12px; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--border);
  color: var(--muted); white-space: nowrap; font-weight: 500;
}
.badge:empty { display: none; }
.badge.warn { color: var(--warn); border-color: currentColor; }
.badge.danger { color: var(--danger); border-color: currentColor; }
.notice {
  padding: 10px 16px; border-bottom: 1px solid var(--border); color: var(--warn); font-weight: 500;
  background: color-mix(in srgb, var(--warn) 12%, var(--surface));
}

/* ----------------------------------------------------------------- layout */
main { padding: 16px; max-width: 1280px; margin: 0 auto; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 16px; margin-bottom: 16px; }
.card.center { text-align: center; padding: 40px 16px; }
.card.callout { border-color: var(--warn); }
.card-head { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.card-head h1, .card-head h2 { margin: 0; }
h1 { font-size: 20px; margin: 0 0 12px; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 16px 0 8px; }
p { margin: 0 0 12px; }
.row { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: end; }
/* Rows of labelled fields line up by label and input; a hint under one field must not
   push the others down. Buttons and checkboxes drop by the label's height to sit level
   with the inputs. */
.row:has(.field) { align-items: flex-start; }
.row:has(.field) > :not(.field):not(.grow) { margin-top: calc(12px * 1.45 + 4px); }
.row.center-items { align-items: center; }
.row.end { justify-content: flex-end; }
.row.centered { justify-content: center; }
.grow { flex: 1 1 200px; }
.stack > * + * { margin-top: 12px; }
details > summary { cursor: pointer; font-weight: 600; font-size: 15px; }
details[open] > summary { margin-bottom: 12px; }

/* ------------------------------------------------------------------ forms */
.field { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 12px; font-weight: 500; }
.field .hint { font-weight: 400; }
.check { display: inline-flex; gap: 6px; align-items: center; min-height: 32px; cursor: pointer; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; min-width: 0; min-height: 32px;
}
input[type="checkbox"] { min-height: 0; width: 16px; height: 16px; accent-color: var(--accent); }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .7; }
textarea {
  width: 100%; min-height: 200px; resize: vertical;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12px;
}
textarea.dragover { border-color: var(--accent); border-style: dashed; }
button, a.button {
  font: inherit; font-weight: 500; cursor: pointer; border-radius: 6px; padding: 5px 12px; min-height: 32px;
  border: 1px solid var(--accent); background: var(--accent); color: var(--accent-text);
  text-decoration: none; display: inline-flex; align-items: center; white-space: nowrap;
}
button.secondary, a.button.secondary { background: transparent; color: var(--accent); border-color: var(--border); }
button.secondary:hover { border-color: var(--accent); }
button.danger { background: transparent; color: var(--danger); border-color: var(--border); }
button.danger:hover { border-color: var(--danger); }
button.danger.solid { background: var(--danger); border-color: var(--danger); color: var(--surface); }
button.small, a.button.small { padding: 2px 8px; min-height: 26px; font-size: 13px; }
button.link { background: none; border: none; color: var(--accent); padding: 0; min-height: 0; }
button:disabled { opacity: .5; cursor: default; }
button[aria-busy="true"] { cursor: progress; }
progress { width: 100%; height: 8px; accent-color: var(--accent); }

/* ----------------------------------------------------------------- tables */
.table-wrap { position: relative; overflow-x: auto; margin: 0 -16px 12px; padding: 0 16px; }
.filters { margin-bottom: 12px; }
.results:not(:empty) { margin-top: 16px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
tbody tr:hover { background: var(--row-hover); }
tbody tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.wrap { white-space: normal; min-width: 220px; }
td.actions { text-align: right; }
td.actions > * + * { margin-left: 6px; }
td.clip { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }

/* --------------------------------------------------- status, tiles, meter */
.pill { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; }
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.status-FREE { color: var(--ok); }
.status-RESERVED { color: var(--accent); }
.status-FETCHED { color: var(--warn); }
.status-EXPIRED { color: var(--muted); }
.status-EXPIRED::before { background: transparent; border: 1.5px solid currentColor; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 16px; }
.tile-label { color: var(--muted); font-size: 12px; font-weight: 500; }
.tile-value { font-size: 26px; font-weight: 650; line-height: 1.2; font-variant-numeric: tabular-nums; }
.tile-note { color: var(--muted); font-size: 12px; }

.usage { display: flex; align-items: center; gap: 8px; min-width: 170px; }
.meter { flex: 1; height: 8px; border-radius: 4px; background: var(--sunken); border: 1px solid var(--border); overflow: hidden; }
.meter-fill { display: block; height: 100%; background: var(--accent); }
.meter-fill.high { background: var(--warn); }
.meter-fill.full { background: var(--danger); }
.usage-text { font-variant-numeric: tabular-nums; min-width: 4.5em; text-align: right; }

.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px 16px; margin: 0 0 12px; }
.kv dt { color: var(--muted); font-size: 12px; font-weight: 500; }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.result { border: 1px solid var(--border); border-radius: 8px; padding: 12px 16px; margin: 12px 0; }
.result h3 { margin-top: 0; }
pre {
  background: var(--sunken); border: 1px solid var(--border); border-radius: 6px; padding: 10px; margin: 0 0 12px;
  overflow: auto; max-height: 360px; font-size: 12px; white-space: pre-wrap; overflow-wrap: anywhere;
}
.secret { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; word-break: break-all; }
.copy-line { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 8px; }

/* --------------------------------------------------------- toasts, dialog */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 40; display: flex; flex-direction: column; gap: 8px; max-width: min(440px, calc(100vw - 32px)); }
.toast {
  display: flex; gap: 12px; align-items: flex-start; justify-content: space-between;
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--ok);
  border-radius: 8px; padding: 10px 12px; box-shadow: var(--shadow);
}
.toast.error { border-left-color: var(--danger); }
.toast button { color: var(--muted); font-size: 14px; line-height: 1.4; }
dialog {
  border: 1px solid var(--border); border-radius: 12px; padding: 20px; width: min(440px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgb(10 14 20 / 55%); }
dialog h2 { margin-bottom: 8px; }

@media (max-width: 640px) {
  .topbar { position: static; }
  nav { flex: 1 1 100%; order: 3; }
  .row { align-items: stretch; }
  .row > .field, .row > .grow { flex: 1 1 100%; }
  .row:has(.field) > :not(.field):not(.grow) { margin-top: 0; }
  .who { margin-left: 0; }
}
@media (prefers-reduced-motion: no-preference) {
  .meter-fill { transition: width .3s ease; }
}
