:root {
  --bg: #f4efe6;
  --surface: rgba(255, 251, 245, 0.82);
  --surface-strong: #fffaf2;
  --ink: #251c15;
  --muted: #706357;
  --line: rgba(54, 39, 24, 0.12);
  --accent: #0a6c74;
  --accent-strong: #09474d;
  --warm: #bf6c2c;
  --danger: #9f3a2f;
  --success: #2f7a47;
  --shadow: 0 20px 60px rgba(37, 28, 21, 0.12);
  --radius-lg: 28px;
  --radius-md: 18px;
  --radius-sm: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  min-height: 100%;
  font-family: "General Sans", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(10,108,116,0.12), transparent 28%),
    radial-gradient(circle at bottom right, rgba(191,108,44,0.14), transparent 24%),
    var(--bg);
  overflow: hidden;
}
button, input, textarea { font: inherit; }

.shell {
  height: 100dvh;
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 18px;
  padding: 18px;
  overflow: hidden;
}

.panel {
  background: var(--surface);
  backdrop-filter: blur(16px);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.sidebar {
  min-height: 0;
  height: 100%;
  padding: 22px;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 18px;
  align-content: stretch;
  overflow: hidden;
}

.sidebar > section:nth-of-type(2) {
  min-height: 0;
  overflow: auto;
  padding-right: 4px;
}

.workspace {
  min-height: 0;
  height: 100%;
  padding: 22px;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  gap: 16px;
  overflow: hidden;
}

.workspace-header,
.sources-header,
.composer-actions,
.actions,
.toggle-row,
.field.two-up {
  display: flex;
  align-items: center;
  gap: 10px;
}

.workspace-header,
.sources-header {
  justify-content: space-between;
}

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

.compact { gap: 10px; }

.eyebrow {
  margin: 0 0 8px;
  color: var(--warm);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.73rem;
  font-weight: 700;
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: 2rem; line-height: 0.95; }
h2 { font-size: 1.1rem; }
h3 { font-size: 0.95rem; }
.lede { margin-top: 10px; color: var(--muted); line-height: 1.5; }

.field {
  display: grid;
  gap: 6px;
}

.field.two-up > div,
.actions.two-up > button { flex: 1; }

label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
}

.field-hint {
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.4;
}

input,
select,
textarea,
.debug-log,
.chat-stream,
.inset {
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}

input,
select,
textarea {
  width: 100%;
  padding: 12px 14px;
  color: var(--ink);
}

textarea {
  min-height: 88px;
  max-height: 140px;
  resize: vertical;
}

button {
  border: none;
  border-radius: 999px;
  padding: 12px 16px;
  cursor: pointer;
  transition: transform 140ms ease, opacity 140ms ease, background 140ms ease;
}
button:hover { transform: translateY(-1px); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary { background: var(--accent); color: white; }
button.secondary { background: #d7c4aa; color: var(--ink); }
button.ghost { background: transparent; border: 1px solid var(--line); color: var(--ink); }

.toggle-row {
  justify-content: space-between;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-strong);
}
.toggle-row small { display: block; margin-top: 4px; color: var(--muted); }
.toggle-row input { width: 20px; height: 20px; }

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
  border-radius: 999px;
  font-weight: 700;
  width: fit-content;
}
.badge.idle { background: rgba(112,99,87,0.12); color: var(--muted); }
.badge.live { background: rgba(47,122,71,0.14); color: var(--success); }
.badge.error { background: rgba(159,58,47,0.14); color: var(--danger); }
.badge.busy { background: rgba(10,108,116,0.14); color: var(--accent); }

.debug-log {
  min-height: 120px;
  max-height: 180px;
  padding: 12px;
  overflow: auto;
  white-space: pre-wrap;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.chat-stream {
  min-height: 0;
  overflow: auto;
  padding: 18px;
  display: grid;
  gap: 14px;
}

.message {
  max-width: min(760px, 88%);
  padding: 14px 16px;
  border-radius: 20px;
  line-height: 1.55;
  white-space: pre-wrap;
  animation: rise 180ms ease;
}
.message.user {
  margin-left: auto;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: white;
}
.message.assistant {
  background: #fff7ee;
  border: 1px solid rgba(191,108,44,0.14);
}
.message.system {
  background: rgba(10,108,116,0.08);
  color: var(--accent-strong);
  max-width: 100%;
}
.message.thinking {
  background: rgba(191,108,44,0.10);
  color: var(--warm);
  border: 1px dashed rgba(191,108,44,0.35);
  font-style: italic;
}

.source-meta {
  color: var(--muted);
  font-size: 0.86rem;
}

.selection-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 44px;
  padding: 10px 12px;
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  color: var(--muted);
}

.selection-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 999px;
  background: rgba(10,108,116,0.10);
  color: var(--accent-strong);
  font-size: 0.78rem;
}

.selection-pill strong {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.composer {
  display: grid;
  gap: 10px;
  min-height: 0;
}
.composer-actions { justify-content: flex-end; }

.composer textarea {
  min-height: 84px;
  max-height: 120px;
}

.sources {
  padding: 16px;
  min-height: 0;
  max-height: 220px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}
.inset {
  background: rgba(255, 250, 244, 0.66);
}
.sources-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
  overflow: auto;
  min-height: 0;
}
.source-card {
  padding: 12px 14px;
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.source-card strong { display: block; margin-bottom: 4px; }
.source-card p { color: var(--muted); font-size: 0.88rem; line-height: 1.45; }

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

@media (max-width: 980px) {
  .shell {
    height: 100dvh;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(320px, 42vh) minmax(0, 1fr);
  }
  .sidebar,
  .workspace {
    height: 100%;
  }
  .sidebar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: minmax(0, 1fr) auto;
    gap: 12px;
  }
  .sidebar > div {
    display: none;
  }
  .sidebar > section:nth-of-type(1) {
    overflow: auto;
    min-height: 0;
  }
  .sidebar > section:nth-of-type(2) {
    display: grid;
    min-height: 0;
    overflow: auto;
  }
  .sidebar > section:nth-of-type(3) {
    grid-column: 1 / -1;
  }
  .workspace { grid-template-rows: auto minmax(240px, 1fr) auto auto; }
  .sources { max-height: 180px; }
}
