/* Dark theme is the default; the light theme is opt-in via the toggle (html[data-theme="light"]) */
:root {
  --bg: #0d1017;
  --bg-soft: #151a24;
  --surface: #141923;
  --border: #252c3a;
  --text: #e8ebf2;
  --muted: #8b95a8;
  --accent: #818cf8;
  --accent-soft: #1e2140;
  --accent-text: #0d1017;
  --ok: #34d399;
  --ok-soft: #0f2a22;
  --warn: #fbbf24;
  --warn-soft: #2b2310;
  --bad: #f87171;
  --bad-soft: #2d1416;
  --idle: #9aa3b5;
  --idle-soft: #1c2230;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  --radius: 14px;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f5f6fa;
  --bg-soft: #eef0f6;
  --surface: #ffffff;
  --border: #e3e6ee;
  --text: #111827;
  --muted: #6b7280;
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --accent-text: #ffffff;
  --ok: #059669;
  --ok-soft: #ecfdf5;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --bad: #dc2626;
  --bad-soft: #fef2f2;
  --idle: #6b7280;
  --idle-soft: #f3f4f6;
  --shadow: 0 1px 2px rgba(17, 24, 39, .04), 0 4px 16px rgba(17, 24, 39, .05);
  color-scheme: light;
}
.theme-icon-light { display: none; }
:root[data-theme="light"] .theme-icon-light { display: block; }
:root[data-theme="light"] .theme-icon-dark { display: none; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1 { font-size: 28px; letter-spacing: -.02em; margin: 0 0 8px; }
h2 { font-size: 15px; margin: 0; font-weight: 600; }
h3 { font-size: 17px; margin: 0 0 14px; }
p { margin: 0; }
code, .mono { font-family: "Cascadia Code", Consolas, ui-monospace, monospace; font-size: 12.5px; }
a { color: var(--accent); }
svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- top bar & tabs ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 24px;
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-title { font-weight: 650; font-size: 15px; }
.brand-sub { color: var(--muted); font-size: 12px; }
.logo {
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6); color: #fff;
}
.logo svg { width: 18px; height: 18px; fill: #fff; stroke: none; }
.logo.big { width: 64px; height: 64px; border-radius: 18px; margin-bottom: 18px; }
.logo.big svg { width: 32px; height: 32px; }
.account { display: flex; align-items: center; gap: 10px; margin-left: auto; }
#themeBtn { flex: none; }
.refresh-info { color: var(--muted); font-size: 12px; }
.avatar {
  display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-weight: 650; font-size: 12px;
}
.user { font-size: 13px; color: var(--muted); }

.tabs {
  position: sticky; top: 59px; z-index: 9;
  display: flex; gap: 4px; padding: 0 24px; overflow-x: auto; scrollbar-width: none;
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  display: inline-flex; align-items: center; gap: 8px; white-space: nowrap;
  padding: 12px 14px; color: var(--muted); text-decoration: none; font-weight: 550;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--idle); }
.tab .dot.ok { background: var(--ok); }
.tab .dot.warn { background: var(--warn); }
.tab .dot.bad { background: var(--bad); }
.tab .count {
  font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--bg-soft); color: var(--muted);
}

/* ---------- layout ---------- */
main { max-width: 1280px; margin: 0 auto; padding: 24px 24px 64px; }
.hero { text-align: center; padding: 96px 16px; max-width: 520px; margin: 0 auto; }
.hero p { color: var(--muted); margin-bottom: 28px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { font-size: 24px; margin: 0; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }

/* ---------- KPI cards ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}
.kpi .label { color: var(--muted); font-size: 12px; font-weight: 550; }
.kpi .value { font-size: 28px; font-weight: 650; letter-spacing: -.02em; margin-top: 4px; }
.kpi .value small { font-size: 15px; color: var(--muted); font-weight: 500; }
.kpi .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* ---------- panels & tables ---------- */
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 18px; overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  /* subtle accent tint so the section titles stand out from the table header rows */
  background: linear-gradient(90deg, var(--accent-soft) 0%, color-mix(in srgb, var(--accent-soft) 35%, transparent) 60%, transparent 100%);
  box-shadow: inset 3px 0 0 var(--accent);
}
.panel-head h2 { color: color-mix(in srgb, var(--accent) 55%, var(--text)); }
.panel-head .hint { color: var(--muted); font-size: 12px; }
.panel-body { padding: 16px 18px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 18px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 11.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; background: var(--bg-soft); }
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: color-mix(in srgb, var(--bg-soft) 60%, transparent); }
td.actions { text-align: right; white-space: nowrap; }
td.actions .btn { margin-left: 4px; }
td .strong { font-weight: 600; }
td .muted, .muted { color: var(--muted); }
.link-row { cursor: pointer; }
.empty { padding: 22px 18px; color: var(--muted); text-align: center; }
.loading { padding: 40px; text-align: center; color: var(--muted); }

dl.props { display: grid; grid-template-columns: max-content 1fr; gap: 8px 20px; margin: 0; }
dl.props dt { color: var(--muted); }
dl.props dd { margin: 0; word-break: break-word; }
.rdp { margin-top: 18px; }

/* ---------- chips ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 550; background: var(--idle-soft); color: var(--idle); white-space: nowrap;
}
.chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.chip.plain::before { display: none; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.accent { background: var(--accent-soft); color: var(--accent); }
.chip.busy::before { animation: pulse 1.1s infinite; }
@keyframes pulse { 50% { opacity: .25; } }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  font: inherit; font-weight: 550; color: var(--text); text-decoration: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: 9px;
  padding: 6px 12px; cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.danger:hover:not(:disabled) { background: var(--bad-soft); border-color: var(--bad); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); }
.btn.small { padding: 3px 9px; font-size: 12.5px; border-radius: 7px; }
.btn.large { padding: 10px 28px; font-size: 15px; border-radius: 11px; }
.btn.launch { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.btn.launch:hover { border-color: var(--accent); }
.icon-btn {
  display: grid; place-items: center; width: 32px; height: 32px; border-radius: 9px;
  background: transparent; border: 1px solid transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--bg-soft); color: var(--text); }
.icon-btn.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
select, input, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 9px; padding: 6px 10px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { width: 100%; min-height: 90px; resize: vertical; }
textarea.code { min-height: 300px; line-height: 1.45; tab-size: 4; white-space: pre; background: var(--bg-soft); }
#dialogBody select { width: 100%; }
#dialogBody select.size-list { margin-top: 8px; padding: 4px; font-family: "Cascadia Code", Consolas, ui-monospace, monospace; font-size: 12.5px; }
#dialogBody select.size-list option { padding: 4px 6px; border-radius: 6px; }
#dialogBody p.muted { margin-top: 6px; font-size: 13px; }
input[type=text] { width: 100%; }

/* ---------- runbooks ---------- */
.runbook {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.runbook:last-child { border-bottom: none; }
.runbook .desc { color: var(--muted); font-size: 13px; margin-top: 2px; }
.inline { display: flex; gap: 8px; align-items: center; }
.inline.wrap { flex-wrap: wrap; justify-content: flex-end; }
.inline select { max-width: 340px; }
#dialogBody p + p { margin-top: 8px; }

/* ---------- app groups ---------- */
.ag-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ag-meta { color: var(--muted); font-size: 12.5px; margin-top: 3px; }
.sub-title { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; margin: 0 0 8px; }

/* ---------- dialog & toast ---------- */
dialog {
  border: 1px solid var(--border); border-radius: 18px; padding: 22px;
  background: var(--surface); color: var(--text); width: min(720px, calc(100vw - 32px));
  box-shadow: 0 24px 64px rgba(0, 0, 0, .25);
}
dialog::backdrop { background: rgba(10, 12, 20, .5); backdrop-filter: blur(2px); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
#dialogBody label { display: block; margin: 12px 0 5px; color: var(--muted); font-size: 13px; }
pre.output {
  background: var(--bg-soft); border: 1px solid var(--border); border-radius: 10px; padding: 12px;
  max-height: 60vh; overflow: auto; white-space: pre-wrap; margin: 12px 0 0;
}
.toast {
  position: fixed; right: 20px; bottom: 20px; max-width: 440px; z-index: 30;
  background: var(--text); color: var(--bg); padding: 12px 16px; border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .25);
}
.toast.error { background: var(--bad); color: #fff; }

@media (max-width: 720px) {
  .topbar { padding: 10px 16px; }
  .tabs { padding: 0 12px; top: 55px; }
  main { padding: 16px 16px 48px; }
  .user, .refresh-info, .btn.launch span { display: none; }
  .grid.two { grid-template-columns: 1fr; }
  .runbook { flex-direction: column; align-items: flex-start; }
  th, td { padding: 10px 12px; }
}
