/* ========== RESPONSIVE GLOBAL - SOREIN WEBSHOP ========== */
/* Ce fichier gère la responsivité de toutes les pages */

/* ========== VARIABLES ========== */
:root {
    --sidebar-width: 260px;
    --topbar-height: 65px;
    --mobile-breakpoint: 768px;
    --tablet-breakpoint: 1024px;
}

/* ========== RESET MOBILE ========== */
* {
    -webkit-tap-highlight-color: transparent;
}

html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

/* ========== TABLET (max-width: 1024px) ========== */
@media (max-width: 1024px) {
    /* Sidebar drawer : géré par layout_sidebar.php pour éviter conflits */
    .sidebar::before,
    .sidebar::after {
        display: none !important;
    }

    /* Main content */
    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
        padding: 20px 15px !important;
    }

    /* Topbar */
    .topbar {
        left: 0 !important;
        width: 100% !important;
    }

    /* Grids - NE PAS forcer les colonnes, laisser auto-fill gérer */
    .dashboard-layout {
        grid-template-columns: 1fr !important;
        gap: 20px !important;
    }

    .dashboard-left,
    .dashboard-right {
        width: 100% !important;
    }

    /* Product grids - Ne PAS écraser, les pages gèrent leur propre responsive */
    /* Les grilles utilisent auto-fill/minmax qui s'adapte automatiquement */

    /* Stats widgets */
    .stats-grid,
    .quick-stats {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Tables */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Search bar */
    .search-bar,
    .topbar-search {
        max-width: 300px;
    }

    /* User menu */
    .user-info .user-name {
        max-width: 100px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}

/* ========== MOBILE (max-width: 768px) ========== */
@media (max-width: 768px) {
    /* Body */
    body {
        font-size: 14px;
    }

    /* Topbar */
    .topbar {
        padding: 10px 15px !important;
        height: auto !important;
        min-height: 55px;
        flex-wrap: wrap;
        gap: 10px;
    }

    .topbar-left {
        order: 1;
        flex: 0 0 auto;
    }

    .topbar-center,
    .topbar-search-wrapper {
        order: 3;
        flex: 1 1 100%;
        width: 100%;
        margin-top: 10px;
    }

    .topbar-right {
        order: 2;
        flex: 1 1 auto;
        justify-content: flex-end;
    }

    .search-bar,
    .topbar-search {
        max-width: 100% !important;
        width: 100% !important;
    }

    /* Hide elements on mobile */
    .topbar .logo-text,
    .hide-mobile,
    .desktop-only {
        display: none !important;
    }

    /* Show mobile elements */
    .mobile-only,
    .show-mobile {
        display: flex !important;
    }

    /* Menu toggle button */
    .menu-toggle,
    .sidebar-toggle,
    .mobile-menu-btn {
        display: flex !important;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        border-radius: 10px;
        background: var(--bg-body, #f5f7fa);
        border: none;
        cursor: pointer;
        font-size: 1.2rem;
        color: var(--text-main, #1a1a2e);
    }

    /* Sidebar overlay */
    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 9998;
        opacity: 0;
        transition: opacity 0.3s ease;
    }

    .sidebar-overlay.show {
        display: block;
        opacity: 1;
    }

    /* Main content */
    .main-content {
        padding: 15px 12px !important;
        margin-top: 120px !important;
    }

    /* Product grids - Ne PAS forcer le nombre de colonnes, juste ajuster le gap */
    .products-grid,
    .product-grid {
        gap: 12px;
    }

    /* Product cards - Ajustements mineurs sans !important */
    .product-card {
        padding: 12px;
    }

    .product-card .product-image {
        height: 120px;
    }

    .product-card .product-name {
        font-size: 0.85rem;
        -webkit-line-clamp: 2;
    }

    .product-card .product-price {
        font-size: 1rem;
    }

    /* Stats widgets */
    .stats-grid,
    .quick-stats {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .stat-card,
    .stat-widget {
        padding: 15px !important;
    }

    /* Cards */
    .card,
    .widget-card,
    .content-card {
        padding: 15px !important;
        border-radius: 12px !important;
    }

    /* Banners */
    .ad-hero,
    .hero-banner {
        width: 100% !important;
        height: 180px !important;
        border-radius: 12px !important;
    }

    .ad-carousel {
        width: 100% !important;
    }

    .promo-slots-row {
        flex-direction: column !important;
        gap: 12px !important;
    }

    .promo-slot {
        width: 100% !important;
        height: 100px !important;
    }

    .promo-slot img,
    .promo-slot .promo-slot-img {
        width: 100% !important;
        height: 100% !important;
        object-fit: cover !important;
    }

    /* Tables - Responsive cards */
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -12px;
        padding: 0 12px;
    }

    table {
        min-width: 600px;
    }

    /* Form elements */
    .form-group {
        margin-bottom: 15px;
    }

    .form-control,
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    select,
    textarea {
        padding: 12px 14px !important;
        font-size: 16px !important; /* Prevent zoom on iOS */
        border-radius: 10px !important;
    }

    /* Buttons */
    .btn,
    button {
        padding: 12px 20px !important;
        font-size: 0.9rem !important;
        border-radius: 10px !important;
    }

    .btn-sm {
        padding: 8px 14px !important;
        font-size: 0.8rem !important;
    }

    /* Modals */
    .modal-content,
    .popup-content {
        width: 95% !important;
        max-width: 100% !important;
        margin: 10px !important;
        max-height: 90vh !important;
        overflow-y: auto;
    }

    /* Dropdowns - ouvrir sous la barre (top) pour lisibilité */
    .dropdown-menu,
    .user-dropdown,
    .notification-dropdown {
        position: fixed !important;
        left: 10px !important;
        right: 10px !important;
        top: 78px !important;
        bottom: auto !important;
        width: auto !important;
        max-height: 60vh !important;
        border-radius: 16px !important;
    }

    /* User menu */
    .user-menu {
        padding: 8px 12px !important;
    }

    .user-info {
        display: none !important;
    }

    .user-avatar {
        width: 35px !important;
        height: 35px !important;
    }

    /* Notification badge */
    .notification-btn {
        width: 40px !important;
        height: 40px !important;
    }

    /* Chat widget */
    .chat-bubble-btn {
        width: 50px !important;
        height: 50px !important;
        bottom: 15px !important;
        right: 15px !important;
    }

    .chat-box,
    .chat-widget-box {
        width: calc(100vw - 20px) !important;
        max-width: 100% !important;
        height: 70vh !important;
        max-height: 500px !important;
        bottom: 75px !important;
        right: 10px !important;
        left: 10px !important;
        border-radius: 16px !important;
    }

    /* FAQ bubble */
    .faq-bubble,
    .faq-btn {
        width: 50px !important;
        height: 50px !important;
    }

    /* Titles */
    h1, .page-title {
        font-size: 1.5rem !important;
    }

    h2, .section-title {
        font-size: 1.25rem !important;
    }

    h3 {
        font-size: 1.1rem !important;
    }

    /* Breadcrumbs */
    .breadcrumb {
        font-size: 0.8rem !important;
        flex-wrap: wrap;
    }

    /* Pagination */
    .pagination {
        flex-wrap: wrap;
        gap: 5px;
        justify-content: center;
    }

    .pagination .page-link {
        padding: 8px 12px !important;
        font-size: 0.85rem !important;
    }

    /* Tabs */
    .tabs,
    .nav-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap;
        gap: 5px;
    }

    .tab,
    .nav-tab {
        flex-shrink: 0;
        padding: 10px 15px !important;
        font-size: 0.85rem !important;
    }

    /* Credit widget */
    .credit-widget {
        padding: 15px !important;
    }

    .credit-amount {
        font-size: 1.5rem !important;
    }

    /* Order cards */
    .order-card,
    .devis-card,
    .command-card {
        padding: 15px !important;
    }

    .order-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 10px !important;
    }

    .order-actions {
        width: 100%;
        justify-content: flex-end;
        align-items: flex-start !important;
    }

    .btn-order-action {
        width: max-content !important;
        max-width: 100% !important;
        flex: 0 0 auto !important;
        padding: 8px 14px !important;
        font-size: 0.8rem !important;
    }

    /* Empty states */
    .empty-state {
        padding: 30px 20px !important;
    }

    .empty-state i {
        font-size: 3rem !important;
    }

    /* Toast notifications */
    .toast,
    .toast-notification {
        left: 10px !important;
        right: 10px !important;
        width: auto !important;
        max-width: 100% !important;
    }
}

/* ========== SMALL MOBILE (max-width: 480px) ========== */
@media (max-width: 480px) {
    /* Product grids - laisser auto-fill gérer, juste ajuster le gap */
    .products-grid,
    .product-grid {
        gap: 10px;
    }

    /* Product cards - ajustements mineurs */
    .product-card {
        padding: 10px;
    }

    .product-card .product-image {
        height: 100px;
    }

    /* Main content */
    .main-content {
        padding: 12px 10px !important;
    }

    /* Cards */
    .card,
    .widget-card {
        padding: 12px !important;
        margin-bottom: 12px !important;
    }

    /* Topbar */
    .topbar {
        padding: 8px 10px !important;
    }

    .topbar-right {
        gap: 5px !important;
    }

    /* Buttons inline */
    .btn-group,
    .action-buttons {
        flex-direction: column !important;
        gap: 8px !important;
    }

    .btn-group .btn,
    .action-buttons .btn {
        width: 100% !important;
    }

    /* Hero banner */
    .ad-hero,
    .hero-banner {
        width: 100% !important;
        height: 140px !important;
    }

    .ad-carousel {
        width: 100% !important;
    }

    /* Titles */
    h1, .page-title {
        font-size: 1.3rem !important;
    }

    /* Text truncate */
    .truncate-mobile {
        max-width: 150px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}

/* ========== LANDSCAPE MOBILE ========== */
@media (max-width: 768px) and (orientation: landscape) {
    .main-content {
        margin-top: 70px !important;
    }

    .sidebar {
        height: 100vh !important;
        overflow-y: auto;
    }

    .chat-box,
    .chat-widget-box {
        height: 50vh !important;
        max-height: 300px !important;
    }

    .modal-content {
        max-height: 85vh !important;
    }
}

/* ========== LARGE SCREENS (min-width: 1400px) ========== */
@media (min-width: 1400px) {
    .main-content {
        max-width: 1600px;
        margin-left: auto;
        margin-right: auto;
    }

    /* Product grids - laisser auto-fill gérer le nombre de colonnes */
    /* Les pages utilisent minmax() qui s'adapte automatiquement */

    .dashboard-layout {
        gap: 30px;
    }
}

/* ========== PRINT STYLES ========== */
@media print {
    .sidebar,
    .topbar,
    .chat-bubble-btn,
    .faq-bubble,
    .notification-btn,
    .user-menu,
    .btn,
    button,
    .no-print {
        display: none !important;
    }

    .main-content {
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
    }

    body {
        background: white !important;
        color: black !important;
    }

    .card,
    .widget-card {
        box-shadow: none !important;
        border: 1px solid #ddd !important;
    }
}

/* ========== ACCESSIBILITY ========== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ========== TOUCH DEVICES ========== */
@media (hover: none) and (pointer: coarse) {
    .btn:hover,
    .card:hover,
    .product-card:hover {
        transform: none !important;
    }

    /* Larger touch targets */
    .btn,
    button,
    a,
    .clickable {
        min-height: 44px;
        min-width: 44px;
    }

    /* Remove hover effects */
    .hover-effect:hover {
        transform: none !important;
        box-shadow: inherit !important;
    }
}

/* ========== DARK MODE RESPONSIVE ========== */
@media (prefers-color-scheme: dark) {
    /* Dark mode handled by main CSS, just ensure mobile compatibility */
    .sidebar-overlay {
        background: rgba(0, 0, 0, 0.7);
    }
}

/* ========== UTILITY CLASSES ========== */
.hide-tablet {
    display: block;
}

.show-tablet {
    display: none;
}

.hide-mobile {
    display: block;
}

.show-mobile {
    display: none;
}

@media (max-width: 1024px) {
    .hide-tablet {
        display: none !important;
    }
    .show-tablet {
        display: block !important;
    }
}

@media (max-width: 768px) {
    .hide-mobile {
        display: none !important;
    }
    .show-mobile {
        display: block !important;
    }
}

/* Flex utilities responsive */
@media (max-width: 768px) {
    .flex-col-mobile {
        flex-direction: column !important;
    }
    .gap-sm-mobile {
        gap: 10px !important;
    }
    .text-center-mobile {
        text-align: center !important;
    }
    .w-full-mobile {
        width: 100% !important;
    }
}

/* ========== NOTIFICATION OVERLAY MODAL ========== */
.notification-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
    padding: 20px;
}

.notification-overlay.show {
    opacity: 1;
}

.notification-modal {
    background: var(--bg-white, #ffffff);
    border-radius: 20px;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.3);
    max-width: 600px;
    width: 100%;
    max-height: 80vh;
    overflow: hidden;
    transform: translateY(20px) scale(0.95);
    transition: transform 0.3s ease;
}

.notification-overlay.show .notification-modal {
    transform: translateY(0) scale(1);
}

.notification-modal-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 24px;
    border-bottom: 1px solid var(--border, #e3def6);
}

.notification-modal-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    flex-shrink: 0;
}

.notification-modal-icon.info {
    background: rgba(59, 130, 246, 0.15);
    color: #3b82f6;
}

.notification-modal-icon.success {
    background: rgba(16, 185, 129, 0.15);
    color: #10b981;
}

.notification-modal-icon.warning {
    background: rgba(245, 158, 11, 0.15);
    color: #f59e0b;
}

.notification-modal-icon.error {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
}

.notification-modal-header h3 {
    flex: 1;
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-main, #1a1a2e);
}

.notification-modal-close {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: none;
    background: var(--bg-body, #f5f7fa);
    color: var(--text-main, #1a1a2e);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: all 0.2s ease;
}

.notification-modal-close:hover {
    background: var(--primary-purple, #6c4bcf);
    color: white;
    transform: rotate(90deg);
}

.notification-modal-body {
    padding: 24px;
    max-height: calc(80vh - 140px);
    overflow-y: auto;
}

.notification-modal-body p {
    margin: 0 0 20px 0;
    line-height: 1.6;
    color: var(--text-main, #1a1a2e);
    white-space: pre-wrap;
}

.notification-modal-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 16px;
    border-top: 1px solid var(--border, #e3def6);
    flex-wrap: wrap;
    gap: 12px;
}

.notification-modal-date {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    color: var(--text-light, #4b4f63);
}

.notification-modal-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: var(--primary-purple, #6c4bcf);
    color: white;
    text-decoration: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.9rem;
    transition: all 0.2s ease;
}

.notification-modal-link:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(108, 75, 207, 0.3);
}

/* Condensation des notifications dans la liste */
.notification-content-compact {
    flex: 1;
    min-width: 0;
    cursor: pointer;
}

.notification-content-compact .notification-title {
    font-weight: 700;
    font-size: 0.95rem;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.notification-expand-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--bg-body, #f5f7fa);
    color: var(--text-light, #4b4f63);
    font-size: 0.9rem;
    transition: all 0.2s ease;
}

.notification-item:hover .notification-expand-icon {
    background: var(--primary-purple, #6c4bcf);
    color: white;
    transform: translateX(3px);
}

/* Dark mode pour l'overlay */
[data-theme="dark"] .notification-modal {
    background: var(--bg-white, #141125);
    border: 1px solid var(--border, #2a2442);
}

[data-theme="dark"] .notification-modal-header {
    border-bottom-color: var(--border, #2a2442);
}

[data-theme="dark"] .notification-modal-close {
    background: rgba(255, 255, 255, 0.05);
}

[data-theme="dark"] .notification-modal-footer {
    border-top-color: var(--border, #2a2442);
}

[data-theme="dark"] .notification-expand-icon {
    background: rgba(255, 255, 255, 0.05);
}

/* Responsive pour l'overlay */
@media (max-width: 768px) {
    .notification-modal {
        max-width: calc(100% - 32px);
        max-height: calc(100vh - 40px);
    }
    
    .notification-modal-header {
        padding: 20px;
    }
    
    .notification-modal-body {
        padding: 20px;
        max-height: calc(100vh - 180px);
    }
    
    .notification-modal-icon {
        width: 40px;
        height: 40px;
        font-size: 1.25rem;
    }
    
    .notification-modal-header h3 {
        font-size: 1.1rem;
    }
}
