/* Backup App — vanilla CSS. One spacing scale, one control height, one card anatomy.
   Light/dark via prefers-color-scheme. No inline styles anywhere (strict CSP). */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e2e5ea;
  --border-strong: #cfd4dc;
  --text: #1b2230;
  --muted: #5f6b7b;
  --primary: #2357c6;
  --primary-hover: #1d4aa9;
  --primary-text: #ffffff;
  --ok: #17703f;
  --ok-bg: #e3f4ea;
  --warn: #8a5800;
  --warn-bg: #fff2d3;
  --err: #b42318;
  --err-bg: #fde8e6;
  --run: #2357c6;
  --run-bg: #e6eefc;

  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --radius: 10px;
  --radius-sm: 6px;
  --control: 38px;
  --pad: 20px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1318;
    --surface: #171c23;
    --surface-2: #1f262f;
    --border: #2a323d;
    --border-strong: #3a4350;
    --text: #e5e9ef;
    --muted: #98a4b4;
    --primary: #6d9cff;
    --primary-hover: #86adff;
    --primary-text: #0b1220;
    --ok: #5fd08f;
    --ok-bg: #12301f;
    --warn: #f3c25b;
    --warn-bg: #33270b;
    --err: #ff8a80;
    --err-bg: #3a1614;
    --run: #8fb3ff;
    --run-bg: #18264a;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0; }
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 15px; font-weight: 650; }
h3 { font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: var(--s5) 0 var(--s3); }
p { margin: 0 0 var(--s3); }
p:last-child { margin-bottom: 0; }
code, .mono { font-family: var(--mono); font-size: 12.5px; overflow-wrap: anywhere; }
small, .muted { color: var(--muted); }
small { font-size: 12px; }
ul { margin: 0; padding-left: 1.2em; }
li + li { margin-top: var(--s1); }

/* ---------- top bar ---------- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar-inner {
  max-width: 1200px; margin: 0 auto; padding: 0 var(--s5);
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: var(--s5);
  min-height: 56px;
}
.brand { display: flex; align-items: center; gap: var(--s2); font-weight: 700; font-size: 15px; color: var(--text); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand img { width: 24px; height: 24px; }
.nav { display: flex; gap: var(--s1); min-width: 0; }
.nav a {
  display: inline-flex; align-items: center; height: 34px; padding: 0 var(--s3);
  border-radius: var(--radius-sm); color: var(--muted); font-weight: 500; white-space: nowrap;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--run-bg); color: var(--primary); }
.user { display: flex; align-items: center; gap: var(--s3); color: var(--muted); white-space: nowrap; }

main { max-width: 1200px; margin: 0 auto; padding: var(--s5) var(--s5) 64px; }

/* ---------- page header ---------- */
.page-head {
  display: flex; justify-content: space-between; align-items: center; gap: var(--s4);
  flex-wrap: wrap; margin-bottom: var(--s5); min-height: var(--control);
}
.page-head > div:first-child { min-width: 0; }
.page-head .subtitle { margin: var(--s1) 0 0; color: var(--muted); }
.back { display: inline-block; margin-bottom: var(--s2); color: var(--muted); font-size: 13px; }

/* ---------- layout ---------- */
.stack { display: grid; gap: var(--s4); }
.grid { display: grid; gap: var(--s4); }
.grid > * { min-width: 0; }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.section { margin-bottom: var(--s4); }

/* ---------- cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); min-width: 0; display: flex; flex-direction: column;
}
.card-head {
  display: flex; justify-content: space-between; align-items: center; gap: var(--s3);
  padding: var(--s3) var(--pad); border-bottom: 1px solid var(--border); min-height: 56px;
}
.card-body { padding: var(--pad); flex: 1; }
.card-foot {
  display: flex; justify-content: flex-end; align-items: center; gap: var(--s2); flex-wrap: wrap;
  padding: var(--s3) var(--pad); border-top: 1px solid var(--border); background: var(--surface-2);
  border-radius: 0 0 var(--radius) var(--radius);
}
.card-foot.between { justify-content: space-between; }
.card > .table-wrap { flex: 1; }
.card > .table-wrap:last-child { border-radius: 0 0 var(--radius) var(--radius); }
.danger-zone { border-color: color-mix(in srgb, var(--err) 35%, var(--border)); }

/* ---------- stat tiles ---------- */
.stats { grid-template-columns: repeat(3, minmax(0, 1fr)); margin-bottom: var(--s4); }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: var(--s4) var(--pad); min-width: 0;
  display: grid; grid-template-rows: auto auto auto; row-gap: var(--s1); align-content: start;
}
.stat .label, .stat .value, .stat .sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat .label { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 22px; font-weight: 700; line-height: 32px; height: 32px; display: flex; align-items: center; gap: var(--s2); }
.stat .value .badge { font-size: 13px; height: 26px; padding: 0 var(--s3); }
.stat .sub { font-size: 13px; color: var(--muted); }

/* ---------- definition lists ---------- */
dl.kv { display: grid; grid-template-columns: 160px minmax(0, 1fr); gap: var(--s2) var(--s4); margin: 0; align-items: baseline; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px var(--s3); border-bottom: 1px solid var(--border); vertical-align: middle; }
th:first-child, td:first-child { padding-left: var(--pad); }
th:last-child, td:last-child { padding-right: var(--pad); }
th {
  color: var(--muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em;
  white-space: nowrap; background: var(--surface-2); height: 38px;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
td.nowrap, th.nowrap { white-space: nowrap; }
td.actions-cell, th.actions-cell { text-align: right; white-space: nowrap; width: 1%; }
td .sub { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }
.empty { color: var(--muted); padding: var(--s6) var(--pad); text-align: center; }

/* ---------- badges ---------- */
.badge {
  display: inline-flex; align-items: center; height: 22px; padding: 0 var(--s2); border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap; line-height: 1; vertical-align: middle;
}
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.err { background: var(--err-bg); color: var(--err); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.run { background: var(--run-bg); color: var(--run); }
.badge.muted { background: var(--surface-2); color: var(--muted); }
.badges { display: inline-flex; gap: var(--s1); flex-wrap: wrap; align-items: center; }

/* ---------- progress ---------- */
progress {
  width: 100%; min-width: 140px; height: 8px; display: block; appearance: none; -webkit-appearance: none;
  border: 0; border-radius: 999px; background: var(--surface-2); overflow: hidden;
}
progress::-webkit-progress-bar { background: var(--surface-2); border-radius: 999px; }
progress::-webkit-progress-value { background: var(--run); border-radius: 999px; }
progress::-moz-progress-bar { background: var(--run); border-radius: 999px; }
.progress-cell { min-width: 220px; }
.progress-cell small { display: block; margin-top: 6px; white-space: nowrap; }

/* ---------- forms ---------- */
form { margin: 0; }
.form-grid { display: grid; gap: var(--s4); grid-template-columns: repeat(var(--cols, 1), minmax(0, 1fr)); align-items: start; }
.form-grid.c2 { --cols: 2; }
.form-grid.c3 { --cols: 3; }
.form-grid.c4 { --cols: 4; }
.form-grid + .form-grid { margin-top: var(--s4); }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field.span-all { grid-column: 1 / -1; }
.field > label, .label { font-weight: 600; font-size: 13px; }
.hint { font-size: 12px; color: var(--muted); line-height: 1.45; }
.error { font-size: 12.5px; color: var(--err); }
input[type=text], input[type=password], input[type=number], input[type=search], select {
  width: 100%; height: var(--control); padding: 0 var(--s3); font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
}
textarea {
  width: 100%; min-height: 96px; padding: var(--s2) var(--s3); font-family: var(--mono); font-size: 13px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); resize: vertical;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.field.invalid input, .field.invalid select, .field.invalid textarea { border-color: var(--err); }
.check { display: flex; align-items: flex-start; gap: var(--s2); font-weight: 500; cursor: pointer; }
.check input { width: 16px; height: 16px; margin: 2px 0 0; flex: none; accent-color: var(--primary); }
.checks { display: grid; gap: var(--s2); }
.actions { display: flex; gap: var(--s2); flex-wrap: wrap; align-items: center; }
.inline { display: inline; }
.form-actions { display: flex; justify-content: flex-end; gap: var(--s2); margin-top: var(--s4); }

/* ---------- buttons ---------- */
.btn, button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: var(--control); padding: 0 var(--s4); font: inherit; font-weight: 600; font-size: 13.5px;
  border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover, button:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary, button.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.primary:hover, button.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.danger, button.danger { color: var(--err); border-color: color-mix(in srgb, var(--err) 45%, transparent); }
.btn.danger:hover, button.danger:hover { background: var(--err-bg); }
.btn.small, button.small { height: 30px; padding: 0 var(--s3); font-size: 12.5px; }
button[disabled] { opacity: .55; cursor: not-allowed; }

/* ---------- alerts ---------- */
.alert { padding: var(--s3) var(--s4); border-radius: var(--radius-sm); margin-bottom: var(--s4); border: 1px solid transparent; }
.alert.ok { background: var(--ok-bg); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 30%, transparent); }
.alert.error { background: var(--err-bg); color: var(--err); border-color: color-mix(in srgb, var(--err) 30%, transparent); }
.alert.warn { background: var(--warn-bg); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.card-body > .alert:last-child { margin-bottom: 0; }

/* ---------- pager & filters ---------- */
.pager {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: var(--s3);
  padding: var(--s3) var(--pad); border-top: 1px solid var(--border); font-size: 13px;
}
.pager > :last-child { justify-self: end; }
.filters { display: flex; gap: var(--s3); flex-wrap: wrap; align-items: flex-end; }
.filters .field { width: 200px; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: var(--s4); }
.login { width: 100%; max-width: 380px; }
.login .brand { margin-bottom: var(--s2); }

/* ---------- directory browser ---------- */
.browse {
  list-style: none; margin: var(--s2) 0 0; padding: 0; border: 1px solid var(--border);
  border-radius: var(--radius-sm); max-height: 260px; overflow: auto;
}
.browse li { display: flex; justify-content: space-between; align-items: center; gap: var(--s2); padding: 6px var(--s3); border-bottom: 1px solid var(--border); margin: 0; }
.browse li:last-child { border-bottom: 0; }

.htmx-indicator { display: none; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline; }
details summary { cursor: pointer; font-weight: 600; }
pre { background: var(--surface-2); padding: var(--s3); border-radius: var(--radius-sm); overflow-x: auto; font-size: 12.5px; margin: var(--s3) 0 0; }

/* ---------- responsive ---------- */
@media (max-width: 960px) {
  .cols-3, .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid.c3, .form-grid.c4 { --cols: 2; }
}
@media (max-width: 760px) {
  .topbar-inner {
    grid-template-columns: 1fr auto; grid-template-areas: "brand user" "nav nav";
    padding: 0 var(--s4); row-gap: 0;
  }
  .brand { grid-area: brand; min-height: 52px; }
  .user { grid-area: user; }
  .nav { grid-area: nav; overflow-x: auto; margin: 0 calc(-1 * var(--s4)); padding: 0 var(--s4) var(--s2); scrollbar-width: none; }
  .nav::-webkit-scrollbar { display: none; }
  main { padding: var(--s4) var(--s4) 48px; }
  .cols-2 { grid-template-columns: minmax(0, 1fr); }
  .form-grid.c2 { --cols: 1; }
  :root { --pad: 16px; }
  .hide-sm { display: none; }
  dl.kv { grid-template-columns: 120px minmax(0, 1fr); }
}
@media (max-width: 480px) {
  .stats { grid-template-columns: minmax(0, 1fr); }
  .form-grid.c3, .form-grid.c4 { --cols: 1; }
  .user .username { display: none; }
  dl.kv { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  dl.kv dd { margin-bottom: var(--s2); }
  .filters .field { width: 100%; }
  .page-head .actions { width: 100%; }
}
.clip { display: block; max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
select.w-auto, input.w-auto { width: auto; min-width: 120px; }
.users-form { flex-wrap: nowrap; }
.card-body h3:first-child { margin-top: 0; }
/* Forms that wrap body + footer stretch so footers of side-by-side cards line up. */
.card > form { display: flex; flex-direction: column; flex: 1; }
.card > form > .card-body { flex: 1; }
.card-body > dl + .alert, .card-body > dl + p { margin-top: var(--s4); }
.note { margin: var(--s4) 0 0; padding: var(--s3) var(--s4); background: var(--surface-2); border-radius: var(--radius-sm); font-size: 13px; }
.form-grid + .note { margin-top: var(--s4); }
details.advanced { margin-top: var(--s4); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: var(--s3) var(--s4); }
details.advanced > summary { color: var(--muted); font-size: 13px; }
details.advanced[open] > summary { margin-bottom: var(--s3); }
details.advanced .hint + .form-grid { margin-top: var(--s3); }
[data-retention] select { max-width: 560px; }
