/* ============================================================
   Mindful — minimalist, calm design system
   Principles: generous whitespace, muted palette, system fonts,
   subtle motion, no visual noise. Dark mode via prefers-color-scheme.
   ============================================================ */

:root {
  --bg: #faf8f4;
  --surface: #ffffff;
  --surface-2: #f2efe9;
  --text: #2b2b28;
  --text-muted: #767268;
  --border: #e7e2d9;
  --accent: #6f9382;
  --accent-strong: #587b6b;
  --accent-contrast: #ffffff;
  --bubble-user: #eaf1ec;
  --bubble-assistant: #f5f3ee;
  --risk-low: #6f9382;
  --risk-medium: #c79a4b;
  --risk-high: #bf6a56;
  --shadow: 0 1px 2px rgba(30, 26, 20, 0.04), 0 4px 16px rgba(30, 26, 20, 0.05);
  --radius: 16px;
  --radius-sm: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181a;
    --surface: #202225;
    --surface-2: #26282b;
    --text: #eae8e3;
    --text-muted: #9a9791;
    --border: #33353a;
    --accent: #83ab97;
    --accent-strong: #9dc3ae;
    --accent-contrast: #12211a;
    --bubble-user: #22322b;
    --bubble-assistant: #26282b;
    --risk-low: #83ab97;
    --risk-medium: #d3ac6a;
    --risk-high: #d68975;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.2), 0 4px 20px rgba(0, 0, 0, 0.28);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

body { overflow: hidden; }

.screen {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- Brand mark ---------- */
.brand-mark {
  display: inline-block;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--accent-strong), var(--accent) 70%);
  box-shadow: var(--shadow);
}
.brand-mark.small { width: 26px; height: 26px; }

/* ==================== AUTH SCREEN ==================== */
#auth-screen {
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 36px 32px;
}

.brand { text-align: center; margin-bottom: 28px; }
.brand h1 {
  font-size: 1.4rem;
  font-weight: 600;
  margin: 12px 0 4px;
  letter-spacing: -0.01em;
}
.brand-sub {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.88rem;
}

.tabs {
  display: flex;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 4px;
  margin-bottom: 24px;
}
.tab {
  flex: 1;
  border: none;
  background: transparent;
  padding: 8px 0;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text-muted);
  border-radius: calc(var(--radius-sm) - 4px);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.field {
  display: block;
  margin-bottom: 16px;
}
.field span {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.field input {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
  font-family: var(--font);
  transition: border-color 0.15s ease;
}
.field input:focus {
  outline: none;
  border-color: var(--accent);
}

.btn-primary {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent-strong);
  color: var(--accent-contrast);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 4px;
  transition: opacity 0.15s ease, transform 0.1s ease;
}
.btn-primary:hover { opacity: 0.92; }
.btn-primary:active { transform: scale(0.99); }
.btn-primary:disabled { opacity: 0.5; cursor: default; }

.error-text {
  color: var(--risk-high);
  font-size: 0.83rem;
  margin: -6px 0 14px;
}

/* ==================== CHAT SCREEN ==================== */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}
.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}
.header-title {
  font-weight: 600;
  font-size: 1.02rem;
  letter-spacing: -0.01em;
}
.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.risk-badge {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--risk-low);
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  letter-spacing: 0.01em;
  transition: color 0.25s ease;
}
.risk-badge[data-level="MEDIUM"] { color: var(--risk-medium); }
.risk-badge[data-level="HIGH"] { color: var(--risk-high); }

.icon-btn {
  border: none;
  background: var(--surface-2);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 0.95rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}
.icon-btn:hover { background: var(--border); }
.icon-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-contrast); }

.connection-banner {
  text-align: center;
  font-size: 0.8rem;
  padding: 6px;
  background: var(--surface-2);
  color: var(--text-muted);
  flex-shrink: 0;
}

/* ---------- Message list ---------- */
.message-list {
  flex: 1;
  overflow-y: auto;
  padding: 24px clamp(16px, 6vw, 120px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

.msg {
  max-width: 72%;
  padding: 11px 15px;
  border-radius: 18px;
  font-size: 0.94rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
  animation: fade-in 0.2s ease;
}
@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg.user {
  align-self: flex-end;
  background: var(--bubble-user);
  border-bottom-right-radius: 4px;
}
.msg.assistant {
  align-self: flex-start;
  background: var(--bubble-assistant);
  border-bottom-left-radius: 4px;
}
.msg.assistant.crisis {
  border-left: 3px solid var(--risk-high);
}
.msg.system {
  align-self: center;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.8rem;
  max-width: 90%;
  text-align: center;
}

.typing-dots {
  display: inline-flex;
  gap: 4px;
  align-self: flex-start;
  padding: 11px 15px;
  background: var(--bubble-assistant);
  border-radius: 18px;
  border-bottom-left-radius: 4px;
}
.typing-dots span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: bounce 1.2s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* ---------- Composer ---------- */
.composer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 14px clamp(16px, 6vw, 120px) 18px;
  flex-shrink: 0;
}
.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--surface-2);
  border-radius: 22px;
  padding: 6px 6px 6px 14px;
}
.composer-row textarea {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  max-height: 120px;
  font-family: var(--font);
  font-size: 0.94rem;
  color: var(--text);
  padding: 8px 0;
  line-height: 1.4;
}
.composer-row textarea:focus { outline: none; }
.composer-row textarea::placeholder { color: var(--text-muted); }

.mic-btn, .btn-send {
  border: none;
  border-radius: 50%;
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  transition: background 0.15s ease, transform 0.1s ease;
}
.mic-btn {
  background: transparent;
  color: var(--text-muted);
}
.mic-btn:hover { background: var(--border); }
.mic-btn.listening {
  background: var(--risk-high);
  color: #fff;
  animation: pulse 1.4s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(191, 106, 86, 0.4); }
  70% { box-shadow: 0 0 0 10px rgba(191, 106, 86, 0); }
  100% { box-shadow: 0 0 0 0 rgba(191, 106, 86, 0); }
}
.mic-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.btn-send {
  background: var(--accent-strong);
  color: var(--accent-contrast);
}
.btn-send:hover { opacity: 0.92; }
.btn-send:disabled { opacity: 0.4; cursor: default; }

.listening-hint {
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin: 8px 0 0;
}

/* ---------- Scrollbar (subtle) ---------- */
.message-list::-webkit-scrollbar { width: 6px; }
.message-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
  .auth-card { padding: 28px 22px; }
  .msg { max-width: 85%; }
}
