:root {
  --bg-main: #ffffff;
  --bg-sidebar: #f9f9f9;
  --bg-hover: #eeeeee;
  --text-main: #000000;
  --text-secondary: #666666;
  --border-color: #e5e5e5;
  --input-bg: #ffffff;
  --accent: #10a37f;
  --sidebar-width: 260px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg-main);
  color: var(--text-main);
  height: calc(var(--vh, 1vh) * 100);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;   /* always column — chat-container handles the horizontal split */
  overflow: hidden;
  position: fixed;
  width: 100%;
}

/* Auth Pages Redesign - Instagram Style Centered Layout */
.auth-body {
  background: #ffffff;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  overflow: hidden;
}

.auth-container {
  width: 100%;
  max-width: 350px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-card {
  background: transparent;
  padding: 40px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.brand-title {
  font-family: 'Poppins', sans-serif;
  font-size: 42px;
  font-weight: 800;
  margin-bottom: 32px;
  color: #000;
  letter-spacing: -1px;
}

.brand-subtitle {
  display: none; /* Hide subtitle for minimalist look */
}

.auth-forms, .auth-form {
  width: 100%;
}

.form-group {
  margin-bottom: 12px;
  width: 100%;
  position: relative;
}

.form-group label {
  display: none; /* Instagram style labels are hidden */
}

.form-group input {
  width: 100%;
  padding: 14px 12px;
  background: #f1f1f1;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  color: #000;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus {
  border-color: #ccc;
}

.password-toggle {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: #666;
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.password-toggle:hover {
  color: #000;
}

.btn-primary {
  width: 100%;
  padding: 12px;
  background: #0095f6;
  border: none;
  border-radius: 8px;
  color: white;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  margin-top: 14px;
  transition: background 0.2s;
}

.btn-primary:hover {
  background: #1877f2;
}

.auth-card-footer {
  background: transparent;
  padding: 20px;
  text-align: center;
  font-size: 14px;
  color: #000;
}

.auth-card-footer p {
  margin: 0;
  color: #000;
}

.auth-card-footer a {
  color: #0095f6;
  text-decoration: none;
  font-weight: 600;
  margin-left: 4px;
}

.error-message {
  color: #ed4956;
  font-size: 12px;
  margin-top: 12px;
  text-align: center;
}

.social-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.btn-social {
  width: 100%;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: background 0.2s, box-shadow 0.2s;
  border: 1px solid #e0e0e0;
  background: #fff;
  color: #111;
}

.btn-social:hover {
  background: #f7f7f7;
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}

.btn-apple {
  background: #000;
  color: #fff;
  border-color: #000;
}

.btn-apple:hover {
  background: #222;
  box-shadow: 0 1px 4px rgba(0,0,0,0.25);
}

.auth-divider {
  display: flex;
  align-items: center;
  width: 100%;
  gap: 12px;
  margin: 4px 0;
  color: #aaa;
  font-size: 13px;
}

.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: #e5e5e5;
}

.auth-divider span {
  white-space: nowrap;
}

/* Chat container: fills remaining body height, splits sidebar | chat horizontally */
.chat-container {
  flex: 1;
  display: flex;
  flex-direction: row;
  overflow: hidden;
  min-height: 0;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  height: 100%;
  border-right: 1px solid var(--border-color);
  transition: transform 0.3s ease;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.logo-container {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
}

.logo-small {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
}

.logo-text {
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.5px;
  color: var(--text-main);
}

.mobile-nav {
  display: none;           /* hidden on desktop/tablet — shown via mobile media query */
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--bg-main);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 1500;
  height: 56px;
  flex-shrink: 0;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}

.btn-new-chat {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: transparent;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-main);
  cursor: pointer;
  font-size: 14px;
  transition: background 0.2s;
  width: 100%;
}

.btn-new-chat:hover {
  background: var(--bg-hover);
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

/* CAi 4.0: Learning Progress */
.learning-progress {
  padding: 12px 12px 10px;
  margin-bottom: 8px;
  border-radius: 10px;
  background: rgba(59, 130, 246, 0.06);
  border: 1px solid rgba(59, 130, 246, 0.12);
}
.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.progress-header span:first-child {
  font-size: 11px;
  font-weight: 600;
  color: #3b82f6;
}
.progress-header span:last-child {
  font-size: 11px;
  font-weight: 700;
  color: #3b82f6;
}
.progress-bar-bg {
  height: 4px;
  background: rgba(59, 130, 246, 0.15);
  border-radius: 2px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: #3b82f6;
  border-radius: 2px;
  transition: width 0.5s ease;
}
.progress-hint {
  margin: 6px 0 0;
  font-size: 10px;
  color: var(--text-secondary);
  line-height: 1.3;
}

/* CAi 4.0: Local AI Panel */
.local-ai-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  margin-bottom: 8px;
  border-radius: 10px;
  background: rgba(16, 185, 129, 0.06);
  border: 1px solid rgba(16, 185, 129, 0.12);
}
.local-ai-info {
  display: flex;
  align-items: center;
  gap: 8px;
}
.local-ai-icon {
  font-size: 16px;
}
.local-ai-title {
  font-size: 11px;
  font-weight: 600;
  color: #10b981;
  margin: 0;
}
.local-ai-status {
  font-size: 10px;
  color: var(--text-secondary);
  margin: 1px 0 0;
}
.local-ai-btn {
  font-size: 10px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 6px;
  border: none;
  background: #10b981;
  color: white;
  cursor: pointer;
  transition: all 0.2s;
}
.local-ai-btn:hover {
  background: #059669;
}
.local-ai-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.history-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 12px 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.dropdown-arrow {
  opacity: 0.7;
}

.conversation-history {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.history-item {
  position: relative;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-secondary);
  transition: background 0.2s, color 0.2s;
  user-select: none;
  -webkit-user-select: none;
}

.history-item .delete-icon {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  display: none;
  color: #ff4d4d;
  align-items: center;
  justify-content: center;
  background: white;
  padding: 4px;
  border-radius: 4px;
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.history-item.show-delete .delete-icon {
  display: block;
}


.history-item:hover, .history-item.active {
  background: var(--bg-hover);
  color: var(--text-main);
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 32px;
  height: 32px;
  background: #eee;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
  color: var(--text-main);
}

.btn-logout-minimal {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: 4px;
}

.btn-logout-minimal:hover {
  background: var(--bg-hover);
  color: var(--text-main);
}

/* Main Chat Area */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 0;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
}

.chat-input-area {
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: var(--bg-main);
  position: relative;
  z-index: 10;
  width: 100%;
}

.chat-input-form {
  background: var(--input-bg);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 8px 16px;
  display: flex;
  align-items: flex-end;
  gap: 12px;
  box-shadow: 0 5px 15px rgba(0,0,0,0.05);
}

#messageInput {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-main);
  font-size: 16px;
  resize: none;
  min-height: 24px;
  max-height: 120px; /* Max 5 lines approx */
  outline: none;
  padding: 8px 0;
  line-height: 1.5;
  overflow-y: auto;
}

.btn-send-minimal {
  background: #000000;
  color: white;
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.2s, background 0.2s;
  padding: 0;
}

.btn-send-minimal svg {
  width: 18px;
  height: 18px;
  transform: rotate(0deg); 
  margin-left: 2px;
}

.cap-bubble {
  background: #ffffff;
  border: 1px solid #e5e5e5;
  border-radius: 20px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}

.cap-bubble:hover {
  background: #f9f9f9;
  border-color: #d1d1d1;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.cap-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cap-icon svg {
  width: 18px;
  height: 18px;
}

.cap-text {
  font-size: 14px;
  font-weight: 500;
  color: #333;
}

.btn-send-minimal:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.input-footer {
  font-size: 12px;
  color: var(--text-secondary);
  text-align: center;
}

/* Welcome Container */
.welcome-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  margin-top: 15vh;
  opacity: 0.9;
  color: var(--text-main);
}

.message {
  padding: 12px 16px;
  width: 100%;
  display: flex;
  flex-direction: column;
}

.message.user {
  align-items: flex-end;
}

.message.ai {
  align-items: flex-start;
}

.message.user .message-bubble {
  background: #f4f4f4;
  padding: 10px 16px;
  border-radius: 18px 18px 2px 18px;
  max-width: 85%;
  color: #000;
  border: 1px solid #e5e5e5;
}

.message.ai .message-bubble {
  background: transparent;
  padding: 0;
  border-radius: 0;
  max-width: 100%;
  color: var(--text-main);
  line-height: 1.65;
}

.message.ai .message-bubble p {
  margin: 0 0 10px 0;
}
.message.ai .message-bubble p:last-child {
  margin-bottom: 0;
}

.message.ai .message-bubble strong {
  color: var(--text-main);
  font-weight: 700;
}
.message.ai .message-bubble em {
  font-style: italic;
  color: var(--text-secondary);
}

.ai-list {
  margin: 0 0 12px 0;
  padding-left: 20px;
}
.ai-list li {
  margin-bottom: 6px;
  line-height: 1.6;
}
.ai-list li:last-child {
  margin-bottom: 0;
}
.ai-list li strong {
  color: var(--text-main);
  font-weight: 700;
}

.ai-divider {
  border: none;
  border-top: 1px solid var(--border-color);
  margin: 14px 0;
  opacity: 0.5;
}

.ai-quote {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  margin: 0 0 12px 0;
  color: var(--text-secondary);
  font-style: italic;
}

.ai-quote p:last-child {
  margin-bottom: 0;
}

/* ── Desktop & Tablet (≥769px): sidebar always visible, no hamburger ── */
@media (min-width: 769px) {
  .mobile-nav {
    display: none !important;
  }

  .sidebar {
    position: relative;
    left: auto;
    top: auto;
    width: var(--sidebar-width);
    height: 100%;
    flex-shrink: 0;
    transform: none !important;
    box-shadow: none;
  }

  .sidebar-overlay {
    display: none !important;
  }

  .chat-main {
    flex: 1;
    height: 100%;
    min-width: 0;
  }

  .chat-messages {
    padding: 24px 20px;
    max-width: 860px;
  }
}

/* ── Tablet only (769px – 1024px): slightly narrower sidebar ── */
@media (min-width: 769px) and (max-width: 1024px) {
  :root { --sidebar-width: 220px; }

  .chat-messages {
    max-width: 100%;
    padding: 20px 16px;
  }
}

/* ── Mobile (≤768px): hamburger drawer ── */
@media (max-width: 768px) {
  .mobile-nav {
    display: flex !important;
    justify-content: space-between;
    height: 56px;
  }

  .sidebar {
    position: fixed;
    left: -100%;
    top: 0;
    z-index: 2000;
    width: 280px;
    height: 100dvh;
    box-shadow: 10px 0 30px rgba(0,0,0,0.12);
    transition: left 0.3s ease;
  }

  .sidebar.active {
    left: 0;
  }

  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.25);
    z-index: 1900;
  }

  .sidebar-overlay.active {
    display: block;
  }

  .chat-main {
    flex: 1;
    min-height: 0;
    overflow: hidden;
  }

  .chat-messages {
    padding: 16px 12px;
  }

  .chat-input-area {
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  }

  .chat-input-form {
    padding: 8px 12px;
  }
}

.menu-btn {
  background: transparent;
  border: none;
  color: var(--text-main);
  cursor: pointer;
  padding: 8px;
  display: flex;
  align-items: center;
}

/* ── AI Switcher ── */
.ai-switcher {
  display: flex;
  align-items: center;
  background: rgba(0, 0, 0, 0.08);
  border-radius: 20px;
  padding: 3px;
  gap: 2px;
  flex-shrink: 0;
}

/* Sidebar AI switcher (desktop/tablet only) */
.sidebar-ai-switcher {
  display: none;          /* hidden on mobile */
  width: 100%;
  border-radius: 10px;
}

.sidebar-ai-switcher .ai-switch-btn {
  flex: 1;
  text-align: center;
  padding: 7px 8px;
  font-size: 13px;
  border-radius: 8px;
}

@media (min-width: 769px) {
  .sidebar-ai-switcher {
    display: flex;         /* show in sidebar on desktop/tablet */
  }
}

.ai-switch-btn {
  background: transparent;
  border: none;
  border-radius: 16px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 600;
  font-family: 'Inter', sans-serif;
  color: #666;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  line-height: 1;
}

.ai-switch-btn.active {
  background: #fff;
  color: #111;
  box-shadow: 0 1px 4px rgba(0,0,0,0.15);
}





/* ── Typing indicator ── */
.typing-bubble {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 14px 18px !important;
  background: transparent !important;
  min-width: 52px;
}

.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #aaa;
  display: inline-block;
  animation: typingPulse 1.2s ease-in-out infinite;
}

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

@keyframes typingPulse {
  0%, 60%, 100% { opacity: 0.25; transform: scale(0.85); }
  30%            { opacity: 1;    transform: scale(1); }
}

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

.waking-dots span {
  display: inline-block;
  font-size: 10px;
  margin: 0 1px;
}
