:root {
  color-scheme: dark;
  --bg: #060913;
  --rail: #090f1d;
  --panel: rgba(15, 23, 42, .84);
  --panel-2: rgba(30, 41, 59, .78);
  --field: rgba(2, 6, 23, .9);
  --line: rgba(148, 163, 184, .18);
  --text: #eaf2ff;
  --muted: #94a3b8;
  --green: #30f2a2;
  --blue: #5cc8ff;
  --yellow: #f8d66d;
  --red: #ff6b92;
  --violet: #a78bfa;
  --cyan: #22d3ee;
  --radius: 8px;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background:
    radial-gradient(circle at 20% 8%, rgba(34, 211, 238, .14), transparent 34%),
    radial-gradient(circle at 85% 12%, rgba(167, 139, 250, .16), transparent 34%),
    linear-gradient(135deg, #050816 0%, #07111f 48%, #05070e 100%);
  color: var(--text);
  display: grid;
  grid-template-columns: 244px minmax(0, 1fr);
  font: 14px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select, textarea { font: inherit; }
button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-2);
  color: var(--text);
  padding: 8px 11px;
  cursor: pointer;
}
button:hover { border-color: #53645e; }
.primary {
  background: linear-gradient(135deg, var(--cyan), var(--green));
  border-color: rgba(48, 242, 162, .6);
  color: #031014;
  font-weight: 800;
  box-shadow: 0 0 18px rgba(34, 211, 238, .18);
}
.ghost, .icon-button { background: transparent; }
.icon-button { width: 38px; padding: 0; font-weight: 800; }

.rail {
  min-height: 100vh;
  padding: 18px;
  background: linear-gradient(180deg, rgba(9, 15, 29, .96), rgba(2, 6, 23, .94));
  border-right: 1px solid var(--line);
  box-shadow: inset -1px 0 0 rgba(92, 200, 255, .08);
}
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.brand strong, .brand small { display: block; }
.brand small, small, .muted { color: var(--muted); }
.mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--cyan), var(--green));
  color: #031014;
  font-weight: 900;
  box-shadow: 0 0 22px rgba(34, 211, 238, .28);
}
nav { display: grid; gap: 7px; }
.nav {
  width: 100%;
  text-align: left;
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}
.nav.active, .nav:hover { background: var(--panel); border-color: var(--line); color: var(--text); }

main { min-width: 0; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 78px;
  padding: 16px 26px;
  border-bottom: 1px solid var(--line);
  background: rgba(5, 8, 22, .82);
  backdrop-filter: blur(12px);
}
h1, h2, p { margin: 0; }
h1 { font-size: 22px; line-height: 1.2; }
h2 { font-size: 15px; }
.topbar p { margin-top: 4px; color: var(--muted); }
.top-actions { display: flex; gap: 8px; align-items: center; }
.view-shell { padding: 22px 26px 40px; }
.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background: rgba(7, 10, 9, .74);
  backdrop-filter: blur(10px);
}
.loading-card {
  display: flex;
  align-items: center;
  gap: 12px;
  width: min(360px, calc(100vw - 32px));
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.loading-card strong, .loading-card small { display: block; }
.loader {
  width: 28px;
  height: 28px;
  border: 3px solid var(--line);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}
.metrics div, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .18), inset 0 1px 0 rgba(255, 255, 255, .04);
  backdrop-filter: blur(16px);
}
.metrics div { padding: 16px; }
.metrics span { display: block; font-size: 27px; font-weight: 900; }

.cockpit-grid, .settings-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(260px, 1fr));
  gap: 14px;
  align-items: start;
}
.span-2 { grid-column: span 2; }
.split, .file-layout, .mission-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(360px, .9fr);
  gap: 14px;
  align-items: start;
}

.panel { min-width: 0; overflow: hidden; }
.panel-head {
  min-height: 50px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.pill, .badge {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 23px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
  color: var(--muted);
  font-size: 12px;
}

.form { padding: 14px; display: grid; gap: 12px; }
.two-cols { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.wide { grid-column: 1 / -1; }
label { display: grid; gap: 6px; color: var(--muted); min-width: 0; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--field);
  color: var(--text);
  padding: 10px 11px;
}
textarea { resize: vertical; }

.list, .timeline, .agent-strip { display: grid; }
.item, .timeline article {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 4px;
}
.item:last-child, .timeline article:last-child { border-bottom: 0; }
.item.row { grid-template-columns: 1fr auto; align-items: center; gap: 12px; }
.item strong, .mission strong, .card strong { overflow-wrap: anywhere; }
.empty { padding: 14px; color: var(--muted); }

.agent-grid {
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 10px;
}
.agent-card, .mission, .card, .agent-strip article {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 7px;
}
.agent-card { padding: 12px; display: grid; gap: 8px; }
.agent-card div { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.agent-card p { color: var(--muted); }
.agent-strip { padding: 12px; gap: 8px; }
.agent-strip article { padding: 10px; display: grid; gap: 2px; }

.mission-layout { grid-template-columns: minmax(280px, 380px) minmax(0, 1fr); }
.mission-list { display: grid; gap: 10px; }
.mission { padding: 13px; display: grid; gap: 8px; }
.mission p { color: var(--muted); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.badge.working { color: var(--blue); }
.badge.queued { color: var(--yellow); }
.badge.turn_done { color: var(--green); }
.badge.interrupted { color: var(--red); }
.log, .code {
  min-height: 360px;
  max-height: 64vh;
  overflow: auto;
  margin: 0;
  padding: 15px;
  background: #070a09;
  color: #e5eee9;
  white-space: pre-wrap;
  border-radius: 0 0 var(--radius) var(--radius);
}
.agent-chat {
  display: grid;
  gap: 10px;
  align-content: start;
  min-height: 520px;
  max-height: 70vh;
  overflow: auto;
  padding: 14px;
  background: #0a0e0d;
}
.chat-bubble {
  width: min(780px, 92%);
  padding: 11px 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 5px;
}
.chat-bubble.user { margin-left: auto; border-color: #365f4a; }
.chat-bubble.system { border-color: #3a4a60; }
.chat-bubble.warning, .chat-bubble.stderr { border-color: #68444b; }
.chat-bubble pre {
  margin: 0;
  white-space: pre-wrap;
  color: #dce8e2;
}

.quick-add, .terminal-form {
  display: grid;
  grid-template-columns: 1fr 140px 190px auto;
  gap: 9px;
  margin-bottom: 14px;
}
.board {
  display: grid;
  grid-template-columns: repeat(7, minmax(220px, 1fr));
  gap: 11px;
  overflow-x: auto;
  align-items: start;
  padding-bottom: 8px;
}
.column {
  min-height: 440px;
  padding: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.column h2 { display: flex; justify-content: space-between; padding: 2px 2px 11px; }
.card { padding: 11px; margin-bottom: 9px; cursor: grab; }
.card p { color: var(--muted); margin-top: 5px; }
.card footer { display: flex; justify-content: space-between; gap: 8px; margin-top: 10px; }

.terminal-form {
  grid-template-columns: minmax(190px, 280px) 1fr auto;
  margin: 0;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}
.file-layout { grid-template-columns: minmax(260px, 380px) minmax(0, 1fr); }
.ide-layout {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: 14px;
  min-height: calc(100vh - 122px);
}
.ide-sidebar, .ide-main { min-height: calc(100vh - 122px); }
.ide-main { display: grid; grid-template-rows: auto auto minmax(0, 1fr); }
.ide-tabs, .ide-toolbar {
  min-height: 46px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}
.ide-tabs { justify-content: space-between; }
.tab.active { background: var(--field); }
.file-tree {
  max-height: calc(100vh - 230px);
  overflow: auto;
}
.file-row {
  width: 100%;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  text-align: left;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  padding: 8px 12px;
}
.file-row:hover { background: var(--panel-2); }
.file-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ide-editor {
  width: 100%;
  height: 100%;
  min-height: 540px;
  border: 0;
  border-radius: 0;
  resize: none;
  padding: 16px;
  background: #070a09;
  color: #e6eee9;
  font: 13px/1.55 "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  tab-size: 2;
}
.error-panel { max-width: 760px; }
.error-body { padding: 16px; display: grid; gap: 12px; color: var(--muted); }
.crumbs { padding: 10px 14px; border-bottom: 1px solid var(--line); color: var(--muted); }
.file-button {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  padding: 11px 14px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
}
.file-button:hover { background: var(--panel-2); }

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(7, 10, 9, .86);
  backdrop-filter: blur(14px);
}
.hidden { display: none !important; }
.login-card {
  width: min(430px, 100%);
  padding: 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: grid;
  gap: 14px;
}
.error { min-height: 20px; color: var(--red); }

.hero-strip {
  min-height: 170px;
  margin-bottom: 16px;
  padding: 22px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: end;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, rgba(34, 211, 238, .13), rgba(167, 139, 250, .09)),
    rgba(15, 23, 42, .7);
  box-shadow: 0 22px 70px rgba(0, 0, 0, .24);
}
.eyebrow {
  color: var(--cyan);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .08em;
}
.hero-strip h2 {
  max-width: 780px;
  margin-top: 8px;
  font-size: 28px;
  line-height: 1.15;
}
.hero-stats {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.hero-stats article {
  min-width: 96px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(2, 6, 23, .42);
}
.hero-stats strong { display: block; font-size: 24px; }
.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 16px;
  align-items: start;
}
.project-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 14px;
}
.project-card {
  min-height: 176px;
  padding: 15px;
  display: grid;
  align-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(30, 41, 59, .78), rgba(15, 23, 42, .72));
  box-shadow: 0 18px 60px rgba(0, 0, 0, .2);
  cursor: pointer;
  transition: transform .16s ease, border-color .16s ease, box-shadow .16s ease;
}
.project-card:hover {
  transform: translateY(-3px);
  border-color: rgba(34, 211, 238, .48);
  box-shadow: 0 24px 80px rgba(34, 211, 238, .12);
}
.project-card div {
  display: flex;
  align-items: center;
  gap: 10px;
}
.project-card strong { font-size: 17px; overflow-wrap: anywhere; }
.project-card p { color: var(--muted); }
.project-card footer {
  display: grid;
  gap: 8px;
}
.project-card footer span {
  width: fit-content;
  padding: 3px 8px;
  border: 1px solid rgba(48, 242, 162, .32);
  border-radius: 999px;
  color: var(--green);
  font-size: 12px;
}
.project-orb {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 16px var(--green);
}
.project-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(330px, 420px);
  gap: 14px;
  align-items: start;
}
.project-chat {
  min-height: calc(100vh - 122px);
  display: grid;
  grid-template-rows: auto minmax(360px, 1fr) auto;
}
.project-side {
  display: grid;
  gap: 14px;
}
.chat-composer {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr) auto;
  gap: 9px;
  padding: 12px;
  border-top: 1px solid var(--line);
}
.chat-composer textarea, .chat-composer .checkline { grid-column: 1 / -1; }
.checkline {
  display: flex;
  align-items: center;
  gap: 8px;
}
.checkline input { width: auto; }
.compact { border-top: 1px solid var(--line); }
.mini-ide {
  display: grid;
  grid-template-rows: auto minmax(160px, 240px) auto minmax(260px, 1fr);
}
.mini-editor {
  min-height: 280px;
  border: 0;
  border-radius: 0;
  resize: vertical;
  padding: 12px;
  background: #050816;
  color: var(--text);
  font: 12px/1.55 "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

@media (max-width: 1180px) {
  .cockpit-grid, .settings-grid { grid-template-columns: repeat(2, minmax(260px, 1fr)); }
  .dashboard-grid, .project-workspace { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
  .metrics { grid-template-columns: repeat(2, minmax(130px, 1fr)); }
}
@media (max-width: 860px) {
  body { grid-template-columns: 1fr; }
  .rail { min-height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar { align-items: flex-start; flex-direction: column; }
  .cockpit-grid, .settings-grid, .split, .file-layout, .mission-layout, .ide-layout, .two-cols { grid-template-columns: 1fr; }
  .hero-strip { grid-template-columns: 1fr; }
  .hero-strip h2 { font-size: 22px; }
  .chat-composer { grid-template-columns: 1fr; }
  .quick-add, .terminal-form { grid-template-columns: 1fr; }
  .view-shell { padding: 16px; }
}
