* { box-sizing: border-box; }
:root {
  --accent: #b88aaf;
  --accent-soft: #7c5b76;
  --bg: #181018;
  --bg-deep: #0d090d;
  --text: #e8ddd9;
  --text-muted: #9c8e88;
  --border: rgba(255,255,255,0.08);
}
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  height: 100%;
  overflow: hidden;
}
#app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }

/* Setup gate (pre-token) */
#setupGate {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.setup-panel { max-width: 420px; text-align: center; }
.setup-panel h1 { color: var(--accent); font-weight: 600; letter-spacing: 1px; margin: 0 0 8px; }
.setup-tagline { color: var(--text-muted); margin: 0 0 24px; font-style: italic; }
.setup-help { color: var(--text-muted); font-size: 14px; }

/* Main app */
#mainApp { height: 100%; display: grid; grid-template-rows: auto 1fr; grid-template-columns: 240px 1fr; grid-template-areas: 'header header' 'sidebar chat'; }

#header {
  grid-area: header;
  display: flex;
  align-items: center;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-deep);
  gap: 12px;
}
.menu-toggle, .settings-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 6px 10px;
}
.header-title { flex: 1; font-weight: 600; color: var(--accent); letter-spacing: 0.5px; }

#sidebar {
  grid-area: sidebar;
  background: var(--bg-deep);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.sidebar-header { padding: 12px 14px; font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); }
.room-list { flex: 1; padding: 0 8px; }
.room-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 4px;
  transition: background 0.15s;
}
.room-item:hover { background: rgba(255,255,255,0.04); }
.room-item.active { background: rgba(184,138,175,0.12); }
.room-emoji { font-size: 18px; }
.room-name { font-weight: 600; color: var(--text); }
.room-greeting { font-size: 10px; color: var(--text-muted); margin-top: 2px; line-height: 1.4; }
.sidebar-footer { padding: 12px 14px; border-top: 1px solid var(--border); }
.sidebar-hint { font-size: 10px; color: var(--text-muted); font-style: italic; line-height: 1.5; }

#chat {
  grid-area: chat;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}
.empty-room {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  text-align: center;
  padding: 24px;
}
.empty-room-icon { font-size: 36px; margin-bottom: 12px; opacity: 0.5; }
.empty-room-text { font-size: 13px; font-style: italic; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.msg { display: flex; flex-direction: column; max-width: 75%; }
.msg.from-lizzie { align-self: flex-end; }
.msg.from-ai { align-self: flex-start; }
.msg-bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg.from-lizzie .msg-bubble { background: var(--accent-soft); color: #fff; border-bottom-right-radius: 4px; }
.msg.from-ai .msg-bubble { background: rgba(255,255,255,0.05); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg-meta { font-size: 10px; color: var(--text-muted); margin-top: 4px; padding: 0 8px; }
.msg-thinking {
  font-size: 11px;
  font-style: italic;
  color: var(--text-muted);
  padding: 6px 10px;
  margin-top: 4px;
  border-left: 2px solid var(--accent-soft);
  background: rgba(255,255,255,0.02);
}
.msg-pending { opacity: 0.6; font-style: italic; }

#composer {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-deep);
  align-items: flex-end;
}
#composeBox {
  flex: 1;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
  max-height: 200px;
  outline: none;
}
#composeBox:focus { border-color: var(--accent); }
#sendBtn {
  background: var(--accent);
  color: var(--bg-deep);
  border: none;
  border-radius: 12px;
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
#sendBtn:disabled { opacity: 0.5; cursor: not-allowed; }

.empty { color: var(--text-muted); font-style: italic; padding: 14px; text-align: center; }

/* Settings modal */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal-content {
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: 14px;
  max-width: 480px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
}
.modal-header { display: flex; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); font-weight: 600; }
.modal-header button { background: none; border: none; color: var(--text-muted); font-size: 18px; cursor: pointer; }
.modal-body { padding: 18px; }
.setting-row { margin-bottom: 16px; }
.setting-row label { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); display: block; margin-bottom: 6px; }
.setting-value-row { display: flex; gap: 6px; }
.setting-value-row input {
  flex: 1; background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; padding: 6px 10px; font-size: 12px; font-family: monospace;
}
.setting-value-row button {
  padding: 6px 12px; border-radius: 6px; border: 1px solid var(--border);
  background: transparent; color: var(--text-muted); font-size: 11px; cursor: pointer;
}
.danger-btn {
  background: rgba(224,64,64,0.1); color: #e07040;
  border: 1px solid rgba(224,64,64,0.3); border-radius: 8px;
  padding: 10px 16px; font-size: 13px; cursor: pointer; width: 100%;
}
.setting-note { font-size: 11px; color: var(--text-muted); line-height: 1.6; font-style: italic; }

/* Mobile */
@media (max-width: 700px) {
  #mainApp { grid-template-columns: 1fr; grid-template-areas: 'header' 'chat'; }
  #sidebar {
    position: fixed; top: 48px; left: 0; bottom: 0; width: 260px;
    z-index: 50; transform: translateX(-100%); transition: transform 0.2s;
  }
  #sidebar.open { transform: translateX(0); }
  .menu-toggle { display: block; }
}
@media (min-width: 701px) {
  .menu-toggle { display: none; }
}
