:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #fbfbfd;
  --line: #e3e6ec;
  --text: #14171f;
  --muted: #667085;
  --accent: #3b6ef5;
  --ok: #12855b;
  --ok-bg: #e6f5ee;
  --warn: #9a6100;
  --warn-bg: #fdf1dd;
  --bad: #b42318;
  --bad-bg: #fdecea;
  --radius: 12px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --panel: #161a22;
    --panel-2: #1b202a;
    --line: #262c38;
    --text: #e6e9ef;
    --muted: #93a0b4;
    --accent: #6f9bff;
    --ok: #4ade80;
    --ok-bg: #12291f;
    --warn: #fbbf5a;
    --warn-bg: #2c2213;
    --bad: #f87171;
    --bad-bg: #2d1618;
  }
}

* { box-sizing: border-box; }

/* Any `display` rule from a class selector outranks the user agent's
   [hidden] { display: none }, so toggling el.hidden on an element that also
   carries a display rule does nothing at all. This must stay. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.mono { font-family: var(--mono); font-size: .92em; }
.muted { color: var(--muted); }
.small { font-size: .85em; }

/* ---------- login ---------- */

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: 0 10px 30px rgba(0,0,0,.06);
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 22px; margin: 0; letter-spacing: -.02em; }

.dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent);
}

.login-card .sub { color: var(--muted); margin: 6px 0 24px; font-size: 14px; }

label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 6px;
}

input {
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 16px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
}

input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}

button {
  font: inherit;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 10px 14px;
}

#login-btn {
  width: 100%;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

#login-btn:disabled { opacity: .6; cursor: progress; }

button.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--text);
}

button.ghost:hover { background: var(--panel-2); }

.error {
  margin: 14px 0 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--bad-bg);
  color: var(--bad);
  font-size: 14px;
}

/* ---------- app shell ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 22px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
  flex-wrap: wrap;
}

.topbar-right { display: flex; align-items: center; gap: 12px; }

.chip {
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: 13px;
}

.banner {
  margin: 16px 22px 0;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--bad-bg);
  color: var(--bad);
  font-size: 14px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  padding: 22px;
  max-width: 1240px;
  margin: 0 auto;
}

.span2 { grid-column: span 2; }
.span3 { grid-column: span 3; }

@media (max-width: 900px) {
  .grid { grid-template-columns: 1fr; }
  .span2, .span3 { grid-column: span 1; }
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  min-width: 0;
}

.card h2 {
  margin: 0 0 16px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
}

.hint {
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
  opacity: .75;
}

.kv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px 20px;
}

.kv-grid > div { display: flex; flex-direction: column; gap: 4px; min-width: 0; }

.label { font-size: 12px; color: var(--muted); }
.value { font-weight: 500; overflow-wrap: anywhere; }

.pill {
  display: inline-block;
  width: fit-content;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  background: var(--panel-2);
  color: var(--muted);
}

.pill.ok   { background: var(--ok-bg);   color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad  { background: var(--bad-bg);  color: var(--bad); }

.stat { display: flex; flex-direction: column; gap: 2px; }
.stat-value { font-size: 30px; font-weight: 650; letter-spacing: -.02em; }
.stat.small .stat-value { font-size: 20px; }
.stat-label { font-size: 12px; color: var(--muted); }
.stat-row { display: flex; gap: 28px; margin-top: 16px; }

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }

th {
  text-align: left;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  padding: 0 12px 8px 0;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

td {
  padding: 10px 12px 10px 0;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

tr:last-child td { border-bottom: none; }

/* Right-aligned cells kept their 12px gutter only on the left, so a numeric
   column immediately followed by another column ran straight into it — the
   repository size and the WAL segment rendered as one string. Keep the gutter
   and drop it only where the column really is last. */
.num { text-align: right; padding-right: 12px; }
tr > .num:last-child, tr > th.num:last-child { padding-right: 0; }
td.empty { text-align: center; color: var(--muted); padding: 18px 0; }

.chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }

.chips li {
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: 13px;
}

.chips .ver { color: var(--muted); font-family: var(--mono); font-size: .85em; }

/* ---------- tabs ---------- */

.tabs {
  display: flex;
  gap: 4px;
  padding: 0 22px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 10px 14px;
  color: var(--muted);
  font-weight: 500;
}

.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------- backups ---------- */

.actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

label.inline { display: inline; margin: 0; }

select {
  padding: 8px 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
}

button.primary { background: var(--accent); color: #fff; font-weight: 600; }
button.primary:disabled { opacity: .6; cursor: progress; }
button.danger { background: var(--bad); color: #fff; font-weight: 600; }
button.danger:disabled { opacity: .45; cursor: not-allowed; }
button.small-btn { padding: 5px 10px; font-size: 13px; }

td.detail { max-width: 380px; overflow: hidden; text-overflow: ellipsis; }

.settings {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px 18px;
  align-items: end;
}

.settings input, .settings select { margin-bottom: 0; }
.settings .checkbox { display: flex; align-items: center; }
.settings .checkbox label { display: flex; align-items: center; gap: 8px; margin: 0; color: var(--text); }
.settings .checkbox input { width: auto; margin: 0; }
.settings-actions { display: flex; align-items: center; gap: 12px; grid-column: 1 / -1; }

/* ---------- modal ---------- */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .55);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 50;
}

.modal-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 480px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
}

.modal-card h3 { margin: 0 0 12px; font-size: 18px; }

.danger-text {
  background: var(--bad-bg);
  color: var(--bad);
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 14px;
  margin: 0 0 16px;
}

.restore-target { display: flex; gap: 10px; align-items: baseline; margin: 0 0 16px; }
.restore-target dt { color: var(--muted); font-size: 13px; }
.restore-target dd { margin: 0; font-weight: 600; }

.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* ---------- activity dock ---------- */

.logdock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  background: var(--panel);
  border-top: 1px solid var(--line);
  box-shadow: 0 -6px 24px rgba(0, 0, 0, .12);
  display: flex;
  flex-direction: column;
  max-height: 45vh;
}

.log-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: none;
  border: none;
  border-radius: 0;
  padding: 9px 22px;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}

.log-header:hover { background: var(--panel-2); }

.log-title { display: flex; align-items: center; gap: 9px; }

.live-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted);
  flex: none;
}

.live-dot.active {
  background: var(--accent);
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .35; }
}

.chev { color: var(--muted); font-size: 11px; }

.log-body { display: flex; flex-direction: column; min-height: 0; }

/* Collapsed keeps the header bar visible and hides only the body, so the dock
   is always one click from expanding. */
.logdock.collapsed .log-body { display: none; }

.log-tools {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 6px 22px;
  border-top: 1px solid var(--line);
  font-size: 13px;
}

.log-tools label { color: var(--muted); display: flex; align-items: center; gap: 6px; }
.log-tools input[type="checkbox"] { width: auto; margin: 0; }

.log-lines {
  list-style: none;
  margin: 0;
  padding: 8px 22px 14px;
  overflow-y: auto;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.65;
  background: var(--panel-2);
  border-top: 1px solid var(--line);
  flex: 1;
  min-height: 160px;
}

.log-line { display: flex; gap: 12px; align-items: baseline; }
.log-line.error .log-msg { color: var(--bad); }
.log-line.warn .log-msg { color: var(--warn); }

.log-ts { color: var(--muted); flex: none; }
.log-src { color: var(--accent); flex: none; min-width: 108px; }
.log-msg { overflow-wrap: anywhere; white-space: pre-wrap; }

/* Keep the dock from covering the last card. */
#app-view { padding-bottom: 46px; }

/* ---------- language switch ---------- */

.lang-switch {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-top: 18px;
}

.lang-switch.inline-switch { margin-top: 0; }

button.lang {
  padding: 4px 10px;
  font-size: 12.5px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
}

button.lang:hover { color: var(--text); background: var(--panel-2); }

button.lang.active {
  color: var(--accent);
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  font-weight: 600;
}

/* ---------- two-factor ---------- */

.qr-wrap {
  display: grid;
  place-items: center;
  padding: 16px;
  background: #fff;           /* scanners need light behind the code */
  border-radius: 10px;
  margin: 4px 0 14px;
}

.qr-wrap img { width: 190px; height: 190px; display: block; }

.secret-box {
  padding: 9px 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  letter-spacing: .12em;
  word-break: break-all;
  margin: 0 0 16px;
  font-size: 13px;
}

.ok-text {
  background: var(--ok-bg);
  color: var(--ok);
  padding: 11px 13px;
  border-radius: 8px;
  font-size: 14px;
  margin: 0 0 16px;
}

#login-code, #totp-code, #totp-disable-code {
  letter-spacing: .35em;
  text-align: center;
  font-family: var(--mono);
  font-size: 17px;
}

/* ---------- schedule builder ---------- */

.sched-builder {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px 18px;
  align-items: end;
  margin-bottom: 18px;
}

.sched-builder input, .sched-builder select { margin-bottom: 0; }
.sched-builder .weekdays { grid-column: 1 / -1; }

.day-toggles { display: flex; flex-wrap: wrap; gap: 6px; }

button.day {
  padding: 6px 12px;
  font-size: 13px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
}

button.day:hover { color: var(--text); }

button.day.on {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.sched-actions {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.sched-preview {
  margin: 0;
  flex: 1;
  min-width: 200px;
  color: var(--text);
  font-size: 14px;
  padding: 8px 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.warn-note {
  background: var(--warn-bg);
  color: var(--warn);
  padding: 11px 13px;
  border-radius: 8px;
  font-size: 13.5px;
  margin: 0 0 16px;
}

/* A time input carries an intrinsic min-content width from its shadow DOM that
   is wider than the grid track, so without min-width:0 it overflows its cell
   and lands on top of the next field. */
.settings > div,
.sched-builder > div { min-width: 0; }

.settings input, .settings select,
.sched-builder input, .sched-builder select {
  width: 100%;
  min-width: 0;
  max-width: 100%;
}

input[type="time"], input[type="number"] {
  font-variant-numeric: tabular-nums;
  height: 40px;            /* matches the select height beside it */
}

.settings select, .sched-builder select { height: 40px; }

.form-mode {
  margin: 0 0 14px;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: 13.5px;
  color: var(--muted);
}

.form-mode strong { color: var(--text); }

/* The pgBackRest repo index, shown beside the name rather than as a column of
   its own: it identifies the location in pgbackrest commands but is not
   something the operator picks. */
.slot-tag {
  margin-left: 8px;
  padding: 1px 6px;
  border-radius: 5px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11.5px;
  cursor: help;
}

tr.row-editing > td { background: color-mix(in srgb, var(--accent) 9%, transparent); }

/* Full-width footnote inside a kv-grid: the "totals since" line belongs to the
   whole panel, not to a single field. */
.kv-grid .span-all {
  grid-column: 1 / -1;
  border-top: 1px solid var(--line);
  padding-top: 8px;
  margin-top: 2px;
}

.kv-grid .span-all:empty, .kv-grid .span-all span:empty { border: 0; padding: 0; margin: 0; }

/* An absolute timestamp is longer than the relative text this slot used to
   hold, so let it wrap instead of pushing the grid wider. */
#a-failtime { font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

/* The username is now the way into account settings, so it has to look
   pressable rather than like the static label it replaced. */
.chip-button {
  font: inherit;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  transition: border-color .12s ease, background .12s ease;
}

.chip-button:hover { border-color: var(--accent); background: var(--panel); }
.chip-button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* The account dialog carries two independent settings, so it is wider than a
   confirmation prompt and rules them apart. */
.modal-wide { max-width: 560px; }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}

.modal-head h3 { margin: 0; }

.account-section {
  padding: 18px 0;
  border-top: 1px solid var(--line);
}

.account-section:first-of-type { border-top: none; }

.account-section h4 {
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
}

.account-section label {
  display: block;
  margin: 12px 0 5px;
  font-size: 13px;
  color: var(--muted);
}

.account-section input { width: 100%; }

.modal-foot { border-top: 1px solid var(--line); padding-top: 16px; }


/* The ETL run controls sit on one line: pick a source, press the button. */
.etl-run {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 14px 0 4px;
}

.etl-run label { color: var(--muted); font-size: 13px; }
.etl-run select { min-width: 180px; height: 40px; }
.etl-status { margin-top: 14px; }

/* A failure count worth noticing without turning the whole row red. */
.bad-text { color: var(--bad, #b3261e); font-weight: 600; }

/* MCP tab */
.mcp-actions { margin-top: 12px; flex-wrap: wrap; }
.mcp-actions input[type="number"] { width: 90px; height: 36px; }
.mcp-status { margin-top: 14px; }
.path { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; word-break: break-all; }
.warn-text { color: var(--bad); }
.row-bad td { background: var(--bad-bg); }
