@import url("https://fonts.googleapis.com/css2?family=Orbitron:wght@500;700;800&family=IBM+Plex+Mono:wght@400;500;600&family=Space+Grotesk:wght@400;500;700&display=swap");

:root {
  --bg-deep: #050c16;
  --bg-mid: #08111d;
  --bg-panel: rgba(8, 18, 31, 0.76);
  --bg-panel-strong: rgba(10, 22, 38, 0.9);
  --border: rgba(112, 211, 255, 0.22);
  --border-strong: rgba(112, 211, 255, 0.48);
  --text: #eff8ff;
  --muted: #8ea8bd;
  --cyan: #78dfff;
  --cyan-strong: #34c6ff;
  --amber: #ffc56e;
  --amber-strong: #ff9c3d;
  --danger: #ff7f7f;
  --success: #8dffcf;
  --shadow: 0 32px 90px rgba(0, 0, 0, 0.34);
  --glow: 0 0 30px rgba(52, 198, 255, 0.25);
}

* {
  box-sizing: border-box;
}

body.console-body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 12% 10%, rgba(52, 198, 255, 0.18), transparent 26%),
    radial-gradient(circle at 82% 18%, rgba(255, 156, 61, 0.12), transparent 18%),
    radial-gradient(circle at 50% 100%, rgba(77, 104, 255, 0.12), transparent 24%),
    linear-gradient(180deg, var(--bg-deep), var(--bg-mid));
}

.console-atmosphere {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.atmosphere-ring,
.atmosphere-grid,
.atmosphere-glow {
  position: absolute;
}

.atmosphere-ring {
  border-radius: 50%;
  border: 1px solid rgba(120, 223, 255, 0.08);
  box-shadow: inset 0 0 40px rgba(120, 223, 255, 0.03);
}

.atmosphere-ring-a {
  width: 52rem;
  height: 52rem;
  top: -18rem;
  right: -12rem;
}

.atmosphere-ring-b {
  width: 38rem;
  height: 38rem;
  bottom: -10rem;
  left: -8rem;
}

.atmosphere-grid {
  inset: 0;
  background:
    linear-gradient(rgba(120, 223, 255, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(120, 223, 255, 0.04) 1px, transparent 1px);
  background-size: 4.5rem 4.5rem;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.75), transparent 90%);
}

.atmosphere-glow {
  filter: blur(80px);
  opacity: 0.25;
}

.atmosphere-glow-left {
  left: -8rem;
  top: 6rem;
  width: 20rem;
  height: 20rem;
  background: var(--cyan);
}

.atmosphere-glow-right {
  right: -6rem;
  bottom: 10rem;
  width: 16rem;
  height: 16rem;
  background: var(--amber);
}

.console-shell {
  position: relative;
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 1rem;
  padding: 1.25rem;
}

.global-loading-indicator {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 50;
  display: none;
  align-items: center;
  gap: 0.55rem;
  padding: 0.8rem 1rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(6, 16, 28, 0.92);
  box-shadow: var(--shadow);
}

.global-loading-indicator.htmx-request {
  display: inline-flex;
}

.topbar,
.statusbar,
.panel {
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(8, 18, 31, 0.92), rgba(6, 14, 26, 0.82));
  backdrop-filter: blur(24px);
  box-shadow: var(--shadow);
}

.topbar,
.statusbar {
  border-radius: 24px;
  padding: 1rem 1.15rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  position: relative;
  overflow: hidden;
}

.topbar::after,
.statusbar::after,
.panel::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: linear-gradient(135deg, rgba(120, 223, 255, 0.08), transparent 28%, transparent 72%, rgba(255, 197, 110, 0.08));
  opacity: 0.8;
}

.topbar-brand,
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  position: relative;
  z-index: 1;
}

.topbar-system,
.statusbar-inner {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.brand-dot,
.status-lamp {
  width: 0.82rem;
  height: 0.82rem;
  border-radius: 999px;
  background: linear-gradient(180deg, #baf1ff, var(--cyan-strong));
  box-shadow: 0 0 18px rgba(52, 198, 255, 0.55);
}

.status-lamp.status-healthy {
  background: linear-gradient(180deg, var(--success), #54f1a5);
}

.status-lamp.status-degraded {
  background: linear-gradient(180deg, #ffd67a, var(--amber-strong));
  box-shadow: 0 0 18px rgba(255, 197, 110, 0.55);
}

.status-lamp.status-unknown {
  background: linear-gradient(180deg, #91a0ad, #6b7884);
  box-shadow: 0 0 18px rgba(145, 160, 173, 0.35);
}

.brand-kicker,
.panel-kicker,
.chat-hero-label {
  color: var(--cyan);
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.73rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
}

.brand-title {
  font-family: "Orbitron", "Space Grotesk", sans-serif;
  font-size: 1.25rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.brand-subtitle,
.panel-header p,
.identity-role,
.task-group h3,
.message-label,
.detail-grid dt,
.status-pill {
  color: var(--muted);
}

.brand-subtitle {
  max-width: 36rem;
}

.identity-card {
  text-align: right;
  padding: 0.65rem 0.9rem;
  border: 1px solid rgba(120, 223, 255, 0.14);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.02);
}

.identity-name {
  font-size: 0.92rem;
  font-family: "IBM Plex Mono", monospace;
}

.topbar-button,
.panel-action,
.topbar-link,
.chat-input-row button {
  border: 1px solid rgba(120, 223, 255, 0.25);
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(120, 223, 255, 0.16), rgba(120, 223, 255, 0.08));
  color: var(--text);
  padding: 0.75rem 1rem;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.topbar-button:hover,
.panel-action:hover,
.chat-input-row button:hover,
.topbar-link:hover {
  transform: translateY(-1px);
  border-color: var(--border-strong);
  box-shadow: var(--glow);
}

.topbar-button.danger {
  border-color: rgba(255, 127, 127, 0.3);
  background: linear-gradient(180deg, rgba(255, 127, 127, 0.16), rgba(255, 127, 127, 0.08));
  color: #ffd5c7;
}

.topbar-button.status {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(15rem, 19rem) minmax(0, 1.5fr) minmax(16rem, 20rem);
  gap: 1rem;
  min-height: 0;
  align-items: start;
}

.panel {
  position: relative;
  border-radius: 28px;
  padding: 1.1rem;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 1rem;
}

.panel-header h2 {
  margin: 0;
  font-family: "Orbitron", sans-serif;
  font-size: 1rem;
  letter-spacing: 0.18em;
}

.task-columns,
.chat-stream,
.panel-details {
  min-height: 0;
}

.task-columns {
  display: grid;
  gap: 0.8rem;
  overflow: auto;
}

.task-group {
  display: grid;
  gap: 0.5rem;
}

.task-group h3 {
  margin: 0;
  text-transform: uppercase;
  font-size: 0.76rem;
  letter-spacing: 0.12em;
}

.group-count {
  margin-left: 0.35rem;
  color: var(--text);
}

.panel-chat {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  background:
    radial-gradient(circle at top center, rgba(52, 198, 255, 0.12), transparent 28%),
    linear-gradient(180deg, rgba(8, 18, 31, 0.96), rgba(5, 12, 22, 0.88));
  height: min(78vh, calc(100vh - 12rem));
  min-height: 36rem;
}

.chat-hero {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.1rem;
  border: 1px solid rgba(120, 223, 255, 0.18);
  border-radius: 20px;
  background: linear-gradient(135deg, rgba(52, 198, 255, 0.12), rgba(120, 223, 255, 0.04));
}

.chat-hero h3 {
  margin: 0.35rem 0 0;
  font-size: 1.15rem;
  line-height: 1.3;
}

.chat-hero-badges {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: end;
}

.hero-badge {
  border-radius: 999px;
  border: 1px solid rgba(255, 197, 110, 0.24);
  background: rgba(255, 197, 110, 0.08);
  color: #ffd7a0;
  padding: 0.35rem 0.65rem;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
}

.task-card,
.detail-card,
.message-bubble {
  border: 1px solid rgba(120, 223, 255, 0.14);
  background: rgba(255, 255, 255, 0.03);
  border-radius: 18px;
  padding: 0.85rem;
}

.task-card-button {
  width: 100%;
  text-align: left;
  color: inherit;
  cursor: pointer;
  transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease;
}

.task-card-button.selected,
.task-card-button:hover {
  transform: translateY(-1px);
  border-color: rgba(120, 223, 255, 0.38);
  background: rgba(52, 198, 255, 0.08);
  box-shadow: inset 0 0 0 1px rgba(120, 223, 255, 0.14), 0 0 28px rgba(52, 198, 255, 0.08);
}

.task-card.skeleton-card {
  min-height: 4rem;
  background:
    linear-gradient(90deg, rgba(255,255,255,0.02), rgba(255,255,255,0.06), rgba(255,255,255,0.02));
}

.task-card.skeleton-card.muted {
  opacity: 0.6;
}

.task-card h4,
.detail-card h3 {
  margin: 0;
}

.detail-card-warning {
  border-color: rgba(255, 143, 112, 0.28);
  background: rgba(255, 143, 112, 0.06);
}

.task-card h4,
.detail-card h3,
.message-bubble .message-label {
  font-family: "IBM Plex Mono", monospace;
}

.pr-card h4 {
  margin: 0.35rem 0 0;
}

.task-card p,
.detail-description {
  margin: 0.45rem 0 0;
  line-height: 1.5;
}

.pr-topline,
.pr-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
}

.pr-topline {
  align-items: start;
}

.pr-actions {
  justify-content: start;
  flex-wrap: wrap;
  margin-top: 0.9rem;
}

.pr-safety {
  border-radius: 14px;
  padding: 0.8rem 0.9rem;
  margin-bottom: 0.9rem;
  border: 1px solid rgba(255, 214, 102, 0.2);
  background: rgba(255, 214, 102, 0.08);
}

.pr-safety-danger {
  border-color: rgba(255, 143, 112, 0.24);
  background: rgba(255, 143, 112, 0.08);
  color: #ffd5c7;
}

.pr-diff {
  max-height: 26rem;
  overflow: auto;
  margin-top: 0.8rem;
}

.task-card-topline,
.detail-title-row,
.detail-badges,
.execution-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.detail-title-row {
  align-items: start;
}

.task-priority,
.task-tier,
.detail-status,
.execution-status {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border: 1px solid rgba(141, 161, 177, 0.2);
}

.task-priority {
  background: rgba(125, 211, 252, 0.08);
}

.task-tier.tier-1 {
  background: rgba(163, 255, 159, 0.1);
}

.task-tier.tier-2 {
  background: rgba(255, 214, 102, 0.1);
}

.task-tier.tier-3 {
  background: rgba(255, 143, 112, 0.12);
}

.task-meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
  margin: 0.8rem 0 0;
}

.task-meta dt {
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
}

.task-meta dd {
  margin: 0.18rem 0 0;
}

.task-card-empty {
  color: var(--muted);
}

.chat-stream {
  display: grid;
  align-content: start;
  gap: 0.8rem;
  overflow: auto;
  padding-right: 0.2rem;
  padding-bottom: 0.35rem;
  scrollbar-gutter: stable;
  overscroll-behavior: contain;
  min-height: 0;
}

.message-bubble.user {
  border-color: rgba(255, 197, 110, 0.25);
  background: rgba(255, 197, 110, 0.06);
}

.message-bubble.assistant {
  border-color: rgba(120, 223, 255, 0.26);
  background: rgba(52, 198, 255, 0.06);
}

.message-bubble p {
  margin: 0.35rem 0 0;
  line-height: 1.5;
}

.chat-input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.75rem;
  align-items: stretch;
  position: sticky;
  bottom: 0;
  z-index: 2;
  margin-top: auto;
  padding-top: 0.65rem;
  background: linear-gradient(180deg, rgba(5, 12, 22, 0), rgba(5, 12, 22, 0.78) 28%, rgba(5, 12, 22, 0.96));
}

.chat-input-shell {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.9rem;
  align-items: start;
  padding: 0.9rem 1rem;
  border-radius: 20px;
  border: 1px solid rgba(120, 223, 255, 0.18);
  background: rgba(4, 12, 22, 0.92);
}

.chat-input-prefix {
  padding-top: 0.3rem;
  color: var(--cyan);
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.75rem;
  letter-spacing: 0.16em;
}

.chat-input-row textarea {
  resize: none;
  min-height: 5.6rem;
  border: 0;
  background: transparent;
  color: var(--text);
  padding: 0;
  font: inherit;
  outline: none;
}

.chat-input-row button[disabled] {
  opacity: 0.65;
  cursor: progress;
}

.detail-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.45rem 0.8rem;
  margin: 0;
}

.detail-grid dd {
  margin: 0;
}

.detail-pre {
  overflow: auto;
  margin: 0.75rem 0 0;
  padding: 0.85rem;
  border-radius: 16px;
  background: rgba(4, 12, 22, 0.82);
}

.execution-list {
  display: grid;
  gap: 0.75rem;
}

.execution-card {
  border: 1px solid rgba(141, 161, 177, 0.16);
  border-radius: 14px;
  padding: 0.8rem;
}

.execution-status-succeeded {
  background: rgba(163, 255, 159, 0.1);
}

.execution-status-failed,
.execution-status-cancelled {
  background: rgba(255, 143, 112, 0.12);
}

.execution-status-running {
  background: rgba(125, 211, 252, 0.1);
}

.execution-error {
  margin: 0.75rem 0 0;
  color: #ffd5c7;
}

.detail-actions {
  display: flex;
  gap: 0.6rem;
  margin-top: 1rem;
}

.panel-action.ghost {
  background: transparent;
}

.statusbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.detail-list {
  margin: 0.75rem 0 0;
  padding-left: 1.1rem;
}

.detail-list li + li {
  margin-top: 0.35rem;
}

.status-pill {
  border: 1px solid rgba(120, 223, 255, 0.16);
  border-radius: 999px;
  padding: 0.45rem 0.7rem;
  background: rgba(255, 255, 255, 0.03);
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.76rem;
}

.status-pill-warning {
  border-color: rgba(255, 127, 127, 0.28);
  background: rgba(255, 127, 127, 0.08);
  color: #ffd5c7;
}

.login-body {
  display: grid;
  place-items: center;
}

.login-card {
  position: relative;
  z-index: 1;
  width: min(34rem, calc(100vw - 2rem));
  padding: 2.4rem;
  border-radius: 28px;
  border: 1px solid rgba(120, 223, 255, 0.18);
  background: linear-gradient(180deg, rgba(8, 18, 31, 0.9), rgba(6, 12, 22, 0.84));
  box-shadow: var(--shadow);
}

.login-kicker {
  color: var(--cyan);
  font-family: "IBM Plex Mono", monospace;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.76rem;
}

.login-card h1 {
  margin: 0.5rem 0 0;
  font-family: "Orbitron", sans-serif;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.login-card p {
  color: var(--muted);
  max-width: 30rem;
  line-height: 1.6;
}

.login-meta {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin: 1.25rem 0 0;
}

.login-meta span {
  border-radius: 999px;
  border: 1px solid rgba(255, 197, 110, 0.22);
  background: rgba(255, 197, 110, 0.08);
  color: #ffd7a0;
  padding: 0.35rem 0.7rem;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
}

.login-link {
  display: inline-block;
  margin-top: 1.4rem;
  padding: 0.95rem 1.25rem;
  border-radius: 14px;
  border: 1px solid rgba(120, 223, 255, 0.28);
  background: linear-gradient(180deg, rgba(120, 223, 255, 0.18), rgba(120, 223, 255, 0.1));
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  box-shadow: var(--glow);
}

@media (max-width: 1080px) {
  .workspace-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    flex-direction: column;
    align-items: start;
  }

  .topbar-actions {
    width: 100%;
    justify-content: space-between;
  }

  .panel-chat {
    height: min(72vh, calc(100vh - 10rem));
    min-height: 32rem;
  }

  .chat-hero {
    flex-direction: column;
  }
}

@media (max-width: 720px) {
  .console-shell {
    padding: 0.75rem;
  }

  .topbar,
  .statusbar {
    padding: 0.85rem;
  }

  .topbar-actions,
  .topbar-brand,
  .task-card-topline,
  .detail-title-row,
  .detail-badges,
  .execution-topline,
  .pr-topline,
  .chat-hero-badges {
    flex-direction: column;
    align-items: start;
  }

  .identity-card {
    text-align: left;
  }

  .chat-input-row,
  .task-meta,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .panel-chat {
    height: min(70vh, calc(100vh - 8rem));
    min-height: 30rem;
  }

  .chat-input-shell {
    grid-template-columns: 1fr;
  }
}

/* Settings page */
.settings-container { max-width: 900px; margin: 0 auto; padding: 2rem 1rem; }
.settings-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; }
.settings-header h1 { font-size: 1.5rem; font-weight: 600; color: var(--text-primary); }
.settings-grid { display: flex; flex-direction: column; gap: 1.5rem; }
.settings-card { background: var(--surface-secondary, #1e1e2e); border: 1px solid var(--border-color, #313244); border-radius: 8px; padding: 1.5rem; }
.settings-card h2 { font-size: 1.15rem; font-weight: 600; margin-bottom: 1rem; color: var(--text-primary); }
.settings-card h3 { font-size: 0.95rem; font-weight: 500; margin-bottom: 0.5rem; color: var(--text-secondary, #a6adc8); }
.settings-desc { font-size: 0.85rem; color: var(--text-secondary, #a6adc8); margin-bottom: 1rem; }
.settings-desc code { background: var(--surface-tertiary, #313244); padding: 0.15em 0.4em; border-radius: 3px; font-size: 0.9em; }
.token-form { display: flex; flex-direction: column; gap: 0.75rem; margin-bottom: 1rem; }
.token-form label { font-size: 0.85rem; color: var(--text-secondary, #a6adc8); }
.token-input { width: 100%; padding: 0.5rem; border: 1px solid var(--border-color, #313244); border-radius: 4px; background: var(--surface-primary, #11111b); color: var(--text-primary); font-family: monospace; font-size: 0.8rem; resize: vertical; }
.token-success { color: #a6e3a1; font-size: 0.85rem; margin-top: 0.25rem; }
.token-error { color: #f38ba8; font-size: 0.85rem; margin-top: 0.25rem; }
.token-help { background: var(--surface-primary, #11111b); border-radius: 6px; padding: 1rem; font-size: 0.85rem; }
.token-help h3 { margin-bottom: 0.5rem; }
.token-help ol { padding-left: 1.5rem; display: flex; flex-direction: column; gap: 0.35rem; }
.token-help code { background: var(--surface-tertiary, #313244); padding: 0.1em 0.3em; border-radius: 3px; font-size: 0.9em; }
.token-help-note { margin-top: 0.75rem; color: var(--text-secondary, #a6adc8); font-style: italic; }
.routing-group { margin-bottom: 1.25rem; }
.radio-group { display: flex; flex-direction: column; gap: 0.5rem; }
.radio-label { display: flex; align-items: center; gap: 0.5rem; padding: 0.5rem 0.75rem; border: 1px solid var(--border-color, #313244); border-radius: 6px; cursor: pointer; font-size: 0.85rem; transition: border-color 0.15s; }
.radio-label:hover { border-color: var(--accent-color, #89b4fa); }
.radio-label input[type="radio"] { accent-color: var(--accent-color, #89b4fa); }
.cost-badge { margin-left: auto; padding: 0.15em 0.5em; border-radius: 3px; font-size: 0.75rem; font-weight: 500; }
.cost-free { background: #1e3a2e; color: #a6e3a1; }
.cost-paid { background: #3a2a1e; color: #fab387; }
.bridge-status { display: flex; align-items: center; gap: 0.5rem; padding: 0.75rem; border-radius: 6px; font-size: 0.85rem; margin-bottom: 1rem; }
.bridge-ok { background: #1e3a2e; }
.bridge-warn { background: #3a3a1e; }
.bridge-bad { background: #3a1e1e; }
.bridge-detail { color: var(--text-secondary, #a6adc8); margin-left: 0.25rem; }
.bridge-status-loading { color: var(--text-secondary, #a6adc8); font-size: 0.85rem; padding: 0.75rem; }
.status-indicator { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.status-indicator.ok { background: #a6e3a1; }
.status-indicator.warn { background: #f9e2af; }
.status-indicator.off { background: #f38ba8; }
.topbar-button.primary { background: var(--accent-color, #89b4fa); color: #11111b; }
.topbar-button.primary:hover { opacity: 0.9; }
.topbar-button.primary:disabled { opacity: 0.5; cursor: not-allowed; }
