/* ──────────────────────────────────────────────────────────────────────
   Applesauce Chat — mobile-first dark theme
   ────────────────────────────────────────────────────────────────────── */

:root {
  --bg: #1a1a1a;
  --bg-elev: #2a2a2a;
  --bg-elev-2: #353535;
  --fg: #e8e8e8;
  --fg-dim: #9aa0a6;
  --border: #3a3a3a;
  --accent: #FF6B35;
  --accent-2: #F7931E;
  --bubble-user: linear-gradient(135deg, #FF6B35, #F7931E);
  --bubble-asst: #2a2a2a;
  --danger: #ff6b6b;
  --ok: #4ade80;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

body { min-height: 100dvh; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

.hidden { display: none !important; }

/* ── Auth (login) page ─────────────────────────────────────────────── */

.auth-bg {
  min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px 20px;
  background:
    radial-gradient(circle at 20% 0%, rgba(255, 107, 53, 0.15), transparent 50%),
    radial-gradient(circle at 80% 100%, rgba(247, 147, 30, 0.1), transparent 50%),
    var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 24px;
  box-shadow: var(--shadow);
}

.auth-logo { text-align: center; margin-bottom: 24px; }

.auth-logo__bubble {
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--bubble-user);
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 800; font-size: 22px;
  margin-bottom: 12px;
  box-shadow: 0 4px 12px rgba(255, 107, 53, 0.3);
}

.auth-logo h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.auth-tagline {
  margin: 6px 0 0;
  color: var(--fg-dim);
  font-size: 14px;
}

.auth-form {
  display: flex; flex-direction: column; gap: 12px;
}

.auth-form input {
  width: 100%;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  font-size: 16px;
  transition: border-color 0.15s;
}
.auth-form input:focus {
  outline: none;
  border-color: var(--accent);
}

.auth-form button {
  background: var(--bubble-user);
  color: #fff;
  border: 0;
  border-radius: 10px;
  padding: 14px 16px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.05s, opacity 0.15s;
}
.auth-form button:active { transform: scale(0.98); }
.auth-form button:disabled { opacity: 0.6; cursor: default; }

.auth-status {
  margin-top: 14px;
  font-size: 14px;
  text-align: center;
  min-height: 20px;
}
.auth-status--ok { color: var(--ok); }
.auth-status--err { color: var(--danger); }

.auth-error {
  background: rgba(255, 107, 107, 0.1);
  border: 1px solid rgba(255, 107, 107, 0.3);
  color: var(--danger);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 14px;
  margin-bottom: 16px;
  text-align: center;
}

.auth-foot {
  text-align: center;
  color: var(--fg-dim);
  font-size: 12px;
  margin: 20px 0 0;
}

/* ── Chat layout ───────────────────────────────────────────────────── */

.chat-bg {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100dvh;
  background: var(--bg);
}

.chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(12px + var(--safe-top)) 16px 12px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}

.chat-header__brand { display: flex; align-items: center; gap: 12px; }

.chat-header__avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--bubble-user);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 14px;
}

.chat-header__title {
  display: flex; flex-direction: column; line-height: 1.2;
}
.chat-header__title strong { font-size: 15px; }
.chat-header__sub { font-size: 11px; color: var(--fg-dim); }

.chat-header__logout {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg-dim);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.chat-header__logout:hover, .chat-header__logout:active {
  background: var(--bg-elev-2);
  color: var(--fg);
}

/* ── Messages list ─────────────────────────────────────────────────── */

.messages {
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 14px 8px;
  display: flex; flex-direction: column; gap: 10px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.msg {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 16px;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  animation: msg-in 0.18s ease-out;
  font-size: 15px;
  line-height: 1.5;
}
@keyframes msg-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg--user {
  align-self: flex-end;
  background: var(--bubble-user);
  color: #fff;
  border-bottom-right-radius: 6px;
}

.msg--assistant {
  align-self: flex-start;
  background: var(--bubble-asst);
  border: 1px solid var(--border);
  border-bottom-left-radius: 6px;
}

.msg--error {
  align-self: center;
  background: rgba(255, 107, 107, 0.1);
  border: 1px solid rgba(255, 107, 107, 0.3);
  color: var(--danger);
  font-size: 13px;
  border-radius: 10px;
}

.msg p { margin: 0 0 8px; }
.msg p:last-child { margin-bottom: 0; }
.msg pre {
  background: rgba(0,0,0,0.4);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 8px 0;
  overflow-x: auto;
  font-size: 13px;
}
.msg code {
  background: rgba(0,0,0,0.3);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 13px;
  font-family: 'SF Mono', Menlo, Consolas, monospace;
}
.msg pre code { background: transparent; padding: 0; }
.msg a { color: var(--accent-2); text-decoration: underline; }
.msg--user a { color: #fff; }
.msg ul, .msg ol { padding-left: 22px; margin: 6px 0; }
.msg h1, .msg h2, .msg h3 {
  margin: 12px 0 6px;
  font-size: 16px;
  color: var(--accent);
}
.msg--user h1, .msg--user h2, .msg--user h3 { color: #fff; }
.msg blockquote {
  border-left: 3px solid var(--border);
  padding-left: 10px;
  margin: 6px 0;
  color: var(--fg-dim);
}

/* ── Typing indicator ──────────────────────────────────────────────── */

.typing {
  align-self: flex-start;
  margin: 0 14px 8px;
  background: var(--bubble-asst);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px 16px;
  display: inline-flex; gap: 4px; width: fit-content;
}
.typing span {
  width: 6px; height: 6px;
  background: var(--fg-dim);
  border-radius: 50%;
  animation: typing-bounce 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.30s; }
@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* ── Composer ──────────────────────────────────────────────────────── */

.composer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 10px calc(8px + var(--safe-bottom));
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
}

.composer textarea {
  flex: 1;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 11px 16px;
  font-size: 16px;
  font-family: inherit;
  line-height: 1.4;
  resize: none;
  max-height: 35dvh;
  outline: none;
  transition: border-color 0.15s;
}
.composer textarea:focus { border-color: var(--accent); }

.composer button {
  flex-shrink: 0;
  width: 44px; height: 44px;
  border: 0; border-radius: 50%;
  background: var(--bubble-user);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: transform 0.05s, opacity 0.15s;
}
.composer button:active { transform: scale(0.94); }
.composer button:disabled {
  background: var(--bg-elev-2);
  color: var(--fg-dim);
  cursor: default;
}

/* Tablet+ widen */
@media (min-width: 720px) {
  .messages { padding: 24px 20%; }
  .msg { max-width: 80%; }
  .composer { padding: 12px 20%; }
}
