:root {
  --bg: #0f1216;
  --bg-2: #161b22;
  --bg-3: #1c232c;
  --line: #2a323d;
  --text: #dbe3ec;
  --muted: #8b97a6;
  --accent: #4f9cf9;
  --ok: #3fb950;
  --warn: #d29922;
  --bad: #f85149;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "Courier New", monospace;
  --console-h: 240px;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f4f6f9;
    --bg-2: #ffffff;
    --bg-3: #eef1f5;
    --line: #d8dee6;
    --text: #1c2430;
    --muted: #5c6875;
    --accent: #1f6feb;
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
}

/* ---------------------------------------------------------------- topbar */

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 15px; font-weight: 600; margin: 0; letter-spacing: .2px; }
.brand .dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

.sys { display: flex; gap: 8px; flex: 1; flex-wrap: wrap; }
.top-actions { display: flex; gap: 8px; }

.chip {
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-3);
  color: var(--muted);
  white-space: nowrap;
}
.chip b { color: var(--text); font-weight: 600; }
.chip.ok    { border-color: color-mix(in srgb, var(--ok) 45%, var(--line)); }
.chip.bad   { border-color: color-mix(in srgb, var(--bad) 55%, var(--line)); color: var(--bad); }

/* ---------------------------------------------------------------- buttons */

.btn {
  font: inherit;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--bg-3);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.btn-sm { padding: 4px 9px; font-size: 12px; }

/* ---------------------------------------------------------------- layout */

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 290px 1fr;
  min-height: 0;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: var(--bg-2);
  overflow-y: auto;
  min-height: 0;
}

.side-head {
  padding: 10px 14px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--bg-2);
}

.app-list { padding: 8px; display: flex; flex-direction: column; gap: 6px; }

.app-card {
  padding: 10px 11px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: var(--bg-3);
  cursor: pointer;
}
.app-card:hover { border-color: var(--line); }
.app-card.active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--bg-3)); }
.app-card .name { font-weight: 600; }
.app-card .dom { font-size: 12px; color: var(--muted); word-break: break-all; }
.app-card .pills { display: flex; gap: 5px; margin-top: 7px; flex-wrap: wrap; }
.app-card.client { margin-left: 16px; border-left: 2px solid var(--line); }

.pill {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--muted);
}
.pill.ok  { color: var(--ok);   border-color: color-mix(in srgb, var(--ok) 40%, var(--line)); }
.pill.bad { color: var(--bad);  border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.pill.warn{ color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, var(--line)); }

/* ---------------------------------------------------------------- detail */

.detail { overflow-y: auto; min-height: 0; padding: 18px 22px 28px; }
.empty { color: var(--muted); padding: 40px 0; }

.guide { max-width: 720px; }
.guide h2 { margin: 6px 0 10px; }
.guide h3 { font-size: 14px; margin: 22px 0 6px; }
.guide p { margin: 0 0 8px; color: var(--muted); }
.guide code {
  font-family: var(--mono);
  font-size: 12.5px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 5px;
  color: var(--text);
}
.guide pre.code { max-height: none; margin: 4px 0 6px; }
.guide b { color: var(--text); }

.detail h2 { margin: 0 0 2px; font-size: 20px; }
.detail .sub { color: var(--muted); margin-bottom: 16px; font-size: 13px; }
.detail .sub a { color: var(--accent); }

.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.card {
  border: 1px solid var(--line);
  background: var(--bg-2);
  border-radius: 8px;
  padding: 11px 13px;
}
.card.wide { grid-column: span 2; }
.card .k { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.card .v { font-size: 15px; font-weight: 600; margin-top: 3px; overflow-wrap: anywhere; }
.card .v.small { font-size: 13px; font-weight: 400; font-family: var(--mono); }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tab {
  padding: 7px 13px;
  font-size: 13px;
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

.pane { display: none; }
.pane.active { display: block; }

pre.code, textarea.code {
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.55;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  overflow: auto;
  max-height: 440px;
  white-space: pre;
  margin: 0;
  color: var(--text);
}
textarea.code { width: 100%; min-height: 300px; resize: vertical; white-space: pre; }

.row { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.note { color: var(--muted); font-size: 12.5px; margin-top: 8px; }
.note.warn { color: var(--warn); }

table.list { width: 100%; border-collapse: collapse; font-size: 13px; }
table.list td { padding: 6px 8px; border-bottom: 1px solid var(--line); }
table.list td:first-child { font-family: var(--mono); color: var(--muted); width: 1%; white-space: nowrap; }

/* --------------------------------------------------------------- console */

.console {
  border-top: 1px solid var(--line);
  background: var(--bg-2);
  display: flex;
  flex-direction: column;
  height: var(--console-h);
  flex: none;
}
.console.collapsed { height: 38px; }
.console.collapsed .console-body { display: none; }

.console-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 12px;
  border-bottom: 1px solid var(--line);
  flex: none;
}
.console-title { font-size: 12px; font-weight: 600; }
.console-status { font-size: 12px; color: var(--muted); flex: 1; }
.console-status.run { color: var(--accent); }
.console-status.ok  { color: var(--ok); }
.console-status.bad { color: var(--bad); }

/* the output pane is a terminal: black background, light text, in both themes */
.console-body {
  flex: 1;
  margin: 0;
  padding: 10px 14px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  background: #000;
  color: #e8e8e8;
}
.console-body .l-ok   { color: #35d75f; }
.console-body .l-warn { color: #f0d64a; }
.console-body .l-bad  { color: #ff5f56; }
.console-body .l-head { color: #4fd2ff; }
.console-body .l-dim  { color: #9aa0a6; }
.console-body:empty::before {
  content: "Nothing has run yet. Output from Deploy / Dry run / service actions shows up here.";
  color: #7d838a;
}

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

.modal-backdrop[hidden] { display: none; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  z-index: 50;
  overflow-y: auto;
}
.modal {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  width: min(720px, 100%);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}
.modal-head h2 { margin: 0; font-size: 16px; }
.modal-body { padding: 16px; }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field input, .field select, .field textarea {
  width: 100%;
  font: inherit;
  font-size: 13px;
  padding: 7px 10px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--bg-3);
  color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.picker {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-3);
  max-height: 230px;
  overflow-y: auto;
}
.picker div {
  padding: 6px 11px;
  cursor: pointer;
  font-family: var(--mono);
  font-size: 12.5px;
  border-bottom: 1px solid var(--line);
}
.picker div:last-child { border-bottom: none; }
.picker div:hover { background: var(--bg-2); }
.picker div.up { color: var(--muted); }
.picker div.taken { color: var(--warn); }

.msg { padding: 9px 12px; border-radius: 6px; font-size: 13px; margin-bottom: 12px; }
.msg.err { background: color-mix(in srgb, var(--bad) 16%, transparent); color: var(--bad); }
.msg.ok  { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }

@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { max-height: 210px; }
  .field-row { grid-template-columns: 1fr; }
}

.found {
  border: 1px solid var(--line);
  background: var(--bg-3);
  border-radius: 8px;
  padding: 4px 4px 4px 0;
  margin-bottom: 12px;
}
.found ul { margin: 6px 0; padding-left: 26px; }
.found li { font-size: 13px; color: var(--muted); margin: 3px 0; }
.found li b { color: var(--text); }
.found code {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 4px;
  color: var(--text);
}
h3.form-sec {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin: 18px 0 8px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.msg.warn { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }

.confirm-msg { font-size: 14px; line-height: 1.6; margin: 0 0 4px; }
.confirm-msg b { color: var(--text); }
.confirm-row { justify-content: flex-end; margin-top: 18px; margin-bottom: 0; }
#ask-no:focus { outline: 2px solid var(--accent); outline-offset: 2px; }

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

body.login-page { align-items: center; justify-content: center; padding: 16px; }
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 24px;
}
.login-card .brand { margin-bottom: 20px; }
.login-btn { width: 100%; padding: 9px; }
.top-user { color: var(--muted); font-size: 13px; }
