:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --ink: #1a1d23;
  --muted: #5c6570;
  --line: #e4e7ec;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --pill: #dcfce7;
  --pill-ink: #166534;
  --radius: 10px;
  --font: "Segoe UI", "IBM Plex Sans", "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: linear-gradient(165deg, #eef2f7 0%, var(--bg) 40%, #e8edf4 100%);
}

.app {
  min-height: 100%;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 650; letter-spacing: -0.02em; font-size: 1.05rem; }
.top-actions { display: flex; gap: 0.5rem; align-items: center; }

.subheader {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  padding: 0.55rem 1.25rem;
  font-size: 0.82rem;
  color: var(--muted);
  background: #fafbfc;
  border-bottom: 1px solid var(--line);
}
.pill {
  background: var(--pill);
  color: var(--pill-ink);
  padding: 0.1rem 0.55rem;
  border-radius: 999px;
  font-weight: 600;
}

.shell {
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr) 260px;
  min-height: 0;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 0.75rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.nav-item {
  text-align: left;
  border: 0;
  background: transparent;
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  cursor: pointer;
  color: var(--ink);
  font: inherit;
}
.nav-item:hover { background: #f1f4f8; }
.nav-item.active {
  background: #e8effc;
  color: #1e3a8a;
  font-weight: 600;
}

.main {
  padding: 1.25rem 1.5rem 2rem;
  overflow: auto;
}
.panel { display: none; }
.panel.active { display: block; }
h1 { margin: 0 0 0.5rem; font-size: 1.55rem; letter-spacing: -0.02em; }
.lede { color: var(--muted); max-width: 42rem; line-height: 1.45; }

.action-row { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 1rem 0 1.25rem; }

.chat-shell {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  position: relative;
}
.working-badge {
  position: absolute;
  top: 0.75rem;
  left: 1rem;
  background: #dbeafe;
  color: #1d4ed8;
  font-size: 0.75rem;
  font-weight: 650;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
}
.working-badge.hidden { display: none; }

.composer textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.75rem;
  font: inherit;
  resize: vertical;
  margin-top: 0.5rem;
}
.composer-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.65rem;
  align-items: center;
}
.chips { display: flex; gap: 0.4rem; flex-wrap: wrap; min-height: 1.5rem; }
.chip {
  background: #dbeafe;
  color: #1d4ed8;
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
  font-size: 0.8rem;
  display: inline-flex;
  gap: 0.35rem;
  align-items: center;
}
.chip button {
  border: 0;
  background: transparent;
  cursor: pointer;
  color: inherit;
  font-size: 0.9rem;
  line-height: 1;
}

.transcript {
  max-height: 280px;
  overflow: auto;
  margin-bottom: 0.75rem;
  display: grid;
  gap: 0.55rem;
}
.bubble {
  padding: 0.65rem 0.8rem;
  border-radius: 10px;
  font-size: 0.92rem;
  line-height: 1.4;
  white-space: pre-wrap;
}
.bubble.user { background: #eff6ff; border: 1px solid #bfdbfe; }
.bubble.assistant { background: #f8fafc; border: 1px solid var(--line); }
.bubble.meta { font-size: 0.78rem; color: var(--muted); border-style: dashed; }
#error-banner {
  display: none;
  margin: 0.5rem 0 0;
  padding: 0.5rem 0.75rem;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
  border-radius: 8px;
  font-size: 0.85rem;
}
#error-banner.visible { display: block; }

.context {
  background: var(--surface);
  border-left: 1px solid var(--line);
  padding: 1rem 1.1rem;
}
.context h2 { margin: 0 0 0.85rem; font-size: 1rem; }
.context dl { margin: 0; display: grid; gap: 0.65rem; }
.context dl > div { display: grid; gap: 0.1rem; }
.context dt { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.context dd { margin: 0; font-size: 0.9rem; }

.statusbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  padding: 0.45rem 1.25rem;
  font-size: 0.75rem;
  color: var(--muted);
  background: var(--surface);
  border-top: 1px solid var(--line);
}

button.primary, button.secondary, button.ghost, button.icon, select {
  font: inherit;
}
button.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border: 0;
  border-radius: 8px;
  padding: 0.45rem 0.9rem;
  cursor: pointer;
  font-weight: 600;
}
button.secondary {
  background: #eef2ff;
  color: #1e3a8a;
  border: 1px solid #c7d2fe;
  border-radius: 8px;
  padding: 0.4rem 0.75rem;
  cursor: pointer;
}
button.ghost {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.35rem 0.7rem;
  cursor: pointer;
  color: var(--ink);
}
button.icon {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  width: 2.2rem;
  height: 2.2rem;
  cursor: pointer;
}
select {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.35rem 0.5rem;
  background: var(--surface);
}
.code {
  background: #0f172a;
  color: #e2e8f0;
  padding: 1rem;
  border-radius: 8px;
  overflow: auto;
  font-size: 0.78rem;
}

@media (max-width: 960px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .context { border-left: 0; border-top: 1px solid var(--line); }
}
