:root {
  color-scheme: light;
  --bg: #f5f8f7;
  --sidebar-bg: #ecf2f0;
  --surface: #ffffff;
  --surface-alt: #e4edea;
  --hairline: rgba(15, 29, 28, 0.1);
  --hairline-strong: rgba(15, 29, 28, 0.2);
  --ink: #0f1d1c;
  --muted: #526664;
  --accent: #0f766e;
  --accent-hover: #0d5e58;
  --accent-soft: rgba(15, 118, 110, 0.08);
  --on-accent: #ffffff;
  --ok: #0f766e;
  --ok-bg: #e4f4f2;
  --ok-border: rgba(15, 118, 110, 0.25);
  --warn: #9a4a00;
  --warn-bg: #fef3eb;
  --warn-border: rgba(154, 74, 0, 0.25);
  --radius: 8px;
  --font-sans: "Space Grotesk", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0c1312;
  --sidebar-bg: #101918;
  --surface: #152120;
  --surface-alt: #1d2d2b;
  --hairline: rgba(232, 243, 241, 0.1);
  --hairline-strong: rgba(232, 243, 241, 0.2);
  --ink: #e8f3f1;
  --muted: #8fa6a3;
  --accent: #14b8a6;
  --accent-hover: #0d9488;
  --accent-soft: rgba(20, 184, 166, 0.14);
  --on-accent: #05201e;
  --ok: #2dd4bf;
  --ok-bg: rgba(20, 184, 166, 0.14);
  --ok-border: rgba(45, 212, 191, 0.3);
  --warn: #fbbf24;
  --warn-bg: rgba(251, 191, 36, 0.14);
  --warn-border: rgba(251, 191, 36, 0.3);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.layout {
  height: 100dvh;
  display: flex;
  overflow: hidden;
}

/* Left Sidebar */
.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--hairline);
  display: flex;
  flex-direction: column;
  padding: 12px;
  gap: 10px;
  transition: width 0.18s ease, padding 0.18s ease;
}

.sidebar.collapsed {
  width: 0;
  padding: 0;
  border-right: none;
  overflow: hidden;
}

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 30px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-dot {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: var(--accent);
}

.brand-name {
  font-weight: 700;
  font-size: 14px;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.icon-btn {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--hairline);
  background: var(--surface);
  color: var(--ink);
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}

.icon-btn:hover {
  border-color: var(--ink);
}

.new-chat-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--hairline-strong);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.new-chat-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.side-nav-btn {
  text-align: left;
  padding: 6px 10px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.side-nav-btn:hover {
  background: rgba(15, 118, 110, 0.08);
  color: var(--ink);
}

.side-nav-btn.active {
  background: var(--surface);
  color: var(--accent);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(15, 29, 28, 0.06);
}

.side-search-wrap {
  margin-top: 2px;
}

.side-search {
  width: 100%;
  padding: 6px 9px;
  border-radius: 6px;
  border: 1px solid var(--hairline);
  background: var(--surface);
  font-family: var(--font-sans);
  font-size: 12px;
  color: var(--ink);
}

.side-search:focus {
  outline: none;
  border-color: var(--accent);
}

.side-section-label {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--muted);
  text-transform: uppercase;
  padding: 4px 4px 0;
}

.chat-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 7px 9px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--ink);
  font-size: 12.5px;
}

.chat-item:hover {
  background: rgba(15, 118, 110, 0.08);
}

.chat-item.active {
  background: var(--ok-bg);
  color: var(--accent);
  font-weight: 600;
}

.chat-item-title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-rename-input {
  flex: 1;
  min-width: 0;
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: 4px;
  padding: 1px 5px;
  outline: none;
}

.chat-del-btn {
  opacity: 0;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0 3px;
}

.chat-item:hover .chat-del-btn {
  opacity: 1;
}

.chat-del-btn:hover {
  color: var(--warn);
}

.chat-empty-hint {
  font-size: 12px;
  color: var(--muted);
  padding: 8px 4px;
}

/* Main Column */
.main-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  position: relative;
}

.topbar {
  height: 54px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 18px;
  background: var(--bg);
}

.top-left,
.top-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pill {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--ok-bg);
  color: var(--ok);
  border: 1px solid rgba(15, 118, 110, 0.25);
}

.model-pill {
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 11px;
  border-radius: var(--radius);
  border: 1px solid var(--hairline-strong);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}

.model-pill:hover {
  border-color: var(--ink);
}

.model-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #b0b4bd;
  z-index: 1;
}

.model-pill.ready .model-dot {
  background: var(--ok);
}

.model-pill.loading .model-dot {
  background: var(--accent);
}

.model-pill span {
  z-index: 1;
}

.caret {
  font-size: 10px;
  color: var(--muted);
}

.pill-progress {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0%;
  background: rgba(15, 118, 110, 0.14);
  z-index: 0 !important;
  transition: width 0.15s ease;
}

.btn-icon,
.btn {
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 12.5px;
  padding: 6px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--hairline-strong);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}

.btn-icon-sq {
  width: 32px;
  height: 32px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.send-icon-btn {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.btn-icon:hover,
.btn:hover:not(:disabled) {
  border-color: var(--ink);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-ghost {
  background: var(--surface-alt);
  border-color: var(--hairline);
}

.btn-sm {
  font-size: 11.5px;
  padding: 5px 10px;
}

.btn-lg {
  font-size: 14px;
  padding: 10px 20px;
}

/* Popover Model Picker */
.popover {
  position: absolute;
  top: 58px;
  right: 18px;
  width: min(360px, calc(100vw - 24px));
  background: var(--surface);
  border: 1px solid var(--hairline-strong);
  border-radius: 10px;
  box-shadow: 0 16px 40px rgba(15, 29, 28, 0.12);
  padding: 12px;
  z-index: 40;
}

.popover-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 10px;
}

.popover-title {
  font-size: 13.5px;
  font-weight: 700;
}

.popover-sub {
  font-size: 11.5px;
  color: var(--muted);
}

.kbd-hint {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--muted);
  border: 1px solid var(--hairline);
  padding: 2px 5px;
  border-radius: 4px;
}

.popover-search {
  width: 100%;
  padding: 6px 9px;
  margin-bottom: 8px;
  border-radius: 6px;
  border: 1px solid var(--hairline);
  background: var(--bg);
  font-family: var(--font-sans);
  font-size: 12px;
  color: var(--ink);
}

.popover-search:focus {
  outline: none;
  border-color: var(--accent);
}

.popover-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 360px;
  overflow-y: auto;
  padding-right: 2px;
}

.popover-empty {
  padding: 14px 10px;
  text-align: center;
  border: 1px dashed var(--hairline-strong);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  font-size: 12.5px;
  color: var(--muted);
}

.popover-section-label {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 4px 2px 0;
}

.score-tag {
  color: var(--accent);
  font-weight: 600;
}

.pop-item {
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 10px;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.pop-item.active {
  border-color: var(--ok);
  background: var(--ok-bg);
}

.pop-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.pop-title {
  font-size: 13.5px;
  font-weight: 700;
}

.pop-human {
  font-size: 12px;
  color: var(--muted);
}

.pop-tech {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--muted);
}

.badge {
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--hairline);
  background: var(--surface);
  white-space: nowrap;
}

.badge-rec {
  background: var(--ok-bg);
  color: var(--ok);
  border-color: var(--ok-border);
}

.badge-cloud {
  background: var(--warn-bg);
  color: var(--warn);
  border-color: var(--warn-border);
}

.pop-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
}

/* Main Stage */
.stage {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.chat-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.chat-stage.is-empty {
  justify-content: center;
}

.chat-stage.is-empty .chat-log {
  flex: 0 0 auto;
  padding-bottom: 12px;
}

.chat-log {
  flex: 1;
  width: 100%;
  max-width: 760px;
  overflow-y: auto;
  padding: 16px 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.welcome-card {
  margin: auto;
  text-align: center;
  max-width: 540px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.welcome-card h1 {
  font-size: clamp(24px, 3vw, 28px);
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin-bottom: 6px;
}

.welcome-sub {
  font-size: 14.5px;
  color: var(--muted);
  max-width: 460px;
}

.welcome-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  margin-top: 4px;
}

.welcome-note {
  font-size: 12px;
  color: var(--muted);
}

.inline-progress {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 12px 14px;
  text-align: left;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 500;
  margin-bottom: 6px;
}

.progress-meta span:last-child {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.progress-track {
  height: 6px;
  border-radius: 999px;
  background: var(--surface-alt);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.15s ease;
}

.starter-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 12px;
}

.chip {
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 500;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  color: var(--ink);
  cursor: pointer;
}

.chip:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.chip.active {
  border-color: var(--accent);
  background: var(--accent-soft, rgba(15, 118, 110, 0.08));
  color: var(--accent);
}

.chip:disabled {
  opacity: 0.7;
  cursor: default;
}

.chip-sub {
  margin-left: 6px;
  font-size: 11px;
  font-weight: 400;
  color: var(--muted);
}

.chip.active .chip-sub {
  color: var(--accent);
}

.msg {
  max-width: 85%;
  padding: 11px 14px;
  border-radius: 10px;
  font-size: 14px;
  line-height: 1.55;
  word-break: break-word;
}

.msg-user {
  align-self: flex-end;
  background: var(--accent);
  color: var(--on-accent);
  white-space: pre-wrap;
}

.msg-assistant {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--hairline);
}

.msg-body p + p {
  margin-top: 8px;
}

.msg-body ul {
  margin: 6px 0 6px 18px;
}

.msg-body code {
  font-family: var(--font-mono);
  font-size: 12.5px;
  background: var(--surface-alt);
  padding: 1px 5px;
  border-radius: 4px;
}

.code-wrap {
  margin: 8px 0;
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  overflow: hidden;
  background: #141c1b;
  color: #f5f8f7;
}

.code-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 10px;
  background: #1d2726;
  font-family: var(--font-mono);
  font-size: 10px;
  color: #9db5b2;
}

.copy-code-btn {
  font-family: var(--font-mono);
  font-size: 10px;
  background: transparent;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  padding: 2px 7px;
  cursor: pointer;
}

.code-wrap pre {
  padding: 10px 12px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
}

.code-wrap pre code {
  background: transparent;
  padding: 0;
  color: inherit;
}

.msg-telemetry {
  margin-top: 7px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  background: transparent;
  border: none;
  padding: 0;
  text-align: left;
  cursor: pointer;
  display: inline-block;
}

.msg-telemetry:hover {
  color: var(--accent);
}

/* Composer */
.composer-wrap {
  width: 100%;
  max-width: 760px;
  padding: 0 18px 18px;
  flex-shrink: 0;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--hairline-strong);
  border-radius: 24px;
  padding: 10px 14px;
  box-shadow: 0 4px 18px rgba(15, 29, 28, 0.06);
}

.composer:focus-within {
  border-color: var(--accent);
}

.composer textarea {
  flex: 1;
  border: none;
  background: transparent;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.45;
  resize: none;
  max-height: 140px;
  padding: 4px 2px;
  color: var(--ink);
}

.composer textarea:focus {
  outline: none;
}

.composer-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Media Stage */
.media-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 18px;
}

.media-card {
  width: 100%;
  max-width: 820px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.media-grid {
  width: 100%;
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  text-align: left;
}

.media-tier {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 10px;
}

/* Inspector Slide-Over */
.inspector {
  position: fixed;
  top: 54px;
  right: 0;
  bottom: 0;
  width: min(330px, 100vw);
  background: var(--surface);
  border-left: 1px solid var(--hairline-strong);
  box-shadow: -12px 0 36px rgba(15, 29, 28, 0.1);
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  z-index: 45;
}

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

.inspector-title {
  font-size: 15px;
  font-weight: 700;
}

.inspector-sub {
  font-size: 11.5px;
  color: var(--muted);
}

.ins-section {
  border-top: 1px solid var(--hairline);
  padding-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.ins-kicker {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.06em;
  margin-bottom: 2px;
}

.theme-segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
  padding: 3px;
  background: var(--surface-alt);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
}

.theme-opt {
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.theme-opt:hover {
  color: var(--ink);
}

.theme-opt.active {
  background: var(--surface);
  border-color: var(--hairline);
  color: var(--accent);
  font-weight: 600;
}

.ins-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  font-size: 12px;
}

.ins-row span {
  color: var(--muted);
  flex-shrink: 0;
}

.ins-row strong {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mono-wrap {
  word-break: break-all;
}

.ins-btn-row {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.state-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #b0b4bd;
  margin-right: 6px;
}

.state-dot.active {
  background: var(--accent);
  animation: pulse 0.9s infinite alternate;
}

@keyframes pulse {
  from { opacity: 0.45; }
  to { opacity: 1; }
}

.slider-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 4px;
  font-size: 12px;
}

.slider-head {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
}

.slider-head strong {
  font-family: var(--font-mono);
  color: var(--ink);
}

.slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: var(--surface-alt);
  border-radius: 999px;
  outline: none;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 29, 28, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 60;
}

.modal-card {
  background: var(--surface);
  border: 1px solid var(--hairline-strong);
  border-radius: 10px;
  max-width: 440px;
  width: 100%;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-body {
  font-size: 13.5px;
  color: var(--muted);
}

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.hidden {
  display: none !important;
}

@media (max-width: 760px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 50;
    box-shadow: 8px 0 28px rgba(15, 29, 28, 0.14);
  }
  .media-grid {
    grid-template-columns: 1fr;
  }
}
