:root {
  color-scheme: dark;
  --brand: #ff5e00;
  --brand-rgb: 255, 94, 0;
  --brand-soft: #fabd6e;
  --brand-dim: rgba(var(--brand-rgb), 0.12);
  --bg: #08090c;
  --bg-elevated: #0e1015;
  --surface: #13161d;
  --surface-hover: #181c25;
  --border: rgba(255, 255, 255, 0.09);
  --border-faint: rgba(255, 255, 255, 0.05);
  --border-brand: rgba(var(--brand-rgb), 0.35);
  --text: #eef0f4;
  --text-secondary: #a8b0be;
  --text-tertiary: #6b7380;
  --ok: #34d399;
  --ok-dim: rgba(52, 211, 153, 0.12);
  --bad: #f87171;
  --bad-dim: rgba(248, 113, 113, 0.12);
  --warn: #fbbf24;
  --warn-dim: rgba(251, 191, 36, 0.12);
  --info: #60a5fa;
  --info-dim: rgba(96, 165, 250, 0.12);
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --sidebar-w: 200px;
  --topbar-h: 56px;
  --font: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", "SF Mono", "Fira Code", ui-monospace, monospace;
  --transition: 150ms ease;
}

*, *::before, *::after { box-sizing: border-box; }

html { font-size: 15px; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(var(--brand-rgb), 0.15), transparent),
    radial-gradient(ellipse 60% 40% at 100% 0%, rgba(var(--brand-rgb), 0.06), transparent);
  pointer-events: none;
  z-index: 0;
}

.hidden { display: none !important; }

/* ── Typography ── */

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.02em; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1rem; }

.muted { color: var(--text-secondary); }
.mono { font-family: var(--mono); font-size: 0.85em; }
.sm { font-size: 0.85rem; }
.error { color: var(--bad); font-size: 0.9rem; margin: 0; }

/* ── Logo ── */

.logo-mark {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--brand), #cc4a00);
  color: #fff;
  font-weight: 700;
  font-size: 1.25rem;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  box-shadow: 0 2px 12px rgba(var(--brand-rgb), 0.35);
}

.logo-mark.sm { width: 32px; height: 32px; font-size: 1rem; border-radius: 8px; }

/* ── Buttons ── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition), opacity var(--transition);
  white-space: nowrap;
}

.btn:hover { background: var(--surface-hover); border-color: rgba(255, 255, 255, 0.14); }
.btn:active { opacity: 0.85; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}
.btn.primary:hover { background: #e65500; border-color: #e65500; }

.btn.ghost {
  background: transparent;
  border-color: var(--border-faint);
  color: var(--text-secondary);
}
.btn.ghost:hover { color: var(--text); border-color: var(--border); }

.btn.danger { color: var(--bad); border-color: rgba(248, 113, 113, 0.25); }
.btn.danger:hover { background: var(--bad-dim); border-color: rgba(248, 113, 113, 0.4); }

.btn.sm { padding: 0.35rem 0.7rem; font-size: 0.82rem; }
.btn.block { width: 100%; }
.btn.icon-only { padding: 0.4rem; }

/* ── Status chip ── */

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 500;
  border: 1px solid var(--border-faint);
  background: var(--surface);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-tertiary);
}

.status-chip.idle .status-dot { background: var(--text-tertiary); }
.status-chip.idle .status-label { color: var(--text-secondary); }

.status-chip.busy {
  border-color: rgba(var(--brand-rgb), 0.3);
  background: var(--brand-dim);
}
.status-chip.busy .status-dot {
  background: var(--brand);
  animation: pulse 1.5s ease infinite;
}
.status-chip.busy .status-label { color: var(--brand-soft); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ── Auth ── */

.auth-gate {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1.5rem;
}

.auth-card {
  width: min(400px, 100%);
}

.auth-brand {
  text-align: center;
  margin-bottom: 1.5rem;
}

.auth-brand .logo-mark { margin: 0 auto 1rem; }
.auth-brand h1 { font-size: 1.75rem; }
.auth-tagline { margin: 0.25rem 0 0; color: var(--text-secondary); font-size: 0.95rem; }

/* ── App shell ── */

.app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--topbar-h);
  padding: 0 1.25rem;
  border-bottom: 1px solid var(--border-faint);
  background: rgba(8, 9, 12, 0.8);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.brand-name { font-size: 1rem; font-weight: 600; }
.brand-sub {
  display: block;
  font-size: 0.72rem;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.topbar-actions { display: flex; align-items: center; gap: 0.65rem; }

.shell {
  display: flex;
  flex: 1;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  padding: 1rem 0.75rem;
  border-right: 1px solid var(--border-faint);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background var(--transition), color var(--transition);
}

.nav-item:hover { background: var(--surface); color: var(--text); }
.nav-item.active {
  background: var(--brand-dim);
  color: var(--brand-soft);
}

.content {
  flex: 1;
  min-width: 0;
  padding: 1.5rem 1.75rem 2.5rem;
}

/* ── Page header ── */

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.page-header h2 { margin-bottom: 0.2rem; }
.page-header-actions { display: flex; gap: 0.5rem; flex-shrink: 0; }

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
  font-size: 0.85rem;
}

.breadcrumb-link {
  background: none;
  border: none;
  color: var(--text-secondary);
  font: inherit;
  cursor: pointer;
  padding: 0;
  transition: color var(--transition);
}
.breadcrumb-link:hover { color: var(--brand-soft); }

.breadcrumb-sep { color: var(--text-tertiary); }
.breadcrumb-current { color: var(--text); font-weight: 500; }

/* ── Subtabs ── */

.subtabs {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--border-faint);
  padding-bottom: 0;
}

.subtab {
  padding: 0.55rem 1rem;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition);
}

.subtab:hover { color: var(--text); }
.subtab.active {
  color: var(--brand-soft);
  border-bottom-color: var(--brand);
}

/* ── Panels ── */

.panel {
  background: var(--surface);
  border: 1px solid var(--border-faint);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.panel-header { margin-bottom: 1rem; }
.panel-header h3 { margin-bottom: 0.2rem; }
.panel-header p { margin: 0; font-size: 0.88rem; }

/* ── Projects grid ── */

.projects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 0.75rem;
}

.project-card {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1.1rem 1.2rem;
  border: 1px solid var(--border-faint);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition), transform var(--transition);
  text-align: left;
  font: inherit;
  color: inherit;
  width: 100%;
}

.project-card:hover {
  border-color: var(--border-brand);
  background: var(--surface-hover);
  transform: translateY(-1px);
}

.project-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.project-card-name { font-weight: 600; font-size: 1rem; }
.project-card-id { font-family: var(--mono); font-size: 0.78rem; color: var(--text-tertiary); margin-top: 0.15rem; }

.project-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.project-card-meta span {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.project-card.disabled { opacity: 0.55; }

.project-card.active-run {
  border-color: color-mix(in srgb, var(--brand) 45%, var(--border));
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--brand) 20%, transparent);
}

.project-card-hint {
  color: var(--brand-soft);
  font-size: 0.78rem;
}

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 3rem 1.5rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
}

.empty-state h3 { margin-bottom: 0.4rem; color: var(--text); }

/* ── Status badge ── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.badge.ok { background: var(--ok-dim); color: var(--ok); }
.badge.bad { background: var(--bad-dim); color: var(--bad); }
.badge.run { background: var(--brand-dim); color: var(--brand-soft); }
.badge.neutral { background: rgba(255, 255, 255, 0.06); color: var(--text-tertiary); }
.badge.off { background: rgba(255, 255, 255, 0.04); color: var(--text-tertiary); }

/* ── Forms ── */

.form { display: grid; gap: 1rem; }

.form-sections {
  display: grid;
  gap: 1rem;
}

.fieldset {
  border: 1px solid var(--border-faint);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  margin: 0;
  background: var(--surface);
}

.fieldset legend {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  padding: 0 0.4rem;
}

.field { display: grid; gap: 0.35rem; }

.field label {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.checks {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
}

.check {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
  cursor: pointer;
}

.check input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  accent-color: var(--brand);
  cursor: pointer;
}

input, textarea, select {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border-faint);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.75rem;
  font: inherit;
  font-size: 0.9rem;
  transition: border-color var(--transition), box-shadow var(--transition);
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--border-brand);
  box-shadow: 0 0 0 3px rgba(var(--brand-rgb), 0.12);
}

input::placeholder, textarea::placeholder { color: var(--text-tertiary); }

.form-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}

.inline-form { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--border-faint); }

/* ── Code editor ── */

.code-editor {
  width: 100%;
  min-height: 280px;
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.55;
  resize: vertical;
  tab-size: 2;
}

.code-editor.sm { min-height: 140px; }

/* ── Script tabs ── */

.script-tabs {
  display: flex;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
}

.script-tab {
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--border-faint);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--mono);
  font-size: 0.8rem;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.script-tab:hover { color: var(--text); }
.script-tab.active {
  background: var(--brand-dim);
  border-color: var(--border-brand);
  color: var(--brand-soft);
}

/* ── Runs ── */

.runs-layout {
  display: grid;
  grid-template-columns: minmax(240px, 320px) 1fr;
  gap: 1rem;
  align-items: start;
}

.runs-list-panel { padding: 0; overflow: hidden; }
.runs-list-panel .panel-header { padding: 1rem 1.25rem 0.75rem; margin: 0; border-bottom: 1px solid var(--border-faint); }

.runs-list { max-height: 520px; overflow-y: auto; }

.run-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.25rem 0.75rem;
  padding: 0.7rem 1.25rem;
  border-bottom: 1px solid var(--border-faint);
  cursor: pointer;
  transition: background var(--transition);
  font-size: 0.88rem;
}

.run-row:hover { background: var(--surface-hover); }
.run-row.active { background: var(--brand-dim); border-left: 2px solid var(--brand); padding-left: calc(1.25rem - 2px); }

.run-row-id { font-family: var(--mono); font-size: 0.78rem; color: var(--text-secondary); }
.run-row-meta { font-size: 0.78rem; color: var(--text-tertiary); grid-column: 1 / -1; }

.log-panel { display: flex; flex-direction: column; min-height: 400px; }
.log-header { display: flex; align-items: baseline; justify-content: space-between; }

.log-viewer {
  flex: 1;
  margin: 0;
  min-height: 360px;
  max-height: 520px;
  overflow: auto;
  background: #040506;
  border: 1px solid var(--border-faint);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem;
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.6;
  color: #c8cdd8;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ── Item lists (keys, secrets) ── */

.item-list { display: grid; gap: 0.35rem; margin-bottom: 0.5rem; }

.item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border-faint);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  font-size: 0.88rem;
}

.item-row-info { min-width: 0; }
.item-row-id { font-family: var(--mono); font-weight: 500; }
.item-row-sub { font-size: 0.8rem; color: var(--text-tertiary); }

.item-list-empty {
  padding: 1rem;
  text-align: center;
  color: var(--text-tertiary);
  font-size: 0.88rem;
  border: 1px dashed var(--border-faint);
  border-radius: var(--radius-sm);
}

/* ── Settings grid ── */

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

/* ── Dialog ── */

dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  color: var(--text);
  padding: 1.5rem;
  width: min(520px, 92vw);
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}

dialog::backdrop { background: rgba(0, 0, 0, 0.75); backdrop-filter: blur(4px); }

dialog h3 { margin-bottom: 0.35rem; }

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin: 1.25rem 0 0;
  padding: 0;
  border: none;
}

/* ── Toasts ── */

.toast-host {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.7rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 0.88rem;
  animation: toast-in 200ms ease;
  max-width: 360px;
}

.toast.ok { border-color: rgba(52, 211, 153, 0.3); }
.toast.err { border-color: rgba(248, 113, 113, 0.3); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Responsive ── */

@media (max-width: 768px) {
  .shell { flex-direction: column; }

  .sidebar {
    width: 100%;
    display: flex;
    border-right: none;
    border-bottom: 1px solid var(--border-faint);
    padding: 0.5rem 0.75rem;
    gap: 0.25rem;
  }

  .nav-item { flex: 1; justify-content: center; }

  .content { padding: 1rem; }

  .page-header { flex-direction: column; }
  .page-header-actions { width: 100%; }
  .page-header-actions .btn { flex: 1; }

  .field-row { grid-template-columns: 1fr; }
  .runs-layout { grid-template-columns: 1fr; }
  .projects-grid { grid-template-columns: 1fr; }
}
