/* ==============================================================
   EduSuite Modern AI Chatbot Styles
   Aesthetic: Clear White Minimalist Canvas with Charcoal Black Inputs
   Optimized for Mobile & Desktop Responsive Usability
   ============================================================== */

:root {
  --bg-main: #ffffff;
  --bg-sidebar: #f9fafb;
  --bg-sidebar-hover: #f3f4f6;
  --bg-card: #ffffff;
  --bg-assistant-bubble: #f3f4f6;
  --bg-user-bubble: #18181b;
  --bg-charcoal: #18181b;
  --bg-charcoal-subtle: #27272a;
  
  --border-color: #e5e7eb;
  --border-charcoal: #27272a;
  
  --text-main: #111827;
  --text-secondary: #4b5563;
  --text-muted: #6b7280;
  --text-subtle: #9ca3af;
  --text-charcoal-light: #ffffff;
  
  --accent-blue: #2563eb;
  --accent-blue-light: #eff6ff;
  --accent-red: #ef4444;
  
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

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

html, body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background-color: var(--bg-main);
  color: var(--text-main);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

/* Main Layout Grid */
.chat-app {
  display: flex;
  width: 100vw;
  height: 100%;
  height: 100dvh;
  position: relative;
  background-color: var(--bg-main);
  overflow: hidden;
}

/* ==============================================================
   SIDEBAR (CONVERSATION HISTORY)
   ============================================================== */
.chat-sidebar {
  width: 280px;
  min-width: 280px;
  height: 100%;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), width 0.25s ease;
  z-index: 50;
  position: relative;
}

.chat-sidebar.collapsed {
  transform: translateX(-100%);
  position: absolute;
}

@media (min-width: 769px) {
  .chat-sidebar.collapsed {
    transform: none;
    width: 0;
    min-width: 0;
    overflow: hidden;
    border-right: none;
  }
}

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

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text-main);
}

.sidebar-brand-logo {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: #18181b;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
}

.sidebar-brand-name {
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
  color: var(--text-main);
}

.btn-sidebar-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

/* New Chat Button */
.new-chat-wrapper {
  padding: 12px 14px;
}

.btn-new-chat {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: #18181b;
  border: 1px solid #18181b;
  color: #ffffff;
  font-weight: 600;
  font-size: 0.9rem;
  padding: 10px 14px;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.btn-new-chat:hover {
  background: #27272a;
}

.new-chat-kbd {
  font-size: 0.72rem;
  background: rgba(255, 255, 255, 0.15);
  padding: 2px 6px;
  border-radius: 4px;
  color: #ffffff;
  font-family: var(--font-mono);
}

/* History Group */
.history-group-label {
  padding: 8px 16px 4px;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.sidebar-conversations {
  flex: 1;
  overflow-y: auto;
  padding: 6px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.conversation-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 0.86rem;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
  position: relative;
  overflow: hidden;
  white-space: nowrap;
}

.conversation-item:hover {
  background: var(--bg-sidebar-hover);
  color: var(--text-main);
}

.conversation-item.active {
  background: #e5e7eb;
  color: var(--text-main);
  font-weight: 600;
}

.conversation-title-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  margin-right: 6px;
}

.conversation-item-actions {
  display: none;
  align-items: center;
  gap: 2px;
}

.conversation-item:hover .conversation-item-actions,
.conversation-item.active .conversation-item-actions {
  display: flex;
}

.btn-chat-action {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 3px;
  border-radius: 4px;
  display: flex;
  align-items: center;
}

.btn-chat-action:hover {
  color: var(--text-main);
  background: rgba(0, 0, 0, 0.08);
}

/* Sidebar Footer */
.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid var(--border-color);
  background: var(--bg-sidebar);
}

.btn-persona {
  background: #ffffff;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.btn-persona.active {
  background: #18181b;
  color: #ffffff;
  border-color: #18181b;
}

/* ==============================================================
   MAIN CHAT INTERFACE
   ============================================================== */
.chat-main {
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--bg-main);
}

/* Header Top Bar */
.chat-topbar {
  flex-shrink: 0;
  height: 54px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #ffffff;
  z-index: 20;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-menu-toggle {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-radius: 8px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-menu-toggle:hover {
  background: var(--bg-sidebar-hover);
}

.chat-header-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text-main);
}

.ai-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #10b981;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-header-tool {
  background: #ffffff;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  transition: all 0.15s ease;
}

.btn-header-tool:hover {
  background: var(--bg-sidebar-hover);
  color: var(--text-main);
}

.btn-header-tool.active {
  background: #18181b;
  color: #ffffff;
  border-color: #18181b;
}

/* ==============================================================
   MESSAGES SCROLL AREA
   ============================================================== */
.chat-messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
}

.chat-messages::-webkit-scrollbar {
  width: 5px;
}
.chat-messages::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 999px;
}

/* Clean Empty State Hero */
.empty-chat-hero {
  margin: auto;
  text-align: center;
  max-width: 580px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px;
  animation: fadeIn 0.3s ease;
}

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

.hero-brand-badge {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: #18181b;
  color: #ffffff;
  font-size: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 18px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.hero-voice-title {
  font-size: 1.85rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 8px;
  color: var(--text-main);
}

.hero-voice-sub {
  font-size: 0.95rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 24px;
  max-width: 440px;
}

.hero-suggestions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
  width: 100%;
}

.hero-suggestion-card {
  background: #ffffff;
  border: 1px solid var(--border-color);
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 0.85rem;
  color: var(--text-main);
  text-align: left;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
}

.hero-suggestion-card:hover {
  border-color: #94a3b8;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
  transform: translateY(-1px);
}

.hero-suggestion-card span.card-icon {
  font-size: 1.15rem;
  line-height: 1;
}

.card-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ==============================================================
   MESSAGE ROWS & BUBBLES
   ============================================================== */
.message-row {
  display: flex;
  gap: 12px;
  width: 100%;
  animation: slideUp 0.2s ease;
}

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

.message-row.user {
  flex-direction: row-reverse;
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 1rem;
}

.message-row.assistant .message-avatar {
  background: #f1f5f9;
  border: 1px solid var(--border-color);
  color: var(--text-main);
}

.message-row.user .message-avatar {
  background: #18181b;
  color: #ffffff;
}

.message-body {
  max-width: 82%;
  display: flex;
  flex-direction: column;
}

@media (max-width: 640px) {
  .message-body {
    max-width: 88%;
  }
}

.message-bubble {
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 0.94rem;
  line-height: 1.6;
  word-break: break-word;
}

/* Assistant Bubble: Soft Light Slate */
.message-row.assistant .message-bubble {
  background: var(--bg-assistant-bubble);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-top-left-radius: 4px;
}

/* User Bubble: Charcoal Black */
.message-row.user .message-bubble {
  background: var(--bg-user-bubble);
  color: #ffffff;
  border-top-right-radius: 4px;
}

.message-attached-photo {
  max-width: 240px;
  max-height: 200px;
  object-fit: cover;
  border-radius: 10px;
  margin-bottom: 8px;
  display: block;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

/* Markdown typography inside assistant bubble */
.message-bubble h1, .message-bubble h2, .message-bubble h3 {
  color: #0f172a;
  margin-top: 12px;
  margin-bottom: 6px;
  font-weight: 800;
}
.message-bubble h1 { font-size: 1.25rem; }
.message-bubble h2 { font-size: 1.1rem; }
.message-bubble h3 { font-size: 1rem; }
.message-bubble p { margin-bottom: 8px; }
.message-bubble p:last-child { margin-bottom: 0; }
.message-bubble ul, .message-bubble ol { padding-left: 20px; margin-bottom: 8px; }
.message-bubble li { margin-bottom: 3px; }
.message-bubble strong { color: #0f172a; font-weight: 700; }
.message-bubble table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 0.86rem;
  background: #ffffff;
  border-radius: 6px;
  overflow: hidden;
}
.message-bubble th, .message-bubble td {
  padding: 8px 10px;
  border: 1px solid #e2e8f0;
  text-align: left;
}
.message-bubble th {
  background: #f8fafc;
  font-weight: 700;
}

/* Message Actions */
.message-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
  padding-left: 4px;
}

.btn-msg-tool {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.76rem;
  padding: 2px 6px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.btn-msg-tool:hover {
  color: var(--text-main);
  background: rgba(0, 0, 0, 0.05);
}

/* ==============================================================
   BOTTOM COMPOSER: CHARCOAL BLACK INPUT DOCK
   ============================================================== */
.chat-input-container {
  flex-shrink: 0;
  width: 100%;
  background: #ffffff;
  padding: 10px 16px max(14px, env(safe-area-inset-bottom));
  border-top: 1px solid #f1f5f9;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-sizing: border-box;
}

/* Voice Active Overlay */
.voice-active-overlay {
  display: none;
  width: 100%;
  max-width: 780px;
  margin-bottom: 8px;
  background: #18181b;
  border: 1px solid #ef4444;
  border-radius: 14px;
  padding: 10px 16px;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 4px 14px rgba(239, 68, 68, 0.2);
}

.voice-wave-bars {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 20px;
}

.voice-bar {
  width: 3px;
  background: #ef4444;
  border-radius: 3px;
  animation: wavePulse 1s infinite ease-in-out;
}
.voice-bar:nth-child(2) { animation-delay: 0.15s; height: 14px; }
.voice-bar:nth-child(3) { animation-delay: 0.3s; height: 20px; }
.voice-bar:nth-child(4) { animation-delay: 0.45s; height: 16px; }
.voice-bar:nth-child(5) { animation-delay: 0.6s; height: 10px; }

@keyframes wavePulse {
  0%, 100% { height: 6px; }
  50% { height: 20px; }
}

.voice-transcription-preview {
  flex: 1;
  margin: 0 12px;
  font-size: 0.88rem;
  color: #ffffff;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.voice-duration {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: #fca5a5;
}

.btn-cancel-voice {
  background: rgba(239, 68, 68, 0.2);
  border: 1px solid #ef4444;
  color: #ffffff;
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 700;
}

/* Charcoal Input Dock Wrapper */
.input-dock-wrapper {
  width: 100%;
  max-width: 780px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Media preview above textarea */
.media-preview-container {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 4px;
}

.media-preview-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #18181b;
  color: #ffffff;
  padding: 4px 10px 4px 4px;
  border-radius: 10px;
  border: 1px solid #27272a;
  font-size: 0.78rem;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.media-preview-chip img {
  width: 28px;
  height: 28px;
  object-fit: cover;
  border-radius: 6px;
}

.media-preview-name {
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-remove-media {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: #ffffff;
  border-radius: 50%;
  width: 18px;
  height: 18px;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-remove-media:hover {
  background: #ef4444;
}

/* Charcoal Black Input Dock */
.input-dock {
  width: 100%;
  background-color: #18181b;
  border: 1px solid #27272a;
  border-radius: 24px;
  padding: 8px 10px 8px 14px;
  display: flex;
  align-items: flex-end; /* Keep buttons cleanly anchored to bottom baseline */
  gap: 8px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.04);
  box-sizing: border-box;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input-dock:focus-within {
  border-color: #3f3f46;
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.14);
}

/* Textarea inside Charcoal Input (Spacious & Expandable) */
.chat-textarea {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: #ffffff;
  font-size: 16px; /* 16px prevents iOS auto-zoom */
  font-family: inherit;
  resize: none;
  max-height: 280px; /* Expands smoothly for long prompts / UNEB essays */
  min-height: 44px;  /* Comfortable, generous starting height */
  line-height: 1.5;
  padding: 8px 4px;
  box-sizing: border-box;
  overflow-y: hidden;
}

.chat-textarea::-webkit-scrollbar {
  width: 5px;
}

.chat-textarea::-webkit-scrollbar-thumb {
  background: #3f3f46;
  border-radius: 999px;
}

.chat-textarea::placeholder {
  color: #9ca3af;
}

/* Clean Dock Action Buttons */
.dock-btn {
  width: 38px;
  height: 38px;
  min-width: 38px;
  border-radius: 50%;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  margin-bottom: 3px; /* Aligns neatly with bottom line of textarea */
  flex-shrink: 0;
}

/* Plus button (+) for photo upload */
.btn-upload {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

.btn-upload:hover, .btn-upload:active {
  background: rgba(255, 255, 255, 0.2);
}

/* Simple Mic button */
.btn-mic {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

.btn-mic:hover, .btn-mic:active {
  background: rgba(255, 255, 255, 0.2);
}

.btn-mic.listening {
  background: #ef4444;
  color: #ffffff;
  animation: pulseMic 1s infinite;
}

@keyframes pulseMic {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

/* Simple Send / Push Message button (Arrow Up) */
.btn-send {
  background: #ffffff;
  color: #18181b;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

.btn-send:hover, .btn-send:active {
  background: #e4e4e7;
  transform: scale(1.04);
}

.btn-send:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
}

/* Mobile Sidebar Backdrop */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(2px);
  z-index: 40;
}

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

/* Typing Indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 6px;
}

.typing-dot {
  width: 6px;
  height: 6px;
  background: #64748b;
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* ==============================================================
   MOBILE RESPONSIVE TWEAKS (< 768px)
   ============================================================== */
@media (max-width: 768px) {
  .no-mobile {
    display: none !important;
  }
  
  .chat-sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: 82%;
    max-width: 320px;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
  }
  
  .chat-messages {
    padding: 14px 12px;
    gap: 14px;
  }
  
  .chat-input-container {
    padding: 8px 12px max(12px, env(safe-area-inset-bottom));
  }
  
  .input-dock {
    padding: 5px 6px 5px 10px;
    gap: 6px;
    border-radius: 24px;
  }
  
  .dock-btn {
    width: 34px;
    height: 34px;
    min-width: 34px;
  }
  
  .hero-voice-title {
    font-size: 1.5rem;
  }
  
  .hero-suggestions-grid {
    grid-template-columns: 1fr;
  }
}
