:root {
  color-scheme: dark;
  --bg: #070a0f;
  --panel: #0f141b;
  --panel-border: rgba(148, 163, 184, 0.16);
  --rail: #0b0f15;
  --rail-soft: #131922;
  --rail-border: rgba(255, 255, 255, 0.08);
  --text: #e7edf4;
  --muted: #92a0ae;
  --soft-text: #c5ced8;
  --user-bg: #182230;
  --user-text: #f1f5f9;
  --assistant-bg: #121922;
  --tool-bg: #10171f;
  --tool-line: rgba(148, 163, 184, 0.16);
  --accent: #2dd4bf;
  --danger: #fb7185;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.34);
  --font-sans: "IBM Plex Sans", "Avenir Next", "Helvetica Neue", sans-serif;
  --font-mono: "IBM Plex Mono", "SFMono-Regular", "Menlo", monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background-color: #06080d;
  background:
    radial-gradient(circle at top left, rgba(45, 212, 191, 0.12), transparent 32%),
    radial-gradient(circle at top right, rgba(56, 189, 248, 0.08), transparent 28%),
    linear-gradient(180deg, #0a0e14 0%, #06080d 100%);
  color: var(--text);
  font-family: var(--font-sans);
}

body {
  min-height: 100vh;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
textarea {
  font: inherit;
}

.page {
  min-height: 100vh;
  padding: 20px;
}

.shell {
  min-height: calc(100vh - 40px);
  display: flex;
  gap: 18px;
}

.rail {
  width: 312px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.03), transparent 28%),
    linear-gradient(180deg, #0b0f15 0%, #111722 100%);
  color: #f8f7f3;
  border-radius: 24px;
  padding: 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 40px);
}

.rail-header {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.eyebrow {
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.62);
}

.rail-title,
.main-title {
  margin: 0;
  font-size: 28px;
  line-height: 1;
  font-weight: 700;
}

.rail-subtitle,
.main-subtitle {
  margin: 0;
  color: var(--muted);
  line-height: 1.4;
}

.search-box {
  width: 100%;
  border: 1px solid var(--rail-border);
  background: rgba(255, 255, 255, 0.04);
  color: #faf9f5;
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 14px;
}

.search-box::placeholder {
  color: rgba(255, 255, 255, 0.38);
}

.list-scroll {
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-right: 4px;
}

.key-card,
.chat-card {
  border: 1px solid var(--rail-border);
  background: rgba(255, 255, 255, 0.03);
  border-radius: 18px;
  padding: 14px;
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.key-card:hover,
.chat-card:hover,
.key-card.active,
.chat-card.active {
  transform: translateY(-1px);
  border-color: rgba(255, 255, 255, 0.24);
  background: rgba(255, 255, 255, 0.08);
}

.key-card.disabled {
  opacity: 0.66;
}

.card-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.key-name,
.chat-name {
  margin: 0;
  font-size: 15px;
  line-height: 1.35;
  word-break: break-word;
}

.chat-preview,
.key-meta {
  margin: 6px 0 0;
  font-size: 12px;
  line-height: 1.45;
  color: rgba(255, 255, 255, 0.62);
}

.meta-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 11px;
  line-height: 1;
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.72);
}

.pill.enabled {
  color: #d9fff8;
  border-color: rgba(15, 118, 110, 0.54);
  background: rgba(15, 118, 110, 0.2);
}

.pill.warn {
  color: #ffe3ea;
  border-color: rgba(159, 18, 57, 0.44);
  background: rgba(159, 18, 57, 0.16);
}

.toggle {
  appearance: none;
  border: 0;
  border-radius: 999px;
  min-width: 82px;
  padding: 9px 12px;
  background: #3b3b3b;
  color: #f7f7f3;
  cursor: pointer;
  transition: background 0.18s ease, transform 0.18s ease;
}

.toggle:hover {
  transform: translateY(-1px);
}

.toggle.enabled {
  background: var(--accent);
}

.main {
  flex: 1;
  min-width: 0;
  background: rgba(14, 19, 26, 0.9);
  border-radius: 28px;
  padding: 26px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--panel-border);
  min-height: calc(100vh - 40px);
}

.main-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 18px;
}

.header-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.ghost-button,
.link-button {
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  cursor: pointer;
}

.ghost-button:hover,
.link-button:hover {
  background: rgba(255, 255, 255, 0.08);
}

.link-button.danger {
  color: var(--danger);
}

.command-panel {
  border-radius: 22px;
  padding: 18px;
  margin-bottom: 18px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0)),
    rgba(15, 20, 27, 0.9);
  border: 1px solid var(--panel-border);
}

.command-panel-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
  margin-bottom: 14px;
}

.command-eyebrow {
  color: var(--muted);
}

.command-title {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
}

.command-meta {
  margin: 0;
  max-width: 320px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  text-align: right;
}

.command-form {
  display: flex;
  gap: 12px;
  align-items: stretch;
}

.command-input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--panel-border);
  background: rgba(9, 13, 18, 0.92);
  color: var(--text);
  border-radius: 14px;
  padding: 14px 16px;
  font-family: var(--font-mono);
}

.command-submit {
  margin-top: 0;
  white-space: nowrap;
}

.command-submit:disabled {
  opacity: 0.72;
  cursor: wait;
}

.command-status {
  margin-top: 12px;
  border-radius: 14px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.5;
}

.command-status.info {
  background: rgba(45, 212, 191, 0.12);
  color: #99f6e4;
}

.command-status.success {
  background: rgba(34, 197, 94, 0.12);
  color: #86efac;
}

.command-status.error {
  background: rgba(251, 113, 133, 0.14);
  color: #fecdd3;
}

.command-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 14px;
}

.command-empty {
  color: var(--muted);
  font-size: 13px;
}

.command-card {
  border-radius: 18px;
  padding: 14px;
  background: rgba(15, 20, 27, 0.92);
  border: 1px solid var(--panel-border);
}

.command-card-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
}

.command-card-meta {
  font-size: 12px;
  color: var(--muted);
  text-align: right;
}

.command-pill {
  border-color: var(--panel-border);
  color: var(--soft-text);
}

.command-pill.pending {
  color: #fdba74;
  border-color: rgba(251, 146, 60, 0.24);
  background: rgba(251, 146, 60, 0.1);
}

.command-pill.dispatched {
  color: #93c5fd;
  border-color: rgba(59, 130, 246, 0.24);
  background: rgba(59, 130, 246, 0.1);
}

.command-pill.completed {
  color: #86efac;
  border-color: rgba(34, 197, 94, 0.24);
  background: rgba(34, 197, 94, 0.1);
}

.command-code,
.command-output {
  margin: 0;
  white-space: pre-wrap;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.55;
}

.command-output {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--panel-border);
  color: var(--soft-text);
}

.command-card-note {
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.command-link {
  display: inline-flex;
  margin-top: 10px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
}

.workspace {
  flex: 1;
  min-height: 0;
  border-radius: 24px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0.01)),
    var(--panel);
  border: 1px solid var(--panel-border);
  padding: 24px;
  overflow: auto;
}

.empty-state {
  height: 100%;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--soft-text);
}

.conversation {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 920px;
  margin: 0 auto;
}

.message-row {
  display: flex;
}

.message-row.user {
  justify-content: flex-end;
}

.message-row.assistant,
.message-row.thinking,
.message-row.tool {
  justify-content: center;
}

.bubble,
.assistant-card,
.thinking-card,
.tool-card {
  border-radius: 22px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.26);
}

.bubble {
  max-width: min(72ch, 74%);
  padding: 16px 18px;
  white-space: pre-wrap;
  line-height: 1.6;
  background: var(--user-bg);
  color: var(--user-text);
}

.assistant-card {
  width: min(76ch, 100%);
  padding: 18px 20px;
  background: var(--assistant-bg);
  line-height: 1.65;
  white-space: pre-wrap;
}

.assistant-phase {
  display: inline-flex;
  margin-bottom: 10px;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--soft-text);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.thinking-card {
  width: min(72ch, 100%);
  padding: 12px 16px;
  color: #b2beca;
  background: rgba(133, 148, 166, 0.12);
  line-height: 1.55;
  white-space: pre-wrap;
}

.tool-card {
  width: min(82ch, 100%);
  overflow: hidden;
  border: 1px solid var(--panel-border);
  background: rgba(16, 23, 31, 0.94);
}

.tool-head {
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  border-bottom: 1px solid var(--tool-line);
}

.tool-title {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
}

.tool-status {
  font-size: 12px;
  color: var(--soft-text);
}

.tool-body {
  display: grid;
  gap: 0;
}

.tool-section {
  padding: 14px 16px;
  border-top: 1px solid var(--tool-line);
}

.tool-section:first-child {
  border-top: 0;
}

.tool-label {
  display: block;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--soft-text);
  margin-bottom: 10px;
}

.code-block,
.plain-block {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.55;
  font-size: 13px;
}

.code-block {
  font-family: var(--font-mono);
}

.tool-code {
  margin: 0;
  overflow-x: auto;
}

.collapsible {
  position: relative;
}

.collapsible[data-collapsed="true"] .collapsible-content {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.collapsible-toggle {
  margin-top: 10px;
  border: 0;
  background: transparent;
  padding: 0;
  color: var(--accent);
  cursor: pointer;
  font-weight: 600;
}

.group-card {
  width: min(72ch, 100%);
  padding: 12px 16px;
  border-radius: 18px;
  background: rgba(133, 148, 166, 0.12);
}

.group-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.group-toggle {
  width: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  padding: 0;
  text-align: left;
}

.group-meta {
  margin-left: auto;
  font-size: 12px;
  color: var(--soft-text);
}

.group-toggle-label {
  font-size: 12px;
  color: var(--accent);
  font-weight: 600;
}

.group-items {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.tool-group-card {
  width: min(82ch, 100%);
  background: rgba(16, 23, 31, 0.94);
  border: 1px solid var(--panel-border);
}

.hidden {
  display: none !important;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 20%, rgba(45, 212, 191, 0.12), transparent 26%),
    radial-gradient(circle at 80% 0%, rgba(56, 189, 248, 0.1), transparent 24%),
    linear-gradient(180deg, rgba(9, 13, 18, 0.94), rgba(6, 8, 13, 0.98));
}

.login-card {
  width: min(460px, 100%);
  border-radius: 28px;
  background: rgba(15, 20, 27, 0.94);
  box-shadow: var(--shadow);
  border: 1px solid var(--panel-border);
  padding: 28px;
  backdrop-filter: blur(14px);
}

.login-title {
  margin: 0 0 8px;
  font-size: 34px;
  color: var(--text);
}

.login-subtitle {
  margin: 0 0 22px;
  color: var(--muted);
  line-height: 1.5;
}

.login-error {
  margin: 0 0 16px;
  color: var(--danger);
}

.login-form {
  display: grid;
  gap: 14px;
}

.field-label {
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--soft-text);
}

.field-input {
  width: 100%;
  border: 1px solid var(--panel-border);
  background: rgba(9, 13, 18, 0.94);
  color: var(--text);
  border-radius: 14px;
  padding: 14px 16px;
  color-scheme: dark;
}

.field-input::placeholder {
  color: var(--muted);
}

.field-input:-webkit-autofill,
.field-input:-webkit-autofill:hover,
.field-input:-webkit-autofill:focus,
.field-input:-webkit-autofill:active {
  -webkit-text-fill-color: var(--text);
  box-shadow: 0 0 0 1000px rgba(9, 13, 18, 0.98) inset;
  transition: background-color 9999s ease-in-out 0s;
}

.submit-button {
  margin-top: 10px;
  border: 0;
  border-radius: 14px;
  padding: 14px 16px;
  background: linear-gradient(135deg, #1f8f84, #2dd4bf);
  color: #041412;
  cursor: pointer;
}

.submit-button:hover {
  filter: brightness(1.04);
}

.footer-note {
  margin-top: 18px;
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 980px) {
  .page {
    padding: 12px;
  }

  .shell {
    flex-direction: column;
    min-height: auto;
  }

  .rail,
  .main {
    min-height: auto;
    width: 100%;
  }

  .workspace {
    min-height: 62vh;
  }

  .command-panel-head,
  .command-form,
  .command-card-head {
    flex-direction: column;
    align-items: stretch;
  }

  .command-meta,
  .command-card-meta {
    text-align: left;
  }

  .bubble {
    max-width: 100%;
  }
}
