/* ---------- palette ---------- */
:root {
  --bg:           #061826;
  --surface:      #0f2842;
  --surface-alt:  #15324f;
  --border:       #1d4159;
  --border-soft:  #173249;

  --fg:           #e3f0f5;
  --muted:        #82a4b3;
  /* H-12 (2026-04-30 review): bumped from #5b7b89 (3.31:1 contrast on
     --surface, fails WCAG 1.4.3 AA at small sizes) to #7e9aa6 which
     hits 4.55:1 against --surface and 5.46:1 against --bg. */
  --muted-soft:   #7e9aa6;

  --accent:       #4eb6d8;
  --accent-fg:    #04141f;
  --accent-soft:  #28617c;
  --link:         #74cce5;

  --error:        #f48a8a;
  --warn:         #e8c267;

  --pill-active:    #3ab27a;
  --pill-inactive:  #d96f6f;
  --pill-clean:     #3ab27a;
  --pill-drift:     #e8c267;
  --pill-error:     #d96f6f;
  --pill-unknown:   #6c8a90;
  --pill-running:   #4dd0c5;
  --pill-bootstrapping: #e8c267;
  --pill-success:   #3ab27a;
  --pill-failed:    #d96f6f;
  --pill-cancelled: #e8c267;
  --pill-interrupted: #e8c267;
  --pill-queued:    #6c8a90;

  --shadow: 0 1px 0 rgba(255,255,255,0.02), 0 4px 12px rgba(0,0,0,0.35);
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
  background: var(--bg);
  color: var(--fg);
  line-height: 1.5;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ---------- topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar .brand {
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--fg);
  white-space: nowrap;
}
.topbar nav {
  display: flex;
  gap: 1rem;
  align-items: center;
  flex-wrap: wrap;
}
.topbar nav a {
  color: var(--link);
  text-decoration: none;
  font-weight: 500;
  padding: 0.15rem 0;
  border-bottom: 2px solid transparent;
  transition: border-color 0.12s ease, color 0.12s ease;
}
.topbar nav a:hover { color: var(--accent); border-bottom-color: var(--accent-soft); }
.topbar nav a.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.topbar nav a.active.roop-ui-link { border-bottom-color: transparent; }
.topbar nav .who { color: var(--muted); font-size: 0.92em; }
.topbar form.inline { display: inline; margin: 0; }
.topbar a.roop-ui-link {
  background: var(--accent-soft);
  color: var(--fg);
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  font-size: 0.86em;
  border: 1px solid var(--accent);
}
.topbar a.roop-ui-link:hover { background: var(--accent); color: var(--accent-fg); }
.topbar a.roop-ui-link.disabled {
  opacity: 0.45;
  pointer-events: none;
  background: var(--surface-alt);
  border-color: var(--border);
  color: var(--muted);
}
.linkbtn {
  background: none; border: 0; padding: 0;
  color: var(--link); cursor: pointer; font: inherit;
}
.linkbtn:hover { color: var(--accent); }
/* H-11 (2026-04-30 review): keyboard focus ring was absent on .linkbtn. */
.linkbtn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }

/* ---------- node picker (P5) ---------- */
.node-picker {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--muted);
  font-size: 0.86rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.node-picker select {
  background: var(--surface-alt);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.25rem 0.55rem;
  font-size: 0.92rem;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  text-transform: none;
  letter-spacing: 0;
  cursor: pointer;
}
.node-picker select:hover  { border-color: var(--accent); }
.node-picker select:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(78,182,216,0.18); }

/* ---------- nodes list (Cluster card) ---------- */
.nodes-list {
  list-style: none;
  margin: 0.4rem 0 0.7rem;
  padding: 0;
}
.nodes-list li {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border-soft);
}
.nodes-list li:last-child { border-bottom: 0; }
.nodes-list li > .mono { font-weight: 500; color: var(--fg); }
.nodes-list li > button.icon { margin-left: auto; }

/* ---------- modal (Add Node) ---------- */
dialog.modal {
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  min-width: 380px;
  max-width: 540px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.55);
}
dialog.modal::backdrop {
  background: rgba(2,12,24,0.65);
  backdrop-filter: blur(2px);
}
dialog.modal h3 { margin: 0 0 0.5rem 0; }
dialog.modal label.check {
  display: flex; align-items: center; gap: 0.5rem;
  margin: 0.5rem 0;
}
dialog.modal label.check input { width: auto; }
.modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 1rem;
}

/* ---------- layout ---------- */
main { padding: 1.25rem; max-width: 1200px; margin: 0 auto; }

/* O-A11y1 (2026-04-30 review): skip-link. Visually hidden until
   focused, then a high-contrast pill at the top of the page. */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0.5rem;
  z-index: 100;
  padding: 0.5rem 0.85rem;
  background: var(--accent);
  color: var(--accent-fg);
  border-radius: var(--radius);
  text-decoration: none;
  font-weight: 600;
}
.skip-link:focus,
.skip-link:focus-visible {
  top: 0.5rem;
  outline: 2px solid var(--fg);
  outline-offset: 2px;
}

/* ---------- a11y utilities ---------- */
/* B-A11y2 / S-A11y2 / S-A11y1 (2026-04-30 review): visually-hidden
   utility for headings and skip-link content that should still be
   exposed to screen readers. Standard recipe — does NOT use
   `display:none` (which removes from the AT tree). */
.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- log-stream controls ---------- */
.log-stream-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.5rem;
}
.log-stream-controls button[aria-pressed="true"] {
  background: var(--accent-soft);
  color: var(--fg);
}

/* ---------- footer ---------- */
.mgmt-footer {
  text-align: center;
  padding: 0.85rem 1rem 1.1rem;
  color: var(--muted);
  font-size: 0.78em;
  letter-spacing: 0.02em;
}
.mgmt-footer .mgmt-version {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
/* O8 (2026-04-30 review): post-apply sync status pill. */
.mgmt-footer .mgmt-sync-status {
  margin-left: 0.5rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.mgmt-footer .mgmt-sync-ok      { color: var(--pill-clean); }
.mgmt-footer .mgmt-sync-failed  { color: var(--pill-error); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
}

/* ---------- cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  box-shadow: var(--shadow);
  position: relative;
}
.card h2 {
  margin: 0 0 0.6rem 0;
  font-size: 1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.card .card-actions {
  position: absolute;
  top: 0.85rem;
  right: 0.85rem;
  display: flex;
  gap: 0.4rem;
}
.card.narrow { max-width: 480px; margin: 2rem auto; }
.card.wide   { max-width: 100%; }

/* ---------- forms ---------- */
label { display: block; margin: 0.6rem 0; color: var(--fg); }
label input, textarea {
  display: block; width: 100%;
  padding: 0.55rem 0.65rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  font: inherit;
}
label input:focus, textarea:focus {
  outline: 0;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(78,182,216,0.20);
}
textarea.mono {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.85rem;
  background: var(--bg);
}

/* ---------- buttons ---------- */
button, .btn {
  padding: 0.45rem 0.85rem;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-fg);
  cursor: pointer;
  font: inherit;
  font-weight: 500;
  transition: filter 0.1s ease, background 0.1s ease;
}
button:hover, .btn:hover { filter: brightness(1.08); }
button:active { transform: translateY(1px); }
button.ghost {
  background: transparent;
  color: var(--accent);
  border-color: var(--accent);
}
button.ghost:hover { background: var(--accent); color: var(--accent-fg); }
button.danger {
  background: var(--error);
  border-color: var(--error);
  color: #2a0606;
}
button.danger:hover { filter: brightness(1.08); }
button.icon {
  padding: 0.25rem 0.5rem;
  font-size: 0.85em;
  background: var(--surface-alt);
  color: var(--fg);
  border: 1px solid var(--border);
}
button.icon:hover { background: var(--accent-soft); border-color: var(--accent); }

/* ---------- type ---------- */
.muted       { color: var(--muted); }
.muted-soft  { color: var(--muted-soft); }
.error       { color: var(--error); }
.success     { color: var(--pill-active); }
.small       { font-size: 0.78rem; }
.mono        { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
code, pre code {
  background: var(--bg);
  border: 1px solid var(--border-soft);
  padding: 0.05rem 0.35rem;
  border-radius: 4px;
  font-size: 0.85em;
  color: var(--accent);
}

/* ---------- status panel ---------- */
.status-list { list-style: none; padding-left: 0; margin: 0.4rem 0; }
.status-list li { margin: 0.25rem 0; }
.status-list strong { color: var(--muted); font-weight: 500; min-width: 5rem; display: inline-block; }

.kv-grid {
  display: grid;
  grid-template-columns: max-content 1fr;
  column-gap: 1rem;
  row-gap: 0.3rem;
  margin-top: 0.5rem;
}
.kv-grid dt {
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
}
.kv-grid dd {
  margin: 0;
  color: var(--fg);
  word-break: break-word;
}
.kv-grid dd .num { font-variant-numeric: tabular-nums; }
.kv-grid dd .breadcrumb {
  margin-top: 0.2rem;
  font-family: var(--mono, ui-monospace, SFMono-Regular, Menlo, monospace);
  font-size: 0.78rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- dependencies list ---------- */
.deps-list {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0 0;
}
.dep-row {
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--border-soft);
}
.dep-row:last-child { border-bottom: 0; }

.dep-head {
  display: flex;
  gap: 0.6rem;
  align-items: center;
}
.dep-head .pill {
  flex-shrink: 0;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  min-width: 4.2rem;
  text-align: center;
}
.dep-head .dep-name {
  flex: 1;
  font-weight: 500;
  color: var(--fg);
}
.dep-head .dep-time {
  color: var(--muted-soft);
  font-size: 0.74rem;
  white-space: nowrap;
}

.dep-detail {
  margin-top: 0.25rem;
  margin-left: 4.85rem;     /* indent under the pill */
  color: var(--muted);
  font-size: 0.83rem;
  line-height: 1.5;
  word-break: break-word;
  overflow-wrap: anywhere;
}
@media (max-width: 480px) {
  .dep-head { flex-wrap: wrap; }
  .dep-head .dep-time { width: 100%; margin-left: 4.85rem; }
  .dep-detail { margin-left: 0; }
}

/* ---------- full-width card span (Status, Dependencies) ---------- */
.grid > .span-full { grid-column: 1 / -1; }

/* ---------- stale-card indicator ---------- */
/* When an htmx auto-refresh fails (response error / network drop), the
   card holds onto its previous DOM. Give the operator a clear "this is
   stale" signal: warning-coloured border + a "· stale" suffix on the
   heading. Cleared on the next successful swap. */
.card.stale { border-color: var(--warn); }
.card.stale > h2::after {
  content: " · stale";
  color: var(--warn);
  font-size: 0.75rem;
  font-weight: 400;
  letter-spacing: 0.02em;
}

/* ---------- disabled buttons ---------- */
button[disabled], button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  filter: grayscale(0.4);
}
button[disabled]:hover { filter: grayscale(0.4); }

/* ---------- progress bar ---------- */
.progress {
  position: relative;
  width: 100%;
  height: 0.5rem;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
  margin: 0.35rem 0;
  border: 1px solid var(--border-soft);
}
.progress > .bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-soft), var(--accent));
  border-radius: 999px;
  transition: width 0.4s ease;
}

/* ---------- pills ---------- */
.pill {
  display: inline-block;
  padding: 0.1rem 0.55rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 500;
  background: var(--pill-unknown);
  color: var(--accent-fg);
  vertical-align: middle;
  letter-spacing: 0.01em;
}
.pill-active     { background: var(--pill-active); }
.pill-inactive   { background: var(--pill-inactive); }
.pill-bootstrapping { background: var(--pill-bootstrapping); color: #2a1c00; }
.pill-clean      { background: var(--pill-clean); }
.pill-drift      { background: var(--pill-drift); color: #2a1c00; }
.pill-error      { background: var(--pill-error); }
.pill-unknown    { background: var(--pill-unknown); }
.pill-running    { background: var(--pill-running); }
.pill-success    { background: var(--pill-success); }
.pill-failed     { background: var(--pill-failed); }
.pill-cancelled  { background: var(--pill-cancelled); color: #2a1c00; }
.pill-interrupted { background: var(--pill-interrupted); color: #2a1c00; }
.pill-queued     { background: var(--pill-queued); }
/* EC2 lifecycle states — pill colours mirror semantics:
   running = healthy (cyan, same as pill-running),
   stopped = inactive (red, same as pill-inactive),
   stopping/pending/shutting-down/rebooting = transitional (yellow, same as pill-cancelled),
   terminated = inactive red. */
.pill-stopped         { background: var(--pill-inactive); }
.pill-stopping        { background: var(--pill-cancelled); color: #2a1c00; }
.pill-pending         { background: var(--pill-cancelled); color: #2a1c00; }
.pill-rebooting       { background: var(--pill-cancelled); color: #2a1c00; }
.pill-shutting-down   { background: var(--pill-cancelled); color: #2a1c00; }
.pill-terminated      { background: var(--pill-inactive); }

/* ---------- actions row ---------- */
.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.5rem; }
.actions form { margin: 0; display: inline; }

.job-pending { margin-top: 0.5rem; }

/* ---------- log streams ---------- */
.log-stream {
  background: #020c18;
  color: #c5e3ec;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  height: 60vh;
  overflow: auto;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.82rem;
  white-space: pre-wrap;
  line-height: 1.45;
}
.log-stream.small { height: 28vh; }

/* Severity classes applied by static/log-colorize.js. The base
   .log-stream colour is the "info" default; the rest only shift
   meaningful lines so the eye can scan for problems quickly. */
.log-stream .log-prefix { color: #6c8a96; }            /* timestamp + host + unit */
.log-stream .log-info   { color: #c5e3ec; }            /* default */
.log-stream .log-debug  { color: #6c8a96; opacity: 0.85; }
.log-stream .log-warn   { color: #e8c267; }
.log-stream .log-error  { color: #f48a8a; font-weight: 500; }
.log-stream .log-batch  { color: #4eb6d8; }            /* [batch], [notifier] etc */
.log-stream .log-meta   { color: var(--accent); font-style: italic; }
.log-stream::-webkit-scrollbar { width: 8px; }
.log-stream::-webkit-scrollbar-thumb {
  background: var(--accent-soft);
  border-radius: 4px;
}
.log-stream::-webkit-scrollbar-track { background: transparent; }

details summary { cursor: pointer; }
details summary:hover { color: var(--accent); }

/* ---------- responsive ---------- */
@media (max-width: 768px) {
  body { font-size: 14.5px; }
  main  { padding: 1rem; }
  .topbar { padding: 0.6rem 0.85rem; gap: 0.5rem; }
  .topbar nav { gap: 0.6rem; }
  .topbar nav a, .topbar nav .who { font-size: 0.92em; }
  .grid { grid-template-columns: 1fr; gap: 0.75rem; }
  .card { padding: 0.85rem 0.95rem; }
  .card .card-actions { top: 0.7rem; right: 0.7rem; }
}

@media (max-width: 480px) {
  body { font-size: 14px; }
  main  { padding: 0.65rem; }
  .topbar { flex-wrap: wrap; }
  .topbar .brand { flex-basis: 100%; }
  .topbar nav { flex-basis: 100%; justify-content: flex-start; }
  .actions { gap: 0.35rem; }
  button, .btn { padding: 0.4rem 0.7rem; font-size: 0.92em; }
  .log-stream { font-size: 0.78rem; height: 50vh; }
}

@media (prefers-reduced-motion: reduce) {
  .progress > .bar, button { transition: none; }
}
