:root {
  /* Palette: Philosophical, Blue Sash, Deep Dungeon, Black Kite, Crowshead */
  --bg: #311b1d;
  --sidebar: #1f0b0a;
  --surface: #563c3b;
  --hover: rgba(118, 121, 124, 0.25);
  --text: #ece8e8;
  --muted: #aeb1b5;
  --accent: #c98f96;
  --accent-text: #1f0b0a;
  --border: #4a4e57;
  --idle: #76797c;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

button, textarea, input { font: inherit; color: inherit; }

.app { display: flex; height: 100%; }

/* Sidebar */
.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--sidebar);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
}
.brand { font-size: 20px; font-weight: 700; padding: 8px 10px; }
.sidebar-btn {
  background: none;
  border: 0;
  border-radius: 10px;
  padding: 10px;
  text-align: left;
  cursor: pointer;
}
.sidebar-btn:hover, .sidebar-btn.active { background: var(--hover); }
.sidebar-spacer { flex: 1; }

.sidebar-label { color: var(--muted); font-size: 12px; padding: 12px 10px 0; }
.history { display: flex; flex-direction: column; gap: 2px; }
.history .sidebar-btn { width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.conversation { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.conversation .title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation .badge {
  background: var(--accent);
  color: var(--accent-text);
  border-radius: 999px;
  font-size: 12px;
  padding: 0 7px;
}

/* Main column */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  font-weight: 600;
}
.status { font-size: 13px; font-weight: 400; color: var(--muted); }
.status::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--idle);
}
.status.online::before { background: var(--accent); }

.messages { flex: 1; overflow-y: auto; padding: 16px 20px; }
.thread { max-width: 768px; margin: 0 auto; display: flex; flex-direction: column; gap: 24px; }

.empty {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--muted);
}
.logo { margin: 0 0 20px; color: var(--accent); font: 20px/1.15 ui-monospace, Menlo, Consolas, monospace; text-align: left; }
.empty h1 { color: var(--text); font-size: 32px; font-weight: 700; margin: 0 0 8px; }

.message { display: flex; gap: 12px; }
.message.user { justify-content: flex-end; }
.message.user .bubble { background: var(--surface); border-radius: 18px; padding: 8px 16px; max-width: 70%; }
.message.assistant .bubble { padding-top: 2px; max-width: 90%; }
.bubble { white-space: pre-wrap; overflow-wrap: anywhere; }

.avatar {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 14px;
  font-weight: 600;
  display: grid;
  place-items: center;
}

.typing .bubble { display: flex; gap: 4px; align-items: center; height: 28px; }
.typing .bubble span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  animation: blink 1.2s infinite;
}
.typing .bubble span:nth-child(2) { animation-delay: 0.2s; }
.typing .bubble span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.3; } 40% { opacity: 1; } }

/* Composer */
.composer {
  width: calc(100% - 40px);
  max-width: 768px;
  margin: 0 auto 8px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--surface);
  border-radius: 26px;
  padding: 10px 10px 10px 20px;
}
.composer textarea {
  flex: 1;
  resize: none;
  background: none;
  border: 0;
  outline: 0;
  max-height: 200px;
  padding: 4px 0;
}
.composer button {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: var(--text);
  color: var(--bg);
  font-size: 18px;
  cursor: pointer;
}
.composer button:disabled { opacity: 0.3; cursor: default; }
.composer textarea::placeholder, .login input::placeholder { color: var(--muted); opacity: 0.8; }
.footnote { text-align: center; color: var(--muted); font-size: 12px; padding: 0 0 12px; }

/* Admin login */
.login {
  max-width: 320px;
  margin: 20vh auto 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login h2 { font-size: 26px; font-weight: 700; margin: 0; }
.login input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
}
.login button {
  background: var(--accent);
  border: 0;
  border-radius: 10px;
  padding: 10px;
  color: var(--accent-text);
  cursor: pointer;
}
.error { color: #f1b5ba; min-height: 1.5em; margin: 0; }

[hidden] { display: none !important; }

.menu-btn { display: none; background: none; border: 0; font-size: 20px; cursor: pointer; padding: 0 12px 0 0; }

@media (max-width: 720px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 10;
    transform: translateX(-100%);
    transition: transform 0.2s;
  }
  .sidebar.open { transform: none; }
  .menu-btn { display: inline-block; }
}
