:root {
  --bg: #1a1f16;
  --bg2: #242b1e;
  --ink: #e8edd9;
  --muted: #9aa68a;
  --accent: #c4e07a;
  --danger: #e8876a;
  --user: #2f3a28;
  --bot: #1e2620;
  --radius: 14px;
  font-family: "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 600px at 10% -10%, #2d3a24 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #3a2f1c 0%, transparent 50%),
    var(--bg);
  color: var(--ink);
}

#app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 12px 12px calc(12px + env(safe-area-inset-bottom));
}

.top {
  padding: 8px 4px 16px;
}

.brand {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.sub {
  color: var(--muted);
  font-size: 0.85rem;
}

.panel {
  background: color-mix(in srgb, var(--bg2) 88%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 18%, transparent);
  border-radius: var(--radius);
  padding: 16px;
}

.hint { color: var(--muted); font-size: 0.9rem; }

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 14px 0;
}

.field span { font-size: 0.8rem; color: var(--muted); }

input, textarea, button {
  font: inherit;
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--ink) 18%, transparent);
  background: var(--bg);
  color: var(--ink);
  padding: 12px 14px;
}

button {
  background: var(--accent);
  color: #152010;
  font-weight: 650;
  border: none;
  cursor: pointer;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.error { color: var(--danger); font-size: 0.9rem; }

.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px 2px 12px;
}

.bubble {
  max-width: 92%;
  padding: 10px 12px;
  border-radius: 14px;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.35;
  font-size: 0.95rem;
}

.bubble.user {
  align-self: flex-end;
  background: var(--user);
}

.bubble.assistant {
  align-self: flex-start;
  background: var(--bot);
  border: 1px solid color-mix(in srgb, var(--accent) 12%, transparent);
}

.bubble.meta {
  align-self: center;
  color: var(--muted);
  font-size: 0.8rem;
  background: transparent;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: end;
}

.composer textarea {
  resize: none;
  min-height: 52px;
}

.status {
  min-height: 1.2em;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

code {
  font-size: 0.85em;
  color: var(--accent);
}

.links {
  margin-top: 12px;
  font-size: 0.85rem;
}

.links a {
  color: var(--accent);
}

.shell {
  flex: 1;
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 10px;
  min-height: 0;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}

.session-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.session-item {
  text-align: left;
  background: var(--bg2);
  color: var(--ink);
  font-size: 0.8rem;
  padding: 8px 10px;
}

.session-item.active {
  outline: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
  background: color-mix(in srgb, var(--accent) 18%, var(--bg2));
}

button.secondary {
  background: color-mix(in srgb, var(--accent) 70%, #fff);
}

button.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid color-mix(in srgb, var(--ink) 14%, transparent);
  font-weight: 500;
  font-size: 0.8rem;
}

.meta-line {
  color: var(--muted);
  font-size: 0.9rem;
}

@media (max-width: 520px) {
  .shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .sidebar {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }
  .session-list {
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    width: 100%;
  }
  .session-item {
    white-space: nowrap;
  }
}
