:root {
  --bg: #d8d8d1;
  --panel: #efefe8;
  --panel-border: rgba(15, 15, 15, 0.08);
  --rail: #111111;
  --rail-soft: #1c1c1c;
  --rail-border: rgba(255, 255, 255, 0.1);
  --text: #141414;
  --muted: #66645e;
  --soft-text: #4d4b46;
  --user-bg: #0c0c0c;
  --user-text: #f5f5f0;
  --assistant-bg: #f7f6ef;
  --tool-bg: #e6e2d8;
  --tool-line: rgba(17, 17, 17, 0.14);
  --accent: #0f766e;
  --danger: #9f1239;
  --shadow: 0 24px 60px rgba(17, 17, 17, 0.1);
  --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(255, 255, 255, 0.52), transparent 34%),
    linear-gradient(180deg, #e4e1d8 0%, #d6d2c8 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.04), transparent 28%),
    linear-gradient(180deg, #0e0e0e 0%, #151515 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(255, 255, 255, 0.44);
  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 rgba(20, 20, 20, 0.16);
  border-radius: 12px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.6);
  color: var(--text);
  cursor: pointer;
}

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

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

.command-panel {
  border-radius: 22px;
  padding: 18px;
  margin-bottom: 18px;
  background:
    linear-gradient(180deg, rgba(12, 12, 12, 0.04), rgba(12, 12, 12, 0)),
    rgba(255, 255, 255, 0.56);
  border: 1px solid rgba(17, 17, 17, 0.08);
}

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

.command-eyebrow {
  color: rgba(20, 20, 20, 0.48);
}

.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(17, 17, 17, 0.12);
  background: rgba(255, 255, 255, 0.82);
  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(15, 118, 110, 0.08);
  color: #115e59;
}

.command-status.success {
  background: rgba(21, 128, 61, 0.09);
  color: #166534;
}

.command-status.error {
  background: rgba(159, 18, 57, 0.1);
  color: #9f1239;
}

.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(247, 246, 239, 0.84);
  border: 1px solid rgba(17, 17, 17, 0.08);
}

.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(17, 17, 17, 0.12);
  color: var(--soft-text);
}

.command-pill.pending {
  color: #9a3412;
  border-color: rgba(154, 52, 18, 0.24);
  background: rgba(154, 52, 18, 0.08);
}

.command-pill.dispatched {
  color: #1d4ed8;
  border-color: rgba(29, 78, 216, 0.22);
  background: rgba(29, 78, 216, 0.08);
}

.command-pill.completed {
  color: #166534;
  border-color: rgba(22, 101, 52, 0.22);
  background: rgba(22, 101, 52, 0.08);
}

.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(17, 17, 17, 0.08);
  color: #3f3b34;
}

.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.52), rgba(255, 255, 255, 0.22)),
    var(--panel);
  border: 1px solid rgba(17, 17, 17, 0.08);
  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 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);
  line-height: 1.65;
  white-space: pre-wrap;
}

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

.thinking-card {
  width: min(72ch, 100%);
  padding: 12px 16px;
  color: #55524a;
  background: rgba(85, 82, 74, 0.08);
  line-height: 1.55;
  white-space: pre-wrap;
}

.tool-card {
  width: min(82ch, 100%);
  overflow: hidden;
  border: 1px solid rgba(17, 17, 17, 0.08);
  background: rgba(245, 243, 235, 0.78);
}

.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(85, 82, 74, 0.08);
}

.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(245, 243, 235, 0.78);
  border: 1px solid rgba(17, 17, 17, 0.08);
}

.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: rgba(255, 255, 255, 0.72);
  box-shadow: var(--shadow);
  border: 1px solid rgba(17, 17, 17, 0.08);
  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(17, 17, 17, 0.12);
  background: rgba(255, 255, 255, 0.78);
  color: var(--text);
  border-radius: 14px;
  padding: 14px 16px;
}

.submit-button {
  margin-top: 10px;
  border: 0;
  border-radius: 14px;
  padding: 14px 16px;
  background: #141414;
  color: #faf9f4;
  cursor: pointer;
}

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