:root {
  --bg: #0d1211;
  --bg-soft: #121a18;
  --surface: rgba(18, 26, 23, 0.78);
  --surface-strong: rgba(23, 33, 29, 0.92);
  --surface-elevated: rgba(28, 40, 35, 0.94);
  --panel-glow: rgba(16, 185, 129, 0.18);
  --border: rgba(255, 255, 255, 0.12);
  --border-light: rgba(255, 255, 255, 0.08);
  --text: #e6efeb;
  --muted: #90a099;
  --accent: #10b981;
  --accent-strong: #34d399;
  --accent-soft: rgba(16, 185, 129, 0.14);
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
  --inset-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
  --record-bg: rgba(20, 29, 26, 0.9);
  --input-bg: rgba(18, 26, 23, 0.94);
  --btn-hover: rgba(36, 50, 44, 0.96);
  --img-bg: linear-gradient(135deg, rgba(16, 185, 129, 0.16), rgba(7, 89, 67, 0.1));
  --code-text: #a7f3d0;
  --reply-bg: rgba(16, 185, 129, 0.1);
  --preview-bg: rgba(16, 185, 129, 0.08);
  --log-good: #48d99e;
  --log-bad: #ff7d7d;
  --log-warn: #ffc857;
}

[data-theme="codex"] {
  --bg: #e6edf3;
  --bg-soft: #dde7ee;
  --surface: rgba(244, 249, 255, 0.84);
  --surface-strong: rgba(249, 252, 255, 0.94);
  --surface-elevated: rgba(232, 240, 248, 0.96);
  --panel-glow: rgba(54, 133, 202, 0.18);
  --border: rgba(18, 26, 34, 0.14);
  --border-light: rgba(18, 26, 34, 0.08);
  --text: #0f1720;
  --muted: #556575;
  --accent: #3685ca;
  --accent-strong: #12558f;
  --accent-soft: rgba(54, 133, 202, 0.12);
  --shadow: 0 24px 80px rgba(28, 48, 67, 0.16);
  --inset-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
  --record-bg: rgba(245, 249, 255, 0.96);
  --input-bg: rgba(247, 250, 255, 0.96);
  --btn-hover: rgba(227, 236, 245, 0.98);
  --img-bg: linear-gradient(135deg, rgba(166, 185, 201, 0.26), rgba(52, 88, 135, 0.15));
  --code-text: #1d2834;
  --reply-bg: rgba(54, 133, 202, 0.1);
  --preview-bg: rgba(54, 133, 202, 0.08);
  --log-good: #24613a;
  --log-bad: #9a3535;
  --log-warn: #8a5411;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--text);
  font-family: "Space Grotesk", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(16, 185, 129, 0.14), transparent 26%),
    radial-gradient(circle at 88% 8%, rgba(16, 185, 129, 0.1), transparent 22%),
    linear-gradient(160deg, var(--bg) 0%, var(--bg-soft) 100%);
  transition: background 0.35s ease, color 0.35s ease;
}

body[data-theme="codex"] {
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.9), transparent 26%),
    radial-gradient(circle at 88% 8%, rgba(54, 133, 202, 0.12), transparent 22%),
    linear-gradient(160deg, var(--bg) 0%, var(--bg-soft) 100%);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 16px;
  min-height: 44px;
  padding: 12px 16px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: transform 180ms ease, background-color 180ms ease, opacity 180ms ease, box-shadow 180ms ease;
}

button:hover {
  transform: translateY(-1px);
  background: var(--accent-strong);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.16);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.is-hidden {
  display: none !important;
}

button.ghost,
button.secondary {
  background: var(--input-bg);
  color: var(--text);
  box-shadow: var(--inset-shadow);
}

button.ghost:hover,
button.secondary:hover {
  background: var(--btn-hover);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--input-bg);
  color: var(--text);
}

textarea,
input,
select {
  outline: none;
}

textarea:focus,
input:focus,
select:focus,
.project-item:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.app-shell {
  min-height: 100vh;
  width: min(1540px, calc(100vw - 24px));
  margin: 0 auto;
  padding: 18px 0 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.app-topbar,
.chat-surface,
.sidebar-module {
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
}

.app-topbar {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.85fr);
  gap: 18px;
  padding: 24px 26px;
  border-radius: 28px;
  position: relative;
  overflow: hidden;
}

.app-topbar::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(120deg, transparent 0%, transparent 58%, var(--panel-glow) 100%);
  pointer-events: none;
}

.brand-block,
.status-tile,
.chat-surface,
.sidebar-module {
  animation: rise-in 280ms ease both;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--accent-strong);
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.brand-block h1,
.chat-header h2 {
  margin: 0;
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1.02;
  letter-spacing: -0.04em;
}

.chat-header h2 {
  font-size: 30px;
}

.hero-text,
.panel-note,
.hint,
.endpoint-note,
.snapshot-meta,
.text-head small,
.module-count {
  color: var(--muted);
  line-height: 1.6;
}

.hero-text {
  max-width: 720px;
  margin: 14px 0 0;
  font-size: 16px;
}

.hero-status {
  display: grid;
  gap: 12px;
  align-content: stretch;
}

.status-tile {
  padding: 16px 18px;
  border: 1px solid var(--border-light);
  border-radius: 18px;
  background: var(--surface-strong);
  box-shadow: var(--inset-shadow);
}

.status-tile .label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.workspace {
  min-height: 0;
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
}

.chat-panel,
.sidebar-panel,
.sidebar-stack {
  min-height: 0;
}

.chat-surface {
  min-height: calc(100vh - 190px);
  border-radius: 30px;
  padding: 22px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 18px;
}

.chat-header,
.panel-actions,
.text-head,
.module-head,
.module-title,
.field,
.snapshot-meta {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-header {
  justify-content: space-between;
  align-items: flex-start;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border-light);
}

.chat-header-copy {
  min-width: 0;
}

.chat-header h2 span {
  color: var(--accent-strong);
}

.panel-note {
  margin: 12px 0 0;
  max-width: 740px;
  font-size: 14px;
}

.panel-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.capture-feed {
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 14px;
  padding: 18px;
  border: 1px solid var(--border-light);
  border-radius: 24px;
  background: var(--surface-strong);
  box-shadow: var(--inset-shadow);
}

.text-head {
  justify-content: space-between;
}

.text-head span {
  display: block;
  font-weight: 700;
  font-size: 18px;
}

.network-capture-list {
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding-right: 4px;
}

.network-empty,
.network-record,
.snapshot-card,
.text-panel,
.project-item {
  border: 1px solid var(--border-light);
  border-radius: 18px;
  background: var(--record-bg);
}

.network-empty,
.network-record {
  padding: 14px;
}

.network-record.conversation {
  padding: 0;
  border: none;
  background: transparent;
}

.conversation-flow {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.conversation-bubble {
  max-width: 84%;
  padding: 14px 16px;
  border-radius: 18px;
  line-height: 1.6;
  word-break: break-word;
  white-space: pre-wrap;
}

.conversation-bubble.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.conversation-bubble.reply {
  align-self: flex-start;
  background: var(--reply-bg);
  border: 1px solid var(--border-light);
  border-bottom-left-radius: 4px;
}

.conversation-text {
  margin: 0;
}

.network-record-head,
.network-preview-grid {
  display: flex;
  gap: 12px;
}

.network-record-head {
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}

.badge,
.network-chip,
.network-label {
  color: var(--accent-strong);
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.network-status {
  color: var(--muted);
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
}

.network-line {
  margin: 8px 0 0;
  line-height: 1.45;
  word-break: break-word;
}

.network-line.subtle {
  color: var(--muted);
  font-size: 13px;
}

.network-preview-grid {
  margin-top: 12px;
  align-items: stretch;
}

.network-preview,
.network-frame {
  min-width: 0;
  flex: 1;
  padding: 12px;
  border-radius: 14px;
  background: var(--preview-bg);
}

.network-preview pre,
.network-frame p {
  margin: 8px 0 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  line-height: 1.55;
}

.network-frames {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.composer {
  position: sticky;
  bottom: 0;
}

.composer-card {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: var(--surface-elevated);
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.08), var(--inset-shadow);
}

.composer-im-layout {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.im-target-select {
  width: 112px;
  height: 52px;
  padding: 0 14px;
  flex-shrink: 0;
}

.im-input-wrapper {
  min-width: 0;
  flex: 1;
}

.im-input-wrapper textarea {
  min-height: 52px;
  max-height: 180px;
  resize: none;
  padding: 14px 16px;
  line-height: 1.5;
}

.im-send-button {
  min-width: 92px;
  height: 52px;
  flex-shrink: 0;
  border-radius: 18px;
  font-weight: 700;
}

.sidebar-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sidebar-module {
  border-radius: 24px;
  padding: 16px 18px;
  overflow: hidden;
}

.module-head {
  justify-content: space-between;
  align-items: flex-start;
}

.module-title {
  min-width: 0;
  align-items: flex-start;
}

.module-title h3 {
  margin: 0;
  font-size: 20px;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.module-count {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid var(--border-light);
  border-radius: 999px;
  background: var(--accent-soft);
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
}

.collapsible-header {
  cursor: pointer;
  user-select: none;
}

.chevron {
  color: var(--muted);
  flex-shrink: 0;
  transition: transform 0.24s ease;
}

.collapsible-section.collapsed .chevron {
  transform: rotate(-90deg);
}

.collapsible-body {
  display: grid;
  gap: 14px;
  margin-top: 16px;
  transition: opacity 0.24s ease, transform 0.24s ease, max-height 0.28s ease, margin-top 0.28s ease;
  max-height: 1600px;
  opacity: 1;
}

.collapsible-section.collapsed .collapsible-body {
  max-height: 0;
  opacity: 0;
  margin-top: 0;
  overflow: hidden;
  pointer-events: none;
  transform: translateY(-6px);
}

.snapshot-card,
.text-panel {
  padding: 14px;
}

.snapshot-card img {
  display: none;
  width: 100%;
  min-height: 180px;
  max-height: 280px;
  border-radius: 14px;
  object-fit: cover;
  background: var(--img-bg);
}

.snapshot-meta {
  flex-wrap: wrap;
  justify-content: space-between;
  margin-top: 12px;
  font-size: 12px;
}

.text-stack {
  display: grid;
  gap: 12px;
}

.text-panel pre {
  margin: 10px 0 0;
  min-height: 90px;
  max-height: 180px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--code-text);
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  line-height: 1.6;
}

.field {
  flex-wrap: wrap;
  align-items: center;
}

.field > span {
  font-weight: 700;
}

.field input[type="password"],
.field input[type="url"],
.field select,
.field input[type="range"] {
  margin-top: 8px;
}

.field input[type="password"],
.field input[type="url"],
.field select {
  padding: 13px 14px;
}

.field.checkbox {
  align-items: flex-start;
  justify-content: flex-start;
}

.field.checkbox input {
  width: auto;
  margin-top: 4px;
}

.field.disabled {
  opacity: 0.55;
}

.stacked-actions {
  justify-content: flex-start;
  flex-wrap: wrap;
}

.endpoint-note {
  display: block;
  word-break: break-all;
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
}

.project-list {
  display: grid;
  gap: 10px;
  max-height: 340px;
  overflow: auto;
}

.project-item {
  width: 100%;
  padding: 13px 14px;
  min-height: 0;
  display: grid;
  gap: 6px;
  text-align: left;
  color: var(--text);
  background: var(--record-bg);
  border-radius: 18px;
}

.project-item:hover {
  background: var(--btn-hover);
}

.project-item.current {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.project-name {
  font-weight: 700;
  font-size: 15px;
}

.project-path,
.project-empty {
  color: var(--muted);
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  line-height: 1.5;
  word-break: break-all;
}

.event-log {
  max-height: 280px;
  overflow: auto;
  display: flex;
  flex-direction: column;
}

.log-row {
  padding: 10px 0;
  border-bottom: 1px solid var(--border-light);
  font-size: 13px;
  color: var(--muted);
}

.log-row.good {
  color: var(--log-good);
}

.log-row.bad {
  color: var(--log-bad);
}

.log-row.warn {
  color: var(--log-warn);
}

@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1180px) {
  .app-shell {
    width: min(100vw - 18px, 1540px);
  }

  .app-topbar,
  .workspace {
    grid-template-columns: 1fr;
  }

  .chat-surface {
    min-height: auto;
  }
}

@media (max-width: 768px) {
  body {
    background:
      radial-gradient(circle at top left, rgba(16, 185, 129, 0.16), transparent 34%),
      linear-gradient(180deg, var(--bg) 0%, var(--bg-soft) 100%);
  }

  body[data-theme="codex"] {
    background:
      radial-gradient(circle at top left, rgba(255, 255, 255, 0.94), transparent 34%),
      linear-gradient(180deg, var(--bg) 0%, var(--bg-soft) 100%);
  }

  .app-shell {
    width: min(100vw - 10px, 1540px);
    padding: 10px 0 calc(10px + env(safe-area-inset-bottom, 0px));
    gap: 10px;
  }

  .app-topbar,
  .chat-surface,
  .sidebar-module {
    border-radius: 22px;
  }

  .app-topbar,
  .chat-surface {
    padding: 16px;
  }

  .brand-block h1,
  .chat-header h2 {
    font-size: 28px;
  }

  .hero-status {
    grid-auto-flow: column;
    grid-auto-columns: minmax(160px, 1fr);
    overflow-x: auto;
  }

  .chat-header,
  .module-head,
  .panel-actions,
  .composer-im-layout,
  .network-record-head,
  .network-preview-grid {
    flex-direction: column;
    align-items: stretch;
  }

  .capture-feed {
    padding: 14px;
  }

  .network-capture-list {
    max-height: 52vh;
  }

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

  .composer {
    bottom: calc(4px + env(safe-area-inset-bottom, 0px));
  }

  .composer-card {
    padding: 10px;
  }

  .im-target-select,
  .im-send-button {
    width: 100%;
  }

  .project-list,
  .event-log {
    max-height: 240px;
  }
}
