:root {
  --bg: #15171c;
  --panel: #1c1f26;
  --panel-2: #232730;
  --border: #2c313c;
  --fg: #e6e8ec;
  --muted: #8b93a1;
  --accent: #4f9cf9;
  --ok: #3fb950;
  --warn: #d29922;
  --err: #f85149;
  --idle: #6e7681;
}

* { box-sizing: border-box; }

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

a { color: var(--accent); text-decoration: none; }

header.host {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1.5rem;
  padding: 0.75rem 1.25rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

header.host .brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: 0.02em;
}
header.host .brand-icon {
  display: block;
  height: 1.6rem;
  width: auto;
}
header.host .brand-name span { color: var(--accent); }

.metric {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}
.metric .label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.metric .value { font-variant-numeric: tabular-nums; font-weight: 600; }
.metric .value .count-ok { color: var(--ok); }
.metric .value .count-err { color: var(--err); }
.metric .value .count-idle { color: var(--muted); }

.spacer { flex: 1; }
.generated { color: var(--muted); font-size: 0.75rem; }
/* Logout control in the header (only shown when authentication is enabled).
   It's a one-button POST form (GET logout was drive-by-triggerable); the
   wrapper dissolves into the header's flex row and the button is restyled
   to look like the link it replaced. */
.logout-form { display: contents; }
header.host .logout {
  color: var(--muted);
  font-size: 0.75rem;
  margin-left: 1rem;
  background: none;
  border: none;
  padding: 0;
  font-family: inherit;
  cursor: pointer;
}
header.host .logout:hover { color: var(--accent); }

/* Host switcher: one tab per monitored host (shown only with several hosts). */
.host-switch { display: flex; flex-wrap: wrap; gap: 0.3rem; align-items: center; }
.host-tab {
  padding: 0.2rem 0.6rem;
  border-radius: 6px;
  font-size: 0.85rem;
  color: var(--muted);
  border: 1px solid transparent;
}
.host-tab:hover { color: var(--accent); }
.host-tab.current {
  color: var(--fg);
  background: var(--panel-2);
  border-color: var(--border);
  font-weight: 600;
}

/* Multi-host landing page: a simple list of hosts to choose from. */
.host-list h2 { margin: 0 0 0.75rem; }
.host-list ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-width: 22rem;
}
.host-list a {
  display: block;
  padding: 0.5rem 0.9rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.host-list a:hover { border-color: var(--accent); }

main { padding: 1.25rem; max-width: 1100px; margin: 0 auto; }

/* Login page: a single centred card, no header or live machinery. */
.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
}
.login {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  width: 100%;
  max-width: 20rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.75rem;
}
.login .brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1.25rem;
  justify-content: center;
  margin-bottom: 0.5rem;
}
.login .brand-icon { height: 1.8rem; width: auto; }
.login .brand-name span { color: var(--accent); }
.login input {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  color: var(--fg);
  font-size: 0.95rem;
}
.login input:focus { outline: none; border-color: var(--accent); }
.login button {
  margin-top: 0.25rem;
  padding: 0.6rem;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #0b1020;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
}
.login button:hover { filter: brightness(1.08); }
.login-error { color: var(--err); font-size: 0.85rem; margin: 0; text-align: center; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.stack {
  margin-bottom: 1.5rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.stack > h2 {
  margin: 0;
  padding: 0.6rem 1rem;
  font-size: 0.95rem;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
}
.stack > h2 .count { color: var(--muted); font-weight: 400; font-size: 0.8rem; }

/* Every stack renders its own <table>; fixed layout plus the shared column
   widths below keep the columns aligned across all of them (auto layout
   computed different widths per stack). Column 1 (name) takes the rest. */
table { width: 100%; border-collapse: collapse; table-layout: fixed; }
/* Widths include the 2×1rem cell padding: value text + 0.5rem gap + 80px bar
   (CPU/Memory), badge + health marker (State) must fit on one line. */
th.col-image { width: 15%; }
th.col-state { width: 190px; }
th.col-cpu { width: 175px; }
th.col-mem { width: 200px; }
th.actions-col { width: 120px; }
td.name, td.image {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
th, td {
  text-align: left;
  padding: 0.55rem 1rem;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}
th {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 600;
}
tr:last-child td { border-bottom: none; }
td.num { text-align: right; }
td.name { font-weight: 600; }
td.image { color: var(--muted); font-size: 0.85rem; }

.badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.badge.running { background: rgba(63,185,80,0.15); color: var(--ok); }
.badge.exited, .badge.dead { background: rgba(248,81,73,0.15); color: var(--err); }
.badge.paused, .badge.restarting, .badge.stopping, .badge.removing,
.badge.created, .badge.unknown { background: rgba(110,118,129,0.2); color: var(--idle); }

/* Exposed ports. Blue (the link/accent colour) reads as "clickable" and stays
   clear of the green/red/grey state badges. Inline after the state badge on the
   detail page; on its own line under the badge in the dense tables. */
.ports {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem;
  vertical-align: middle;
}
td .ports { display: flex; margin-top: 0.4rem; }
.port-pill, .port-more {
  display: inline-block;
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
  font-size: 0.7rem;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.port-pill { background: rgba(79,156,249,0.15); color: var(--accent); }
a.port-pill:hover { background: rgba(79,156,249,0.3); }
.port-pill.muted { background: rgba(110,118,129,0.2); color: var(--muted); }
.port-more { background: rgba(110,118,129,0.2); color: var(--muted); cursor: default; }

.health { margin-left: 0.4rem; font-size: 0.7rem; }
.health.healthy { color: var(--ok); }
.health.unhealthy { color: var(--err); }
.health.starting { color: var(--warn); }

.bar {
  position: relative;
  height: 6px;
  width: 80px;
  background: var(--panel-2);
  border-radius: 3px;
  overflow: hidden;
  display: inline-block;
  vertical-align: middle;
  margin-left: 0.5rem;
}
.bar > span {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  background: var(--accent);
}
.bar.warn > span { background: var(--warn); }
.bar.err > span { background: var(--err); }

.empty { color: var(--muted); text-align: center; padding: 3rem; }

.charts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
@media (max-width: 640px) {
  .charts { grid-template-columns: 1fr; }
}
.chart-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem 0.8rem 0.3rem;
}
.chart-card .chart-head {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}
.chart-card .chart-title {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 600;
}
/* Hover readout ("21:43:05 · 3.2%"), filled by live.js. */
.chart-card .chart-readout {
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  color: var(--fg);
  white-space: nowrap;
  margin-left: auto;
}
.chart-card .u-legend { display: none; }
/* Dual-line chart legend: a coloured key per series — rx/read blue (the line
   colour), tx/write green — so the two lines are tellable apart at a glance. */
.chart-card .chart-legend {
  display: inline-flex;
  gap: 0.6rem;
  font-size: 0.65rem;
  color: var(--muted);
}
.chart-card .chart-legend .k {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.chart-card .chart-legend .k::before {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
}
.chart-card .chart-legend .in::before { background: var(--accent); }
.chart-card .chart-legend .out::before { background: var(--ok); }
.chart-zoom {
  cursor: pointer;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1;
  padding: 0 0.1rem;
}
.chart-zoom:hover { color: var(--fg); }

/* History overlay (see history.js). */
#history-dialog {
  width: min(94vw, 1100px);
  background: var(--panel);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0;
}
#history-dialog::backdrop { background: rgba(0, 0, 0, 0.55); }
.history-body { padding: 0.8rem 1rem 1rem; }
.history-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
.history-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}
.history-ranges { display: inline-flex; gap: 0.3rem; }
.history-ranges button {
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--muted);
  border-radius: 6px;
  padding: 0.15rem 0.55rem;
  font-size: 0.75rem;
}
.history-ranges button:hover { color: var(--fg); }
.history-ranges button.active {
  color: var(--fg);
  border-color: var(--accent);
}
.history-hint {
  color: var(--muted);
  font-size: 0.7rem;
  white-space: nowrap;
  display: none;
}
.history-hint.show { display: inline; }
.history-head .chart-readout {
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  margin-left: auto;
}
.history-close {
  cursor: pointer;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1;
}
.history-close:hover { color: var(--fg); }
#history-chart {
  min-height: 420px;
  color: var(--muted);
  font-size: 0.85rem;
}
#history-chart .u-legend { display: none; }

td.actions-cell { text-align: right; white-space: nowrap; }
th.actions-col { text-align: right; }
.actions { display: inline-flex; gap: 0.3rem; }
.act {
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--fg);
  border-radius: 6px;
  width: 1.9rem;
  height: 1.7rem;
  font-size: 0.8rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s, border-color 0.12s;
}
.act:hover { background: var(--border); }
.act.start:hover { color: var(--ok); border-color: var(--ok); }
.act.restart:hover { color: var(--warn); border-color: var(--warn); }
.act.stop:hover { color: var(--err); border-color: var(--err); }
.act.htmx-request { opacity: 0.5; pointer-events: none; }
/* Read-only host: actions are shown but disabled. */
.act:disabled { opacity: 0.4; cursor: not-allowed; }
.act:disabled:hover { background: var(--panel-2); color: var(--fg); border-color: var(--border); }

h2 a.stack-link { color: var(--fg); }
h2 a.stack-link:hover { color: var(--accent); }

.detail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}
.detail-title { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.detail-title h1 { margin: 0; font-size: 1.4rem; }
.detail-title .count { color: var(--muted); font-size: 0.9rem; }
.back { font-size: 0.8rem; color: var(--muted); }
.back:hover { color: var(--accent); }
.stack-pill {
  font-size: 0.75rem;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--border);
}

.status-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}
.fact {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}
.fact-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.fact-value {
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  margin-bottom: 1.5rem;
}
.panel h3 {
  margin: 0 0 0.5rem;
  font-size: 0.9rem;
}
.panel h3 .count { color: var(--muted); font-weight: 400; font-size: 0.75rem; }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.refresh {
  cursor: pointer;
  background: var(--panel-2);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.25rem 0.6rem;
  font-size: 0.75rem;
}
.refresh:hover { background: var(--border); }
.refresh.htmx-request { opacity: 0.5; pointer-events: none; }
.logs {
  margin: 0;
  max-height: 420px;
  overflow: auto;
  background: #0e1014;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.8rem;
  font: 12px/1.5 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  white-space: pre-wrap;
  word-break: break-word;
  color: #c9d1d9;
}
.logs .log-ts { color: var(--muted); }
.muted { color: var(--muted); }

/* Terminal panel (xterm.js). The view holds the live terminal; fullscreen
   lifts the whole panel over the page so a session can use the screen. */
.term-controls { display: flex; align-items: center; gap: 0.4rem; }
.term-cmd {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--fg);
  padding: 0.25rem 0.5rem;
  font: 12px ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  width: 9rem;
}
.term-cmd:focus { outline: none; border-color: var(--accent); }
.term-connect,
.term-fs {
  cursor: pointer;
  background: var(--panel-2);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.25rem 0.6rem;
  font-size: 0.75rem;
  line-height: 1;
}
.term-connect:hover,
.term-fs:hover { background: var(--border); }
.term-view {
  height: 360px;
  margin-top: 0.5rem;
  background: #0e1014;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem;
}
.term-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 60;
  margin: 0;
  border-radius: 0;
  display: flex;
  flex-direction: column;
}
.term-fullscreen .term-view {
  flex: 1;
  height: auto;
  margin-top: 0.5rem;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  transform: translateX(-50%);
  max-width: min(90vw, 40rem);
  background: var(--panel-2);
  border: 1px solid var(--err);
  color: var(--fg);
  border-radius: 8px;
  padding: 0.6rem 1rem;
  font-size: 0.85rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 100;
}
#toast.show { opacity: 1; }

.compose-file + .compose-file { margin-top: 0.75rem; }
.compose-path {
  font: 12px/1.5 ui-monospace, Menlo, Consolas, monospace;
  color: var(--muted);
  margin-bottom: 0.25rem;
  word-break: break-all;
}
