:root {
  color-scheme: dark;
  --bg: #071018;
  --panel: #111827;
  --panel-border: rgba(148, 163, 184, 0.16);
  --rail: #08111b;
  --rail-soft: #101a27;
  --rail-border: rgba(148, 163, 184, 0.14);
  --text: #e5eef8;
  --muted: #8b9bb0;
  --soft-text: #b7c4d6;
  --user-bg: #0f2e31;
  --user-text: #ecfeff;
  --assistant-bg: #16202e;
  --tool-bg: #111926;
  --tool-line: rgba(148, 163, 184, 0.12);
  --accent: #2dd4bf;
  --danger: #fb7185;
  --shadow: 0 24px 60px rgba(2, 6, 23, 0.45);
  --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:
    radial-gradient(circle at top left, rgba(45, 212, 191, 0.12), transparent 28%),
    radial-gradient(circle at top right, rgba(59, 130, 246, 0.12), transparent 30%),
    linear-gradient(180deg, #071018 0%, #0d1725 52%, #09111a 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 {
  height: 100vh;
  padding: 20px;
}

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

.rail {
  width: 312px;
  background:
    linear-gradient(180deg, rgba(45, 212, 191, 0.08), transparent 22%),
    linear-gradient(180deg, #08111b 0%, #0f1724 100%);
  color: #f8f7f3;
  border-radius: 24px;
  padding: 18px;
  box-shadow: var(--shadow);
  border: 1px solid var(--rail-border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.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 {
  flex: 1;
  min-height: 0;
  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;
  min-height: 0;
  background:
    linear-gradient(180deg, rgba(45, 212, 191, 0.05), transparent 18%),
    rgba(9, 15, 23, 0.84);
  border-radius: 28px;
  padding: 26px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--panel-border);
  overflow: hidden;
}

.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 rgba(148, 163, 184, 0.18);
  border-radius: 12px;
  padding: 10px 14px;
  background: rgba(15, 23, 36, 0.92);
  color: var(--text);
  cursor: pointer;
}

.back-arrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 0;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
  font-size: 13px;
  font-weight: 600;
}

.back-arrow:hover {
  color: #67e8f9;
}

.ghost-button:hover,
.link-button:hover {
  background: rgba(24, 35, 51, 0.96);
}

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

.command-panel {
  border-radius: 22px;
  padding: 18px;
  margin-bottom: 18px;
  background:
    linear-gradient(180deg, rgba(45, 212, 191, 0.08), rgba(12, 12, 12, 0)),
    rgba(15, 23, 36, 0.92);
  border: 1px solid rgba(148, 163, 184, 0.12);
}

.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 rgba(148, 163, 184, 0.18);
  background: rgba(7, 16, 24, 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: #7dd3fc;
}

.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;
  max-height: 260px;
  overflow: auto;
  padding-right: 4px;
}

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

.command-card {
  border-radius: 18px;
  padding: 14px;
  background: rgba(17, 25, 38, 0.9);
  border: 1px solid rgba(148, 163, 184, 0.12);
}

.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: rgba(148, 163, 184, 0.14);
  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 rgba(148, 163, 184, 0.12);
  color: var(--soft-text);
}

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

.command-actions {
  margin-top: 10px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.command-action-button {
  font-size: 12px;
}

.command-toolcall {
  margin: 10px 0 0;
  padding-top: 10px;
  border-top: 1px solid rgba(148, 163, 184, 0.12);
  white-space: pre-wrap;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.55;
  color: var(--soft-text);
}

.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(45, 212, 191, 0.05), rgba(8, 17, 27, 0)),
    var(--panel);
  border: 1px solid rgba(148, 163, 184, 0.12);
  padding: 24px;
  overflow: auto;
}

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

.root-dashboard {
  display: grid;
  gap: 18px;
}

.root-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.stat-tile {
  border-radius: 16px;
  padding: 14px;
  border: 1px solid rgba(148, 163, 184, 0.12);
  background: rgba(17, 25, 38, 0.9);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stat-tile span {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stat-tile strong {
  font-size: 24px;
  line-height: 1;
}

.root-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.root-key-card {
  border-radius: 18px;
  padding: 14px;
  border: 1px solid rgba(148, 163, 184, 0.12);
  background: rgba(17, 25, 38, 0.9);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.root-key-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: flex-start;
}

.root-key-head h3 {
  margin: 0;
  font-size: 16px;
  line-height: 1.3;
}

.root-key-subtitle {
  margin: 0;
  font-family: var(--font-mono);
  color: var(--soft-text);
  font-size: 12px;
}

.root-key-note {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  min-height: 38px;
}

.root-key-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 2px;
}

.key-overview {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  gap: 16px;
}

.key-overview-card {
  border-radius: 18px;
  border: 1px solid rgba(148, 163, 184, 0.12);
  background: rgba(17, 25, 38, 0.9);
  padding: 16px;
}

.key-overview-head h2 {
  margin: 4px 0 0;
  font-size: 22px;
}

.key-profile-form {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}

.key-profile-form label {
  display: grid;
  gap: 6px;
}

.key-profile-form label > span {
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--soft-text);
}

.key-note-input {
  min-height: 180px;
  resize: vertical;
}

.key-profile-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.key-profile-hint {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.key-stats-grid {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.key-overview-meta {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.command-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(2, 6, 23, 0.72);
  display: grid;
  place-items: center;
  padding: 20px;
}

.command-modal-window {
  width: min(1000px, 100%);
  max-height: min(86vh, 900px);
  border-radius: 18px;
  background: rgba(9, 15, 23, 0.98);
  border: 1px solid rgba(148, 163, 184, 0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.command-modal-head {
  padding: 14px 16px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.14);
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.command-modal-title {
  margin: 0;
  font-size: 18px;
}

.command-modal-sections {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0;
  min-height: 0;
  flex: 1;
}

.command-modal-section {
  min-width: 0;
  border-right: 1px solid rgba(148, 163, 184, 0.12);
  display: flex;
  flex-direction: column;
}

.command-modal-section:last-child {
  border-right: 0;
}

.command-modal-label {
  margin: 0;
  padding: 12px 14px 8px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--soft-text);
}

.command-modal-code {
  margin: 0;
  padding: 0 14px 14px;
  font-family: var(--font-mono);
  white-space: pre-wrap;
  overflow: auto;
  line-height: 1.55;
  font-size: 12px;
  color: var(--soft-text);
  min-height: 0;
  flex: 1;
}

.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 12px 32px rgba(18, 18, 18, 0.08);
}

.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);
}

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

.assistant-markdown {
  line-height: 1.68;
  color: var(--text);
}

.assistant-markdown > :first-child {
  margin-top: 0;
}

.assistant-markdown > :last-child {
  margin-bottom: 0;
}

.assistant-markdown p,
.assistant-markdown ul,
.assistant-markdown ol {
  margin: 0 0 12px;
}

.assistant-markdown ul,
.assistant-markdown ol {
  padding-left: 20px;
}

.assistant-markdown code {
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 1px 6px;
  border-radius: 6px;
  background: rgba(148, 163, 184, 0.14);
}

.assistant-markdown .md-code {
  margin: 0 0 14px;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(7, 16, 24, 0.88);
  border: 1px solid rgba(148, 163, 184, 0.16);
  overflow-x: auto;
}

.assistant-markdown .md-code code {
  background: transparent;
  padding: 0;
  border-radius: 0;
  display: block;
  line-height: 1.55;
}

.assistant-markdown .md-link {
  color: #67e8f9;
  text-decoration: none;
  border-bottom: 1px dashed rgba(103, 232, 249, 0.45);
}

.assistant-markdown .md-link:hover {
  border-bottom-color: rgba(103, 232, 249, 0.9);
}

.assistant-markdown .md-h1,
.assistant-markdown .md-h2,
.assistant-markdown .md-h3 {
  margin: 4px 0 10px;
  line-height: 1.3;
  letter-spacing: 0.01em;
}

.assistant-markdown .md-h1 {
  font-size: 20px;
}

.assistant-markdown .md-h2 {
  font-size: 18px;
}

.assistant-markdown .md-h3 {
  font-size: 16px;
}

.thinking-card {
  width: min(72ch, 100%);
  padding: 12px 16px;
  color: var(--soft-text);
  background: rgba(24, 35, 51, 0.84);
  line-height: 1.55;
  white-space: pre-wrap;
}

.tool-card {
  width: min(82ch, 100%);
  overflow: hidden;
  border: 1px solid rgba(148, 163, 184, 0.12);
  background: rgba(17, 25, 38, 0.92);
}

.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(24, 35, 51, 0.84);
}

.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(17, 25, 38, 0.92);
  border: 1px solid rgba(148, 163, 184, 0.12);
}

.hidden {
  display: none !important;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(460px, 100%);
  border-radius: 28px;
  background:
    linear-gradient(180deg, rgba(45, 212, 191, 0.08), rgba(45, 212, 191, 0)),
    rgba(15, 23, 36, 0.92);
  box-shadow: var(--shadow);
  border: 1px solid rgba(148, 163, 184, 0.14);
  padding: 28px;
}

.login-title {
  margin: 0 0 8px;
  font-size: 34px;
}

.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 rgba(148, 163, 184, 0.18);
  background: rgba(7, 16, 24, 0.92);
  color: var(--text);
  border-radius: 14px;
  padding: 14px 16px;
}

.submit-button {
  margin-top: 10px;
  border: 0;
  border-radius: 14px;
  padding: 14px 16px;
  background: linear-gradient(135deg, #14b8a6 0%, #0f766e 100%);
  color: #ecfeff;
  cursor: pointer;
}

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

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

  .shell {
    flex-direction: column;
    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;
  }

  .root-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .key-overview {
    grid-template-columns: 1fr;
  }

  .command-modal-sections {
    grid-template-columns: 1fr;
  }

  .command-modal-section {
    border-right: 0;
    border-bottom: 1px solid rgba(148, 163, 184, 0.12);
  }

  .command-modal-section:last-child {
    border-bottom: 0;
  }

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