:root {
  --bg: #0f1115;
  --panel: #171a21;
  --border: #2a2e37;
  --text: #e7e9ee;
  --muted: #9aa1ad;
  --accent: #5b8cff;
  --danger: #ff5b6a;
  --bubble-user: #5b8cff;
  --bubble-bot: #1f232c;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

.hidden { display: none !important; }

.expired-screen {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.expired-box {
  text-align: center;
  max-width: 420px;
  padding: 32px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
}
.expired-box code {
  background: #000;
  padding: 2px 6px;
  border-radius: 4px;
}

.app {
  display: grid;
  grid-template-columns: 260px 1fr;
  height: 100vh;
}

.sidebar {
  background: var(--panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 12px;
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.sidebar-header h2 { font-size: 15px; margin: 0; color: var(--muted); }

.persona-list {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
  overflow-y: auto;
}
.persona-list li {
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 4px;
  color: var(--text);
  font-size: 14px;
}
.persona-list li:hover { background: #1f232c; }
.persona-list li.active { background: var(--accent); color: #fff; }

.sidebar-footer { padding-top: 8px; border-top: 1px solid var(--border); }
.expiry-note { font-size: 12px; color: var(--muted); }

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}
#active-persona-name { font-weight: 600; }
.header-actions { display: flex; gap: 8px; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.msg {
  max-width: 70%;
  padding: 10px 14px;
  border-radius: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg.user {
  align-self: flex-end;
  background: var(--bubble-user);
  color: #fff;
  border-bottom-left-radius: 4px;
}
.msg.bot {
  align-self: flex-start;
  background: var(--bubble-bot);
  border-bottom-right-radius: 4px;
}
.msg.error {
  align-self: center;
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
}
.msg.pending { opacity: 0.6; }

.chat-form {
  display: flex;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}
.chat-form textarea {
  flex: 1;
  resize: none;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 10px 12px;
  font-family: inherit;
  font-size: 14px;
}

button {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-family: inherit;
}
button:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: #262b35; color: var(--text); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn-icon { background: var(--accent); color: #fff; width: 28px; height: 28px; padding: 0; border-radius: 50%; font-size: 16px; line-height: 1; }
#send-btn { background: var(--accent); color: #fff; padding: 8px 20px; }

dialog {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  padding: 20px;
  width: min(480px, 90vw);
}
dialog::backdrop { background: rgba(0,0,0,0.5); }
#persona-form { display: flex; flex-direction: column; gap: 12px; }
#persona-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
#persona-form input, #persona-form textarea {
  background: #0f1115;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 10px;
  font-family: inherit;
  font-size: 14px;
}
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
