/* One stylesheet, no framework, no build step.
 *
 * The interface is dense on purpose: an operator looking at a cluster
 * wants every node's state on one screen, not a card per node with
 * whitespace between them. */

:root {
  --bg: #12151a;
  --panel: #1a1f27;
  --panel-2: #212833;
  --line: #2f3845;
  --ink: #e6e9ee;
  --ink-dim: #9aa5b4;
  --accent: #4c9aff;
  --ok: #3fb950;
  --warn: #d29922;
  --bad: #f85149;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7f9;
    --panel: #ffffff;
    --panel-2: #f0f2f5;
    --line: #d8dde5;
    --ink: #1c2027;
    --ink-dim: #5d6775;
    --accent: #0b5cd5;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

a { color: var(--accent); }

code, .mono, pre { font-family: var(--mono); font-size: 12.5px; }

/* Layout: a fixed sidebar and a scrolling main column. */
.shell { display: grid; grid-template-columns: 224px 1fr; min-height: 100vh; }

nav.side {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 16px 0;
  display: flex;
  flex-direction: column;
}

nav.side .brand {
  font-weight: 650;
  letter-spacing: 0.02em;
  padding: 0 18px 14px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 10px;
}
nav.side .brand small { display: block; font-weight: 400; color: var(--ink-dim); font-size: 11.5px; }

nav.side a {
  display: block;
  padding: 7px 18px;
  color: var(--ink);
  text-decoration: none;
  border-left: 3px solid transparent;
}
nav.side a:hover { background: var(--panel-2); }
nav.side a.on { border-left-color: var(--accent); background: var(--panel-2); font-weight: 550; }

nav.side .who {
  margin-top: auto;
  padding: 12px 18px 0;
  border-top: 1px solid var(--line);
  color: var(--ink-dim);
  font-size: 12px;
}
nav.side .who strong { color: var(--ink); display: block; font-size: 13px; }

main { padding: 22px 26px 60px; max-width: 1400px; min-width: 0; }

h1 { font-size: 19px; margin: 0 0 4px; font-weight: 600; }
h2 { font-size: 15px; margin: 26px 0 8px; font-weight: 600; }
.sub { color: var(--ink-dim); margin: 0 0 18px; }

/* Panels and tables. */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 14px 16px;
  margin-bottom: 16px;
}

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); }
th { color: var(--ink-dim); font-weight: 550; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-family: var(--mono); }

.empty { color: var(--ink-dim); padding: 14px 10px; }

/* Performance timings keep small durations legible and wide tables scrollable. */
.performance-table { overflow-x: auto; }
.performance-table .num { white-space: nowrap; }
.performance-operation { min-width: 260px; overflow-wrap: anywhere; }
.performance-description { color: var(--ink-dim); font-size: 12px; margin-top: 4px; }

main:has(.machines-table) { max-width: none; }
.machines-table { overflow-x: auto; }
.machines-table table { min-width: 1220px; }
.machines-table .mono { overflow-wrap: anywhere; }
.machines-table .num, .machine-time, .machine-status { white-space: nowrap; }
.machines-table .machine-time .sub { white-space: normal; }
.machines-table > .sub { margin: 12px 0 0; }
.machine-status a { text-decoration: none; }
.machine-status a:hover { text-decoration: underline; }
.machine-session-log { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 65vh; overflow: auto; }
.vm-restore-table { overflow-x: auto; }
.vm-restore-table td { overflow-wrap: anywhere; }
.vm-restore-confirm { display: flex; align-items: start; gap: 8px; color: var(--ink); margin: 0; }
.vm-restore-confirm input { width: auto; margin-top: 3px; }

.storage-disks { overflow-x: auto; }
.storage-disks .num { white-space: nowrap; }
.storage-disks .storage-node th {
  background: var(--panel-2);
  color: var(--ink);
  text-transform: none;
  letter-spacing: normal;
  overflow-wrap: anywhere;
}
.storage-address { display: block; color: var(--ink-dim); margin-top: 3px; }
.storage-path { overflow-wrap: anywhere; min-width: 160px; }
.storage-disks > .sub { margin: 12px 0 0; }
.storage-fill .bar { margin-top: 5px; }
.storage-check-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.storage-check-progress { margin: 8px 0 0; }
.storage-status th[scope="row"] { text-transform: none; letter-spacing: normal; color: var(--ink); }
.storage-status th, .storage-status td { vertical-align: top; }
.storage-status .storage-address { overflow-wrap: anywhere; }
.storage-status .storage-status-label { white-space: nowrap; min-width: 140px; }
.storage-status td p { margin: 0; }
.storage-status td p + p { margin-top: 4px; }
.storage-state-label { display: none; }
.storage-status-banner.bad { background: #fff1f0; color: #8f1712; border-left: 4px solid #c22b23; }
.storage-status-banner.warn { background: #fff8e1; color: #6b4700; border-left: 4px solid #b77900; }
.storage-status .pill.bad { background: #b42318; color: #fff; border-color: #b42318; }
.storage-status .pill.warn { background: #fff4cc; color: #714b00; border-color: #c79c32; }
.storage-status .pill.info { color: var(--accent); border-color: var(--accent); }
.storage-status th[scope="row"] { max-width: 280px; overflow-wrap: anywhere; }
.storage-progress { min-width: 260px; max-width: 420px; }
.storage-first-passes { margin: 6px 0; font-size: 12px; color: var(--ink-dim); }
.storage-first-passes progress { display: block; width: 100%; height: 6px; margin-top: 4px; accent-color: var(--accent); }
.storage-progress details { margin: 6px 0; }
.storage-progress summary { cursor: pointer; color: var(--accent); }
.storage-task-list { list-style: none; margin: 8px 0; padding: 0; }
.storage-task-list li { padding: 8px 0; border-top: 1px solid var(--line); }
.storage-task-list .sub { margin: 3px 0; }
.storage-transfer { margin-top: 8px; padding-top: 6px; border-top: 1px solid var(--line); }
.storage-refresh-failed { color: var(--bad); font-weight: 600; }
.storage-flow { padding: 14px 16px 10px; }
.storage-flow-heading { display: flex; align-items: center; gap: 8px 12px; flex-wrap: wrap; margin-bottom: 12px; }
.storage-flow h3, .storage-flow h4, .storage-flow h5 { margin: 0; font-size: 13px; font-weight: 600; }
.storage-flow-heading h3 { font-size: 14px; }
.storage-flow-heading .sub { margin: 0; overflow-wrap: anywhere; }
.storage-flow-sampled { margin-left: auto !important; font-size: 12px; }
.storage-flow-stages { display: grid; grid-template-columns: 1fr 1.35fr 1fr 1fr; gap: 18px; list-style: none; padding: 0; margin: 0; }
.storage-flow-stage { position: relative; min-width: 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 5px; background: var(--panel-2); }
.storage-flow-stage + .storage-flow-stage::before { content: "\2192"; position: absolute; left: -17px; top: 12px; color: var(--ink-dim); }
.storage-flow-stage h4 { margin-bottom: 9px; }
.storage-flow-step { color: var(--ink-dim); font-size: 11px; margin-right: 4px; }
.storage-flow p { margin: 5px 0; }
.storage-flow-stage .sub { font-size: 12px; }
.storage-flow-total { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }
.storage-flow dl { margin: 0 0 8px; }
.storage-flow dl div { margin: 4px 0; }
.storage-flow dt { color: var(--ink-dim); font-size: 12px; }
.storage-flow dd { margin: 0; font-weight: 600; }
.storage-flow-pools section + section { border-top: 1px solid var(--line); margin-top: 9px; padding-top: 9px; }
.storage-flow-pools .bar { margin-top: 6px; }
.storage-flow-pools .pill { font-size: 11px; }
.storage-flow-transfer { margin-top: 10px; padding-top: 6px; font-size: 13px; }
.storage-flow-pressure { margin: 8px 0; padding-left: 20px; color: var(--warn); font-size: 12px; }
.storage-flow-details { border-top: 1px solid var(--line); margin-top: 8px; padding-top: 9px; }
.storage-flow-details summary { cursor: pointer; color: var(--accent); }
.storage-flow-details > .sub { margin-top: 10px; font-size: 12px; }
.storage-flow-budgets { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin: 12px 0; }
.storage-flow-budgets section { border-left: 2px solid var(--line); padding-left: 10px; }
.storage-flow-budgets p { font-size: 12px; }
.storage-flow-unavailable { padding: 10px 0; }
.storage-flow .storage-flow-subheading { margin-top: 16px; margin-bottom: 6px; }
.storage-flow-table { overflow-x: auto; max-height: 360px; overflow-y: auto; }
.storage-flow-table table { table-layout: fixed; min-width: 650px; }
.storage-flow-table th, .storage-flow-table td { vertical-align: top; overflow-wrap: anywhere; }
.storage-flow-table th { position: sticky; top: 0; background: var(--panel); }
.storage-flow-table .sub { font-size: 12px; }
.storage-flow-table .error { margin: 5px 0; padding: 6px 8px; }
.storage-scan { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
.storage-scan > .sub { font-size: 12px; }
.storage-scan-pools { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 12px 0; }
.storage-scan-pool { min-width: 0; padding: 12px; border: 1px solid var(--line); border-radius: 5px; background: var(--panel-2); }
.storage-scan-pool .sub, .storage-scan-categories, .storage-scan-ages { font-size: 12px; }
.storage-scan-ages { list-style: none; padding: 0; margin: 10px 0 14px; }
.storage-scan-ages li { margin: 7px 0; }
.storage-scan-ages li > div:first-child { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 2px 10px; }
.storage-scan-ages .bar { margin-top: 3px; }
.storage-scan-age-recent { --bar-fill: var(--ok); }
.storage-scan-age-day { --bar-fill: var(--accent); }
.storage-scan-age-week { --bar-fill: var(--warn); }
.storage-scan-age-old { --bar-fill: var(--bad); }
.storage-scan-age-unknown { --bar-fill: var(--ink-dim); }
.storage-scan-categories th, .storage-scan-categories td { padding: 5px 4px; overflow-wrap: anywhere; }
@media (max-width: 1100px) {
  .storage-flow-stages { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .storage-flow-stage:nth-child(3)::before { content: none; }
}
@media (max-width: 600px) {
  .storage-flow-stages, .storage-flow-budgets, .storage-scan-pools { grid-template-columns: 1fr; }
  .storage-flow-stage + .storage-flow-stage::before { content: "\2193"; top: -19px; left: 13px; }
  .storage-flow-sampled { margin-left: 0 !important; }
}
@media (max-width: 1000px) {
  .storage-status { overflow-x: visible; }
  .storage-status table, .storage-status tbody { display: block; }
  .storage-status thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .storage-status tr { display: grid; grid-template-columns: auto 1fr; gap: 6px 10px; padding: 12px 0; border-bottom: 1px solid var(--line); }
  .storage-status tr:last-child { border-bottom: 0; }
  .storage-status th, .storage-status td { padding: 0; border: 0; min-width: 0; }
  .storage-status th[scope="row"], .storage-status td:last-child, .storage-status .storage-reasons { grid-column: 1 / -1; }
  .storage-status th[scope="row"], .storage-status .storage-progress { max-width: none; }
  .storage-status .storage-status-label { min-width: 0; }
  .storage-status .storage-path { min-width: 0; }
  .storage-status .storage-state-label { display: inline; color: var(--ink-dim); }
}

/* Status pills. */
.pill {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 550;
  border: 1px solid var(--line);
  background: var(--panel-2);
}
.pill.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.pill.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.pill.bad { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }

/* Native meter values size the fill without inline styles, which CSP blocks. */
.bar { appearance: none; display: block; width: 100%; height: 8px; min-width: 90px; border: 0; border-radius: 3px; overflow: hidden; background: var(--line); }
.bar::-webkit-meter-bar { height: 100%; background: var(--line); border: 0; border-radius: 3px; box-shadow: none; }
.bar::-webkit-meter-optimum-value, .bar::-webkit-meter-suboptimum-value, .bar::-webkit-meter-even-less-good-value { background: var(--bar-fill, var(--accent)); }
.bar::-moz-meter-bar { background: var(--bar-fill, var(--accent)); }

/* Forms. */
label { display: block; margin: 10px 0 3px; color: var(--ink-dim); font-size: 12.5px; }
input, select, textarea {
  width: 100%;
  padding: 7px 9px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--ink);
  font: inherit;
}
input:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: -1px; }

button,
a.button {
  padding: 7px 14px;
  border-radius: 4px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  display: inline-block;
  box-sizing: border-box;
  font: inherit;
  line-height: normal;
  text-decoration: none;
  font-weight: 550;
  cursor: pointer;
}
button.quiet,
a.button.quiet { background: transparent; color: var(--ink); border-color: var(--line); }
button.danger { background: transparent; color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, transparent); }
button:disabled { opacity: 0.5; cursor: default; }

.row { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.row > * { flex: 1 1 180px; }
.row > .tight { flex: 0 0 auto; }
.actions { display: flex; gap: 8px; align-items: center; }
.actions form { margin: 0; }

/* The permission grid on the user form. */
.perms { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 2px 14px; margin-top: 6px; }
.perms label { display: flex; gap: 7px; align-items: center; margin: 3px 0; color: var(--ink); font-size: 13px; }
.perms input { width: auto; }

/* Messages. */
.note, .error {
  border-radius: 4px;
  padding: 9px 12px;
  margin: 12px 0;
  border: 1px solid var(--line);
  background: var(--panel-2);
}
.error { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
.secret { font-family: var(--mono); background: var(--bg); padding: 8px 10px; border-radius: 4px; word-break: break-all; }

/* Login. */
.login { display: grid; place-items: center; min-height: 100vh; }
.login .panel { width: 360px; }

/* htmx swaps: dim while a request is in flight, so a click that is doing
 * something slow does not look like a click that did nothing. */
.htmx-request, .htmx-request * { opacity: 0.55; transition: opacity 120ms; }

/* Day-of-week checkboxes, for a schedule. */
.days { display: flex; flex-wrap: wrap; gap: 10px; padding-top: 4px; }
.day { display: inline-flex; align-items: center; gap: 4px; font-size: 12.5px; color: var(--ink-dim); }
.day input { margin: 0; }

/* The customer console: a customer list that opens onto every resource a
 * customer has. The seven-day history is one square per backup session, the
 * same widget on both pages, because a week of marks answers "is this
 * landing every night" faster than any single timestamp can. */
.console-toolbar { display: flex; gap: 12px 16px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.console-toolbar .actions { margin-left: auto; }
.console-toolbar .customer-summary { margin: 0; }
.crumb { margin: 0 0 10px; font-size: 13px; }
main:has(.resource-table) { max-width: none; }

.console-table { overflow-x: auto; }
.customers-table { min-width: 1040px; }
.customers-table td { vertical-align: middle; }
.customer-link { display: inline-flex; align-items: center; gap: 8px; color: var(--ink); text-decoration: none; font-weight: 600; }
.customer-link:hover .mono { text-decoration: underline; }
.customer-badge {
  width: 22px; height: 22px; border-radius: 5px; flex: 0 0 auto;
  display: inline-grid; place-items: center; font-size: 11px; font-weight: 700;
  text-transform: uppercase; color: var(--accent);
  background: var(--panel-2); border: 1px solid var(--line);
}

/* Seven-day history. The container is a row of day cells; each cell holds one
 * thin mark per session, so a quiet day and a busy day are visibly different
 * and a failure cannot hide behind a recent success. */
.history { display: inline-flex; gap: 3px; align-items: flex-end; vertical-align: middle; }
.history-day { display: inline-flex; flex-direction: column; align-items: center; gap: 2px; width: 18px; }
.history-ticks {
  display: flex; align-items: flex-end; justify-content: center; gap: 1px;
  width: 18px; height: 17px; padding: 2px 1px;
  border: 1px solid var(--line); border-radius: 3px; background: var(--bg);
  overflow: hidden;
}
.history-gap-day .history-ticks { background: transparent; border-style: dashed; }
.history-label { font-size: 9px; line-height: 1; color: var(--ink-dim); }
.tick { display: inline-block; width: 3px; height: 100%; min-height: 11px; border-radius: 1px; background: var(--ink-dim); }
.tick.ok { background: var(--ok); }
.tick.warn { background: var(--warn); }
.tick.bad { background: var(--bad); }
.tick.info { background: var(--accent); }
.tick.dim { background: var(--line); }

.history-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin: 10px 0 18px; font-size: 12px; }
.history-legend .history-day { width: auto; }
.history-legend .history-day .history-ticks { width: 15px; height: 15px; }
.history-legend .tick { height: 13px; width: 4px; }
.history-note { color: var(--ink-dim); }

/* The customer's resources: a host row with its workloads indented beneath,
 * or a single row for a machine that holds only itself. */
.resource-table { min-width: 1180px; }
.resource-table td { vertical-align: top; }
.resource-table .pick { width: 34px; }
.resource-table .pick input { width: auto; margin: 3px 0 0; accent-color: var(--accent); }
.resource-table .num { white-space: nowrap; }
.resource-table .res-name { overflow-wrap: anywhere; }
.resource-table .res-cell .sub { display: block; font-size: 11.5px; }
.resource-host td { background: color-mix(in srgb, var(--panel-2) 55%, transparent); border-top: 1px solid var(--line); }
.resource-host .res-name { font-weight: 650; }
.resource-child .res-cell { padding-left: 30px; }
.resource-child .res-name { font-weight: 500; }
.res-icon {
  display: inline-grid; place-items: center; width: 18px; height: 18px;
  margin-right: 6px; border-radius: 4px; vertical-align: middle;
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  background: var(--panel-2); border: 1px solid var(--line);
}
.icon-w { color: #4c9aff; }
.icon-h { color: #c586c0; }
.icon-p { color: var(--warn); }
.icon-c { color: var(--ok); }
.icon-vm { color: var(--ink-dim); }
.latest { display: block; }
.latest-ok { color: var(--ok); }
.latest-warn { color: var(--warn); }
.latest-bad { color: var(--bad); }
.latest-info { color: var(--accent); }
.pill.info { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }

/* The bulk action bar above the resource table. One form holds every
 * checkbox, so selecting rows and choosing an action needs no script. */
.resource-form { display: block; }
.bulkbar { display: flex; flex-direction: column; gap: 10px; }
.bulkbar-row { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; }
.bulkbar-title { flex: 1 1 320px; min-width: 240px; }
.bulkbar-title strong { display: block; margin-bottom: 2px; }
.bulkbar-field { flex: 0 1 340px; min-width: 220px; }
.bulkbar-field label { margin-top: 0; }
.bulkbar-buttons { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.bulkbar-note { margin: 0; font-size: 12px; }

/* The cluster line above the customer list: a customer-first page still needs
 * an operator to notice a cluster that cannot place data. */
.cluster-strip { font-size: 12px; margin: -4px 0 14px; }
