*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

.hidden { display: none !important; }

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --accent: #4f7cff;
  --accent-dim: #2d4fb8;
  --text: #e8eaf6;
  --text-dim: #7b82a8;
  --user-bg: #1e3a8a;
  --bot-bg: #1a1d27;
  --border: #2e3350;
  --success: #22c55e;
  --radius: 14px;
}

html, body { height: 100%; font-family: 'Segoe UI', system-ui, sans-serif; background: var(--bg); color: var(--text); font-size: 15px; }

body { display: flex; flex-direction: column; }

/* ── Login screen ── */
#login-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.login-logo {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.4px;
  margin-bottom: 2px;
}

.login-subtitle {
  font-size: 0.82rem;
  color: var(--text-dim);
  margin-bottom: 20px;
}

.login-card label {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 6px;
  display: block;
}

.login-card input[type="password"] {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 11px 14px;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s;
  margin-bottom: 4px;
}
.login-card input[type="password"]:focus { border-color: var(--accent); }

.login-error {
  font-size: 0.82rem;
  color: #f87171;
  margin-bottom: 2px;
}

.login-card button[type="submit"] {
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 12px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
  transition: background 0.15s;
}
.login-card button[type="submit"]:hover { background: var(--accent-dim); }
.login-card button[type="submit"]:disabled { opacity: 0.6; cursor: not-allowed; }

/* ── App screen ── */
#app-screen { display: flex; flex-direction: column; flex: 1; overflow: hidden; }

/* ── Header ── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 20px;
  flex-shrink: 0;
}
.header-inner { display: flex; align-items: center; justify-content: space-between; max-width: 780px; margin: 0 auto; width: 100%; }
.logo { font-size: 1.1rem; font-weight: 700; color: var(--accent); letter-spacing: -0.3px; }
.method { font-size: 0.78rem; color: var(--text-dim); }

/* ── Main / messages ── */
main { flex: 1; overflow: hidden; display: flex; flex-direction: column; }

#chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 24px 16px 12px;
  scroll-behavior: smooth;
}

#messages { max-width: 780px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }

/* ── Bubbles ── */
.bubble {
  max-width: 76%;
  padding: 12px 16px;
  border-radius: var(--radius);
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  animation: fadeIn 0.15s ease;
}

@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.bubble.bot {
  background: var(--bot-bg);
  border: 1px solid var(--border);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.bubble.user {
  background: var(--user-bg);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.bubble.playbook {
  background: var(--surface2);
  border: 1px solid var(--accent-dim);
  max-width: 100%;
  font-size: 0.88rem;
  font-family: 'Menlo', 'Consolas', monospace;
}

.typing-dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-dim);
  animation: blink 1.2s infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.2; } 40% { opacity: 1; } }

/* ── Footer ── */
footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  flex-shrink: 0;
}

#playbook-actions {
  max-width: 780px;
  margin: 0 auto 10px;
  display: flex;
  gap: 10px;
}

#playbook-actions.hidden { display: none; }

#playbook-actions button {
  padding: 8px 18px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  transition: opacity 0.15s;
}
#btn-copy { background: var(--accent); color: #fff; }
#btn-download { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
#playbook-actions button:hover { opacity: 0.85; }

#input-area {
  display: flex;
  gap: 10px;
  max-width: 780px;
  margin: 0 auto;
}

#user-input {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 10px 14px;
  font-size: 0.95rem;
  resize: none;
  line-height: 1.5;
  outline: none;
  transition: border-color 0.15s;
}
#user-input:focus { border-color: var(--accent); }
#user-input::placeholder { color: var(--text-dim); }

#send-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 0 20px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  align-self: flex-end;
  height: 42px;
}
#send-btn:hover { background: var(--accent-dim); }
#send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Toast ── */
#toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--success);
  color: #fff;
  padding: 8px 20px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
  pointer-events: none;
  transition: opacity 0.3s;
}
#toast.hidden { opacity: 0; }

/* ── Markdown inside bot bubbles ── */
.bubble.bot h1, .bubble.bot h2, .bubble.bot h3 {
  color: var(--text);
  margin: 14px 0 6px;
  line-height: 1.3;
}
.bubble.bot h1 { font-size: 1.1rem; border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.bubble.bot h2 { font-size: 1rem; color: var(--accent); }
.bubble.bot h3 { font-size: 0.95rem; color: var(--text-dim); }

.bubble.bot p { margin: 6px 0; }
.bubble.bot p:first-child { margin-top: 0; }
.bubble.bot p:last-child { margin-bottom: 0; }

.bubble.bot ul, .bubble.bot ol {
  padding-left: 20px;
  margin: 6px 0;
}
.bubble.bot li { margin: 3px 0; }
.bubble.bot li > ul, .bubble.bot li > ol { margin: 2px 0; }

.bubble.bot strong { color: var(--text); font-weight: 700; }
.bubble.bot em { color: var(--text-dim); font-style: italic; }

.bubble.bot hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 12px 0;
}

.bubble.bot code {
  background: #0d0f1a;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: 'Menlo', 'Consolas', monospace;
  font-size: 0.85em;
  color: #a5b4fc;
}

.bubble.bot pre {
  background: #0d0f1a;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
  margin: 8px 0;
}
.bubble.bot pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.83rem;
  color: #c7d2fe;
}

.bubble.bot blockquote {
  border-left: 3px solid var(--accent);
  margin: 8px 0;
  padding: 4px 12px;
  color: var(--text-dim);
  background: #0d0f1a;
  border-radius: 0 6px 6px 0;
}

/* playbook override: keeps monospace feel but still renders lists/headings */
.bubble.playbook { font-family: inherit; }

/* ── Option buttons ── */
.options-group {
  max-width: 76%;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 0 2px 4px;
  animation: fadeIn 0.15s ease;
}

.option-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text);
  padding: 7px 14px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  line-height: 1.3;
}
.option-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.option-btn.selected {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.options-confirm {
  background: transparent;
  border: 1.5px solid var(--accent);
  border-radius: 20px;
  color: var(--accent);
  padding: 7px 18px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  margin-top: 4px;
  width: 100%;
}
.options-confirm:hover:not(:disabled) {
  background: var(--accent);
  color: #fff;
}
.options-confirm:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* ── Scrollbar ── */
#chat-container::-webkit-scrollbar { width: 6px; }
#chat-container::-webkit-scrollbar-track { background: transparent; }
#chat-container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Mobile ── */
@media (max-width: 600px) {
  .bubble { max-width: 92%; }
  .logo { font-size: 1rem; }
}
