:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef2f6;
  --text: #18212f;
  --muted: #607086;
  --line: #d9e0ea;
  --accent: #126b5c;
  --accent-2: #e2f4ef;
  --danger: #a73535;
  --shadow: 0 18px 45px rgba(23, 38, 59, 0.12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

button, input, textarea { font: inherit; }

button {
  border: 0;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  min-height: 36px;
  padding: 0 14px;
  border-radius: 4px;
}

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

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}

.btn-ghost:hover { background: var(--surface-2); }

.hidden { display: none !important; }

/* ── Login screen ─────────────────────────────────────── */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  border-radius: 16px;
  padding: 48px 40px 40px;
  width: min(420px, 100%);
}

.login-brand {
  text-align: center;
  margin-bottom: 32px;
}

.login-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 28px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
}

.login-brand h1 {
  font-size: 28px;
  font-weight: 700;
  margin: 0 0 6px;
}

.login-brand p {
  color: var(--muted);
  font-size: 15px;
  margin: 0;
}

.login-form {
  display: grid;
  gap: 16px;
}

.login-form label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}

.login-form input {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  padding: 10px 12px;
  border-radius: 6px;
  outline: none;
  font-size: 15px;
}

.login-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(18, 107, 92, 0.12);
}

.login-url-label { font-size: 12px; }

.login-url-label input { font-size: 13px; }

.login-form button[type="submit"] {
  width: 100%;
  min-height: 44px;
  font-size: 15px;
  font-weight: 600;
  border-radius: 8px;
  margin-top: 4px;
}

.login-error {
  min-height: 18px;
  color: var(--danger);
  font-size: 13px;
  text-align: center;
  margin: 0;
}

/* ── App shell ────────────────────────────────────────── */
.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 20px;
  width: min(1200px, calc(100vw - 32px));
  height: calc(100vh - 32px);
  margin: 16px auto;
}

.chat-pane, .side-pane { min-height: 0; }

.chat-pane {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  border-radius: 8px;
  overflow: hidden;
}

/* ── Topbar ───────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.stream-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.stream-toggle input { width: auto; cursor: pointer; }

h1, h2, p { margin: 0; }

h1 { font-size: 18px; font-weight: 700; }

h2 {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.topbar p {
  color: var(--muted);
  font-size: 13px;
  margin-top: 2px;
}

/* ── Messages ─────────────────────────────────────────── */
.messages {
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message {
  max-width: min(680px, 86%);
  padding: 12px 14px;
  border: 1px solid var(--line);
  white-space: pre-wrap;
  line-height: 1.5;
  border-radius: 6px;
  font-size: 15px;
}

.message.user {
  align-self: flex-end;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.message.assistant {
  align-self: flex-start;
  background: var(--surface-2);
}

.message.error {
  align-self: center;
  color: var(--danger);
  background: #fff2f2;
  border-color: #f1c4c4;
  font-size: 13px;
}

/* ── Composer ─────────────────────────────────────────── */
.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 16px;
  border-top: 1px solid var(--line);
}

textarea, input[type="text"], input[type="url"], input[type="number"] {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  padding: 8px 10px;
  outline: none;
  border-radius: 4px;
}

textarea:focus, input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(18, 107, 92, 0.12);
}

textarea {
  resize: vertical;
  min-height: 48px;
  max-height: 150px;
}

/* ── Side pane ────────────────────────────────────────── */
.side-pane {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 16px;
  border-radius: 8px;
  flex-shrink: 0;
}

.panel label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.status { color: var(--muted); font-size: 12px; }
.status.error { color: var(--danger); }

/* ── Session info ─────────────────────────────────────── */
.session-info {
  margin: 10px 0 0;
  display: grid;
  gap: 6px;
}

.session-info div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 6px;
  font-size: 13px;
}

.session-info dt { color: var(--muted); }

.session-info dd {
  margin: 0;
  text-align: right;
  overflow-wrap: anywhere;
  font-weight: 500;
}

/* ── Metadata ─────────────────────────────────────────── */
.metadata {
  margin: 10px 0 0;
  display: grid;
  gap: 6px;
}

.metadata div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 6px;
  font-size: 13px;
}

.metadata dt { color: var(--muted); }

.metadata dd {
  margin: 0;
  text-align: right;
  overflow-wrap: anywhere;
}

/* ── Memories ─────────────────────────────────────────── */
.memories-panel {
  flex: 1;
  min-height: 120px;
  display: flex;
  flex-direction: column;
}

.memories {
  margin-top: 12px;
  overflow-y: auto;
  display: grid;
  gap: 8px;
}

.memory {
  background: var(--accent-2);
  border: 1px solid #b9ded5;
  padding: 10px;
  font-size: 13px;
  line-height: 1.4;
  border-radius: 4px;
}

.memory-score {
  display: inline-block;
  margin-left: 6px;
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.empty { color: var(--muted); font-size: 13px; }

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
  }
  .chat-pane { min-height: 70vh; }
  .side-pane { overflow-y: unset; }
}
