/* public/styles.css
   Modern, “delightful” chat UI with light/dark themes, accessible switch,
   typing indicator, and normalized font sizes.
*/

/* ========= THEME TOKENS ========= */
:root {
  --bg: #f8f9fa;
  --surface: #ffffff;
  --text: #1a1a2e;
  --muted: #6b7280;
  --primary: #7c3aed; /* The purple from the mock */
  --primary-hover: #6d28d9;
  --bot-bg: #ececf7; /* Light purple */
  --bot-avatar: #635bff;
  --user-bg: #ffffff;
  --danger: #fee2e2;
  --danger-text: #991b1b;
  --radius: 8px;
  --bubble-radius: 8px;
}

/* Explicit dark-mode override when toggled */
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0d10;
  --surface: #1a1c22;
  --text: #e5e7eb;
  --muted: #9aa4b2;
  --primary: #9f67ff;
  --primary-hover: #b388ff;
  --bot-bg: #222436;
  --bot-avatar: #7b6eea;
  --user-bg: #1f2229;
  --danger: #5a1a1a;
  --danger-text: #fca5a5;
}
/* Keep UA controls consistent for the light theme too */
html[data-theme="light"] { color-scheme: light; }

/* ========= BASE ========= */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* ========= LAYOUT ========= */
.app-header {
  width: 100%;
  padding: 16px clamp(24px, 5vw, 48px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border-bottom: 1px solid color-mix(in srgb, var(--muted) 20%, transparent);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 32px;
}

.brand { display: flex; align-items: center; gap: 12px; color: #1a1a3a; }
html[data-theme="dark"] .brand { color: var(--text); }
.title { font-size: 1.75rem; margin: 0; font-weight: 700; letter-spacing: -0.5px; }

.user-profile {
  display: flex;
  align-items: center;
  gap: 16px;
}
.user-avatar-header {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: #e5e7eb;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #374151;
}
html[data-theme="dark"] .user-avatar-header { background: #374151; color: #9ca3af; }

.user-info { display: flex; flex-direction: column; }
.user-name { font-size: 1.05rem; font-weight: 600; color: #1a1a3a; line-height: 1.2; }
html[data-theme="dark"] .user-name { color: var(--text); }
.user-email { font-size: 0.85rem; color: #475569; font-weight: 600; margin-top: 2px; }
html[data-theme="dark"] .user-email { color: var(--muted); }

.chat-shell {
  max-width: 900px;
  margin: 0 auto;
  padding: 8px clamp(16px, 4vw, 24px) 40px;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 140px);
}

.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 24px 0 40px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  scroll-behavior: smooth;
}

/* ========= MESSAGES ========= */
.msg-row {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  width: 100%;
}
.msg-row--bot {
  justify-content: flex-start;
}
.msg-row--user {
  justify-content: flex-end;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}
.avatar--bot {
  background: var(--bot-avatar);
}
.avatar--user {
  background: #e5e7eb;
  color: #374151;
}
html[data-theme="dark"] .avatar--user {
  background: #374151;
  color: #d1d5db;
}
.avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.msg-content {
  display: flex;
  flex-direction: column;
  max-width: 75%;
}
.msg-row--bot .msg-content { align-items: flex-start; }
.msg-row--user .msg-content { align-items: flex-end; }

.msg-bubble {
  padding: 14px 18px;
  border-radius: var(--bubble-radius);
  font-size: 0.95rem;
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.msg-row--bot .msg-bubble { 
  background: var(--bot-bg); 
}
.msg-row--user .msg-bubble { 
  background: var(--user-bg); 
  border: 1px solid color-mix(in srgb, var(--muted) 20%, transparent);
}
.msg-row--error .msg-bubble { 
  background: var(--danger); 
  color: var(--danger-text);
  border: 1px solid color-mix(in srgb, var(--danger-text) 20%, transparent);
}
.msg-row--error .avatar--error {
  background: var(--danger);
}
.msg-row--error .avatar--error svg {
  stroke: var(--danger-text);
}

.msg-meta {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 6px;
  font-weight: 500;
}

/* ========= INPUT ROW ========= */
.chat-input-form {
  margin-top: auto;
}

.chat-input-container {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--primary);
  border-radius: 8px;
  padding: 10px 14px;
}

.attach-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.7;
  transition: opacity 0.2s;
}
.attach-btn:hover { opacity: 1; }

.chat-input-container input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  padding: 8px 0;
}
.chat-input-container input::placeholder { color: var(--muted); opacity: 0.8; }

.send-btn {
  background: var(--primary);
  color: white;
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s;
}
.send-btn:hover { background: var(--primary-hover); }
.send-btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* ========= ACCESSIBLE SWITCH (theme toggle) ========= */
.switch {
  position: relative;
  display: inline-block;
  width: 54px;
  height: 28px;
}
.switch input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  margin: 0;
  cursor: pointer;
  z-index: 2;
}
.switch-track {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid color-mix(in srgb, var(--muted) 25%, transparent);
  transition: background .2s, border-color .2s;
}
html[data-theme="dark"] .switch-track {
  background: #2a2a35;
  border-color: #2a2a35;
}
.switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--primary);
  transition: transform .2s cubic-bezier(0.4, 0, 0.2, 1);
}
.switch-icon { 
  display: flex; 
  align-items: center; 
  justify-content: center;
  color: var(--muted);
  width: 14px;
  height: 14px;
}
.switch-icon--sun { color: #f59e0b; }
.switch-icon--moon { color: #d1d5db; }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(26px); }

/* ========= TYPING INDICATOR ========= */
.msg-bubble.typing {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-width: 40px;
  min-height: 24px;
}
.msg-bubble.typing .dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--text);
  opacity: .4;
  animation: typingBlink 1s infinite ease-in-out;
}
.msg-bubble.typing .dot:nth-child(2) { animation-delay: .15s; }
.msg-bubble.typing .dot:nth-child(3) { animation-delay: .30s; }

@keyframes typingBlink {
  0%, 100% { opacity: .4; transform: translateY(0); }
  40%      { opacity: 1; transform: translateY(-3px); }
}

/* ========= FOOTER ========= */
.app-footer {
  color: var(--muted);
  font-size: .8rem;
  justify-content: center;
  text-align: center;
  padding-top: 16px;
}
.visually-hidden {
  position: absolute !important;
  clip: rect(1px, 1px, 1px, 1px);
  padding: 0 !important;
  border: 0 !important;
  height: 1px !important;
  width: 1px !important;
  overflow: hidden;
}

/* ========= GATE / LANDING ========= */
.gate {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
  background: var(--bg);
}
.gate-card {
  text-align: center;
  max-width: 420px;
  width: 100%;
  padding: 3rem 2rem;
  background: var(--surface);
  border-radius: 16px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.08);
}
html[data-theme="dark"] .gate-card { box-shadow: 0 4px 24px rgba(0,0,0,0.3); }
.gate-logo { margin-bottom: 1rem; }
.gate-title { font-size: 1.5rem; font-weight: 600; color: var(--text); margin: 0 0 0.5rem; }
.gate-subtitle { font-size: 0.9rem; color: var(--muted); margin: 0 0 2rem; }
.gate-buttons { display: flex; flex-direction: column; gap: 0.75rem; }
.gate-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  padding: 0.75rem 1.5rem; border-radius: 8px; font-size: 0.95rem; font-weight: 600;
  cursor: pointer; border: none; transition: all 0.15s ease;
}
.gate-btn--primary {
  background: var(--primary); color: #fff;
}
.gate-btn--primary:hover { background: var(--primary-hover); }
.gate-btn--secondary {
  background: transparent; color: var(--text); border: 2px solid var(--muted);
}
.gate-btn--secondary:hover { border-color: var(--primary); color: var(--primary); }
.gate-hint { font-size: 0.75rem; color: var(--muted); margin-top: 1rem; }

/* ========= MODE BADGE ========= */
.mode-badge {
  font-size: 0.7rem; font-weight: 600; padding: 0.2rem 0.6rem;
  border-radius: 12px; margin-left: 0.5rem; text-transform: uppercase;
}
.mode-badge--user { background: #dcfce7; color: #166534; }
.mode-badge--agent { background: #fef3c7; color: #92400e; }
html[data-theme="dark"] .mode-badge--user { background: #14532d; color: #86efac; }
html[data-theme="dark"] .mode-badge--agent { background: #78350f; color: #fde68a; }

/* ========= LOGOUT BTN ========= */
.logout-btn {
  background: none; border: none; cursor: pointer; padding: 0.4rem;
  color: var(--muted); border-radius: 6px; transition: color 0.15s;
}
.logout-btn:hover { color: var(--primary); }

/* ========= APP CONTAINER ========= */
.app-container { display: flex; flex-direction: column; height: 100vh; }
