/* ─── Design tokens — Dark theme is default ─────────────────── */
:root,
[data-theme="dark"] {
  --background: oklch(0.09 0.008 265);
  --sidebar:    oklch(0.07 0.008 265);
  --card:       oklch(0.12 0.008 265);
  --secondary:  oklch(0.16 0.008 265);
  --accent:     oklch(0.17 0.008 265);
  --muted:      oklch(0.17 0.008 265);
  --popover:    oklch(0.13 0.008 265);

  --foreground:         oklch(0.94 0.006 265);
  --muted-foreground:   oklch(0.58 0.012 265);

  --primary:            oklch(0.97 0 0);
  --primary-foreground: oklch(0.14 0.005 265);

  --border:             oklch(0.23 0.008 265);
  --input:              oklch(0.23 0.008 265);
  --ring:               oklch(0.70 0.02 265);

  --destructive:            oklch(0.56 0.22 27);
  --destructive-foreground: oklch(0.97 0 0);

  --scroll-thumb:       oklch(0.28 0.008 265);
  --scroll-thumb-hover: oklch(0.35 0.008 265);

  --row-hover:    rgb(255 255 255 / 0.025);
  --nav-hover:    rgb(255 255 255 / 0.05);
  --nav-active:   rgb(255 255 255 / 0.08);

  --shadow-lg:  0 10px 15px -3px rgb(0 0 0 / 0.25), 0 4px  6px -4px rgb(0 0 0 / 0.25);
  --shadow-xl:  0 20px 25px -5px rgb(0 0 0 / 0.35), 0 8px 10px -6px rgb(0 0 0 / 0.30);
  --shadow-2xl: 0 25px 50px -12px rgb(0 0 0 / 0.55);

  color-scheme: dark;
}

/* ─── Light theme ─────────────────────────────────────────── */
[data-theme="light"] {
  --background: oklch(0.99 0.002 265);
  --sidebar:    oklch(0.97 0.004 265);
  --card:       oklch(1.00 0 0);
  --secondary:  oklch(0.96 0.005 265);
  --accent:     oklch(0.94 0.006 265);
  --muted:      oklch(0.94 0.006 265);
  --popover:    oklch(1.00 0 0);

  --foreground:         oklch(0.18 0.005 265);
  --muted-foreground:   oklch(0.48 0.012 265);

  --primary:            oklch(0.18 0.005 265);
  --primary-foreground: oklch(0.99 0 0);

  --border:             oklch(0.90 0.005 265);
  --input:              oklch(0.90 0.005 265);
  --ring:               oklch(0.50 0.02 265);

  --destructive:            oklch(0.56 0.22 27);
  --destructive-foreground: oklch(0.99 0 0);

  --scroll-thumb:       oklch(0.78 0.008 265);
  --scroll-thumb-hover: oklch(0.65 0.008 265);

  --row-hover:    rgb(0 0 0 / 0.03);
  --nav-hover:    rgb(0 0 0 / 0.04);
  --nav-active:   rgb(0 0 0 / 0.07);

  --shadow-lg:  0 8px 16px -6px rgb(15 23 42 / 0.10), 0 4px 6px -4px rgb(15 23 42 / 0.06);
  --shadow-xl:  0 20px 25px -5px rgb(15 23 42 / 0.10), 0 8px 10px -6px rgb(15 23 42 / 0.07);
  --shadow-2xl: 0 25px 50px -12px rgb(15 23 42 / 0.18);

  color-scheme: light;
}

/* ─── Shared status triplets + radius (theme-independent) ─── */
:root {
  --green-400: 74 222 128;
  --green-500: 34 197 94;
  --red-400:   248 113 113;
  --red-500:   239 68 68;
  --amber-400: 251 191 36;
  --amber-500: 245 158 11;
  --blue-400:  96 165 250;
  --blue-500:  59 130 246;
  --zinc-400:  161 161 170;
  --zinc-500:  113 113 122;
  --purple-400: 192 132 252;
  --purple-500: 168 85 247;

  --radius:    0.75rem;
  --radius-sm: calc(var(--radius) - 4px);
  --radius-md: calc(var(--radius) - 2px);
  --radius-lg: var(--radius);
  --radius-xl: calc(var(--radius) + 4px);
}

/* ─── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; padding: 0; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--background);
  color: var(--foreground);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; font-size: 0.92em; }

::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scroll-thumb); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--scroll-thumb-hover); }

:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--ring); }

/* ─── App shell ─────────────────────────────────────────────── */
.app-shell { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: 240px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
}
.sidebar-header { padding: 20px 16px 16px; border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 600; color: var(--foreground); letter-spacing: -0.01em; }
.brand-mark {
  width: 28px; height: 28px;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: var(--primary-foreground);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px;
}
.sidebar-nav { flex: 1; overflow-y: auto; padding: 12px 8px; display: flex; flex-direction: column; gap: 2px; }
.sidebar-section { font-size: 10px; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted-foreground); padding: 12px 12px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--muted-foreground);
  transition: background 150ms, color 150ms;
}
.nav-item:hover { color: var(--foreground); background: var(--nav-hover); text-decoration: none; }
.nav-item.active { color: var(--foreground); background: var(--nav-active); }
.nav-item .grow { flex: 1; }
.sidebar-footer { padding: 12px 8px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 2px; }

.app-main { flex: 1; display: flex; flex-direction: column; overflow: hidden; background: var(--background); }
.app-main.fullwidth { /* no-op, kept for symmetry */ }
.page-header {
  padding: 18px 32px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px;
  flex-shrink: 0;
}
.page-title { font-size: 16px; font-weight: 600; color: var(--foreground); margin: 0; letter-spacing: -0.01em; }
.page-subtitle { font-size: 12px; color: var(--muted-foreground); margin: 2px 0 0; }
.page-content { flex: 1; overflow-y: auto; padding: 24px 32px; }
.page-content.fullwidth { padding: 16px 24px; }
.page-actions { display: flex; gap: 8px; align-items: center; }

/* ─── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 500;
  background: var(--secondary);
  color: var(--foreground);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: background 150ms, opacity 150ms, border-color 150ms;
  font-family: inherit;
  text-decoration: none;
  line-height: 1.2;
  white-space: nowrap;
}
.btn:hover { background: var(--accent); text-decoration: none; }
.btn.primary { background: var(--primary); color: var(--primary-foreground); border-color: transparent; }
.btn.primary:hover { opacity: 0.9; background: var(--primary); }
.btn.danger { background: transparent; color: rgb(var(--red-400)); border-color: rgb(var(--red-500) / 0.4); }
.btn.danger:hover { background: rgb(var(--red-500) / 0.12); border-color: rgb(var(--red-500) / 0.6); }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn.icon { padding: 6px; }

/* ─── Forms ──────────────────────────────────────────────────── */
input[type="text"], input[type="number"], input[type="password"], input:not([type]), textarea, select {
  width: 100%;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  background: var(--secondary);
  border: 1px solid var(--border);
  color: var(--foreground);
  font-family: inherit;
  transition: box-shadow 150ms, border-color 150ms;
  line-height: 1.4;
}
input:focus, textarea:focus, select:focus { outline: none; box-shadow: 0 0 0 1px var(--ring); border-color: var(--ring); }
input::placeholder, textarea::placeholder { color: var(--muted-foreground); }
input[type="hidden"] { display: none; }

label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted-foreground);
  margin-bottom: 6px;
}
label input, label textarea, label select { margin-top: 6px; }

fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px 14px;
  margin: 0 0 16px;
  background: var(--card);
  box-shadow: var(--shadow-lg);
}
legend {
  font-size: 10px; font-weight: 600;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--muted-foreground);
  padding: 0 8px;
}

textarea { resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; font-size: 13px; line-height: 1.55; }
textarea.code { width: 100%; min-height: calc(100vh - 280px); tab-size: 2; padding: 12px; }

/* ─── Cards ──────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  box-shadow: var(--shadow-lg);
}
.card h3 { font-size: 13px; font-weight: 600; margin: 0 0 10px; color: var(--foreground); }

/* ─── Tables ─────────────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table-wrap {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}
.table-wrap thead { border-bottom: 1px solid var(--border); }
.table-wrap th {
  text-align: left; padding: 10px 16px;
  font-size: 11px; font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted-foreground);
}
.table-wrap td { padding: 12px 16px; border-top: 1px solid var(--border); color: var(--foreground); font-size: 13px; }
.table-wrap tbody tr { transition: background 150ms; }
.table-wrap tbody tr:hover { background: var(--row-hover); }
.table-wrap tbody tr:first-child td { border-top: 0; }
.table-wrap td code { color: var(--muted-foreground); font-size: 12px; }

/* ─── Badges & chips ────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 9999px;
  font-size: 12px; font-weight: 500; line-height: 1.4;
}
.badge.success { background: rgb(var(--green-500) / 0.15); color: rgb(var(--green-400)); }
.badge.error   { background: rgb(var(--red-500) / 0.15);   color: rgb(var(--red-400)); }
.badge.warning { background: rgb(var(--amber-500) / 0.15); color: rgb(var(--amber-400)); }
.badge.info    { background: rgb(var(--blue-500) / 0.15);  color: rgb(var(--blue-400)); }
.badge.neutral { background: rgb(var(--zinc-500) / 0.15);  color: rgb(var(--zinc-400)); }

.dot { width: 6px; height: 6px; border-radius: 9999px; display: inline-block; }
.dot.success { background: rgb(var(--green-400)); }
.dot.error   { background: rgb(var(--red-400)); }
.dot.warning { background: rgb(var(--amber-400)); }
.dot.muted   { background: rgb(var(--zinc-400)); }

.chip {
  display: inline-flex; align-items: center;
  padding: 1px 8px;
  border-radius: 9999px;
  font-size: 11px;
  background: var(--secondary);
  color: var(--muted-foreground);
  border: 1px solid var(--border);
  font-family: ui-monospace, monospace;
}

/* ─── Layout helpers ───────────────────────────────────────── */
.row { display: flex; gap: 16px; flex-wrap: wrap; }
.row.between { justify-content: space-between; align-items: center; }
.row.tight { gap: 8px; }
.col { display: flex; flex-direction: column; gap: 8px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.grid-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.actions { display: flex; gap: 8px; align-items: center; }
.muted { color: var(--muted-foreground); }
.small { font-size: 12px; }
.tiny { font-size: 11px; }
.ml-auto { margin-left: auto; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.mt-3 { margin-top: 12px; }
.section { margin-bottom: 28px; }

/* ─── Crumbs ───────────────────────────────────────────────── */
.crumbs { font-size: 12px; color: var(--muted-foreground); margin: 0 0 4px; }
.crumbs strong { color: var(--foreground); font-weight: 500; }
.crumbs a { color: var(--muted-foreground); }
.crumbs a:hover { color: var(--foreground); text-decoration: none; }

/* ─── Flash / error ────────────────────────────────────────── */
.flash {
  background: rgb(var(--green-500) / 0.1);
  border: 1px solid rgb(var(--green-500) / 0.25);
  color: rgb(var(--green-400));
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  margin: 0 0 16px;
}
.error {
  background: rgb(var(--red-500) / 0.1);
  border: 1px solid rgb(var(--red-500) / 0.25);
  color: rgb(var(--red-400));
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  margin: 0 0 16px;
}

/* ─── Stack cards (dashboard) ───────────────────────────────── */
.stack-card {
  display: block;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  color: var(--foreground);
  transition: border-color 150ms, background 150ms;
  box-shadow: var(--shadow-lg);
}
.stack-card:hover { border-color: rgb(var(--blue-500) / 0.5); background: var(--accent); text-decoration: none; }
.stack-card .name { font-size: 14px; font-weight: 600; margin: 0 0 2px; }
.stack-card .file { font-size: 11px; color: var(--muted-foreground); font-family: ui-monospace, monospace; }
.stack-card .svcs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }

/* ─── Stat cards (dashboard / stage) ─────────────────────────── */
.stat {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  box-shadow: var(--shadow-lg);
}
.stat .label {
  font-size: 10px; font-weight: 600;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--muted-foreground);
  margin: 0 0 6px;
}
.stat .value { font-size: 18px; font-weight: 600; color: var(--foreground); font-feature-settings: "tnum"; }
.stat .value code {
  font-size: 14px;
  background: var(--secondary);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  color: var(--foreground);
}

/* ─── Diff & log blocks ─────────────────────────────────────── */
.diff {
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  font-family: ui-monospace, monospace;
  font-size: 12px;
  white-space: pre;
  overflow: auto;
  max-height: 500px;
  line-height: 1.5;
}
.deploy-log {
  background: oklch(0.05 0 0);
  color: oklch(0.86 0.005 265);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  max-height: 600px;
  overflow-y: auto;
  font-family: ui-monospace, monospace;
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.5;
}

/* ─── Ace editor ────────────────────────────────────────────── */
.ace-editor {
  width: 100%;
  height: calc(100vh - 200px);
  min-height: 480px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--card);
}
.ace-editor .ace_gutter { background: var(--sidebar); }
.ace-editor .ace_active-line { background: rgb(var(--blue-500) / 0.08) !important; }

/* ─── Inline form (config rename, commit) ───────────────────── */
.inline-form { display: inline-flex; gap: 6px; align-items: center; }
.inline-form input { padding: 4px 8px; font-size: 12px; }

.commit-form { display: flex; flex-direction: column; gap: 8px; max-width: 600px; }

/* ─── kv tables in service form ────────────────────────────── */
.kv { width: 100%; border-collapse: collapse; font-size: 13px; }
.kv th {
  text-align: left;
  font-size: 11px; font-weight: 500;
  color: var(--muted-foreground);
  text-transform: uppercase; letter-spacing: 0.05em;
  padding: 4px 4px 8px;
}
.kv td { padding: 3px 4px; vertical-align: top; }
.kv input { padding: 6px 10px; font-size: 13px; }
.kv td.rm { width: 36px; text-align: right; }

/* ─── Plain list ───────────────────────────────────────────── */
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
ul.plain li:last-child { border-bottom: 0; }
ul.plain code { color: var(--foreground); }

/* ─── Headings ─────────────────────────────────────────────── */
h1 { font-size: 18px; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
h2 {
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--muted-foreground);
  margin: 24px 0 12px;
}
h2:first-child { margin-top: 0; }
h3 { font-size: 13px; font-weight: 600; margin: 0 0 10px; color: var(--foreground); }

/* ─── Bump card ─────────────────────────────────────────────── */
.bump-card { flex: 1; min-width: 360px; }

/* ─── Login ────────────────────────────────────────────────── */
.login-shell { height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--background); }
.login-card {
  width: 360px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 32px;
  box-shadow: var(--shadow-2xl);
}
.login-card h1 { font-size: 18px; font-weight: 600; text-align: center; margin: 0 0 4px; }
.login-card .subtitle { text-align: center; font-size: 12px; color: var(--muted-foreground); margin: 0 0 24px; }
.login-card .field { margin-bottom: 14px; }
.login-card button { width: 100%; margin-top: 8px; }

/* ─── Modal ────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgb(0 0 0 / 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: modal-fade 120ms ease-out;
}
.modal.hidden { display: none; }
.modal-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 960px;
  max-height: 84vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-2xl);
  overflow: hidden;
}
.modal-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 12px;
  align-items: center;
}
.modal-title { flex: 1; font-size: 14px; font-weight: 600; color: var(--foreground); margin: 0; letter-spacing: -0.01em; }
.modal-close {
  background: transparent;
  border: 0;
  color: var(--muted-foreground);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  font-size: 18px;
  line-height: 1;
}
.modal-close:hover { background: var(--accent); color: var(--foreground); }
.modal-body { flex: 1; overflow: hidden; display: flex; }
.modal-body .deploy-log { flex: 1; margin: 0; border: 0; border-radius: 0; max-height: none; }
.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
@keyframes modal-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ─── Animations ───────────────────────────────────────────── */
@keyframes pulse-dot { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }
.live-dot { animation: pulse-dot 1.2s ease-in-out infinite; }
