/* ── Reset & base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

:root {
  --purple:      #6B4FA8;
  --purple-dark: #4E3780;
  --purple-soft: #EDE8F7;
  --purple-pale: #F7F4FD;
  --text:        #1A1523;
  --text-mid:    #6B6478;
  --text-light:  #9B95A3;
  --border:      #E2DCF0;
  --white:       #FFFFFF;
  --error:       #C0392B;
  --radius-sm:   8px;
  --radius-md:   14px;
  --radius-lg:   20px;
  --shadow:      0 4px 24px rgba(107, 79, 168, 0.10);
  --font:        'Inter', system-ui, -apple-system, sans-serif;
}

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 16px;
  color: var(--text);
  background: var(--purple-pale);
  -webkit-font-smoothing: antialiased;
}

/* ── Login Screen ── */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, #F0EBF8 0%, #EAE3F5 100%);
}

.login-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 40px 36px 36px;
  width: 100%;
  max-width: 360px;
}

.login-header {
  text-align: center;
  margin-bottom: 32px;
}

.login-mark {
  font-size: 28px;
  color: var(--purple);
  margin-bottom: 8px;
  line-height: 1;
}

.login-header h1 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.login-header p {
  font-size: 0.875rem;
  color: var(--text-mid);
}

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-mid);
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.9375rem;
  color: var(--text);
  background: var(--white);
  transition: border-color 0.15s;
  outline: none;
}

.field input:focus {
  border-color: var(--purple);
  box-shadow: 0 0 0 3px rgba(107, 79, 168, 0.12);
}

.error-msg {
  font-size: 0.8125rem;
  color: var(--error);
  margin-bottom: 12px;
}

#login-btn {
  width: 100%;
  padding: 11px;
  background: var(--purple);
  color: var(--white);
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.9375rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  margin-top: 4px;
}

#login-btn:hover { background: var(--purple-dark); }
#login-btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* ── Chat Screen ── */
#chat-screen {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 720px;
  margin: 0 auto;
  background: var(--white);
  box-shadow: 0 0 40px rgba(107, 79, 168, 0.08);
}

/* Header */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--purple);
  color: var(--white);
  flex-shrink: 0;
}

.header-left {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.header-title {
  font-size: 0.9375rem;
  font-weight: 600;
}

.header-user {
  font-size: 0.75rem;
  opacity: 0.75;
}

.header-actions {
  display: flex;
  gap: 6px;
}

.btn-ghost {
  background: rgba(255,255,255,0.15);
  color: var(--white);
  border: none;
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-family: var(--font);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-ghost:hover { background: rgba(255,255,255,0.25); }

.btn-tts { opacity: 0.55; }
.btn-tts.active { opacity: 1; background: rgba(255,255,255,0.25); }

/* Messages area */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

.messages:empty::before {
  content: attr(data-greeting);
  display: block;
  text-align: center;
  color: var(--text-light);
  font-size: 0.9375rem;
  margin-top: 60px;
}

/* Message bubbles */
.msg {
  display: flex;
  flex-direction: column;
  max-width: 82%;
  gap: 4px;
}

.msg.user {
  align-self: flex-end;
  align-items: flex-end;
}

.msg.assistant {
  align-self: flex-start;
  align-items: flex-start;
}

.msg-bubble {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 0.9375rem;
  line-height: 1.55;
  word-break: break-word;
}

.msg.user .msg-bubble {
  background: var(--purple);
  color: var(--white);
  border-bottom-right-radius: 4px;
}

.msg.assistant .msg-bubble {
  background: var(--purple-soft);
  color: var(--text);
  border-bottom-left-radius: 4px;
}
.msg.assistant .msg-bubble p { margin: 0 0 0.5em; }
.msg.assistant .msg-bubble p:last-child { margin-bottom: 0; }
.msg.assistant .msg-bubble strong { font-weight: 600; }

/* Thinking / typing indicator */
.msg.thinking .msg-bubble {
  background: var(--purple-soft);
  padding: 12px 16px;
}

.dots {
  display: flex;
  gap: 5px;
  align-items: center;
}

.dots span {
  width: 7px;
  height: 7px;
  background: var(--purple);
  border-radius: 50%;
  opacity: 0.4;
  animation: blink 1.2s infinite ease-in-out;
}

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

@keyframes blink {
  0%, 80%, 100% { opacity: 0.4; transform: scale(1); }
  40%            { opacity: 1;   transform: scale(1.15); }
}

/* Input footer */
.chat-footer {
  flex-shrink: 0;
  border-top: 1.5px solid var(--border);
  padding: 12px 16px;
  background: var(--white);
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.message-input {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  font-family: var(--font);
  font-size: 0.9375rem;
  color: var(--text);
  background: var(--white);
  resize: none;
  outline: none;
  max-height: 120px;
  overflow-y: auto;
  line-height: 1.5;
  transition: border-color 0.15s;
}

.message-input:focus {
  border-color: var(--purple);
  box-shadow: 0 0 0 3px rgba(107, 79, 168, 0.10);
}

.btn-mic {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  background: var(--purple-soft);
  color: var(--purple);
  border: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, opacity 0.15s;
  position: relative;
}

.btn-mic:hover    { background: var(--border); }
.btn-mic:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-mic.listening {
  background: var(--purple);
  color: var(--white);
}

/* Pulsing ring while listening */
.btn-mic.listening::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--purple);
  opacity: 0;
  animation: mic-pulse 1.4s ease-out infinite;
}

@keyframes mic-pulse {
  0%   { transform: scale(1);    opacity: 0.7; }
  100% { transform: scale(1.55); opacity: 0; }
}

.btn-send {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  background: var(--purple);
  color: var(--white);
  border: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}

.btn-send:hover    { background: var(--purple-dark); }
.btn-send:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-send.stopping { background: var(--error); opacity: 1; cursor: pointer; }
.btn-send.stopping:hover { background: #a93226; }

/* Error notice inside chat */
.msg.error .msg-bubble {
  background: #FEF2F2;
  color: var(--error);
}

/* Responsive */
@media (max-width: 480px) {
  .login-card { padding: 32px 24px 28px; }
  .messages   { padding: 16px; gap: 12px; }
  .msg        { max-width: 90%; }
  .chat-footer { padding: 10px 12px; }
  .header-title { font-size: 0.875rem; }
}
