:root {
  --bg: #0b0d12;
  --bg-elevated: #10131a;
  --surface: #161a24;
  --surface-2: #1d2230;
  --border: #262c3a;
  --border-soft: #1c212c;
  --text: #e9ebf1;
  --text-dim: #8b93a7;
  --text-faint: #545c70;

  --orange: #f76e2e;
  --orange-dim: #f76e2e33;
  --blue: #3390e6;
  --blue-dim: #3390e633;
  --green: #34d399;
  --green-dim: #34d39933;
  --red: #f2545b;
  --red-dim: #f2545b33;
  --amber: #fbbf24;
  --amber-dim: #fbbf2433;

  --font-display: "Space Grotesk", ui-sans-serif, system-ui, sans-serif;
  --font-body: "Inter", ui-sans-serif, system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;

  --radius: 12px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; }

/* The `hidden` attribute must always win over any component's own display
   rule (.app, .modal-backdrop, .job-console, .login-screen all set their
   own `display`, which — being author CSS — otherwise overrides the
   browser's default `[hidden]{display:none}` UA rule). Without this,
   elements marked hidden still render. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--orange-dim); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-2); border-radius: 8px; border: 2px solid var(--bg); }

button, input, select { font-family: inherit; color: inherit; }

a { color: var(--blue); }

:focus-visible {
  outline: 2px solid var(--orange);
  outline-offset: 2px;
}

/* ─────────────────────── Wordmark ─────────────────────── */
.wordmark {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.02em;
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.wordmark--lg { font-size: 30px; justify-content: center; }
.wm-orange { color: var(--orange); }
.wm-blue { color: var(--text); }
.wm-tag {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.16em;
  color: var(--text-faint);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 6px;
  margin-left: 2px;
}

/* ─────────────────────── Buttons / fields ─────────────────────── */
.btn {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 9px 16px;
  cursor: pointer;
  transition: transform .08s ease, border-color .15s ease, background .15s ease;
}
.btn:hover { border-color: #3a4256; background: #232a3a; }
.btn:active { transform: scale(0.97); }
.btn--primary { background: var(--orange); border-color: var(--orange); color: #1a0d05; }
.btn--primary:hover { background: #ff7f3f; border-color: #ff7f3f; }
.btn--secondary { background: var(--blue); border-color: var(--blue); color: #071a2e; }
.btn--secondary:hover { background: #4aa2f2; }
.btn--danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn--danger:hover { background: #ff6168; border-color: #ff6168; }
.btn--ghost { background: transparent; }
.btn--sm { padding: 6px 12px; font-size: 12px; }
.btn--block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field > span { font-size: 12px; color: var(--text-dim); font-weight: 600; letter-spacing: .02em; }
.field input, .field select {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 14px;
}
.field input:focus, .field select:focus { border-color: var(--orange); }

.checkbox-field { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-dim); }

.search-input {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 13px;
}
.search-input:focus { border-color: var(--orange); }

/* ─────────────────────── Login ─────────────────────── */
.login-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 0%, #161c2a 0%, #0b0d12 60%);
  overflow: hidden;
}
.login-grid {
  position: absolute; inset: -2px;
  background-image:
    linear-gradient(to right, rgba(247,110,46,0.05) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(51,144,230,0.05) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: radial-gradient(circle at 50% 35%, black, transparent 70%);
}
.login-card {
  position: relative;
  width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px 32px 28px;
  box-shadow: 0 30px 80px -20px rgba(0,0,0,.6);
}
.login-sub {
  text-align: center;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: .28em;
  color: var(--text-faint);
  margin: 8px 0 28px;
}
.login-error {
  color: var(--red);
  font-size: 13px;
  text-align: center;
  margin-top: 12px;
}

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

.topbar {
  height: 60px;
  flex: none;
  display: flex; align-items: center; gap: 24px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg-elevated);
}
.topbar-stats { display: flex; gap: 18px; margin-right: auto; }
.stat-chip { display: flex; align-items: center; gap: 6px; font-family: var(--font-mono); font-size: 12px; color: var(--text-dim); }
.stat-chip b { color: var(--text); font-weight: 600; }

.topbar-right { display: flex; align-items: center; gap: 14px; }
.session-chip {
  display: flex; align-items: center; gap: 7px;
  font-family: var(--font-mono); font-size: 12px; color: var(--text-dim);
  border: 1px solid var(--border); border-radius: 20px; padding: 6px 12px;
}
.admin-chip { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 500; }
.admin-pic { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; border: 1px solid var(--border); }

.layout { flex: 1; display: flex; min-height: 0; }

/* ─────────────────────── Sidebar / fleet list ─────────────────────── */
.sidebar {
  width: 320px; flex: none;
  border-right: 1px solid var(--border-soft);
  background: var(--bg-elevated);
  display: flex; flex-direction: column;
  min-height: 0;
}
.sidebar-head { padding: 14px; border-bottom: 1px solid var(--border-soft); }
.fleet-list { overflow-y: auto; flex: 1; padding: 8px; display: flex; flex-direction: column; gap: 6px; }

.fleet-card {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease;
}
.fleet-card:hover { background: var(--surface); }
.fleet-card.is-active { background: var(--surface-2); border-color: var(--border); }

.fleet-card-top { display: flex; align-items: center; gap: 8px; }
.fleet-card-name { font-weight: 600; font-size: 13.5px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fleet-card-domain { font-family: var(--font-mono); font-size: 11px; color: var(--text-faint); margin: 3px 0 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.mini-bars { display: flex; gap: 10px; }
.mini-bar { flex: 1; }
.mini-bar-label { font-family: var(--font-mono); font-size: 9px; color: var(--text-faint); display: flex; justify-content: space-between; margin-bottom: 3px; }
.mini-bar-track { height: 4px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.mini-bar-fill { height: 100%; border-radius: 3px; transition: width .4s ease; }
.mini-bar-fill--cpu { background: var(--orange); }
.mini-bar-fill--mem { background: var(--blue); }

/* status dot */
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; display: inline-block; }
.dot--green { background: var(--green); box-shadow: 0 0 8px var(--green); }
.dot--red { background: var(--red); box-shadow: 0 0 8px var(--red); }
.dot--amber { background: var(--amber); box-shadow: 0 0 8px var(--amber); }
.dot--gray { background: var(--text-faint); }
.pulse { animation: pulse 1.8s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

/* ─────────────────────── Main / detail ─────────────────────── */
.main { flex: 1; overflow-y: auto; padding: 28px 32px 60px; min-width: 0; }

.empty-state { height: 60vh; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--text-faint); gap: 10px; }
.empty-glyph { font-size: 38px; color: var(--orange); opacity: .5; }

.detail-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 22px; gap: 20px; flex-wrap: wrap; }
.detail-title-row { display: flex; align-items: center; gap: 12px; }
.detail-title-row h1 { font-family: var(--font-display); font-size: 26px; margin: 0; letter-spacing: -0.01em; }
.detail-origin { font-family: var(--font-mono); font-size: 12.5px; color: var(--text-dim); text-decoration: none; }
.detail-origin:hover { color: var(--blue); text-decoration: underline; }
.detail-actions { display: flex; gap: 10px; }

.status-pill {
  font-family: var(--font-mono); font-size: 10.5px; font-weight: 600; letter-spacing: .06em;
  padding: 4px 10px; border-radius: 20px; border: 1px solid var(--border);
  text-transform: uppercase;
}
.status-pill--online { color: var(--green); border-color: var(--green-dim); background: var(--green-dim); }
.status-pill--errored { color: var(--red); border-color: var(--red-dim); background: var(--red-dim); }
.status-pill--stopped, .status-pill--offline { color: var(--text-dim); }
.status-pill--processing { color: var(--amber); border-color: var(--amber-dim); background: var(--amber-dim); }

/* Gauges */
.gauge-row { display: flex; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.gauge-card {
  background: var(--surface); border: 1px solid var(--border-soft); border-radius: var(--radius);
  padding: 14px; display: flex; align-items: center; gap: 4px; width: 150px;
}
.gauge { width: 64px; height: 64px; transform: rotate(-90deg); flex: none; }
.gauge-track { fill: none; stroke: var(--surface-2); stroke-width: 10; }
.gauge-value { fill: none; stroke-width: 10; stroke-linecap: round; stroke-dasharray: 314; stroke-dashoffset: 314; transition: stroke-dashoffset .5s ease; }
.gauge-value--orange { stroke: var(--orange); }
.gauge-value--blue { stroke: var(--blue); }
.gauge-label { display: flex; flex-direction: column; margin-left: 6px; }
.gauge-num { font-family: var(--font-mono); font-weight: 600; font-size: 17px; }
.gauge-name { font-size: 10px; color: var(--text-faint); letter-spacing: .1em; margin-top: 2px; }

.stat-card {
  background: var(--surface); border: 1px solid var(--border-soft); border-radius: var(--radius);
  padding: 14px 18px; display: flex; flex-direction: column; justify-content: center; gap: 6px; min-width: 110px;
}
.stat-label { font-size: 10px; color: var(--text-faint); letter-spacing: .1em; text-transform: uppercase; }
.stat-value { font-family: var(--font-mono); font-size: 18px; font-weight: 600; }

.sparkline-card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 16px 16px 12px;
  margin-bottom: 22px;
}
.sparkline-header {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 10px;
}
.sparkline-title {
  font-family: var(--font-display); font-size: 14px; margin: 0 0 3px; color: var(--text-dim); font-weight: 600; letter-spacing: .02em; text-transform: uppercase;
}
.sparkline-copy {
  margin: 0; font-size: 12px; color: var(--text-faint);
}
.sparkline-legend {
  display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--text-dim);
}
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-swatch { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.legend-swatch--cpu { background: var(--orange); }
.legend-swatch--mem { background: var(--blue); }
.sparkline {
  width: 100%; height: 240px; display: block;
  background: linear-gradient(180deg, rgba(16,19,26,0.98), rgba(11,13,18,0.98));
  border: 1px solid var(--border-soft); border-radius: var(--radius-sm);
}

.detail-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .detail-columns { grid-template-columns: 1fr; } }

.panel { background: var(--surface); border: 1px solid var(--border-soft); border-radius: var(--radius); padding: 18px 20px; }
.panel h2 { font-family: var(--font-display); font-size: 14px; margin: 0 0 14px; color: var(--text-dim); font-weight: 600; letter-spacing: .02em; text-transform: uppercase; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 9px 14px; margin: 0; }
.kv dt { font-size: 12px; color: var(--text-faint); white-space: nowrap; }
.kv dd { margin: 0; font-family: var(--font-mono); font-size: 12.5px; word-break: break-all; }


/* Module card UI */
.module-card { display:flex; gap:12px; align-items:flex-start; padding:10px; border:1px solid var(--border-soft); border-radius:10px; background:var(--surface); }
.module-card + .module-card { margin-top:10px; }
.module-card-left { flex: 0 0 36px; display:flex; align-items:flex-start; }
.module-toggle { width:18px; height:18px; transform: translateY(2px); }
.module-card-main { flex:1; }
.module-title { font-weight:700; font-size:13px; }
.module-desc { font-size:12px; color:var(--text-faint); margin-top:4px; }

/* ─────────────────────── Modals ─────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(6,8,12,.7); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; z-index: 60;
}
.modal {
  width: 440px; max-width: calc(100vw - 32px);
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  overflow: hidden;
  max-height: 82vh; display: flex; flex-direction: column;
}
.modal--wide { width: 720px; }
.modal-head { display: flex; align-items: center; gap: 14px; padding: 16px 20px; border-bottom: 1px solid var(--border-soft); }
.modal-head h3 { margin: 0; font-family: var(--font-display); font-size: 16px; flex: 1; }
.modal-close { background: none; border: none; color: var(--text-faint); font-size: 15px; cursor: pointer; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border-soft); align-items: center; }

.changelog { background: var(--bg-elevated); border: 1px solid var(--border-soft); border-radius: var(--radius-sm); padding: 12px 14px; margin-bottom: 16px; font-size: 12.5px; color: var(--text-dim); max-height: 160px; overflow-y: auto; }
.changelog ul { margin: 0; padding-left: 18px; }
.changelog li { margin-bottom: 6px; line-height: 1.5; }
.changelog li a { color: var(--blue); }

.log-tabs { display: flex; gap: 4px; }
.log-tab { background: transparent; border: 1px solid var(--border); color: var(--text-faint); font-size: 11px; padding: 5px 10px; border-radius: 6px; cursor: pointer; font-family: var(--font-mono); }
.log-tab.is-active { color: var(--text); border-color: var(--orange); }

.logs-body, .job-console-body {
  font-family: var(--font-mono); font-size: 12px; line-height: 1.6; white-space: pre-wrap; word-break: break-all;
  background: var(--bg-elevated); margin: 0; padding: 16px 20px; flex: 1; overflow-y: auto;
}
.logs-body { min-height: 320px; max-height: 50vh; }

/* Job console — bottom-right slide-up drawer with live script output */
.job-console {
  position: fixed; right: 20px; bottom: 20px; width: 480px; max-width: calc(100vw - 40px);
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 20px 50px -12px rgba(0,0,0,.6);
  display: flex; flex-direction: column; z-index: 70;
  max-height: 46vh;
}
.job-console-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--border-soft); }
.job-console-title { font-weight: 600; font-size: 13px; flex: 1; }
.job-console-status { font-family: var(--font-mono); font-size: 10px; letter-spacing: .08em; padding: 3px 8px; border-radius: 20px; }
.job-console-status.RUNNING { color: var(--amber); background: var(--amber-dim); }
.job-console-status.SUCCESS { color: var(--green); background: var(--green-dim); }
.job-console-status.FAILED { color: var(--red); background: var(--red-dim); }
.job-console-body { max-height: 34vh; }

/* Toasts */
.toast-host { position: fixed; top: 74px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 80; }
.toast { background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--blue); border-radius: 8px; padding: 10px 14px; font-size: 12.5px; min-width: 220px; box-shadow: 0 10px 30px -10px rgba(0,0,0,.5); animation: toastIn .2s ease; }
.toast.success { border-left-color: var(--green); }
.toast.error { border-left-color: var(--red); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }

.log-line-err { color: var(--red); }
.log-line-system { color: var(--blue); }
.log-line-error { color: var(--red); }
