/* ==========================================================================
   RESPONSIVE.CSS - Sistema Responsive Completo para La Comarca GastroPark
   ========================================================================== 
   Breakpoints:
   - xs: < 576px   (móviles pequeños)
   - sm: 576-767px  (móviles)
   - md: 768-991px  (tablets)
   - lg: 992-1199px (desktop pequeño)
   - xl: >= 1200px  (desktop grande)
   ========================================================================== */

/* ==========================================================================
   0. BASE / RESET RESPONSIVE
   ========================================================================== */
*, *::before, *::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

body {
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

img, video, iframe {
    max-width: 100%;
    height: auto;
}

/* ==========================================================================
   1. BOTÓN HAMBURGUESA MÓVIL (visible cuando sidebar está oculto)
   ========================================================================== */
.mobile-hamburger {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 1200;
    width: 44px;
    height: 44px;
    background: #0C0C0E;
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 10px;
    color: #ff9900;
    font-size: 1.2rem;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    transition: all 0.3s ease;
}

.mobile-hamburger:hover {
    background: #915016;
    color: #fff;
}

/* Mostrar hamburguesa solo en mobile/tablet cuando sidebar está oculto */
@media (max-width: 991.98px) {
    .mobile-hamburger {
        display: flex;
    }

    /* Ocultar cuando sidebar está abierto */
    body.sidebar-open .mobile-hamburger {
        display: none;
    }
}

/* ==========================================================================
   2. SIDEBAR RESPONSIVE
   ========================================================================== */

/* Mobile: sidebar oculto por defecto, desliza desde la izquierda */
@media (max-width: 991.98px) {
    .drawer {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        height: 100vh !important;
        width: 280px !important;
        transform: translateX(-100%) !important;
        z-index: 1100 !important;
    }

    .drawer.open {
        transform: translateX(0) !important;
    }

    .drawer.collapsed {
        width: 280px !important;
    }

    /* Sidebar toggle visible dentro del sidebar en mobile */
    .sidebar-toggle-btn {
        display: flex !important;
        position: absolute !important;
        right: 10px !important;
        top: 15px !important;
        transform: none !important;
        width: 32px !important;
        height: 32px !important;
    }

    /* Main content ocupa 100% */
    #mainContent {
        margin-left: 0 !important;
        width: 100% !important;
        padding-top: 60px !important;
    }

    /* Backdrop oscuro */
    body.sidebar-open::after {
        content: '';
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.5);
        z-index: 1050;
        animation: fadeInBackdrop 0.3s ease;
    }
}

@keyframes fadeInBackdrop {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Desktop: sidebar visible */
@media (min-width: 992px) {
    .mobile-hamburger {
        display: none !important;
    }

    .drawer {
        transform: translateX(0) !important;
    }

    #mainContent {
        padding-top: 0 !important;
    }

    .sidebar-toggle-btn {
        display: flex !important;
    }
}

/* ==========================================================================
   3. HEADER RESPONSIVE
   ========================================================================== */
.header {
    flex-wrap: wrap;
}

.header h1 {
    word-break: break-word;
}

@media (max-width: 767.98px) {
    .header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 8px;
        padding-bottom: 10px;
    }

    .header h1 {
        font-size: 1.2rem !important;
        padding: 8px !important;
    }

    .header .d-flex {
        flex-wrap: wrap;
        gap: 8px;
    }
}

@media (max-width: 575.98px) {
    .header h1 {
        font-size: 1.05rem !important;
        padding: 6px !important;
    }
}

/* ==========================================================================
   4. DASHBOARD - STATS & CARDS RESPONSIVE
   ========================================================================== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
}

.quick-links {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
}

.cards-grid {
    display: grid;
    gap: 16px;
}

@media (min-width: 992px) {
    .cards-grid {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 991.98px) {
    .cards-grid {
        grid-template-columns: 1fr !important;
    }
}

@media (max-width: 575.98px) {
    .stats-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 8px;
    }

    .stat-card {
        padding: 12px !important;
        gap: 8px !important;
    }

    .stat-icon {
        width: 36px !important;
        height: 36px !important;
    }

    .stat-number {
        font-size: 22px !important;
    }

    .stat-title,
    .stat-label {
        font-size: 10px !important;
    }

    .quick-links {
        grid-template-columns: 1fr !important;
        gap: 8px;
    }

    .quick-link {
        padding: 10px 12px !important;
    }

    .dash-container {
        padding: 12px !important;
    }
}

@media (max-width: 400px) {
    .stats-grid {
        grid-template-columns: 1fr !important;
    }
}

/* ==========================================================================
   5. TABLES RESPONSIVE
   ========================================================================== */
.table-wrapper,
.table-container,
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Scroll indicator shadow on tables */
.table-wrapper {
    position: relative;
}

@media (max-width: 767.98px) {
    table {
        min-width: 600px;
    }

    th, td {
        padding: 8px 6px !important;
        font-size: 0.85rem !important;
        white-space: nowrap;
    }

    .actions {
        flex-direction: row !important;
        gap: 4px !important;
        flex-wrap: nowrap;
    }

    .btn-action {
        padding: 4px 8px !important;
        font-size: 12px !important;
    }

    .btn-action span,
    .btn-action .btn-text {
        display: none;
    }
}

@media (max-width: 575.98px) {
    th, td {
        padding: 6px 4px !important;
        font-size: 0.8rem !important;
    }
}

/* ==========================================================================
   6. FORMULARIOS RESPONSIVE
   ========================================================================== */

/* Grids de formulario de 2 columnas -> 1 columna en mobile */
.form-grid-2col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

@media (max-width: 767.98px) {
    .form-grid-2col,
    .form-grid2 {
        grid-template-columns: 1fr !important;
    }

    /* Bootstrap row con col-md-6 ya colapsa automáticamente */

    /* Inputs más grandes en móvil para evitar zoom en iOS */
    .form-control,
    .form-select,
    input[type="text"],
    input[type="email"],
    input[type="number"],
    input[type="password"],
    input[type="tel"],
    input[type="url"],
    select,
    textarea {
        font-size: 16px !important;
    }
}

/* Form container responsive */
.form-container {
    max-width: 100% !important;
}

@media (min-width: 768px) {
    .form-container {
        max-width: 700px !important;
    }
}

/* Page wrapper responsive */
.page-wrapper {
    padding: 16px !important;
}

@media (max-width: 575.98px) {
    .page-wrapper {
        padding: 8px !important;
    }
}

/* ==========================================================================
   7. PRODUCTS INDEX RESPONSIVE
   ========================================================================== */
.products-container,
.users-container {
    padding: 16px;
}

@media (max-width: 767.98px) {
    .products-container,
    .users-container {
        padding: 12px !important;
        border-radius: 8px !important;
    }

    .header-section {
        flex-direction: column !important;
        align-items: stretch !important;
    }

    .header-section h2 {
        font-size: 20px !important;
        text-align: center;
    }

    .header-actions {
        flex-direction: row !important;
        align-items: center !important;
        justify-content: center !important;
        width: 100%;
    }

    .search-filter-group {
        flex-direction: column !important;
    }

    .search-input,
    .filter-select {
        width: 100% !important;
        min-width: 0 !important;
    }

    .btn-create {
        width: 100% !important;
        justify-content: center;
    }
}

@media (max-width: 575.98px) {
    .products-container,
    .users-container {
        padding: 8px !important;
        margin-top: 0 !important;
    }

    .header-section h2 {
        font-size: 18px !important;
    }
}

/* ==========================================================================
   8. PRODUCT SHOW - 2 COLUMN LAYOUT FIX
   ========================================================================== */

/* Fix for inline @media that doesn't work in style attributes */
.product-detail-grid {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 1rem;
}

@media (max-width: 767.98px) {
    .product-detail-grid {
        grid-template-columns: 1fr !important;
    }
}

/* Gallery layout fix */
.gallery-layout-grid {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 1rem;
}

@media (max-width: 767.98px) {
    .gallery-layout-grid {
        grid-template-columns: 1fr !important;
    }
}

/* Gallery image grid */
@media (max-width: 575.98px) {
    .gallery-layout-grid .col-md-4 {
        flex: 0 0 100%;
        max-width: 100%;
    }

    .gallery-layout-grid .col-md-6 {
        flex: 0 0 100%;
        max-width: 100%;
    }
}

/* ==========================================================================
   9. EVENTS PAGE RESPONSIVE
   ========================================================================== */

/* Fix events bar negative margin */
.events-bar {
    flex-wrap: wrap;
    gap: 12px;
}

.events-bar .btn-new {
    margin-top: 0 !important;
}

@media (max-width: 767.98px) {
    .events-bar {
        flex-direction: column !important;
        align-items: stretch;
    }

    .events-bar .btn-new {
        width: 100%;
        justify-content: center;
    }

    .events-bar .section-title {
        font-size: 22px !important;
        margin: 0 !important;
        text-align: center;
    }

    /* Filters row */
    .filters-row {
        flex-direction: column !important;
        gap: 8px !important;
    }

    .filter-input,
    .filter-input.with-icon,
    .filter-input.date {
        width: 100% !important;
    }

    .filters-row .btn {
        width: 100%;
        justify-content: center;
    }

    /* Event cards */
    .cards-grid.grid-separated {
        grid-template-columns: 1fr !important;
        gap: 16px;
    }

    .event-thumb {
        height: 200px !important;
    }

    .event-title {
        font-size: 18px !important;
    }

    .event-actions {
        flex-wrap: wrap;
        gap: 8px !important;
    }

    .event-actions .btn {
        flex: 1;
        min-width: 80px;
        justify-content: center;
    }
}

@media (max-width: 575.98px) {
    .event-thumb {
        height: 180px !important;
    }

    .event-body {
        padding: 12px !important;
    }

    .event-meta {
        flex-direction: column;
        gap: 4px !important;
    }
}

/* ==========================================================================
   10. MODALS RESPONSIVE
   ========================================================================== */
@media (max-width: 575.98px) {
    .custom-modal {
        padding: 5px !important;
    }

    .modal-content {
        width: 100% !important;
        max-height: 98vh !important;
        border-radius: 8px !important;
        margin: 0 !important;
    }

    .modal-header {
        padding: 10px 12px !important;
    }

    .modal-header h3 {
        font-size: 0.95rem !important;
    }

    .modal-body {
        padding: 10px 12px 5px !important;
    }

    .modal-actions {
        flex-direction: column !important;
        gap: 8px;
    }

    .modal-actions .btn {
        width: 100%;
    }

    /* SweetAlert modals */
    .sage-modal .modal-card {
        width: 98% !important;
        max-width: 100% !important;
        margin: 0 4px !important;
    }
}

/* ==========================================================================
   11. WELCOME / LOGIN PAGE RESPONSIVE
   ========================================================================== */
@media (max-width: 767.98px) {
    .welcome-card {
        padding: 30px 20px !important;
        max-width: 100% !important;
        margin: 10px !important;
    }

    .welcome-title {
        font-size: 1.8rem !important;
    }

    .welcome-subtitle {
        font-size: 0.95rem !important;
    }

    .btn-gestionar {
        padding: 10px 28px !important;
        font-size: 1.1rem !important;
    }

    .logo-img {
        max-width: 200px !important;
        margin: -60px !important;
    }

    .feature-icons {
        gap: 20px !important;
    }

    .feature-icons i {
        font-size: 1.5rem !important;
    }
}

@media (max-width: 575.98px) {
    .welcome-card {
        padding: 24px 16px !important;
        border-radius: 14px !important;
    }

    .welcome-title {
        font-size: 1.5rem !important;
    }

    .logo-img {
        max-width: 160px !important;
        margin: -40px !important;
    }
}

/* ==========================================================================
   12. BUTTONS RESPONSIVE
   ========================================================================== */
@media (max-width: 575.98px) {
    .btn-add {
        width: 100% !important;
        min-width: unset !important;
    }

    .btn-primary {
        width: auto !important;
    }

    .btn-addNew,
    .btn-save {
        width: 100% !important;
    }

    .btn-group {
        display: flex;
        flex-wrap: wrap;
        gap: 4px;
    }

    .btn-group .btn {
        flex: 1;
        min-width: 40px;
    }

    .btn-help {
        padding: 8px 12px !important;
        font-size: 12px !important;
    }
}

/* ==========================================================================
   13. PAGINATION RESPONSIVE
   ========================================================================== */
@media (max-width: 575.98px) {
    .pagination {
        gap: 2px !important;
    }

    .pagination .page-item a,
    .pagination .page-item span {
        padding: 4px 8px !important;
        min-width: 32px !important;
        height: 32px !important;
        font-size: 11px !important;
    }
}

/* ==========================================================================
   14. ALERTS RESPONSIVE
   ========================================================================== */
@media (max-width: 575.98px) {
    .alert {
        padding: 10px 12px !important;
        font-size: 0.85rem;
    }

    .alert-dismissible {
        padding-right: 2.5rem !important;
    }
}

/* ==========================================================================
   15. BADGES RESPONSIVE
   ========================================================================== */
@media (max-width: 575.98px) {
    .badge,
    .status-badge,
    .role-badge,
    .category-badge {
        font-size: 10px !important;
        padding: 3px 8px !important;
    }
}

/* ==========================================================================
   16. CARD RESPONSIVE
   ========================================================================== */
@media (max-width: 767.98px) {
    .card {
        border-radius: 8px !important;
    }

    .card-header {
        padding: 10px 12px !important;
        flex-wrap: wrap;
        gap: 8px;
    }

    .card-title {
        font-size: 0.9rem !important;
    }

    .card-body {
        padding: 12px !important;
    }
}

/* ==========================================================================
   17. PROFILE PAGE RESPONSIVE
   ========================================================================== */
@media (max-width: 767.98px) {
    .profile-edit .max-w-xl,
    .profile-edit .max-w-7xl {
        max-width: 100% !important;
        padding: 0 8px !important;
    }
}

/* ==========================================================================
   18. UTILITY RESPONSIVE HELPERS
   ========================================================================== */

/* Hide elements on mobile */
.hide-mobile {
    display: block;
}

@media (max-width: 767.98px) {
    .hide-mobile {
        display: none !important;
    }
}

/* Show elements only on mobile */
.show-mobile {
    display: none;
}

@media (max-width: 767.98px) {
    .show-mobile {
        display: block !important;
    }
}

/* Full width on mobile */
@media (max-width: 767.98px) {
    .mobile-full-width {
        width: 100% !important;
        max-width: 100% !important;
    }
}

/* Overflow container for horizontal scroll */
.overflow-scroll-x {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Text truncation */
.text-truncate-mobile {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Flex responsive */
@media (max-width: 767.98px) {
    .flex-column-mobile {
        flex-direction: column !important;
    }

    .flex-wrap-mobile {
        flex-wrap: wrap !important;
    }

    .gap-sm-mobile {
        gap: 8px !important;
    }
}

/* Padding/margin responsive utilities */
@media (max-width: 767.98px) {
    .p-responsive {
        padding: 12px !important;
    }

    .px-responsive {
        padding-left: 8px !important;
        padding-right: 8px !important;
    }
}

@media (max-width: 575.98px) {
    .p-responsive {
        padding: 8px !important;
    }

    .px-responsive {
        padding-left: 4px !important;
        padding-right: 4px !important;
    }
}

/* ==========================================================================
   19. PRINT STYLES
   ========================================================================== */
@media print {
    .drawer,
    .mobile-hamburger,
    .sidebar,
    .sidebar-toggle-btn,
    .btn-create,
    .btn-action,
    .modal,
    .custom-modal {
        display: none !important;
    }

    #mainContent {
        margin-left: 0 !important;
        width: 100% !important;
    }

    body {
        background: white !important;
    }
}

/* ==========================================================================
   20. SAFE AREA (NOTCH) SUPPORT
   ========================================================================== */
@supports (padding: env(safe-area-inset-top)) {
    .mobile-hamburger {
        top: calc(12px + env(safe-area-inset-top));
        left: calc(12px + env(safe-area-inset-left));
    }

    @media (max-width: 991.98px) {
        #mainContent {
            padding-left: env(safe-area-inset-left);
            padding-right: env(safe-area-inset-right);
        }
    }
}

/* ==========================================================================
   21. FIX INLINE GRID COLUMNS (products create page)
   ========================================================================== */
@media (max-width: 767.98px) {
    /* Override inline grid-template-columns: 1fr 1fr */
    [style*="grid-template-columns: 1fr 1fr"],
    [style*="grid-template-columns:1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }

    /* Override inline grid-template-columns: 1fr 2fr */
    [style*="grid-template-columns: 1fr 2fr"],
    [style*="grid-template-columns:1fr 2fr"] {
        grid-template-columns: 1fr !important;
    }
}

/* ==========================================================================
   22. SCROLLBAR STYLES (consistent across devices)
   ========================================================================== */
@media (max-width: 767.98px) {
    /* Thinner scrollbar on mobile */
    ::-webkit-scrollbar {
        width: 4px;
        height: 4px;
    }

    .table-wrapper::-webkit-scrollbar,
    .table-container::-webkit-scrollbar {
        height: 4px;
    }

    .table-wrapper::-webkit-scrollbar-thumb,
    .table-container::-webkit-scrollbar-thumb {
        background: rgba(0, 0, 0, 0.2);
        border-radius: 2px;
    }
}

/* ==========================================================================
   23. LANDSCAPE MOBILE FIXES
   ========================================================================== */
@media (max-height: 500px) and (orientation: landscape) {
    .welcome-container {
        min-height: auto !important;
        padding: 20px 0;
    }

    .welcome-card {
        padding: 20px !important;
    }

    .login-wrapper {
        min-height: auto !important;
    }

    .login-panel,
    .register-panel {
        padding: 20px !important;
        min-height: auto !important;
    }
}
