/* Perelyn Chat — mobile-first PWA */
@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600;700&family=PT+Sans:wght@400;700&display=swap');

:root {
  --bg: #121212;
  --bg-surface: #1a1a1a;
  --bg-hover: #222222;
  --bg-input: #1e1e1e;
  --text: #f0f0f0;
  --text-muted: #999;
  --accent: #ff5a50;
  --accent-dim: #cc483f;
  --accent-glow: rgba(255, 90, 80, 0.15);
  --user-bubble: #3a1f1d;
  --assistant-bubble: #1e1e1e;
  --border: #2a2a2a;
  --danger: #ff5a50;
  --radius: 12px;
  --radius-sm: 8px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  height: 100%; width: 100%;
  font-family: "PT Sans", -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 16px; line-height: 1.5;
  background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

h1, h2, .chat-title, .conv-item .title, .mode-option strong {
  font-family: "Montserrat", -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ---- Screens ---- */
.screen { display: none; height: 100%; flex-direction: column; }
.screen.active { display: flex; }

/* ---- Logo ---- */
.logo {
  width: 140px; height: auto; margin-bottom: 24px;
}

/* ---- Auth screens ---- */
.auth-screen {
  justify-content: center; align-items: center;
  padding: 24px; text-align: center;
}
.auth-screen h1 {
  font-family: "Montserrat", sans-serif;
  font-size: 24px; font-weight: 600; margin-bottom: 8px; letter-spacing: -0.3px;
}
.auth-screen p { color: var(--text-muted); margin-bottom: 32px; font-size: 15px; }
.auth-screen input {
  width: 100%; max-width: 320px; padding: 14px 16px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text); font-size: 16px;
  outline: none; margin-bottom: 16px;
  font-family: "PT Sans", sans-serif;
}
.auth-screen input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.auth-screen input::placeholder { color: var(--text-muted); }
.auth-screen .code-input {
  font-family: "Montserrat", monospace;
  font-size: 32px; text-align: center; letter-spacing: 8px; font-weight: 600;
}
.auth-screen button {
  width: 100%; max-width: 320px; padding: 14px;
  background: var(--accent); color: #fff; border: none;
  border-radius: var(--radius-sm); font-size: 16px; font-weight: 600;
  cursor: pointer; font-family: "Montserrat", sans-serif;
  transition: background 0.2s;
}
.auth-screen button:hover { background: var(--accent-dim); }
.auth-screen button:disabled { opacity: 0.5; cursor: not-allowed; }
.auth-screen .error { color: var(--danger); font-size: 14px; margin-top: 12px; }
.auth-screen .back-link {
  color: var(--text-muted); font-size: 14px; margin-top: 16px; cursor: pointer;
}
.auth-screen .back-link:hover { color: var(--text); }

/* ---- Conversation list ---- */
#list-screen .header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
#list-screen .header h1 { font-size: 20px; font-weight: 700; }
#list-screen .header .logo-sm { width: 100px; height: auto; }
.new-btn {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--accent); border: none; color: #fff;
  font-size: 24px; cursor: pointer; display: flex;
  align-items: center; justify-content: center;
  transition: background 0.2s;
}
.new-btn:hover { background: var(--accent-dim); }
.conv-list {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
}
.conv-item {
  display: flex; align-items: center; padding: 14px 20px;
  border-bottom: 1px solid var(--border); cursor: pointer;
  transition: background 0.15s;
}
.conv-item:active { background: var(--bg-hover); }
.conv-item .info { flex: 1; min-width: 0; }
.conv-item .title {
  font-size: 15px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-item .meta { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.conv-item .mode-badge {
  font-family: "Montserrat", sans-serif;
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px;
  padding: 3px 8px; border-radius: 4px; margin-left: 12px;
  background: var(--bg-hover); color: var(--text-muted); white-space: nowrap;
}
.conv-item .mode-badge.workflow { background: #2a1a1a; color: var(--accent); }
.empty-state {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 40px; color: var(--text-muted); text-align: center;
}
.empty-state .logo { width: 120px; opacity: 0.4; margin-bottom: 20px; }
.empty-state p { margin-bottom: 16px; }

/* ---- Mode picker modal ---- */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.6); z-index: 100;
  align-items: flex-end; justify-content: center;
}
.modal-overlay.active { display: flex; }
.modal-sheet {
  background: var(--bg-surface); border-radius: 16px 16px 0 0;
  width: 100%; max-width: 500px; padding: 24px 20px;
  padding-bottom: calc(24px + var(--safe-bottom));
}
.modal-sheet h2 {
  font-family: "Montserrat", sans-serif;
  font-size: 18px; font-weight: 600; margin-bottom: 16px;
}
.mode-option {
  display: block; width: 100%; padding: 16px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font-size: 15px; text-align: left; cursor: pointer; margin-bottom: 8px;
  transition: border-color 0.2s;
}
.mode-option:hover { border-color: var(--accent); }
.mode-option:active { background: var(--bg-hover); }
.mode-option strong {
  display: block; font-size: 16px; margin-bottom: 4px;
  font-family: "Montserrat", sans-serif;
}
.mode-option span { color: var(--text-muted); font-size: 13px; }
.modal-cancel {
  width: 100%; padding: 14px; margin-top: 8px;
  background: none; border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-muted);
  font-size: 15px; cursor: pointer;
}

/* ---- Chat screen ---- */
#chat-screen .chat-header {
  display: flex; align-items: center; padding: 12px 16px;
  border-bottom: 1px solid var(--border); gap: 12px;
}
.back-btn {
  background: none; border: none; color: var(--accent);
  font-size: 16px; cursor: pointer; padding: 4px 8px;
  font-family: "PT Sans", sans-serif;
}
.chat-title {
  flex: 1; font-size: 16px; font-weight: 600; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-family: "Montserrat", sans-serif;
}
.chat-mode {
  font-family: "Montserrat", sans-serif;
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px;
  padding: 3px 10px; border-radius: 4px;
  background: var(--bg-hover); color: var(--text-muted);
  transition: all 0.3s ease;
}
.chat-mode.workflow { background: #2a1a1a; color: var(--accent); }

/* Messages */
.messages {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 16px; display: flex; flex-direction: column; gap: 8px;
}
.message {
  max-width: 85%; padding: 10px 14px;
  border-radius: var(--radius); font-size: 15px; word-wrap: break-word;
}
.message.user {
  align-self: flex-end; background: var(--user-bubble);
  border-bottom-right-radius: 4px;
}
.message.assistant {
  align-self: flex-start; background: var(--assistant-bubble);
  border-bottom-left-radius: 4px;
}
.message.assistant p { margin-bottom: 8px; }
.message.assistant p:last-child { margin-bottom: 0; }
.message.assistant strong { color: var(--accent); }
.message.assistant code {
  background: #252525; padding: 2px 6px; border-radius: 4px; font-size: 14px;
}
.message.assistant pre {
  background: #252525; padding: 12px; border-radius: var(--radius-sm);
  overflow-x: auto; margin: 8px 0;
}
.message.assistant pre code { background: none; padding: 0; }
.message.assistant ul, .message.assistant ol {
  padding-left: 20px; margin: 4px 0;
}
.typing-indicator {
  align-self: flex-start; padding: 10px 14px;
  background: var(--assistant-bubble); border-radius: var(--radius);
  border-bottom-left-radius: 4px; display: none;
}
.typing-indicator.active { display: block; }
.typing-dots span {
  display: inline-block; width: 8px; height: 8px;
  border-radius: 50%; background: var(--accent); opacity: 0.6;
  margin: 0 2px; animation: bounce 1.4s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* Prompt suggestions */
.suggestions {
  display: flex; flex-wrap: wrap; gap: 8px;
  padding: 0 16px 12px; justify-content: center;
}
.suggestion-chip {
  padding: 8px 14px; background: var(--bg-input);
  border: 1px solid var(--border); border-radius: 20px;
  color: var(--text-muted); font-size: 13px; cursor: pointer;
  white-space: nowrap; font-family: "PT Sans", sans-serif;
  transition: border-color 0.2s, color 0.2s;
}
.suggestion-chip:hover { border-color: var(--accent); color: var(--accent); }
.suggestion-chip:active { background: var(--bg-hover); color: var(--text); }

/* Brain reference cards */
.brain-card {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; margin: 6px 0;
  background: #1e1515; border: 1px solid #3a2020;
  border-radius: var(--radius-sm); cursor: pointer;
  text-decoration: none; color: inherit;
  transition: background 0.2s;
}
.brain-card:active { background: #2a1a1a; }
.brain-card .card-icon { font-size: 20px; flex-shrink: 0; }
.brain-card .card-body { min-width: 0; }
.brain-card .card-title {
  font-family: "Montserrat", sans-serif;
  font-size: 14px; font-weight: 600; color: var(--accent);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.brain-card .card-preview {
  font-size: 12px; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Input bar */
.input-bar {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 12px 16px; padding-bottom: calc(12px + var(--safe-bottom));
  border-top: 1px solid var(--border); background: var(--bg);
}
.input-bar textarea {
  flex: 1; resize: none; padding: 10px 14px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: 20px; color: var(--text); font-size: 15px;
  font-family: "PT Sans", sans-serif; line-height: 1.4; outline: none;
  max-height: 120px; min-height: 40px;
}
.input-bar textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.input-bar textarea::placeholder { color: var(--text-muted); }
.mic-btn, .send-btn {
  width: 40px; height: 40px; border-radius: 50%;
  border: none; cursor: pointer; display: flex;
  align-items: center; justify-content: center; flex-shrink: 0;
}
.mic-btn { background: var(--bg-input); color: var(--text-muted); font-size: 18px; }
.mic-btn.recording { background: var(--accent); color: #fff; animation: pulse 1.5s infinite; }
.send-btn { background: var(--accent); color: #fff; font-size: 18px; }
.send-btn:hover { background: var(--accent-dim); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.6; } }

/* Utility */
.hidden { display: none !important; }
