:root {
  color-scheme: dark;
  --canvas: #090d10;
  --surface: #11171b;
  --surface-raised: #171f24;
  --surface-hover: #1c272d;
  --ink: #e7edf0;
  --muted: #8c9aa2;
  --line: #2b373d;
  --line-strong: #3b4a51;
  --accent: #39c6a3;
  --accent-strong: #26a98a;
  --accent-soft: #123c35;
  --danger: #ff7777;
  --danger-soft: #351b20;
  --success: #5bd295;
  --warning: #e2b75e;
  --warning-soft: #322b19;
}

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

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--canvas);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: var(--canvas);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button, select, input { font: inherit; }
button, select, .module-option { min-height: 44px; }

button, select {
  border: 0;
  border-radius: 5px;
  background: var(--surface-raised);
  color: var(--ink);
}

button:focus-visible,
select:focus-visible,
input:focus-visible,
.log-output:focus-visible,
.skip-link:focus {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.skip-link {
  position: fixed;
  z-index: 10;
  top: 8px;
  left: 8px;
  padding: 8px 12px;
  background: var(--surface-raised);
  color: var(--ink);
  transform: translateY(-150%);
}

.skip-link:focus { transform: none; }

.topbar {
  height: 62px;
  padding: 0 clamp(20px, 3vw, 56px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #0d1215;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 5px;
  background: var(--accent-soft);
  color: #7aebce;
  font-weight: 800;
}

.environment-badge {
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: #7aebce;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.console-shell {
  width: 100%;
  min-height: calc(100vh - 62px);
  margin: auto;
  display: grid;
  grid-template-columns: minmax(360px, 440px) minmax(0, 1fr);
  background: var(--surface);
}

.deploy-controls {
  min-width: 0;
  padding: 34px 30px;
  background: #101619;
}

.runtime-region {
  min-width: 0;
  padding: 34px clamp(28px, 3vw, 52px);
  background: var(--canvas);
}

.section-heading, .runtime-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 26px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 25px; font-weight: 720; }
h2 { margin-bottom: 0; font-size: 21px; font-weight: 700; }

.icon-button {
  width: 44px;
  padding: 0;
  color: var(--muted);
  font-size: 24px;
  cursor: pointer;
  transition: color 150ms ease, background 150ms ease, transform 150ms ease;
}

.icon-button:hover {
  background: var(--accent-soft);
  color: var(--accent);
  transform: rotate(12deg);
}

.project-form {
  display: grid;
  gap: 8px;
  margin-bottom: 26px;
}

.project-form label, legend { font-weight: 700; }

.project-form select {
  width: 100%;
  padding: 0 38px 0 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  background: var(--surface-raised);
  transition: background 150ms ease;
}

.project-form select:hover {
  background: var(--surface-hover);
}

.deploy-form fieldset { margin: 0; padding: 0; border: 0; }
.deploy-form[data-busy="true"] .module-list { pointer-events: none; opacity: .65; }

.module-list {
  display: grid;
  gap: 9px;
  margin: 11px 0 22px;
}

.module-option {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 11px 12px;
  border: 0;
  border-radius: 5px;
  background: var(--surface);
  cursor: pointer;
  transition: background 150ms ease, box-shadow 150ms ease, transform 150ms ease;
}

.module-option:hover {
  background: var(--surface-hover);
  transform: translateX(2px);
}

.module-option:has(input:checked) {
  background: #122520;
  box-shadow: inset 3px 0 var(--accent);
}

.module-option input {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  margin: 2px 0 0;
  accent-color: var(--accent);
}

.module-option span { min-width: 0; display: grid; }
.module-option strong, .module-option small { overflow-wrap: anywhere; }
.module-option small { color: var(--muted); }

.deploy-button {
  width: 100%;
  padding: 0 16px;
  background: var(--accent-strong);
  color: #06130f;
  font-weight: 800;
  cursor: pointer;
  transition: background 150ms ease, transform 150ms ease;
}

.deploy-button:hover:not(:disabled) {
  background: #50d8b6;
  transform: translateY(-1px);
}

.deploy-button:active:not(:disabled) { transform: translateY(0); }
.deploy-button:disabled { cursor: not-allowed; opacity: .48; }

.notice, .form-notice, .form-error {
  padding: 11px 13px;
  border-left: 3px solid var(--warning);
  background: var(--warning-soft);
  color: #e8cf98;
  overflow-wrap: anywhere;
}

.form-error {
  border-color: var(--danger);
  background: var(--danger-soft);
  color: #ffaaaa;
}

.empty-state { padding: 24px 0; color: var(--muted); }
.runtime-panel { min-width: 0; }

.status {
  flex: 0 0 auto;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-weight: 700;
}

.status-running, .status-queued { background: var(--accent-soft); color: #7aebce; }
.status-succeeded { background: #153225; color: var(--success); }
.status-failed, .status-detached, .status-canceled { background: var(--danger-soft); color: var(--danger); }

.job-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  margin: 0 0 22px;
  background: var(--canvas);
}

.job-summary div {
  min-width: 0;
  padding: 12px 14px;
  background: var(--surface);
}

.job-summary dt { color: var(--muted); font-size: 12px; }
.job-summary dd { margin: 4px 0 0; overflow-wrap: anywhere; }

.failure-summary {
  margin-bottom: 18px;
  padding: 15px;
  border-left: 4px solid var(--danger);
  background: var(--danger-soft);
}

.failure-summary h3 { margin-bottom: 8px; }
.failure-summary p { margin-bottom: 5px; overflow-wrap: anywhere; }

.connection-state {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  padding: 10px 13px;
  background: var(--danger-soft);
  color: var(--danger);
}

.connection-state button { padding: 0 12px; cursor: pointer; }

.log-toolbar {
  display: flex;
  justify-content: space-between;
  padding: 10px 14px;
  background: #172026;
  color: #d8e1e5;
}

.log-output {
  min-height: 430px;
  max-height: calc(100vh - 294px);
  overflow: auto;
  padding: 10px 0;
  background: #070b0e;
  color: #cbd6db;
  font: 12px/1.6 ui-monospace, SFMono-Regular, Consolas, monospace;
  scrollbar-color: #3a4a51 #11171b;
}

.log-line {
  display: grid;
  grid-template-columns: 168px 38px minmax(0, 1fr);
  gap: 10px;
  padding: 3px 14px;
}

.log-line:hover { background: #10171b; }
.log-line time { color: #6f828b; white-space: nowrap; }
.log-stream { color: #61c9e8; font-weight: 800; }
.log-stderr .log-stream, .log-stderr code { color: #ff9292; }
.log-system .log-stream { color: var(--warning); }
.log-line code { min-width: 0; color: inherit; white-space: pre-wrap; overflow-wrap: anywhere; }
.log-empty, .runtime-empty, .runtime-placeholder { padding: 28px; color: var(--muted); }

@media (max-width: 980px) {
  .console-shell { grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); }
  .deploy-controls { padding-inline: 24px; }
  .runtime-region { padding-inline: 28px; }
}

@media (max-width: 800px) {
  .console-shell { grid-template-columns: 1fr; }
  .job-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .log-output { min-height: 320px; max-height: 60vh; }
}

@media (max-width: 480px) {
  .topbar, .deploy-controls, .runtime-region { padding-left: 16px; padding-right: 16px; }
  .job-summary { grid-template-columns: 1fr; }
  .log-line { grid-template-columns: 1fr auto; gap: 2px 8px; padding: 6px 11px; }
  .log-line code { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    transition: none !important;
    animation: none !important;
  }
}

.topbar-actions { display: flex; align-items: center; gap: 12px; }
.topbar-actions form { margin: 0; }
.logout-button { min-height: 32px; padding: 0 12px; border: 1px solid var(--border); background: transparent; color: var(--muted); cursor: pointer; }
.logout-button:hover { color: var(--text); border-color: var(--muted); }

.auth-page { min-height: 100vh; background: #090d10; }
.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-panel { width: min(100%, 420px); padding: 36px; border: 1px solid #28343a; background: #11171b; }
.auth-panel h1 { margin: 5px 0 10px; font-size: 27px; }
.auth-description, .field-hint { color: var(--muted); }
.auth-description { margin-bottom: 26px; }
.auth-form { display: grid; gap: 10px; }
.auth-form label { margin-top: 8px; font-weight: 700; }
.auth-form input { width: 100%; min-height: 44px; padding: 0 12px; border: 1px solid #34434a; background: #090d10; color: var(--text); }
.auth-form input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.auth-form button { min-height: 44px; margin-top: 14px; border: 0; background: var(--accent); color: #07120f; font-weight: 800; cursor: pointer; }
.auth-error { padding: 11px 13px; border-left: 3px solid var(--danger); background: var(--danger-soft); color: #ffaaaa; }
.field-hint { margin: 0; font-size: 12px; }

@media (max-width: 480px) {
  .auth-shell { padding: 0; place-items: stretch; }
  .auth-panel { width: 100%; min-height: 100vh; padding: 32px 20px; border: 0; }
}
