/* ========================================
   RESPONSIVE DESIGN - MARTONEWORKSHOP
   Archivo unificado de media queries
   ======================================== */

/* ========== GLOBAL MOBILE FIX ========== */
html, body {
    overflow-x: hidden;
    max-width: 100vw;
}

body {
    position: relative;
}

/* ========================================
   DESKTOP LARGE (1200px)
   ======================================== */
@media (max-width: 1200px) {
    .products-container {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* ========================================
   TABLET LARGE (768px - 1024px)
   ======================================== */
@media (max-width: 1024px) {
    /* Navbar */
    .navbar {
        padding: 0.5rem 3%;
    }
    
    .navbar-search {
        max-width: 350px;
    }
    
    /* Dashboard sidebar */
    .sidebar {
        width: 200px;
    }
    
    .main-content {
        margin-left: 200px;
        max-width: calc(100vw - 200px);
    }
    
    .sidebar-item span {
        font-size: 0.9rem;
    }
    
    /* Tables */
    .custom-table-wrapper {
        font-size: 0.9rem;
    }
    
    .custom-table th,
    .custom-table td {
        padding: 0.7rem 0.5rem;
    }
}

/* ========================================
   TABLET (768px - 992px)
   ======================================== */
@media (max-width: 992px) {
    .products-container {
        grid-template-columns: repeat(2, 1fr);
    }
    .footer-content {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ========================================
   TABLET PORTRAIT (768px)
   ======================================== */
@media (max-width: 768px) {
    /* ===== NAVBAR ===== */
    .logo {
        width: 160px !important;
        max-width: 160px !important;
        min-width: 160px !important;
        flex-shrink: 0;
    }
    
    .logo-img {
        height: 40px;
        width: 40px;
    }
    
    .logo-text-container {
        display: flex !important;
        font-size: 0.6em;
        left: 44px;
    }
    
    .navbar-search {
        order: 3;
        flex-basis: 100%;
        max-width: 180px;
        width: 180px;
        margin: 0.5rem auto 0.25rem auto;
        position: relative !important;
        left: 0 !important;
        transform: none !important;
    }
    
    .navbar {
        flex-wrap: wrap;
        justify-content: space-between;
        padding: 0.5rem 3%;
    }
    
    .nav-icons {
        min-width: auto;
        width: auto;
        gap: 1rem;
        flex-shrink: 0;
    }
    
    .search-input {
        height: 35px;
    }
    
    /* ===== HERO SECTION ===== */
    .nav-links {
        margin: 1rem 0;
    }
    
    .hero h1 {
        font-size: 2.5rem;
    }
    
    .hero p {
        font-size: 1.2rem;
    }
    
    /* ===== PRODUCTS ===== */
    .products-container {
        grid-template-columns: 1fr;
    }
    
    .carousel-controls {
        display: none;
    }
    
    .product-actions {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .add-to-cart, .view-details {
        width: 100%;
        text-align: center;
    }
    
    /* ===== FOOTER ===== */
    .footer-content {
        grid-template-columns: 1fr;
    }
    
    /* ===== DASHBOARD SIDEBAR ===== */
    .sidebar {
        width: 70px;
        padding: 1rem 0;
    }
    
    .sidebar-header h2,
    .sidebar-item span {
        display: none;
    }
    
    .sidebar-item {
        justify-content: left;
        padding: 1rem 0.5rem;
    }
    
    .sidebar-item i {
        font-size: 1.4rem;
    }
    
    .main-content {
        margin-left: 70px;
        max-width: calc(100vw - 70px);
        padding: 1rem;
    }
    
    /* ===== SECTION HEADERS ===== */
    .section-header {
        flex-direction: row;
        gap: 1rem;
        align-items: center;
        flex-wrap: wrap;
    }
    
    .section-header h1 {
        font-size: 1.4rem;
    }
    
    .section-header .btn-group {
        flex-direction: row;
        flex-wrap: wrap;
    }
    
    .section-header .add-btn {
        font-size: 0.85rem;
        padding: 0.6rem 1rem;
        width: auto;
    }
    
    /* ===== MODALS ===== */
    .modal-content {
        width: 95%;
        max-width: 95%;
        margin: 5vh auto;
        padding: 1.5rem;
    }
    
    .small-modal {
        max-width: 90%;
    }
    
    .medium-modal {
        max-width: 95%;
    }
    
    .modal-content h2 {
        font-size: 1.4rem;
    }
    
    /* ===== FORMS ===== */
    .form-row {
        grid-template-columns: 1fr !important;
        gap: 0.5rem;
    }
    
    /* ===== TABLES ===== */
    .custom-table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .custom-table {
        min-width: 600px;
    }
    
    .custom-table th,
    .custom-table td {
        padding: 0.6rem 0.4rem;
        font-size: 0.85rem;
    }
    
    /* ===== CONFIG CARDS ===== */
    .config-item {
        flex-direction: row;
        align-items: center;
        gap: 0.5rem;
        flex-wrap: wrap;
    }
    
    .config-actions {
        width: auto;
        justify-content: flex-end;
        flex-shrink: 0;
    }
    
    /* ===== PRODUCT DETAILS ===== */
    .product-details-container {
        flex-direction: column;
    }
    
    .product-details-images,
    .product-details-info {
        width: 100%;
    }
}

/* ========================================
   MOBILE (480px - 600px)
   ======================================== */
@media (max-width: 600px) {
    /* Fix overflow */
    * {
        max-width: 100vw;
    }
    
    /* ===== NAVBAR ===== */
    .navbar {
        padding: 0.5rem 1%;
        display: flex;
        justify-content: space-between;
        align-items: center;
        position: sticky;
        width: 100%;
        gap: 0.5rem;
    }
    
    .logo {
        width: 100px !important;
        max-width: 100px !important;
        min-width: 100px !important;
        flex-shrink: 0;
        order: 1;
    }
    
    .logo-img {
        height: 32px;
        width: 32px;
    }
    
    .logo-text-container {
        font-size: 0.55em;
        left: 36px;
    }
    
    .navbar-search {
        max-width: 180px;
        width: 180px;
        margin: 0 auto;
        position: relative !important;
        left: 0 !important;
        transform: none !important;
        flex-grow: 1;
        flex-shrink: 0;
        order: 2;
    }
    
    .nav-icons {
        min-width: auto;
        width: auto;
        gap: 0.5rem;
        flex-shrink: 0;
        justify-content: flex-end;
        order: 3;
    }
    
    #user-name {
        display: none !important;
    }
    
    .navbar-search-icon {
        display: block;
        right: 8px;
        width: 16px;
        height: 16px;
    }
    
    .search-input {
        padding: 5px 28px 5px 8px;
        font-size: 0.75em;
        width: 100%;
        height: 28px;
        box-sizing: border-box;
        text-align: left;
    }
    
    .menu-icon {
        font-size: 1.3em;
    }
    
    /* ===== DROPDOWNS ===== */
    .user-dropdown {
        min-width: 200px;
        right: -10px;
    }
    
    .dropdown-item {
        font-size: 0.85rem;
        padding: 0.7rem 1rem;
    }
    
    /* ===== HERO SECTION ===== */
    .hero {
        height: 70vh;
    }
    
    .hero h1 {
        font-size: 2rem;
    }
    
    .section-title {
        font-size: 2rem;
    }
    
    .carousel-title {
        font-size: 1.5rem;
    }
    
    .nav-links {
        gap: 1rem;
        flex-wrap: wrap;
        justify-content: center;
    }
    
    /* ===== DASHBOARD ===== */
    .sidebar-toggle {
        display: block !important;
    }
    
    .sidebar {
        position: fixed;
        left: -220px;
        transition: left 0.3s ease;
        z-index: 1100;
        width: 220px;
        top: 0;
        height: 100vh;
        overflow-y: auto;
    }
    
    /* Mostrar texto en sidebar mobile */
    .sidebar-header h2,
    .sidebar-item span {
        display: block;
    }
    
    .sidebar.mobile-open {
        left: 0;
        box-shadow: 4px 0 12px rgba(0,0,0,0.3);
    }
    
    .main-content {
        margin-left: 0;
        max-width: 100vw;
        padding: 0.75rem;
    }
    
    /* ===== SECTION HEADERS ===== */
    .section-header {
        padding: 1rem;
    }
    
    .section-header h1 {
        font-size: 1.2rem;
    }
    
    .section-header .add-btn {
        font-size: 0.8rem;
        padding: 0.5rem 0.8rem;
        width: auto;
    }
    
    .section-header .add-btn i {
        font-size: 0.9rem;
    }
    
    /* ===== MODALS ===== */
    /* Modals pequeños (login, registro) - Centrados */
    .modal-content {
        width: 90%;
        max-width: 400px;
        margin: 10vh auto;
        border-radius: 12px;
        overflow-y: auto;
        max-height: 80vh;
    }
    
    /* Modals grandes (carrito, detalles) - Más espacio */
    #cart-modal .modal-content,
    #product-details-modal .modal-content {
        width: 95%;
        max-width: 95%;
        margin: 5vh auto;
    }
    
    .modal-content h2 {
        font-size: 1.2rem;
        margin-bottom: 1rem;
    }
    
    /* ===== FORMS ===== */
    .form-group {
        margin-bottom: 0.8rem;
        flex: 1 1 100% !important;
        min-width: 100% !important;
    }
    
    .form-group label {
        font-size: 0.9rem;
        margin-bottom: 0.3rem;
    }
    
    .form-group input,
    .form-group select,
    .form-group textarea {
        font-size: 0.9rem;
        padding: 0.6rem;
    }
    
    .profile-fields {
        gap: 0.8rem 1rem;
        flex-direction: column;
    }
    
    .profile-block {
        margin-bottom: 1rem;
        padding: 1.2rem;
    }
    
    /* ===== BUTTONS ===== */
    .submit-btn,
    .add-btn {
        padding: 0.7rem 1rem;
        font-size: 0.9rem;
    }
    
    /* ===== TABLES ===== */
    .custom-table {
        font-size: 0.75rem;
    }
    
    .custom-table th,
    .custom-table td {
        padding: 0.5rem 0.3rem;
    }
    
    .custom-table th:nth-child(3),
    .custom-table td:nth-child(3) {
        display: none;
    }
    
    /* ===== PAGINATION ===== */
    .custom-pagination {
        flex-wrap: wrap;
        gap: 0.3rem;
    }
    
    .custom-pagination button {
        padding: 0.4rem 0.6rem;
        font-size: 0.8rem;
    }
    
    /* ===== CONFIG LISTS ===== */
    .config-list {
        max-height: 300px;
    }
    
    .config-item {
        padding: 0.75rem;
    }
    
    .config-actions button {
        width: 35px;
        height: 35px;
    }
    
    /* ===== ACTION DROPDOWNS ===== */
    .action-dropdown {
        min-width: 140px;
    }
    
    .action-dropdown-btn {
        font-size: 0.85rem;
        padding: 0.6rem 0.8rem;
    }
}

/* ========================================
   SMALL MOBILE (< 480px)
   ======================================== */
@media (max-width: 480px) {
    /* ===== NAVBAR ===== */
    .navbar {
        padding: 0.5rem 1%;
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 0.3rem;
    }
    
    .logo {
        width: 80px !important;
        max-width: 80px !important;
        min-width: 80px !important;
        order: 1;
    }
    
    .logo-img {
        height: 28px;
        width: 28px;
    }
    
    .logo-text-container {
        display: none;
    }
    
    .navbar-search {
        width: 190px;
        max-width: 190px;
        margin: 0 auto;
        position: relative !important;
        left: 0 !important;
        transform: none !important;
        flex-grow: 1;
        flex-shrink: 0;
        order: 2;
    }
    
    #user-name {
        display: none !important;
    }
    
    .navbar-search-icon {
        display: block;
        right: 6px;
        width: 14px;
        height: 14px;
    }
    
    .search-input {
        font-size: 0.7em;
        padding: 4px 26px 4px 6px;
        height: 26px;
    }
    
    .nav-icons {
        min-width: auto;
        width: auto;
        gap: 0.4rem;
        order: 3;
        margin-right: 10px;
    }
    
    .search-input {
        font-size: 0.7em;
        padding: 4px 26px 4px 6px;
        height: 40px;
    }
    
    .nav-icons {
        min-width: auto;
        width: auto;
        gap: 0.4rem;
    }
    
    /* ===== DROPDOWNS ===== */
    #main-menu-dropdown {
        margin-top: 8px;
        margin-right: -14px;
        min-width: 110px;
    }
    
    #user-dropdown {
        margin-top: 8px;
        margin-right: -10px;
        min-width: 180px;
        max-width: 90vw;
    }
    
    /* ===== DASHBOARD ===== */
    .sidebar-toggle {
        display: block !important;
    }
    
    .sidebar {
        position: fixed;
        left: -220px;
        width: 220px;
        top: 0;
    }
    
    /* Mostrar texto en sidebar mobile */
    .sidebar-header h2,
    .sidebar-item span {
        display: block;
    }
    
    .main-content {
        padding: 0.5rem;
        margin-left: 0;
    }
    
    .section-header {
        padding: 0.75rem;
    }
    
    .section-header h1 {
        font-size: 1.1rem;
    }
    
    /* Compact add button - hide extra text */
    .section-header .add-btn {
        font-size: 0.75rem;
        padding: 0.45rem 0.7rem;
        white-space: nowrap;
        width: auto;
    }
    
    /* Hide extra text in buttons (Producto, Categoría, Marca, Proveedor) */
    .btn-extra-text {
        display: none;
    }
    
    /* ===== MODALS ===== */
    /* Modals pequeños (login, registro) - Centrados en pantallas pequeñas */
    #login-modal .modal-content,
    #register-modal .modal-content {
        width: 92%;
        max-width: 350px;
        margin: 8vh auto;
        border-radius: 10px;
        overflow-y: auto;
        max-height: 84vh;
        padding: 1.25rem;
    }
    
    /* Modals grandes (carrito, detalles) - Casi fullscreen */
    #cart-modal .modal-content,
    #product-details-modal .modal-content {
        width: 98%;
        max-width: 98%;
        margin: 2vh auto;
        max-height: 96vh;
        border-radius: 8px;
    }
    
    /* Modal de movimiento de inventario - más grande en móvil */
    .modal-content.movement-modal {
        width: 95%;
        max-width: 95%;
        margin: 2vh auto;
        max-height: 94vh;
        padding: 1.5rem 1.25rem;
    }
    
    .modal-content h2 {
        font-size: 1.1rem;
        margin-bottom: 0.8rem;
    }
    
    /* ===== CONTENT CARDS ===== */
    .content-card {
        padding: 1rem;
    }
    
    /* ===== FORMS ===== */
    .form-row {
        grid-template-columns: 1fr !important;
    }
    
    /* ===== TABLES ===== */
    .custom-table-wrapper {
        border-radius: 8px;
    }
    
    .custom-table th,
    .custom-table td {
        padding: 0.5rem 0.3rem;
        font-size: 0.75rem;
        white-space: nowrap;
    }
    
    /* Keep table layout on small screens */
    .custom-table {
        display: table;
        width: 100%;
        table-layout: auto;
    }
    
    .custom-table thead {
        display: table-header-group;
    }
    
    .custom-table tbody {
        display: table-row-group;
    }
    
    .custom-table tbody tr {
        display: table-row;
    }
    
    .custom-table tbody td {
        display: table-cell;
        vertical-align: middle;
    }
    
    /* Enable horizontal scroll for tables on small screens */
    .table-body-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* ========================================
   LANDSCAPE MODE
   ======================================== */
@media (max-width: 768px) and (orientation: landscape) {
    .modal-content {
        height: auto;
        max-height: 90vh;
    }
    
    .sidebar {
        width: 60px;
    }
    
    .main-content {
        margin-left: 60px;
    }
}

/* ========================================
   PRINT STYLES
   ======================================== */
@media print {
    .navbar,
    .sidebar,
    .floating-cart,
    .section-header .add-btn,
    .action-btn,
    .custom-pagination {
        display: none;
    }
    
    .main-content {
        margin-left: 0;
        max-width: 100%;
    }
    
    .custom-table {
        font-size: 10pt;
    }
}
