/* Adaptation commune aux pages élèves, à l’assistant et à l’administration. */
.header-breadcrumbs, .header-inner > *, .page-wrapper, #course-rendered-container,
.notion-callout-content, .main-shell, .preview-pane, .section-heading > *, .stat { min-width: 0; }
.page-wrapper, .preview-content { overflow-wrap: anywhere; }
.page-wrapper img, .preview-content img { max-width: 100%; height: auto; }
.notion-table-wrapper, .notion-code-block, .notion-mermaid-container, .notion-math-block { max-width: 100%; overscroll-behavior-x: contain; }
.search-palette-input { min-width: 0; }
.search-modal { max-height: calc(100dvh - 100px); }
.search-input-wrapper, .search-filter-pills, .search-modal-footer { flex-shrink: 0; }
.search-results-list { min-height: 0; }
.search-filter-pill { flex-shrink: 0; }
.mobile-overlay-open { overflow: hidden; }
.mobile-nav-backdrop { display: none; }
.public-modal-open .chatbot-root { visibility: hidden; }

@media (max-width: 900px) {
  .page-wrapper { padding-right: 18px; }
  body.has-course-outline .page-wrapper { padding-right: 48px; }
  .course-outline { max-width: calc(100vw - 24px); }
  .course-outline-item { min-height: 36px; }
  .course-outline.is-open .course-outline-item { min-height: 44px; }
}

@media (max-width: 900px) {
  .admin-body .main-shell { margin-left: 0; width: 100%; }
  .admin-body .mobile-only { display: flex; }
  .admin-body .sidebar { transform: translateX(-100%); transition: transform .2s; width: min(300px, calc(100vw - 48px)); padding-top: max(18px, env(safe-area-inset-top)); padding-bottom: env(safe-area-inset-bottom); overflow-y: auto; overscroll-behavior: contain; }
  .admin-body .sidebar .brand { flex-shrink: 0; }
  .admin-body .sidebar .subject-tree { flex-shrink: 0; min-height: 110px; }
  .admin-body .sidebar .sidebar-bottom { margin-top: auto; }
  .admin-body .sidebar.open { transform: translateX(0); z-index: 40; }
  .admin-body .mobile-nav-backdrop:not([hidden]) { display: block; position: fixed; inset: 0; z-index: 35; border: 0; background: #0009; backdrop-filter: blur(2px); }
  .admin-body .topbar { position: sticky; top: 0; z-index: 25; background: var(--bg); padding: 0 12px; }
  .admin-body .breadcrumbs { min-width: 0; gap: 8px; }
  .admin-body .breadcrumbs strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .admin-body .session-badge { flex-shrink: 0; }
  .admin-body .page { padding: 24px 16px max(40px, env(safe-area-inset-bottom)); }
  .admin-body .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .admin-body .stats .stat:last-child { grid-column: 1 / -1; }
  .admin-body .section-heading { align-items: flex-start; gap: 12px; flex-wrap: wrap; }
  .admin-body .section-heading h2 { font-size: 16px; }
  .admin-body .table-wrap { max-width: 100%; overscroll-behavior-x: contain; }
  .admin-body .content-table { table-layout: fixed; }
  .admin-body .content-table th:last-child { width: 124px; }
  .admin-body .content-table th:nth-child(2) { width: 88px; }
  .admin-body .content-table th:nth-child(3), .admin-body .content-table td:nth-child(3) { display: none; }
  .admin-body .course-title-button { max-width: 100%; gap: 6px; overflow-wrap: anywhere; }
  .admin-body .course-title-button svg { flex-shrink: 0; }
  .admin-body .content-table th, .admin-body .content-table td { padding: 10px 7px; }
  .admin-body .filters { gap: 8px; }
  .admin-body .filters input { width: 100%; }
  .admin-body .filters select { width: 100%; flex: 1 1 120px; }
  .admin-body .subject-card { padding: 18px; }
  .admin-body .subject-card .button { margin-top: 8px; }
  .admin-body .editor-head-actions { width: 100%; flex-wrap: wrap; align-items: center; }
  .admin-body .save-status { flex-basis: 100%; }
  .admin-body .editor-meta { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 8px; }
  .admin-body .editor-meta select { width: 100%; }
  .admin-body .editor-toolbar { padding: 10px 8px; }
  .admin-body .mode-switch { width: 100%; margin-top: 5px; }
  .admin-body .mode-switch button { flex: 1; }
  .admin-body .editor-pane { height: clamp(280px, 55dvh, 500px); }
  .admin-body .editor-footer { flex-wrap: wrap; }
  .admin-body .feedback-card { padding: 16px; }
  .admin-body .feedback-card header { flex-wrap: wrap; }
  .admin-body .settings-card { padding: 20px 16px; }
  .admin-body .search-dialog { margin: max(12px, env(safe-area-inset-top)) auto; max-height: calc(var(--mobile-vh, 100dvh) - 24px); }
  .admin-body .search-results { max-height: calc(var(--mobile-vh, 100dvh) - 155px); }
  .admin-body .search-field { gap: 6px; padding: 10px; }
  .admin-body .search-field input { width: 100%; min-width: 0; }
  .admin-body .search-result { padding: 12px 8px; overflow-wrap: anywhere; }
  .admin-body .confirm-dialog { padding: 20px; }
  .admin-body .dialog-actions { flex-wrap: wrap; }
  .admin-body .toast { bottom: calc(16px + env(safe-area-inset-bottom)); overflow-wrap: anywhere; }
  .admin-body .button, .admin-body .icon-button, .admin-body .nav-item, .admin-body .tree-course, .admin-body .block-button { min-height: 44px; }
  .admin-body .icon-button { min-width: 36px; }
  .admin-body .nav-item { font-size: 13px; }
  .admin-body input, .admin-body select, .admin-body textarea { font-size: 16px; }
  .admin-body .editor-title { font-size: 24px; }
}

@media (max-width: 600px) {
  body { -webkit-text-size-adjust: 100%; }
  .header-inner { gap: 8px; padding: max(6px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 6px max(10px, env(safe-area-inset-left)); }
  .header-breadcrumbs { flex: 1; font-size: 12px; }
  .header-breadcrumbs > .crumb-item:first-child { flex-shrink: 0; min-height: 44px; }
  .header-breadcrumbs > a.crumb-item:not(:first-child), .header-breadcrumbs > .crumb-sep:nth-child(2) { display: none; }
  .header-actions { gap: 4px; }
  .header-search-btn, .header-action-btn { min-width: 40px; min-height: 44px; justify-content: center; padding: 8px; }
  .header-search-btn > span, .header-search-btn kbd, #btn-share-course > span { display: none; }
  .header-actions svg { width: 18px; height: 18px; }
  .page-wrapper { padding: 22px max(16px, env(safe-area-inset-right)) calc(90px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
  body.has-course-outline .page-wrapper { padding-right: 48px; }
  .main-title { font-size: clamp(25px, 7vw, 32px); line-height: 1.3; overflow-wrap: anywhere; margin-bottom: 24px; }
  .back-link, .course-link-item, .notion-btn-link { min-height: 44px; }
  .back-link, .course-link-item, .notion-btn-link { white-space: normal; max-width: 100%; }
  .course-link-item .course-title-text { min-width: 0; overflow-wrap: anywhere; }
  .course-pagination { gap: 14px; }
  .course-pagination-link { min-width: 0; overflow-wrap: anywhere; min-height: 44px; }
  .notion-callout { padding: 16px 14px; gap: 10px; }
  .notion-table { font-size: 14px; }
  .notion-table th, .notion-table td { min-width: 125px; padding: 10px; }
  .notion-mermaid-container { padding: 10px; }
  .notion-math-block { overflow-x: auto; }
  .feedback-widget { padding: 18px 14px; }
  .feedback-header { align-items: flex-start; gap: 8px; }
  .feedback-title { font-size: 14px; line-height: 1.5; }
  .feedback-footer { flex-wrap: wrap; gap: 10px; }
  .feedback-textarea { font-size: 16px; min-height: 100px; }
  .search-modal-backdrop { padding: max(10px, env(safe-area-inset-top)) 8px calc(10px + env(safe-area-inset-bottom)); height: var(--mobile-vh, 100dvh); top: var(--mobile-vtop, 0px); bottom: auto; }
  .search-modal { max-height: 100%; }
  .search-input-wrapper { padding: 10px; gap: 8px; }
  .search-palette-input { font-size: 16px; width: 100%; }
  .search-close-btn { min-width: 40px; min-height: 44px; }
  .search-filter-pills { padding: 8px; }
  .search-filter-pill { min-height: 40px; padding: 8px 12px; }
  .search-results-list { flex: 1; max-height: none; overflow: auto; }
  .search-result-item { min-height: 52px; gap: 8px; padding: 10px 8px; }
  .search-result-title { white-space: normal; overflow-wrap: anywhere; line-height: 1.45; flex: 1; min-width: 0; }
  .search-result-title > svg { flex-shrink: 0; }
  .search-result-badge { max-width: 78px; white-space: normal; font-size: 10px; }
  .search-modal-footer { font-size: 11px; gap: 8px; }
  .lightbox-backdrop { padding: calc(60px + env(safe-area-inset-top)) 12px calc(20px + env(safe-area-inset-bottom)); }
  .lightbox-inner { max-width: 100%; max-height: calc(100dvh - 90px); }
  .lightbox-img { max-height: calc(100dvh - 150px); }
  .lightbox-caption { overflow: auto; max-height: 70px; font-size: 13px; }
  .lightbox-close-btn { width: 44px; height: 44px; top: -50px; }
  .global-toast { max-width: calc(100vw - 24px); width: max-content; bottom: calc(78px + env(safe-area-inset-bottom)); font-size: 12px; text-align: center; }
  .chatbot-fab { right: calc(12px + env(safe-area-inset-right)); bottom: calc(12px + env(safe-area-inset-bottom)); min-height: 44px; }
  .chatbot-drawer { right: env(safe-area-inset-right); left: env(safe-area-inset-left); bottom: calc(var(--mobile-vbottom, 0px) + env(safe-area-inset-bottom)); width: auto; max-width: none; height: min(700px, var(--mobile-vh, 100dvh)); max-height: var(--mobile-vh, 100dvh); border-radius: 16px 16px 0 0; }
  .chatbot-header { padding-top: max(12px, env(safe-area-inset-top)); }
  .chatbot-action-icon, .chat-add, .chatbot-send-btn { min-width: 44px; min-height: 44px; }
  .chatbot-textarea, .chat-picker input[type=search] { font-size: 16px; }
  .chatbot-messages { padding: 14px; overscroll-behavior: contain; }
  .chatbot-empty-state { padding: 20px 8px; }
  .chatbot-empty-icon { display: none; }
  .chat-picker { inset: 115px 8px 92px; padding: 12px; }
  .chat-picker-heading button { min-width: 36px; min-height: 36px; }
  .chat-course { min-height: 52px; }
  .chat-search-option { min-height: 40px; }
  .chat-search-option input { width: 18px; height: 18px; flex-shrink: 0; }
  .login-body { min-height: 100dvh; padding: calc(16px + env(safe-area-inset-top)) 12px calc(16px + env(safe-area-inset-bottom)); }
  .login-card { width: 100%; max-width: 430px; padding: 28px 20px; }
  .login-card input { font-size: 16px; min-width: 0; }
  .password-field .icon-button { min-width: 44px; min-height: 44px; }
  .login-submit { min-height: 48px; }
  .back-public { padding: 10px; }
}

@media (max-width: 360px) {
  .admin-body .session-badge { display: none; }
  .admin-body .content-table th:nth-child(2), .admin-body .content-table td:nth-child(2) { display: none; }
  .admin-body .stats { grid-template-columns: minmax(0, 1fr); }
  .admin-body .stats .stat:last-child { grid-column: auto; }
}

@media (max-width: 900px) and (max-height: 500px) {
  .chatbot-drawer { left: env(safe-area-inset-left); right: env(safe-area-inset-right); bottom: var(--mobile-vbottom, 0px); width: auto; max-width: none; height: var(--mobile-vh, 100dvh); max-height: var(--mobile-vh, 100dvh); }
  .search-modal-backdrop { padding: 8px; height: var(--mobile-vh, 100dvh); top: var(--mobile-vtop, 0px); bottom: auto; }
  .search-modal { max-height: 100%; }
  .chatbot-subtitle, .chatbot-footer-caption { display: none; }
  .chatbot-header { padding: 4px 10px; }
  .chat-context { padding: 4px 12px; }
  .chat-picker { inset: 8px 8px 78px; gap: 6px; padding: 8px; }
  .chat-picker > small { display: none; }
  .chat-picker-heading { min-height: 26px; }
  .chat-picker-heading button { min-height: 26px; }
  .chat-all, .chat-picker input[type=search] { padding: 6px 10px; }
}

/* Le clavier peut réduire la zone visible sans changer la largeur du téléphone. */
.compact-viewport .chatbot-subtitle, .compact-viewport .chatbot-footer-caption { display: none; }
.compact-viewport .chatbot-header { padding: 4px 10px; }
.compact-viewport .chat-context { padding: 4px 12px; }
.compact-viewport .chat-picker { inset: 8px 8px 78px; gap: 6px; padding: 8px; }
.compact-viewport .chat-picker > small { display: none; }
.compact-viewport .chat-picker-heading { min-height: 26px; }
.compact-viewport .chat-picker-heading button { min-height: 26px; }
.compact-viewport .chat-all, .compact-viewport .chat-picker input[type=search] { padding: 6px 10px; }

@media (prefers-reduced-motion: reduce) {
  .page-wrapper, .search-modal-backdrop, .lightbox-backdrop { animation: none; }
  .course-link-item:hover { transform: none; }
}
