:root {
  --bg: #0a0e12;
  --surface: #11171d;
  --surface-raised: #161e26;
  --surface-soft: #0e141a;
  --border: #25313c;
  --border-soft: #1b252e;
  --text: #ecf2f7;
  --muted: #8fa1b2;
  --faint: #5f7181;
  --accent: #54d6ad;
  --accent-dark: #123e34;
  --blue: #6ab9ff;
  --amber: #f4be63;
  --red: #ff7c76;
  --radius: 10px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    radial-gradient(circle at 85% -20%, rgba(84, 214, 173, 0.08), transparent 30rem),
    var(--bg);
}

button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.topbar {
  height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  border-bottom: 1px solid var(--border);
  background: rgba(10, 14, 18, 0.92);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  color: var(--text);
  text-decoration: none;
}

.brand strong, .brand small { display: block; }
.brand strong { font-size: 14px; letter-spacing: 0.01em; }
.brand small { margin-top: 2px; color: var(--muted); font-size: 11px; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 35px;
  height: 35px;
  border: 1px solid #3d6b5f;
  border-radius: 8px;
  color: var(--accent);
  background: linear-gradient(145deg, #16352e, #0d1d1a);
  font: 700 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.08em;
}

.brand-mark.large { width: 46px; height: 46px; margin-bottom: 20px; }
.topbar-actions, .log-actions { display: flex; align-items: center; gap: 9px; }

.button {
  min-height: 34px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  background: var(--surface-raised);
  cursor: pointer;
  text-decoration: none;
  font-size: 12px;
  font-weight: 600;
}

.button:hover { border-color: #425465; background: #1a2530; }
.button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.button.ghost { background: transparent; color: #bdcbd7; }
.button.primary { border-color: #4ec9a4; color: #07130f; background: var(--accent); }
.button.primary:hover { background: #73e3bf; }

.connection { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; }
.connection i { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); box-shadow: 0 0 0 3px rgba(95, 113, 129, 0.12); }
.connection.online i { background: var(--accent); box-shadow: 0 0 0 3px rgba(84, 214, 173, 0.12); }
.connection.error i { background: var(--red); box-shadow: 0 0 0 3px rgba(255, 124, 118, 0.12); }

.dashboard { display: grid; grid-template-columns: 286px minmax(0, 1fr); min-height: calc(100vh - 68px); }
.sidebar { border-right: 1px solid var(--border); background: rgba(14, 20, 26, 0.72); }
.sidebar-heading { padding: 27px 20px 15px; }
.sidebar h1, .run-header h1, .panel h2 { margin: 0; }
.sidebar h1 { font-size: 20px; }

.eyebrow {
  margin: 0 0 7px;
  color: var(--accent);
  font: 700 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.count { color: var(--faint); font-size: 12px; font-weight: 500; }
.search { display: block; padding: 0 14px 15px; }
.search input, .auth-card input, select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  background: var(--surface-soft);
}
.search input { height: 36px; padding: 0 11px; font-size: 12px; }
.search input::placeholder { color: var(--faint); }

.run-list { padding: 0 8px 28px; }
.run-item {
  width: 100%;
  display: grid;
  grid-template-columns: 8px minmax(0, 1fr);
  gap: 10px;
  padding: 11px 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.run-item:hover { background: rgba(255, 255, 255, 0.025); color: var(--text); }
.run-item.active { border-color: var(--border); color: var(--text); background: var(--surface-raised); }
.run-item .state-dot { width: 7px; height: 7px; margin-top: 5px; border-radius: 50%; background: var(--faint); }
.run-item .state-dot.active { background: var(--accent); }
.run-item strong, .run-item small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.run-item strong { font-size: 12px; font-weight: 650; }
.run-item small { margin-top: 5px; color: var(--faint); font-size: 10px; }
.no-runs { padding: 18px 12px; color: var(--faint); font-size: 12px; }

.main { min-width: 0; padding: 28px; }
.empty-state { min-height: 60vh; display: grid; place-content: center; text-align: center; color: var(--muted); }
.empty-state h2 { margin: 13px 0 4px; color: var(--text); font-size: 18px; }
.empty-state p { margin: 0; font-size: 13px; }
.empty-glyph { color: var(--faint); font: 42px/1 ui-monospace, monospace; }

.run-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 23px; }
.title-line { display: flex; align-items: center; gap: 12px; }
.run-header h1 { overflow-wrap: anywhere; font-size: clamp(23px, 3vw, 32px); letter-spacing: -0.035em; }
.muted { margin: 7px 0 0; color: var(--muted); font-size: 12px; }

.badge, .mini-badge {
  display: inline-flex;
  align-items: center;
  width: max-content;
  border: 1px solid #37544c;
  border-radius: 999px;
  color: var(--accent);
  background: var(--accent-dark);
  font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}
.badge { padding: 6px 8px; }
.mini-badge { padding: 4px 7px; }
.badge.destroyed, .mini-badge.terminated, .mini-badge.exited { border-color: #394752; color: #9badbb; background: #182029; }
.mini-badge.launching, .mini-badge.assigned { border-color: #63522e; color: var(--amber); background: #2b2417; }
.mini-badge.failed, .mini-badge.error { border-color: #653c3c; color: var(--red); background: #2a191b; }

.summary { display: grid; grid-template-columns: repeat(4, minmax(130px, 1fr)); gap: 12px; margin-bottom: 18px; }
.summary-card { min-height: 91px; padding: 16px; border: 1px solid var(--border-soft); border-radius: var(--radius); background: linear-gradient(145deg, var(--surface-raised), var(--surface)); }
.summary-card span { display: block; color: var(--muted); font-size: 11px; }
.summary-card strong { display: block; margin-top: 9px; font: 650 23px/1 ui-monospace, SFMono-Regular, Menlo, monospace; }
.summary-card small { display: block; margin-top: 7px; color: var(--faint); font-size: 10px; }
.cost-summary { grid-template-columns: repeat(3, minmax(130px, 1fr)); margin-bottom: 10px; }
.cost-note { color: var(--muted); font-size: 11px; line-height: 1.5; margin: 0 0 18px; }

.panel { margin-top: 14px; border: 1px solid var(--border-soft); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.panel-heading { min-height: 70px; display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 14px 17px; border-bottom: 1px solid var(--border-soft); }
.panel h2 { font-size: 15px; }
.panel-total { color: var(--faint); font-size: 11px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 11px; }
th, td { padding: 11px 14px; border-bottom: 1px solid var(--border-soft); text-align: left; white-space: nowrap; }
th { color: var(--faint); background: var(--surface-soft); font: 650 9px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 0.08em; text-transform: uppercase; }
td { color: #c3d0db; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: rgba(255, 255, 255, 0.018); }
td.primary-cell { color: var(--text); font-weight: 600; }
td.mono { color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.empty-row td { padding: 25px 14px; color: var(--faint); text-align: center; }

.log-heading { align-items: flex-end; }
.log-actions select { min-width: 190px; height: 34px; padding: 0 30px 0 10px; font-size: 11px; }
.auto-scroll { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 11px; }
.auto-scroll input { accent-color: var(--accent); }
#log-output {
  min-height: 230px;
  max-height: 560px;
  margin: 0;
  padding: 17px;
  overflow: auto;
  color: #cad7df;
  background: #080c0f;
  font: 11px/1.65 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.log-note { margin: 0; padding: 10px 17px; border-top: 1px solid var(--border-soft); color: var(--faint); font-size: 10px; }

.auth-overlay { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 20px; background: rgba(5, 8, 10, 0.88); backdrop-filter: blur(10px); }
.auth-card { width: min(420px, 100%); padding: 30px; border: 1px solid var(--border); border-radius: 13px; background: var(--surface); box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45); }
.auth-card h1 { margin: 0 0 10px; font-size: 22px; letter-spacing: -0.025em; }
.auth-card p:not(.eyebrow) { margin: 0 0 22px; color: var(--muted); font-size: 12px; line-height: 1.6; }
.auth-card code { color: #cde0ec; }
.auth-card label { display: block; margin-bottom: 7px; color: #c5d2db; font-size: 11px; font-weight: 650; }
.auth-card input { height: 42px; padding: 0 11px; }
.auth-card .button { width: 100%; min-height: 41px; margin-top: 13px; }
.auth-card small { display: block; margin-top: 17px; overflow: hidden; color: var(--faint); font: 10px/1.4 ui-monospace, monospace; text-overflow: ellipsis; }
.auth-card .error { min-height: 18px; margin: 8px 0 0; color: var(--red); font-size: 11px; }

.toast { position: fixed; right: 20px; bottom: 20px; z-index: 30; max-width: min(380px, calc(100vw - 40px)); padding: 10px 13px; border: 1px solid var(--border); border-radius: 8px; color: var(--text); background: var(--surface-raised); box-shadow: 0 12px 35px rgba(0, 0, 0, 0.35); font-size: 11px; opacity: 0; transform: translateY(8px); pointer-events: none; transition: opacity 120ms, transform 120ms; }
.toast.visible { opacity: 1; transform: translateY(0); }
.toast.error { border-color: #653c3c; color: #ffc0bc; }

@media (max-width: 900px) {
  .dashboard { grid-template-columns: 220px minmax(0, 1fr); }
  .summary { grid-template-columns: repeat(2, minmax(130px, 1fr)); }
  .main { padding: 21px; }
  #agora-link { display: none; }
}

@media (max-width: 680px) {
  .topbar { height: auto; min-height: 63px; padding: 12px 14px; }
  .brand small, .connection, #change-token { display: none; }
  .dashboard { display: block; min-height: 0; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--border); }
  .sidebar-heading { padding: 18px 16px 10px; }
  .run-list { display: flex; gap: 6px; padding: 0 12px 13px; overflow-x: auto; }
  .run-item { min-width: 190px; }
  .main { padding: 18px 12px; }
  .run-header, .panel-heading.log-heading { align-items: flex-start; }
  .run-header { flex-direction: column; }
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .log-heading { flex-direction: column; }
  .log-actions { width: 100%; flex-wrap: wrap; }
  .log-actions label:first-child { flex: 1; }
  .log-actions select { min-width: 0; }
}

.badge.failed, .mini-badge.setup_failed { border-color: #653c3c; color: var(--red); background: #2a191b; }
.badge.blocked, .badge.starting, .mini-badge.retrying { border-color: #63522e; color: var(--amber); background: #2b2417; }
.state-dot.failed { background: var(--red); }
.state-dot.blocked, .state-dot.starting { background: var(--amber); }
.health-message { font-size: 13px; }
.health-message.failed { color: var(--red); }
.health-message.blocked { color: var(--amber); }
