:root {
  --bg: #121016;
  --panel: #1b1820;
  --panel-2: #241f2b;
  --text: #eee9f3;
  --muted: #a49cae;
  --accent: #e0789a;
  --accent-2: #f3a6bf;
  --border: #322b3a;
  --error: #ff8080;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }

button {
  background: var(--accent);
  color: #1a0f14;
  border: 0;
  border-radius: 10px;
  padding: 8px 14px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
button:hover { background: var(--accent-2); }
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); font-weight: 500; }
button.ghost:hover { color: var(--text); border-color: var(--muted); }
button:disabled { opacity: .5; cursor: default; }

input, select, textarea {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  font: inherit;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.muted { color: var(--muted); }
.error { color: var(--error); min-height: 1.2em; margin: 0; }

/* Centered card screens */
.card-screen { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  width: min(480px, 100%);
  display: grid;
  gap: 14px;
}
.card h1 { margin: 0; }
.card ul { padding-left: 18px; margin: 0; display: grid; gap: 8px; }

/* App layout */
#main { display: grid; grid-template-columns: 260px 1fr; height: 100%; }
#sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.side-head, .side-foot { display: flex; gap: 8px; padding: 14px; align-items: center; }
.side-head { justify-content: space-between; }
.side-foot { margin-top: auto; border-top: 1px solid var(--border); }
.brand { font-size: 20px; font-weight: 700; color: var(--accent-2); }
#conversations { overflow-y: auto; padding: 0 8px; flex: 1; }
#conversations a {
  display: block;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#conversations a:hover { background: var(--panel-2); color: var(--text); }
#conversations a.active { background: var(--panel-2); color: var(--text); }

#chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
#chat-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
}
#chat-head h2 { margin: 0; font-size: 16px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#toggle-sidebar { display: none; }
.ai-badge {
  font-size: 12px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 10px;
  white-space: nowrap;
}

#messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: min(720px, 85%); padding: 10px 14px; border-radius: var(--radius); white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--accent); color: #1a0f14; border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--panel-2); border-bottom-left-radius: 4px; }
.msg.notice { align-self: center; max-width: 560px; font-size: 13px; color: var(--muted); background: transparent; border: 1px dashed var(--border); text-align: center; }
.msg.notice.crisis { color: var(--text); border: 1px solid var(--accent); }
.msg.error { align-self: center; color: var(--error); font-size: 13px; }
.msg.typing::after { content: "▍"; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.empty { margin: auto; text-align: center; color: var(--muted); }

#composer { display: flex; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--border); align-items: flex-end; }
#input { resize: none; max-height: 200px; }

/* Settings dialog */
dialog {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: min(560px, 94vw);
  max-height: 90vh;
  padding: 0;
}
dialog::backdrop { background: rgba(0, 0, 0, .6); }
.settings-body { padding: 24px; display: grid; gap: 10px; }
.settings-body h2, .settings-body h3 { margin: 6px 0 0; }
.settings-body h3 { font-size: 14px; color: var(--accent-2); }
.settings-body label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.settings-body label.row { display: flex; align-items: center; gap: 8px; }
.settings-body label.row input { width: auto; }
.provider { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: var(--panel-2); border-radius: 10px; }
.provider span { flex: 1; }
.provider small { color: var(--muted); }
details { display: grid; gap: 8px; }
details[open] > summary { margin-bottom: 8px; }
summary { cursor: pointer; color: var(--accent-2); }
.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }

@media (max-width: 760px) {
  #main { grid-template-columns: 1fr; }
  #sidebar { position: fixed; inset: 0 30% 0 0; z-index: 10; transform: translateX(-100%); transition: transform .2s; }
  #main.show-sidebar #sidebar { transform: none; }
  #toggle-sidebar { display: inline-block; }
  .msg { max-width: 92%; }
}
