/* ===== Mobile Styles (max-width: 768px) ===== */
/* Loaded only on mobile/tablet viewports */

@media (max-width: 768px) {
  /* -- Navbar -- */
  .nav-tagline { display: none; }
  .nav-zoom { display: none; }
  .navbar {
    padding: 0 12px; height: 50px;
    position: fixed; top: 0; left: 0; right: 0; z-index: 200;
    transition: transform 0.25s ease;
  }
  .navbar.mobile-hidden { transform: translateY(-100%); }
  .nav-brand { font-size: 1.1rem; }

  /* -- Home page -- */
  .features { grid-template-columns: 1fr; }
  .home-page { padding: 60px 12px 80px; }
  .home-hero h1 { font-size: 1.5rem; letter-spacing: -0.5px; margin-bottom: 10px; }
  .home-hero-subtitle { font-size: 0.88rem; }
  .home-hero { margin-bottom: 20px; }
  .home-input-section { padding: 16px; border-radius: 12px; margin-bottom: 12px; }
  .home-title { font-size: 1.2rem; margin-bottom: 12px; }
  .home-input-row { flex-direction: column; }
  .home-start-btn { width: 100%; padding: 12px; }
  .home-topic-input { font-size: 0.85rem; padding: 10px 12px; }
  .home-topic-input::placeholder { font-size: 0.8rem; }
  .home-suggestions { overflow-x: auto; flex-wrap: nowrap; padding-bottom: 4px; }
  .suggestion-chip { white-space: nowrap; flex-shrink: 0; }
  .session-card { padding: 14px 16px; border-radius: 12px; }
  .card-title { font-size: 0.92rem; }
  .card-delete { opacity: 1; }
  .model-select-wrap { width: 100%; }
  .tab-bar { width: 100%; }
  .tab-btn { flex: 1; }

  /* -- Session layout: stack everything -- */
  .session-container { flex-direction: column; position: relative; }

  /* Hide resize handles on mobile */
  .resize-handle { display: none; }

  /* ===== Mobile Bottom Tab Bar ===== */
  .mobile-bottom-bar {
    display: flex;
    position: fixed; bottom: 0; left: 0; right: 0;
    z-index: 300;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    padding: 6px 0 calc(6px + env(safe-area-inset-bottom, 0px));
    transition: transform 0.25s ease;
  }
  .mobile-bottom-bar.hidden { transform: translateY(100%); }

  .mobile-tab {
    flex: 1;
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    background: none; border: none; padding: 10px 0;
    color: var(--text-muted); font-family: inherit;
    cursor: pointer; transition: color 0.15s;
    -webkit-tap-highlight-color: transparent;
    min-height: 48px; /* Minimum touch target per WCAG */
  }
  .mobile-tab.active { color: var(--primary-light); }
  .mobile-tab-icon { font-size: 1.3rem; line-height: 1; }
  .mobile-tab-label { font-size: 0.72rem; font-weight: 600; letter-spacing: 0.3px; }

  /* -- Sidebar as full-screen sheet from bottom -- */
  .sidebar {
    position: fixed; left: 0; right: 0;
    bottom: 0; top: auto;
    height: 75vh; max-height: 75vh;
    width: 100%; max-width: 100%;
    z-index: 250;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
    border-right: none;
    border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -8px 30px rgba(0,0,0,0.5);
  }
  .sidebar.mobile-open { transform: translateY(0); z-index: 310; }

  /* Sheet drag handle indicator */
  .sidebar::before {
    content: '';
    display: block;
    width: 36px; height: 4px;
    background: var(--bg-surface);
    border-radius: 2px;
    margin: 8px auto 4px;
    flex-shrink: 0;
  }

  .sidebar-header { padding: 12px 16px 10px; }
  .sidebar-header h2 { font-size: 0.95rem; margin-bottom: 6px; }
  .sidebar-footer { padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px)); }

  /* -- Chat aside as full-screen sheet from bottom -- */
  .chat-aside {
    position: fixed; left: 0; right: 0;
    bottom: 0; top: auto;
    height: 80vh; max-height: 80vh;
    width: 100%; max-width: 100%;
    z-index: 250;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
    border-left: none;
    border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -8px 30px rgba(0,0,0,0.5);
  }
  .chat-aside.mobile-open { transform: translateY(0); z-index: 310; }
  .chat-aside.collapsed { transform: translateY(100%); }

  /* Sheet drag handle indicator */
  .chat-aside::before {
    content: '';
    display: block;
    width: 36px; height: 4px;
    background: var(--bg-surface);
    border-radius: 2px;
    margin: 8px auto 4px;
    flex-shrink: 0;
  }

  /* Remove collapsed hiding on mobile — we use transform instead */
  .chat-aside.collapsed .chat-aside-header,
  .chat-aside.collapsed .chat-messages,
  .chat-aside.collapsed .chat-input-area { display: flex; }
  .chat-aside .chat-messages { display: flex; }
  .chat-aside .chat-input-area { display: flex; }

  /* Chat input: row layout on mobile — textarea + send side by side */
  .chat-aside .chat-input-area {
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
    flex-shrink: 0;
    flex-direction: row;
    align-items: flex-end;
    gap: 8px;
  }
  .chat-aside #chatInput { min-height: 40px; max-height: 80px; font-size: 0.9rem; flex: 1; }
  .chat-input-hint { display: none; }
  .chat-input-footer { display: contents; }
  .chat-send-btn { padding: 10px 16px; font-size: 0.88rem; flex-shrink: 0; }

  /* -- Main content fills screen -- */
  .main-content {
    flex: 1; overflow: hidden; display: flex; flex-direction: column;
    padding-bottom: calc(52px + env(safe-area-inset-bottom, 0px)); /* space for bottom bar */
  }
  .content-body { padding: 16px 14px; }

  /* Compact content nav on mobile */
  .content-nav {
    padding: 8px 12px; gap: 6px; font-size: 0.82rem;
    flex-wrap: nowrap; overflow-x: auto;
    transition: transform 0.25s ease, max-height 0.25s ease;
    max-height: 50px; overflow: hidden;
  }
  .content-nav.mobile-hidden {
    max-height: 0; padding-top: 0; padding-bottom: 0;
    border-bottom: none;
  }
  .content-nav strong {
    flex: 1; min-width: 0;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    font-size: 0.85rem;
  }
  /* Simplify nav buttons on mobile — larger touch targets */
  .content-nav .btn-primary,
  .content-nav .btn-secondary {
    padding: 8px 14px; font-size: 0.82rem;
    min-height: 36px; min-width: 36px;
  }
  .content-nav .btn-done { padding: 8px 12px; font-size: 0.82rem; min-height: 36px; }
  .content-nav .btn-quiz,
  .content-nav .btn-refresh {
    min-height: 36px; min-width: 36px;
    display: flex; align-items: center; justify-content: center;
  }

  /* Hide step counter text on very small screens */
  .content-nav > span:first-child { display: none; }

  /* Hide desktop chat toggle (bottom bar replaces it) */
  .chat-toggle-btn { display: none; }

  /* Thinking panel compact on mobile */
  .thinking-panel { max-height: 120px; }
  .thinking-body { font-size: 0.72rem; padding: 6px 12px; }

  /* Lesson content optimized for mobile reading */
  .lesson-content { font-size: 0.95rem; line-height: 1.75; }
  .lesson-content h1 { font-size: 1.35rem; margin-top: 1em; }
  .lesson-content h2 { font-size: 1.1rem; }
  .lesson-content h3 { font-size: 0.98rem; }
  .lesson-content pre { padding: 12px; font-size: 0.78rem; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .lesson-content table { font-size: 0.85rem; display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Code copy button always visible on mobile (no hover) */
  .code-copy-btn { opacity: 1; }

  /* -- Overlay backdrop -- */
  .mobile-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 240;
    -webkit-tap-highlight-color: transparent;
  }
  .mobile-overlay.show { display: block; }

  /* -- Auth pages -- */
  .auth-card { margin: 20px 12px; padding: 24px 16px; }
  .profile-page { padding: 16px 12px; }
  .profile-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }

  /* -- Doc viewer in mobile sheet -- */
  .doc-viewer { padding: 12px; }
  .doc-viewer-header { gap: 8px; padding-bottom: 10px; margin-bottom: 12px; }
  .doc-viewer-filename { font-size: 0.88rem; }
  .doc-viewer-native { min-height: 0; }
  .doc-viewer-pdf, .doc-viewer-iframe { min-height: 300px; }
  .doc-viewer-image { border-radius: 6px; }
  .doc-viewer-text { font-size: 0.82rem; line-height: 1.65; }

  /* Hide right-panel tabs on mobile (bottom bar replaces them) */
  .right-panel-tabs { display: none; }
  .chat-aside-title { display: block; }

  /* -- Plan generating -- */
  .plan-gen-header { gap: 12px; flex-direction: column; text-align: center; }
  .plan-gen-header h2 { font-size: 1.1rem; }

  /* -- Plan overview cards -- */
  .plan-overview { padding: 0; }
  .plan-overview-header { margin-bottom: 20px; }
  .plan-overview-header h1 { font-size: 1.3rem; }
  .plan-card {
    flex-direction: row; gap: 12px;
    padding: 14px 16px;
  }
  .plan-card-num { width: 32px; height: 32px; font-size: 0.85rem; }
  .plan-card-desc { display: none; }
  .plan-card-footer { gap: 6px; }
  .plan-card-arrow { display: none; }
  .concept-tag { font-size: 0.7rem; padding: 1px 8px; }

  /* Debug toggle above bottom bar */
  .debug-view-toggle { bottom: calc(56px + env(safe-area-inset-bottom, 0px)); }

  /* -- Step items in sidebar (mobile) -- */
  .step-item { padding: 10px 12px; margin-bottom: 4px; }

  /* -- Quiz mobile -- */
  .quiz-question { padding: 14px; }
  .quiz-q-text { font-size: 0.95rem; }
  .quiz-choice { padding: 10px 12px; font-size: 0.88rem; }
  .quiz-submit-area { flex-direction: column; align-items: stretch; }
  .quiz-score-actions { flex-direction: column; }

  /* -- Progress bar -- */
  .step-progress-bar { display: none; }

  /* -- Classroom -- */
  .classroom-page { padding: 16px 12px; }
  .classroom-header { flex-direction: column; align-items: flex-start; }
  .classroom-header h1 { font-size: 1.2rem; }

  .home-classroom-card { flex-direction: column; align-items: flex-start; padding: 16px; }
  .hc-actions { width: 100%; }
  .hc-join-row { flex: 1; }
  .hc-join-input { flex: 1; width: auto; }

  .cq-card-top { flex-direction: column; }
  .cq-card-code { flex-direction: row; gap: 8px; align-self: flex-start; }
  .cq-card-actions { flex-wrap: wrap; }

  .cq-dash-meta { flex-direction: column; align-items: flex-start; gap: 6px; }
  .cq-dash-actions { width: 100%; justify-content: flex-start; }
  .cq-stats { flex-direction: column; }
  .cq-stat-card { min-width: auto; }
  .cq-table { font-size: 0.75rem; }
  .cq-table th, .cq-table td { padding: 6px 8px; }

  .cq-take-choice { padding: 8px 10px; font-size: 0.85rem; }
  .cq-take-letter { width: 24px; height: 24px; font-size: 0.7rem; }
  .cq-name-row { flex-direction: column; }
  .cq-name-row .cq-input { max-width: 100%; }

  .cq-code-big { font-size: 1.8rem; letter-spacing: 4px; }
  .cq-published { padding: 24px 12px; }

  .cq-question-edit { padding: 12px 14px; }
  .cq-num-picker { gap: 8px; }

  .cq-toast-container { top: 10px; right: 10px; left: 10px; }
  .cq-toast { max-width: 100%; }

  .cq-distribution { padding: 14px 16px; }
  .cq-dist-bars { height: 60px; }

  /* Toast positioned above bottom bar on mobile */
  .sf-toast {
    bottom: calc(64px + env(safe-area-inset-bottom, 0px));
    max-width: calc(100vw - 24px);
    font-size: 0.82rem;
    padding: 8px 14px;
  }

}

@media (max-width: 400px) {
  .home-hero h1 { font-size: 1.25rem; }
  .plan-card-footer .concept-tag { display: none; }
}
