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

:root {
  --bg: #0a0a0f;
  --surface: #12121a;
  --surface2: #1a1a28;
  --accent: #4f46e5;
  --accent-light: #818cf8;
  --text: #e2e8f0;
  --text-muted: #64748b;
  --user-bubble: #3730a3;
  --bot-bubble: #1e1e2e;
  --danger: #ef4444;
  --radius: 18px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ─── Login ─── */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: radial-gradient(ellipse at 50% 40%, #1a1040 0%, var(--bg) 70%);
}

.login-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  width: 100%;
  max-width: 320px;
  padding: 0 24px;
}

.logo-ring {
  width: 100px;
  height: 100px;
  animation: rotate 20s linear infinite;
}

@keyframes rotate { to { transform: rotate(360deg); } }

.login-label {
  color: var(--text-muted);
  font-size: 13px;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.pin-dots {
  display: flex;
  gap: 16px;
}

.pin-dots span {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--text-muted);
  transition: background 0.15s, border-color 0.15s;
}

.pin-dots span.filled {
  background: var(--accent-light);
  border-color: var(--accent-light);
}

.pin-dots.error span {
  border-color: var(--danger);
  background: var(--danger);
  animation: shake 0.4s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  60% { transform: translateX(6px); }
}

.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 72px);
  gap: 12px;
}

.pin-key {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 1px solid #2a2a3a;
  background: var(--surface);
  color: var(--text);
  font-size: 22px;
  cursor: pointer;
  transition: background 0.1s, transform 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pin-key:active { background: var(--accent); transform: scale(0.94); }
.pin-clear { font-size: 18px; }
.pin-empty { opacity: 0; pointer-events: none; }

.login-error {
  color: var(--danger);
  font-size: 13px;
  min-height: 18px;
  text-align: center;
}

/* ─── Chat ─── */
#chat-screen {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  padding-top: max(16px, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid #1e1e2e;
  flex-shrink: 0;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--accent-light);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 6px #22c55e;
  animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

#btn-logout {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
}

#btn-logout:hover { color: var(--danger); }

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

#messages::-webkit-scrollbar { width: 4px; }
#messages::-webkit-scrollbar-track { background: transparent; }
#messages::-webkit-scrollbar-thumb { background: #2a2a3a; border-radius: 2px; }

.bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: var(--radius);
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 15px;
  animation: pop-in 0.2s ease;
}

@keyframes pop-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

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

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

.bubble.transcript {
  background: transparent;
  border: 1px dashed #2a2a3a;
  color: var(--text-muted);
  font-size: 13px;
  align-self: flex-end;
  border-radius: 10px;
}

/* Typing indicator */
#typing-indicator {
  padding: 0 16px 8px;
}

#typing-indicator .bubble {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 12px 16px;
  width: fit-content;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-light);
  animation: bounce 1.2s infinite;
}

.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-6px); opacity: 1; }
}

/* ─── Footer ─── */
footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid #1e1e2e;
  flex-shrink: 0;
}

#msg-input {
  flex: 1;
  background: var(--surface2);
  border: 1px solid #2a2a3a;
  border-radius: 24px;
  padding: 10px 16px;
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
}

#msg-input:focus { border-color: var(--accent); }
#msg-input::placeholder { color: var(--text-muted); }

footer button {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: var(--surface2);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s, transform 0.1s;
  flex-shrink: 0;
}

footer button svg { width: 18px; height: 18px; }

footer button:active { transform: scale(0.92); }

#btn-send {
  background: var(--accent);
  color: #fff;
}

#btn-send:hover { background: #4338ca; }

#btn-mic.recording {
  background: var(--danger);
  color: #fff;
  animation: pulse-rec 1s infinite;
}

@keyframes pulse-rec {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.4); }
  50% { box-shadow: 0 0 0 8px rgba(239,68,68,0); }
}

#btn-photo:hover, #btn-mic:hover { color: var(--accent-light); }
