/* ══════════════════════════════════════════════════════════
    RESPONSIVE MOBILE — DocAvocat v2
    Mobile-first, fluide, sans débordement
══════════════════════════════════════════════════════════ */

/* ═══════ GLOBAL ═══════ */
html {
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
}
body {
    overflow-x: hidden;
    max-width: 100vw;
}
img, video, iframe, embed, object {
    max-width: 100%;
    height: auto;
}

/* ═══════ TABLE RESPONSIVE ═══════ */
.table-modern { width: 100%; }

@media (max-width: 900px) {
    .card-body { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .table-modern, table.table-striped, table.table-hover, table.table { min-width: 560px; }
    .table-responsive { overflow-x: auto !important; -webkit-overflow-scrolling: touch; width: 100%; }
    .card, .card-elevated { overflow: visible; }
}

@media (max-width: 768px) {
    [style*="grid-template-columns: 2fr 1fr"],
    [style*="grid-template-columns: 2fr  1fr"] { grid-template-columns: 1fr !important; }
}

/* ═══════ TABLETTES (≤ 992px) ═══════ */
@media (max-width: 992px) {
    .sidebar { transform: translateX(-100%); z-index: 1050; }
    .sidebar.open { transform: translateX(0); box-shadow: 4px 0 24px rgba(0,0,0,0.25); }
    .sidebar-overlay.active { display: block; }
    .main-content { margin-left: 0 !important; width: 100% !important; max-width: 100vw !important; }
    .mobile-menu-btn { display: flex !important; }
    .page-content { padding: 1.25rem; width: 100%; max-width: 100%; }
    .topbar { padding: 0.75rem 1rem; }
    .topbar-search { min-width: 160px; flex: 1 1 180px; }
    .table-responsive, .table-modern-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 1rem; }
    .modal-dialog.modal-lg { max-width: 95vw; margin: 0.5rem auto; }
    .kpi-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 1rem !important; }
    .quick-actions-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 1rem !important; }
}

/* ═══════ MOBILE (≤ 768px) ═══════ */
@media (max-width: 768px) {
    .page-content { padding: 0.875rem 0.75rem; width: 100%; max-width: 100%; }

    /* Topbar */
    .topbar { padding: 0 0.75rem; height: 56px; gap: 0.5rem; }
    .topbar-search { display: none !important; }
    .topbar-actions { gap: 0.25rem; }
    .icon-btn { width: 38px; height: 38px; font-size: 1rem; }

    /* Sidebar */
    .sidebar { width: 280px; }
    .sidebar-header { padding: 1.25rem 1rem; }
    .nav-link { padding: 0.875rem 1rem; font-size: 0.9375rem; }

    /* Notif panel */
    #notifPanel {
        position: fixed; top: 56px; left: 0; right: 0;
        width: 100% !important; max-height: calc(100vh - 56px);
        border-radius: 0; border-left: none; border-right: none;
    }

    /* Stats */
    .stats-grid { grid-template-columns: 1fr !important; gap: 0.75rem; }
    .stat-card { padding: 1rem; }
    .stat-value { font-size: 1.5rem; }
    .stat-icon { width: 40px; height: 40px; font-size: 1.25rem; }
    .kpi-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 0.75rem !important; }
    .kpi-value { font-size: 1.75rem !important; }

    /* Cards */
    .card { padding: 1rem; border-radius: 10px; }
    .card-header { font-size: 1rem; }

    /* Hero */
    .hero-banner { padding: 1.25rem !important; border-radius: 10px !important; }
    .hero-banner h1 { font-size: 1.25rem !important; }

    /* Tables */
    .table-responsive, .table-modern-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
    .table { max-width: 100%; }
    .card .table, .card-body .table { margin-bottom: 0; }
    .table thead th { font-size: 0.7rem; padding: 0.5rem 0.625rem; white-space: nowrap; }
    .table tbody td { font-size: 0.8125rem; padding: 0.625rem; }
    .table .col-hide-mobile { display: none; }
    .table .btn-sm { padding: 0.375rem 0.5rem; font-size: 0.75rem; }
    .table .btn-sm .btn-label { display: none; }

    /* Forms */
    .form-floating > .form-control,
    .form-group input, .form-group select, .form-group textarea,
    .form-control, .form-select { font-size: 16px; }
    .row.g-3 > [class*="col-md-"] { flex: 0 0 100%; max-width: 100%; }
    .form-floating > label { font-size: 0.875rem; }

    /* Page headers */
    .dashboard-header, .page-header { flex-direction: column !important; align-items: flex-start !important; gap: 0.75rem; }
    .dashboard-header h1, .page-header h1, .page-header h2, .page-title { font-size: 1.25rem; }
    .page-header .d-flex { flex-wrap: wrap; gap: 0.5rem !important; }

    /* Quick actions */
    .quick-actions-grid, .quick-actions-row { display: grid !important; grid-template-columns: 1fr 1fr !important; gap: 0.75rem; }
    .quick-action, .action-card { padding: 1rem !important; }
    .action-card-title { font-size: 0.9375rem !important; }
    .action-card-description { display: none; }
    .action-card-icon { width: 40px !important; height: 40px !important; font-size: 1.125rem !important; margin-bottom: 0.625rem !important; }

    /* RPVA */
    .rpva-quick-actions, .quick-actions { flex-direction: column !important; gap: 0.75rem !important; }
    .action-btn { width: 100% !important; }
    .feature-grid { grid-template-columns: 1fr 1fr !important; gap: 0.75rem !important; }
    .feature-card { padding: 1rem !important; }
    .stats-dashboard { grid-template-columns: 1fr 1fr !important; gap: 0.75rem !important; }

    /* Modals */
    .modal-dialog { margin: 0 !important; max-width: 100% !important; min-height: 100dvh; }
    .modal-content { border-radius: 0 !important; min-height: 100dvh; }
    .modal-dialog-centered { min-height: 100dvh; align-items: stretch; }
    .modal-dialog.modal-sm { margin: 1rem auto !important; max-width: 90vw !important; min-height: auto; }
    .modal-dialog.modal-sm .modal-content { border-radius: 12px !important; min-height: auto; }

    /* Settings tabs */
    #settingsTabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
    #settingsTabs::-webkit-scrollbar { display: none; }
    #settingsTabs .nav-item { flex-shrink: 0; }

    /* Cookie banner */
    .cookie-banner-inner { flex-direction: column; text-align: center; gap: 0.75rem; }

    /* App modal */
    #appModalBox { max-width: 95vw; margin: 0 auto; }
    .app-modal-body { padding: 20px 16px 0; }
    #appModalFooter { padding: 16px; flex-direction: column-reverse; gap: 0.5rem; }
    .app-modal-btn, .app-modal-btn-ok { width: 100%; }

    /* Misc */
    .d-flex.flex-wrap-mobile, .header-actions { flex-wrap: wrap; }
    .badge { font-size: 0.7rem; padding: 0.25rem 0.5rem; }
    .dropdown-menu { min-width: auto; width: 200px; }

    /* Timeline */
    .timeline-content { flex-direction: column; gap: 0.25rem; }
    .timeline-date { white-space: normal; font-size: 0.75rem; }
    .timeline-icon { width: 32px; height: 32px; font-size: 0.875rem; }

    /* Filter card */
    .filter-card { padding: 1rem !important; }
    .filter-card .btn-group { flex-wrap: wrap; gap: 0.375rem; }

    /* Dashboard */
    .dashboard-container { padding: 1rem !important; }
    .dashboard-actions { flex-direction: column; width: 100%; }
    .dashboard-actions .btn { width: 100%; justify-content: center; }
}

/* ═══════ PETITS TÉLÉPHONES (≤ 480px) ═══════ */
@media (max-width: 480px) {
    .page-content { padding: 0.75rem 0.5rem; }
    .topbar { padding: 0 0.5rem; }

    h1, .h1 { font-size: 1.125rem; }
    h2, .h2 { font-size: 1rem; }
    h3, .h3 { font-size: 0.9375rem; }

    .card { padding: 0.75rem; border-radius: 8px; }
    .kpi-grid { grid-template-columns: 1fr !important; }
    .kpi-value { font-size: 1.5rem !important; }
    .quick-actions-grid { grid-template-columns: 1fr !important; }
    .action-card-description { display: block; font-size: 0.75rem !important; }
    .feature-grid, .stats-dashboard { grid-template-columns: 1fr !important; }

    .btn-group { flex-direction: column; width: 100%; }
    .btn-group .btn { width: 100%; border-radius: 8px !important; margin-bottom: 0.25rem; margin-left: 0 !important; }
    .action-buttons, .btn-toolbar { flex-direction: column; gap: 0.5rem; }
    .action-buttons .btn, .btn-toolbar .btn { width: 100%; }
    .sidebar { width: 260px; }
}

/* ═══════ PAYSAGE ═══════ */
@media (max-height: 500px) and (orientation: landscape) {
    .sidebar { overflow-y: auto; }
    .sidebar-header { padding: 0.625rem 1rem; }
    .sidebar-nav { padding: 0.375rem 0.75rem; }
    .nav-link { padding: 0.5rem 0.75rem; font-size: 0.875rem; }
    .topbar { height: 48px; }
    .page-content { padding: 0.625rem; }
}

/* ═══════ CIBLES TACTILES ═══════ */
@media (pointer: coarse) {
    .nav-link { min-height: 44px; }
    .btn { min-height: 44px; }
    .icon-btn { min-width: 44px; min-height: 44px; }
    .form-check-input { width: 1.25rem; height: 1.25rem; cursor: pointer; }
    .dropdown-item { padding: 0.75rem 1rem; }
    .table tbody td a, .table tbody td button { min-height: 36px; display: inline-flex; align-items: center; }
}

/* ═══════ SAFE AREA IPHONE ═══════ */
@supports (padding: env(safe-area-inset-bottom)) {
    .sidebar { padding-bottom: env(safe-area-inset-bottom); }
    .page-content { padding-bottom: calc(0.875rem + env(safe-area-inset-bottom)); }
    #cookieConsentBanner { padding-bottom: env(safe-area-inset-bottom); }
    .topbar { padding-top: max(0px, env(safe-area-inset-top)); }
}

/* ═══════ PWA STANDALONE ═══════ */
@media (display-mode: standalone) {
    .topbar { padding-top: max(0.75rem, env(safe-area-inset-top, 0.75rem)); height: calc(56px + env(safe-area-inset-top, 0px)); }
    body { overscroll-behavior-y: none; }
}

/* ═══════ IMPRESSION ═══════ */
@media print {
    .sidebar, .topbar, .mobile-menu-btn, #cookieConsentBanner,
    #notifPanel, .pwa-install-banner, .btn:not(.btn-print), .dropdown { display: none !important; }
    .main-content { margin-left: 0 !important; }
    .page-content { padding: 0; }
    .card { box-shadow: none !important; border: 1px solid #ccc !important; break-inside: avoid; }
}
