/* ==========================================================================
   AVENOR — ADAPTATIONS RESPONSIVES
   Gestion multi-écrans : Mobiles, Tablettes, Portables et Grands Écrans
   ========================================================================== */

/* Écrans Larges (Desktop > 1400px) */
@media (min-width: 1400px) {
  .container {
    max-width: min(1320px, calc(100% - 5rem));
  }
}

/* Écrans PC Portables & Moyens (max 1366px : ex. 1280px / 1366px) */
@media (max-width: 1366px) {
  .app-sidebar {
    width: 230px;
  }

  .app-main {
    margin-left: 230px;
    width: calc(100% - 230px);
    max-width: calc(100% - 230px);
  }

  .app-kpi-grid,
  .crm-kpi-grid,
  .comm-kpi-grid,
  .tresor-kpi-grid {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)) !important;
    gap: 1rem !important;
  }

  .quick-actions-grid {
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)) !important;
    gap: 0.75rem !important;
  }

  .ai-automations-summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .dashboard-main-grid {
    grid-template-columns: 1fr !important;
  }

  .app-content {
    padding: 1.25rem 1.25rem 2rem 1.25rem !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  .app-topbar {
    padding: 0.6rem 1.25rem !important;
  }

  .topbar-search {
    width: 200px;
  }

  .topbar-search input:focus {
    width: 220px;
  }
}

/* Verrouillage du scroll en arrière-plan lorsque le menu mobile est ouvert */
body.menu-open {
  overflow: hidden !important;
  touch-action: none !important;
}

/* Tablettes & Écrans Réduits (max 992px) */
@media (max-width: 992px) {
  .app-layout {
    flex-direction: column;
  }

  .app-sidebar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    bottom: 0 !important;
    width: 280px !important;
    z-index: 1050 !important;
    transform: translateX(-100%) !important;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1) !important;
    box-shadow: none !important;
    filter: none !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    pointer-events: auto !important;
  }

  .app-sidebar.is-open {
    transform: translateX(0) !important;
    box-shadow: 16px 0 40px rgba(0, 0, 0, 0.65) !important;
  }

  .app-sidebar-backdrop {
    display: none !important;
    position: fixed !important;
    inset: 0 !important;
    background: rgba(5, 7, 12, 0.45) !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    z-index: 1040 !important;
    opacity: 0 !important;
    pointer-events: none !important;
    visibility: hidden !important;
    transition: opacity 0.25s ease, visibility 0.25s ease !important;
  }

  .app-sidebar-backdrop.is-open {
    display: block !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    visibility: visible !important;
  }

  .sidebar-close-btn {
    display: inline-flex !important;
  }

  .app-main {
    margin-left: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }

  .mobile-toggle {
    display: inline-flex !important;
  }

  .site-header,
  .site-header.scrolled {
    height: 64px !important;
    background: rgba(11, 14, 22, 0.96) !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    border-bottom: 1px solid var(--border-light) !important;
  }

  .nav-links {
    position: fixed !important;
    top: 64px !important;
    right: 0 !important;
    left: auto !important;
    width: min(320px, 85vw) !important;
    height: calc(100vh - 64px) !important;
    height: calc(100dvh - 64px) !important;
    background: #0b0e17 !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    flex-direction: column !important;
    align-items: flex-start !important;
    justify-content: flex-start !important;
    padding: 2rem 1.75rem !important;
    gap: 1.25rem !important;
    transform: translateX(100%) !important;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.25s ease, visibility 0.25s ease !important;
    z-index: 1050 !important;
    border-top: 1px solid var(--border-light) !important;
    border-left: 1px solid var(--border-light) !important;
    box-shadow: -16px 0 40px rgba(0, 0, 0, 0.65) !important;
    overflow-y: auto !important;
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
  }

  .nav-links.is-open {
    transform: translateX(0) !important;
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
  }

  .nav-link {
    font-size: 1.15rem;
    font-weight: 600;
    width: 100%;
    padding: 0.4rem 0;
  }

  .header-actions {
    display: none !important;
  }

  .nav-links .mobile-actions {
    display: flex !important;
    flex-direction: column;
    gap: 0.85rem;
    width: 100%;
    margin-top: 1.25rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border-light);
  }

  .ai-priority-grid {
    grid-template-columns: 1fr !important;
  }

  .app-content {
    padding: 1.5rem 1.25rem !important;
    max-width: 100% !important;
    width: 100% !important;
    margin: 0 !important;
  }

  .topbar-search {
    width: 180px;
  }
}

/* Tablettes & Petits Ordinateurs (max 1024px) */
@media (max-width: 1024px) {
  .pricing-grid {
    grid-template-columns: 1fr;
    max-width: 520px;
    margin: 0 auto;
  }

  .pricing-card.featured {
    transform: none;
  }
  
  .pricing-card.featured:hover {
    transform: translateY(-4px);
  }

  .grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }

  .features-grid-7 {
    grid-template-columns: repeat(2, 1fr);
  }

  .feature-bento-card.wide {
    grid-column: span 2;
  }

  .feature-split {
    grid-template-columns: 1fr;
    gap: 2.5rem;
  }

  .feature-split:nth-child(even) {
    direction: ltr;
  }

  .footer-top {
    grid-template-columns: 1fr 1fr;
    gap: 2.5rem;
  }

  .scroll-flame-tracker {
    right: 1rem;
    bottom: 1rem;
    padding: 0.5rem 0.4rem;
  }
}

/* Tablettes Portables & Mobiles (max 768px) */
@media (max-width: 768px) {
  .section {
    padding: 4rem 0;
  }

  .section-hero {
    padding-top: 7.5rem;
    padding-bottom: 3rem;
  }

  .hero-actions {
    flex-direction: column;
    width: 100%;
  }

  .hero-actions .btn {
    width: 100%;
  }

  .grid-2, .grid-3, .grid-4 {
    grid-template-columns: 1fr;
  }

  .features-grid-7 {
    grid-template-columns: 1fr;
  }

  .feature-bento-card.wide {
    grid-column: span 1;
  }

  .benefits-grid {
    grid-template-columns: 1fr;
  }

  .demo-tabs-nav {
    gap: 0.35rem;
  }

  .demo-tab-btn {
    font-size: 0.78rem;
    padding: 0.45rem 0.8rem;
  }

  .demo-view-panel {
    padding: 1rem 0.85rem;
  }

  .footer-top {
    grid-template-columns: 1fr;
    gap: 2rem;
  }

  .footer-bottom {
    flex-direction: column;
    align-items: flex-start;
  }

  .auth-card {
    padding: 2rem 1.5rem;
  }

  /* App SaaS Layout Mobile */
  .app-layout {
    flex-direction: column;
  }

  .app-main {
    margin-left: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }

  .app-topbar {
    height: auto;
    min-height: 64px;
    padding: 0.5rem 1rem;
    gap: 0.5rem;
    flex-wrap: wrap;
  }

  .topbar-search {
    display: none !important;
  }

  .topbar-left {
    gap: 0.65rem;
    flex-wrap: wrap;
  }

  .page-title {
    font-size: 1.05rem;
  }

  .demo-mode-pill {
    padding: 0.15rem 0.45rem;
    font-size: 0.68rem;
  }

  .topbar-actions,
  .app-topbar-actions {
    gap: 0.4rem;
    flex-wrap: wrap;
  }

  .greeting-banner {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.85rem;
  }

  .app-content {
    padding: 1.25rem 1rem !important;
    max-width: 100% !important;
  }

  .app-kpi-grid {
    grid-template-columns: 1fr !important;
  }

  .quick-actions-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .ai-automations-summary-grid {
    grid-template-columns: 1fr !important;
  }

  .ai-actions-sub-bar {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 0.35rem !important;
  }

  .dashboard-main-grid {
    grid-template-columns: 1fr !important;
  }

  .ai-priority-grid {
    grid-template-columns: 1fr !important;
  }

  .ai-priority-footer {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }

  .ai-priority-btn {
    justify-content: center;
    text-align: center;
  }

  .appointment-modern-card {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  .apt-right {
    width: 100%;
    justify-content: space-between;
  }

  .app-messages-layout {
    grid-template-columns: 1fr !important;
  }

  .app-message-preview {
    display: none;
  }

  .app-message-preview.active-mobile {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 1050;
    background: var(--bg-deep);
    overflow-y: auto;
  }

  .calendar-view-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }

  .calendar-grid {
    overflow-x: auto;
  }
}

/* Petits Mobiles (max 480px) */
@media (max-width: 480px) {
  h1 {
    font-size: 2.15rem;
  }

  h2 {
    font-size: 1.75rem;
  }

  .card {
    padding: 1.5rem 1.25rem;
  }

  .pricing-amount {
    font-size: 2.5rem;
  }

  .btn-lg {
    padding: 0.85rem 1.5rem;
    font-size: 1rem;
  }

  .scroll-flame-tracker {
    display: none;
  }

  .quick-actions-grid {
    grid-template-columns: 1fr !important;
  }
}

/* ==========================================================================
   OPTIMISATIONS RESPONSIVES SLIDER DEVIS & FACTURES (HAUTE LISIBILITÉ)
   ========================================================================== */

/* Laptops et écrans moyens (max 1024px) */
@media (max-width: 1024px) {
  .doc-modal-slide-card {
    max-width: 95vw !important;
    width: 95vw !important;
  }

  .doc-slide-pane {
    max-height: calc(88vh - 160px) !important;
    padding: 1.25rem 1.5rem !important;
  }
}

/* Tablettes (max 768px) */
@media (max-width: 768px) {
  .doc-modal-slide-card {
    width: 98vw !important;
    max-width: 98vw !important;
    max-height: 96vh !important;
    border-radius: var(--radius-lg) !important;
  }

  /* MODALE FICHE CLIENT SUR TABLETTE */
  .modal-client-card {
    width: 95vw !important;
    max-width: 95vw !important;
    max-height: 90vh !important;
    border-radius: var(--radius-lg, 12px) !important;
    margin: auto !important;
  }

  .modal-client-header {
    padding: 0.95rem 1.25rem !important;
  }

  .client-modal-body {
    padding: 1.15rem 1.2rem !important;
  }

  .client-form-grid {
    grid-template-columns: 1fr !important;
    gap: 0.85rem !important;
  }

  .client-modal-footer {
    padding: 0.85rem 1.25rem !important;
    gap: 0.75rem !important;
  }

  .modal-overlay {
    padding: 0.5rem !important;
  }

  .modal-header {
    padding: 0.85rem 1.15rem !important;
  }

  .modal-title {
    font-size: 1rem !important;
  }

  /* La barre de progression / Stepper parfaitement responsive */
  .doc-slide-stepper-wrap {
    padding: 0.55rem 0.85rem !important;
    flex-wrap: nowrap !important;
    justify-content: space-between !important;
    gap: 0.5rem !important;
  }

  .doc-slide-stepper {
    gap: 0.35rem !important;
    overflow-x: auto !important;
    scrollbar-width: none !important;
    -webkit-overflow-scrolling: touch !important;
  }

  .doc-slide-stepper::-webkit-scrollbar {
    display: none !important;
  }

  .doc-step-item {
    padding: 0.32rem 0.6rem !important;
    font-size: 0.74rem !important;
    gap: 0.35rem !important;
  }

  .doc-step-num {
    width: 20px !important;
    height: 20px !important;
    font-size: 0.68rem !important;
  }

  .doc-step-arrow {
    display: inline-block !important;
    font-size: 0.65rem !important;
    opacity: 0.4 !important;
  }

  .slide-step-progress-text {
    font-size: 0.72rem !important;
  }

  /* Contenu du slide */
  .doc-slide-pane {
    padding: 1.15rem 1rem !important;
    max-height: calc(90vh - 150px) !important;
  }

  /* Grille des formulaires en 2 colonnes ou 1 colonne */
  #modalCreateDoc .grid.grid-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 0.75rem !important;
  }

  #modalCreateDoc .grid.grid-2 {
    gap: 0.75rem !important;
  }

  /* Menus déroulants personnalisés fond noir sur mobile / tablette */
  .custom-dark-dropdown-menu {
    position: fixed !important;
    top: auto !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 16px 16px 0 0 !important;
    border-bottom: none !important;
    padding: 1rem !important;
    box-shadow: 0 -12px 45px rgba(0, 0, 0, 0.95), 0 0 25px rgba(56, 189, 248, 0.15) !important;
    max-height: 75vh !important;
    z-index: 2500 !important;
  }

  .custom-dropdown-scrollable {
    max-height: 50vh !important;
  }

  /* Lignes de prestation & Tableau */
  .lines-editor-wrap {
    margin-bottom: 1rem !important;
    border-radius: var(--radius-sm) !important;
    border: 1px solid rgba(56, 189, 248, 0.2) !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }

  .lines-editor-table {
    min-width: 580px !important;
    font-size: 0.8rem !important;
  }

  .lines-editor-table th,
  .lines-editor-table td {
    padding: 0.45rem 0.5rem !important;
  }

  .line-input {
    padding: 0.4rem 0.55rem !important;
    font-size: 0.82rem !important;
  }

  /* Panneau des totaux et notes */
  .calc-summary-panel {
    flex-direction: column !important;
    gap: 1rem !important;
  }

  .calc-notes-box,
  .calc-totals-box {
    width: 100% !important;
    flex: 1 1 100% !important;
  }

  .calc-totals-box {
    padding: 1rem !important;
    background: rgba(14, 20, 32, 0.9) !important;
  }

  .calc-row.total-ttc {
    font-size: 1.2rem !important;
  }

  /* Pied de modale parfaitement cadré et responsive */
  .doc-slider-footer {
    padding: 0.75rem 1rem !important;
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: space-between !important;
    flex-wrap: nowrap !important;
    width: 100% !important;
    box-sizing: border-box !important;
    gap: 0.5rem !important;
  }

  .doc-footer-left {
    display: flex !important;
    align-items: center !important;
    gap: 0.5rem !important;
    flex: 0 1 auto !important;
  }

  .doc-footer-right {
    display: flex !important;
    align-items: center !important;
    gap: 0.45rem !important;
    flex: 0 1 auto !important;
  }

  .btn-doc-cancel {
    padding: 0.45rem 0.8rem !important;
    font-size: 0.82rem !important;
    flex-shrink: 0 !important;
  }

  .btn-doc-next,
  .btn-doc-prev,
  .btn-doc-save {
    padding: 0.48rem 0.95rem !important;
    font-size: 0.82rem !important;
    flex-shrink: 0 !important;
  }

  .slide-next-step-bar,
  .slide-nav-between-bar {
    gap: 0.6rem !important;
  }
}

/* Mobiles (max 560px) */
@media (max-width: 560px) {
  .doc-modal-slide-card {
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100vh !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
    border: none !important;
  }

  .modal-overlay {
    padding: 0 !important;
  }

  /* Affichage des libellés courts sur le Stepper mobile */
  .step-full-label {
    display: none !important;
  }

  .step-short-label {
    display: inline !important;
  }

  .step-badge-counter,
  .step-badge-total {
    font-size: 0.65rem !important;
    padding: 0.1rem 0.35rem !important;
  }

  #modalCreateDoc .grid.grid-4,
  #modalCreateDoc .grid.grid-2 {
    grid-template-columns: 1fr !important;
    gap: 0.65rem !important;
  }

  .doc-slide-pane {
    padding: 0.9rem 0.75rem !important;
    max-height: calc(100vh - 150px) !important;
  }

  .slide-pane-title {
    font-size: 1rem !important;
  }

  .slide-next-step-bar,
  .slide-nav-between-bar {
    flex-direction: column-reverse !important;
    align-items: stretch !important;
  }

  .slide-next-step-bar button,
  .slide-nav-between-bar button {
    width: 100% !important;
    min-height: 42px !important;
  }

  /* Pied de modale sur mobile : toujours 100% cadré sur une seule ligne propre */
  .doc-slider-footer {
    padding: 0.65rem 0.75rem !important;
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: space-between !important;
    flex-wrap: nowrap !important;
    gap: 0.4rem !important;
    background: #080c14 !important;
  }

  .doc-footer-left {
    display: flex !important;
    align-items: center !important;
    gap: 0.4rem !important;
    flex: 0 1 auto !important;
  }

  .doc-footer-right {
    display: flex !important;
    align-items: center !important;
    gap: 0.35rem !important;
    flex: 0 1 auto !important;
  }

  .btn-doc-cancel {
    padding: 0.42rem 0.7rem !important;
    font-size: 0.78rem !important;
    min-height: 38px !important;
  }

  .btn-doc-next,
  .btn-doc-prev,
  .btn-doc-save {
    padding: 0.45rem 0.85rem !important;
    font-size: 0.78rem !important;
    min-height: 38px !important;
  }

  /* Cacher les points sur petits mobiles pour éviter tout risque de débordement */
  .doc-slide-dots {
    display: none !important;
  }

  /* MODALE FICHE CLIENT SUR MOBILE : PARFAITEMENT CADRÉE & BOUTONS DU BAS TOUJOURS VISIBLES */
  #modalAddClient.modal-overlay,
  .modal-client-overlay {
    align-items: flex-end !important;
    padding: 0 !important;
  }

  .modal-client-card {
    width: 100vw !important;
    max-width: 100vw !important;
    height: auto !important;
    max-height: 94vh !important;
    border-radius: 16px 16px 0 0 !important;
    border-bottom: none !important;
    margin: 0 !important;
    box-shadow: 0 -15px 45px rgba(0, 0, 0, 0.95), 0 0 25px rgba(56, 189, 248, 0.15) !important;
  }

  .modal-client-header {
    padding: 0.85rem 1rem !important;
  }

  .client-modal-icon {
    width: 32px !important;
    height: 32px !important;
    font-size: 1.1rem !important;
  }

  .modal-client-subtitle {
    font-size: 0.7rem !important;
  }

  .client-modal-body {
    padding: 0.95rem 1rem !important;
    max-height: calc(94vh - 125px) !important;
    overscroll-behavior: contain !important;
  }

  .client-modal-footer {
    padding: 0.75rem 1rem !important;
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: space-between !important;
    flex-wrap: nowrap !important;
    gap: 0.65rem !important;
    width: 100% !important;
    box-sizing: border-box !important;
    background: #080c14 !important;
  }

  .btn-client-cancel {
    flex: 0 0 auto !important;
    min-width: 80px !important;
    padding: 0.52rem 0.85rem !important;
    font-size: 0.82rem !important;
    min-height: 40px !important;
    text-align: center !important;
    justify-content: center !important;
  }

  .btn-client-save {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    padding: 0.52rem 0.95rem !important;
    font-size: 0.82rem !important;
    min-height: 40px !important;
    text-align: center !important;
    justify-content: center !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }
}

