/* css/styles.css */
:root {
    --bg: #ffffff;
    --panel: #ffffff;
    --muted: #6b7280;
    --text: #111827;
    --line: #e5e7eb;
    --accent: #065f46;
    --soft: #f8fafc;
    --hover: #f9fafb;
    --success: #166534;
}

* {
    box-sizing: border-box;
}

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    font-family: system-ui, -apple-system, sans-serif;
    background: var(--soft);
    color: var(--text);
}

/* Login */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background: var(--soft);  /* Mismo gris del fondo principal (#f8fafc) */
}

.login-box {
    background: white;
    padding: 40px;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    text-align: center;
    max-width: 400px;
    width: 90%;
}

.login-box h1 {
    color: var(--accent);
    margin-bottom: 20px;
}

.login-btn {
    background: linear-gradient(180deg, var(--success), var(--accent));
    color: white;
    border: none;
    padding: 12px 30px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    font-size: 16px;
    transition: transform 0.2s;
    margin-top: 20px;
}

.login-btn:hover {
    transform: translateY(-2px);
}

/* Estados */
.loading {
    display: none;
    text-align: center;
    padding: 20px;
    color: var(--muted);
}

.error {
    color: #dc3545;
    background: #f8d7da;
    padding: 12px;
    border-radius: 8px;
    margin: 10px 0;
    display: none;
}

.success {
    color: #155724;
    background: #d4edda;
    padding: 12px;
    border-radius: 8px;
    margin: 10px 0;
    display: none;
}

/* Header */
header {
    padding: 18px 16px;
    position: sticky;
    top: 0;
    z-index: 50;
    background: rgba(255,255,255,.9);
    backdrop-filter: blur(6px);
    border-bottom: 1px solid var(--line);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1400px;
    margin: 0 auto;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 15px;
    font-size: 14px;
    color: var(--muted);
}

.logout-btn {
    background: var(--muted);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
}

h1 {
    margin: 0;
    font-size: clamp(20px, 2.2vw, 30px);
    color: var(--text);
}

.subtitle {
    color: var(--muted);
    font-size: 13px;
    margin-top: 4px;
}

/* Layout principal */
.wrap {
    max-width: 1400px;
    margin: 0 auto;
    padding: 12px 16px 80px;
}

/* Navegación */
.tabs {
    display: flex;
    gap: 2px;
    margin-bottom: 20px;
    background: var(--panel);
    border-radius: 14px;
    padding: 4px;
    border: 1px solid var(--line);
    box-shadow: 0 6px 18px rgba(0,0,0,.05);
}

.tab {
    background: transparent;
    border: none;
    padding: 12px 20px;
    cursor: pointer;
    border-radius: 10px;
    font-weight: 500;
    font-size: 14px;
    color: var(--muted);
    transition: all 0.2s ease;
    flex: 1;
    text-align: center;
}

.tab.active {
    background: linear-gradient(180deg, var(--success), var(--accent));
    color: white;
    box-shadow: 0 2px 8px rgba(6,95,70,.25);
}

/* Contenido */
.content {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 24px;
    box-shadow: 0 6px 18px rgba(0,0,0,.05);
    min-height: 600px;
}

.controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    gap: 15px;
}

/* Botones */
.btn {
    background: linear-gradient(180deg, var(--success), var(--accent));
    border-color: var(--accent);
    color: white;
    padding: 10px 16px;
    border-radius: 10px;
    border: none;
    cursor: pointer;
    font-weight: 500;
    transition: transform 0.2s;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn-small {
    padding: 6px 12px;
    font-size: 12px;
}

/* Botón expandir/colapsar - discreto */
.btn-expand {
    background: transparent;
    border: none;
    color: var(--accent);
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
    padding: 4px 8px;
    transition: transform 0.2s;
}

.btn-expand:hover {
    transform: scale(1.1);
}

.btn-readonly {
    background: linear-gradient(180deg, #9ca3af, #6b7280);
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-readonly:hover {
    transform: none;
}

.btn-danger {
    background: #dc3545;
}

.btn-delete {
    background: transparent;
    border: 1px solid #dc3545;
    color: #dc3545;
    font-size: 12px;
    opacity: 0.7;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
}

/* Tablas */
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    background: var(--bg);
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid var(--line);
}

th, td {
    border-bottom: 1px solid var(--line);
    padding: 12px;
    text-align: left;
}

th {
    background: #f3f4f6;
    font-weight: 600;
    font-size: 12px;
    position: relative;
}

/* Iconos de filtro y ordenamiento */
.filter-icon, .sort-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: 6px;
    cursor: pointer;
    color: var(--muted);
    transition: color 0.2s;
    background: transparent;
    border: none;
    padding: 2px;
    width: 16px;
    height: 16px;
    vertical-align: middle;
}

.filter-icon:hover, .sort-icon:hover {
    color: var(--accent);
}

.sort-icon.active {
    color: var(--accent);
}

.filter-icon svg, .sort-icon svg {
    width: 14px;
    height: 14px;
}

/* Dropdown de filtros */
.filter-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    z-index: 100;
    padding: 8px;
}

.filter-dropdown select {
    width: 100%;
    border: none;
    background: transparent;
    padding: 4px;
    font-size: 12px;
}

/* Status badges */
.status-badge {
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
}

.status-colocando { background: #fff3cd; color: #856404; }
.status-produccion { background: #cce5ff; color: #004085; }
.status-transito { background: #d4edda; color: #155724; }
.status-importacion { background: #f8d7da; color: #721c24; }
.status-cedi { background: #e2e3e5; color: #383d41; }
.status-cerrado { background: #d1ecf1; color: #0c5460; }

/* Formularios */
input, select, textarea {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px 12px;
    outline: none;
    font-size: 14px;
    margin: 5px;
}

textarea {
    width: 100%;
    resize: vertical;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin: 15px 0;
}

.form-section {
    background: var(--soft);
    padding: 20px;
    border-radius: 10px;
    margin: 20px 0;
}

/* Formularios superiores */
.form-section-top {
    position: relative;
    background: var(--panel);
    border: 2px solid var(--accent);
    border-radius: 14px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 8px 20px rgba(6, 95, 70, 0.1);
    z-index: 20;
    animation: slideDown 0.3s ease-out;
}

.form-section-top.hidden {
    display: none;
}

.form-section-top h3 {
    color: var(--accent);
    margin-top: 0;
    margin-bottom: 15px;
    font-size: 18px;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Filtros en controles */
.controls-filter {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--soft);
    padding: 8px 12px;
    border-radius: 8px;
}

.controls-filter select {
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 12px;
    margin: 0;
}

.controls-filter label {
    font-size: 12px;
    color: var(--muted);
    font-weight: 500;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
    overflow-y: auto;
}

.modal-content {
    background: #ffffff;
    margin: 20px auto;
    padding: 0;
    border-radius: 14px;
    width: 90%;
    max-width: 900px;  /* Cambiado de 700px a 1200px */
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    border: none;
}

/* Header sticky gris claro - inicia desde arriba */
.modal-header-sticky {
    position: sticky;
    top: 0;
    z-index: 100;
    background: #f3f4f6;
    border-radius: 14px 14px 0 0;
}

.modal-header-content {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    padding: 12px 20px;
    border-bottom: 1px solid var(--line);
}

.modal-header-content h3 {
    margin: 0;
    color: var(--text);
    font-size: 16px;
    font-weight: 600;
    text-align: left;
    min-width: 150px;
    width: 100px;
}

.modal-header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-self: center;
}

.modal-header-content .close {
    justify-self: end;
}

/* Botones centrados */
.icon-btn {
    background: white;
    border: 1px solid var(--line);
    color: var(--text);
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 14px;
    font-weight: 500;
}

.icon-btn:hover {
    background: var(--soft);
}

.icon-btn svg {
    display: block;
}

.modal-header-sticky .tabs {
    margin-bottom: 0;
    border-radius: 0;
    border: none;
    border-top: 1px solid var(--line);
    background: white;
    padding: 6px;
}

.modal-header-sticky .tab {
    padding: 8px 16px;
    font-size: 13px;
}

.modal-header-sticky .tab.active {
    background: var(--accent);
    color: white;
}

.close {
    color: var(--text);
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    background: none;
    border: none;
    padding: 4px;
    border-radius: 6px;
    transition: background 0.2s;
    line-height: 1;
    margin-left: auto;  /* Empuja la X al extremo derecho */
}

.close:hover {
    background: var(--soft);
}

.modal-body-content {
    padding: 24px;
}

.modal-form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 15px;
}

.modal-form-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.modal-form-group label {
    font-size: 12px;
    color: var(--muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.modal-form-group input,
.modal-form-group select,
.modal-form-group textarea {
    margin: 0;
    font-size: 14px;
    font-family: system-ui, -apple-system, sans-serif;
}

/* Campos readonly - fondo gris, TEXTO NEGRO */
.readonly {
    background-color: #f3f4f6 !important;
    color: #111827 !important;
    cursor: default !important;
}

/* Headers de secciones */
.modal-body-content h4 {
    margin: 20px 0 15px 0;
    color: var(--accent);
    font-size: 15px;
    font-weight: 600;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--line);
}

.modal-body-content h4:first-child {
    margin-top: 0;
}

/* Toasts flotantes */
#toastContainer {
    position: fixed;
    right: 20px;
    bottom: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 2000;
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    min-width: 280px;
    max-width: 360px;
    background: #ffffff;
    color: #111827;
    border: 1px solid var(--line);
    border-left: 6px solid var(--accent);
    box-shadow: 0 8px 24px rgba(0,0,0,.15);
    border-radius: 10px;
    padding: 12px 14px 12px 12px;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px 12px;
    animation: toast-in 200ms ease-out;
}

.toast.success { border-left-color: #16a34a; }
.toast.error   { border-left-color: #dc2626; }

.toast-title {
    font-weight: 600;
    font-size: 14px;
    margin: 0;
}

.toast-msg {
    font-size: 13px;
    color: var(--muted);
    grid-column: 1 / -1;
}

.toast-close {
    background: transparent;
    border: none;
    color: var(--muted);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    padding: 0 2px;
    border-radius: 6px;
}
.toast-close:hover { background: #f3f4f6; }

@keyframes toast-in {
    from { transform: translateY(8px); opacity: 0; }
    to   { transform: translateY(0);   opacity: 1; }
}

/* Tablas dentro del modal - tamaño estandarizado */
#lineasTableEditable,
#lineasCosteoTable,
#contenedoresTable {
    margin-top: 10px;
    font-size: 14px;
}

#lineasTableEditable th,
#lineasCosteoTable th,
#contenedoresTable th {
    background: var(--soft);
    padding: 8px;
    font-size: 12px;
}

#lineasTableEditable td,
#lineasCosteoTable td,
#contenedoresTable td {
    padding: 8px;
    font-size: 14px;
}

#lineasTableEditable input,
#lineasTableEditable select,
#contenedoresTable input {
    margin: 0;
    font-size: 14px;
    border: 1px solid var(--line);
    font-family: system-ui, -apple-system, sans-serif;
}

.btn-eliminar-linea {
    padding: 4px 8px;
    font-size: 14px;
    line-height: 1;
    background: transparent;
    border: 1px solid #dc3545;
    color: #dc3545;
    border-radius: 4px;
    cursor: pointer;
}

.btn-eliminar-linea:hover {
    background: #dc3545;
    color: white;
}

/* Responsive */
@media (max-width: 768px) {
    .tabs {
        overflow-x: auto;
        flex-wrap: nowrap;
    }
    .tab {
        min-width: 120px;
        flex: none;
    }
    .modal-content {
        width: 95%;
        margin: 10px auto;
    }
    .modal-form-row, .form-grid {
        grid-template-columns: 1fr;
    }
    .controls {
        flex-direction: column;
        align-items: stretch;
    }

    .controls-filter {
        justify-content: center;
        flex-wrap: wrap;
    }

    #toastContainer {
        right: 12px;
        left: 12px;
        bottom: 12px;
    }
    .toast { max-width: none; }

    .form-section-top {
        margin: 10px 0;
        padding: 15px;
    }
    
    .form-grid {
        grid-template-columns: 1fr;
    }
    
    .modal-header-content {
        padding: 10px 15px;
    }
    
    .modal-header-content h3 {
        font-size: 16px;
    }
    
    .icon-btn {
        padding: 6px 10px;
        font-size: 13px;
    }
    
    .icon-btn svg {
        width: 14px;
        height: 14px;
    }
}

/* ========================================
   ESTILOS DE CALENDARIO
   Agregar al final de styles.css
======================================== */

.calendar-container {
    background: var(--panel);
    border-radius: 14px;
    padding: 20px;
    border: 1px solid var(--line);
}

.calendar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid var(--line);
}

.calendar-header h3 {
    margin: 0;
    color: var(--accent);
    font-size: 24px;
    font-weight: 600;
}

.calendar-days-header {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
    margin-bottom: 10px;
}

.calendar-day-name {
    text-align: center;
    font-weight: 600;
    font-size: 12px;
    color: var(--muted);
    padding: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.calendar-days-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 8px;
}

.calendar-day {
    min-height: 120px;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px;
    position: relative;
    overflow: hidden;
    transition: box-shadow 0.2s;
}

.calendar-day:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.calendar-day.empty {
    background: var(--soft);
    border: none;
    opacity: 0.5;
}

.calendar-day.today {
    border: 2px solid var(--accent);
    background: #f0fdf4;
    box-shadow: 0 0 0 3px rgba(6, 95, 70, 0.1);
}

.calendar-day-number {
    font-weight: 600;
    font-size: 16px;
    color: var(--text);
    margin-bottom: 8px;
    padding-bottom: 5px;
    border-bottom: 1px solid var(--line);
}

.calendar-day.today .calendar-day-number {
    color: var(--accent);
    font-weight: 700;
}

.calendar-day-events {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 80px;
    overflow-y: auto;
}

/* Scrollbar personalizada para eventos */
.calendar-day-events::-webkit-scrollbar {
    width: 4px;
}

.calendar-day-events::-webkit-scrollbar-track {
    background: transparent;
}

.calendar-day-events::-webkit-scrollbar-thumb {
    background: var(--line);
    border-radius: 2px;
}

.calendar-day-events::-webkit-scrollbar-thumb:hover {
    background: var(--muted);
}

.calendar-event {
    background: var(--soft);
    border-left: 4px solid var(--accent);
    padding: 6px 8px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 11px;
    line-height: 1.3;
}

.calendar-event:hover {
    transform: translateX(3px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
    background: white;
}

.calendar-event-title {
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.calendar-event-subtitle {
    color: var(--muted);
    font-size: 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Colores de borde según el estatus */
.calendar-event.status-colocando { 
    border-left-color: #856404;
    background: #fff3cd;
}

.calendar-event.status-produccion { 
    border-left-color: #004085;
    background: #cce5ff;
}

.calendar-event.status-transito { 
    border-left-color: #155724;
    background: #d4edda;
}

.calendar-event.status-importacion { 
    border-left-color: #721c24;
    background: #f8d7da;
}

.calendar-event.status-cedi { 
    border-left-color: #383d41;
    background: #e2e3e5;
}

.calendar-event.status-cerrado { 
    border-left-color: #0c5460;
    background: #d1ecf1;
}

/* Responsive para tablets */
@media (max-width: 1024px) {
    .calendar-day {
        min-height: 100px;
    }
    
    .calendar-header h3 {
        font-size: 20px;
    }
    
    .calendar-event {
        font-size: 10px;
        padding: 4px 6px;
    }
}

/* Responsive para móviles */
@media (max-width: 768px) {
    .calendar-container {
        padding: 12px;
    }
    
    .calendar-header {
        flex-direction: column;
        gap: 10px;
        align-items: stretch;
    }
    
    .calendar-header h3 {
        font-size: 18px;
        text-align: center;
    }
    
    .calendar-header .btn {
        width: 100%;
    }
    
    .calendar-days-grid {
        gap: 4px;
    }
    
    .calendar-day {
        min-height: 70px;
        padding: 4px;
    }
    
    .calendar-day-number {
        font-size: 12px;
        margin-bottom: 4px;
        padding-bottom: 3px;
    }
    
    .calendar-day-name {
        font-size: 10px;
        padding: 6px 2px;
    }
    
    .calendar-event {
        font-size: 9px;
        padding: 3px 4px;
        border-left-width: 3px;
    }
    
    .calendar-event-title {
        font-size: 9px;
    }
    
    .calendar-event-subtitle {
        font-size: 8px;
    }
    
    .calendar-day-events {
        max-height: 50px;
        gap: 2px;
    }
}

/* Muy pequeño - mostrar solo día */
@media (max-width: 480px) {
    .calendar-day {
        min-height: 60px;
        padding: 3px;
    }
    
    .calendar-day-number {
        font-size: 11px;
    }
    
    .calendar-event {
        padding: 2px 3px;
    }
    
    .calendar-event-subtitle {
        display: none;
    }
}
/* ========================================
   ESTILOS PARA DÍAS EN TRÁNSITO
   Agregar al final de styles.css (después de los estilos del calendario)
======================================== */

/* Badges para días en tránsito */
.dias-transito-muy-anticipado {
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    background: #dbeafe;
    color: #1e40af;
}

.dias-transito-anticipado {
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    background: #d1fae5;
    color: #065f46;
}

.dias-transito-hoy {
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    background: #fef3c7;
    color: #92400e;
}

.dias-transito-leve {
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    background: #fed7aa;
    color: #9a3412;
}

.dias-transito-moderado {
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    background: #fecaca;
    color: #991b1b;
}

.dias-transito-critico {
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 700;
    background: #dc2626;
    color: white;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.8;
    }
}
/* REEMPLAZAR la sección de "Status badges" en styles.css con esto: */

/* Status badges - Estatus automáticos basados en fechas */
.status-badge {
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
}

.status-produccion { 
    background: #cce5ff; 
    color: #004085; 
}

.status-transito { 
    background: #d4edda; 
    color: #155724; 
}

.status-importacion { 
    background: #f8d7da; 
    color: #721c24; 
}

.status-cedi { 
    background: #e2e3e5; 
    color: #383d41; 
}

/* Mantener estilos antiguos por compatibilidad con datos existentes */
.status-colocando { background: #fff3cd; color: #856404; }
.status-cerrado { background: #d1ecf1; color: #0c5460; }

/* Scrollbar para las tarjetas de estatus */
.status-card-scroll::-webkit-scrollbar {
    width: 6px;
}

.status-card-scroll::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 3px;
}

.status-card-scroll::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

.status-card-scroll::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

/* Responsive para vista por estatus */
@media (max-width: 768px) {
    .status-view-grid {
        grid-template-columns: 1fr !important;
    }
}
/* Botones de vista (Lista, Calendario, Estatus) */
.view-toggle-btn {
    background: #d1d5db;
    color: #4b5563;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 500;
    font-size: 14px;
    transition: background 0.2s, color 0.2s;
    cursor: pointer;
}

.view-toggle-btn.active {
    background: #6b7280;
    color: white;
}

.view-toggle-btn:hover {
    transform: none;
}

/* Contenedor de botones de vista */
.view-toggle-container {
    display: flex;
    justify-content: center;
    gap: 8px;
}

/* ========================================
   ESTILOS MÓVIL MEJORADOS
   Mobile-first responsive design
======================================== */

/* Tablets y pantallas medianas */
@media (max-width: 1024px) {
    .wrap {
        padding: 10px 12px 100px;
    }

    .content {
        padding: 16px;
    }
}

/* Móviles */
@media (max-width: 768px) {
    /* ===== HEADER COMPACTO ===== */
    header {
        padding: 12px;
    }

    .header-content {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }

    .header-content h1 {
        font-size: 16px;
    }

    .header-content .subtitle {
        display: none;
    }

    .user-info {
        gap: 8px;
    }

    .user-info span {
        display: none;
    }

    .logout-btn {
        padding: 8px 12px;
        font-size: 12px;
    }

    /* ===== NAVEGACIÓN INFERIOR FIJA ===== */
    .tabs {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 1000;
        margin: 0;
        border-radius: 0;
        background: white;
        border: none;
        border-top: 1px solid var(--line);
        box-shadow: 0 -4px 20px rgba(0,0,0,0.1);
        padding: 8px 4px;
        display: flex;
        justify-content: space-around;
        gap: 0;
    }

    .tab {
        flex: 1;
        padding: 10px 4px;
        font-size: 10px;
        min-width: auto;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 4px;
        border-radius: 8px;
    }

    .tab::before {
        font-size: 18px;
        display: block;
    }

    .tab[data-page="pedidos"]::before { content: "📦"; }
    .tab[data-page="transito"]::before { content: "🚢"; }
    .tab[data-page="cotizaciones"]::before { content: "💰"; }
    .tab[data-page="proveedores"]::before { content: "🏭"; }
    .tab[data-page="productos"]::before { content: "📋"; }

    .tab.active {
        background: var(--soft);
        color: var(--accent);
        box-shadow: none;
    }

    /* ===== CONTENIDO PRINCIPAL ===== */
    .wrap {
        padding: 8px 10px 80px; /* Espacio para nav inferior */
    }

    .content {
        padding: 12px;
        min-height: auto;
        border-radius: 12px;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    /* ===== CONTROLES FIJOS ===== */
    .controls {
        flex-direction: column;
        gap: 12px;
        align-items: stretch;
        flex-shrink: 0; /* No se encoge */
        position: sticky;
        top: 0;
        background: var(--panel);
        z-index: 20;
        padding-bottom: 12px;
        margin-bottom: 0;
    }

    .controls h2 {
        font-size: 18px;
        text-align: center;
        margin: 0;
    }

    .view-toggle-container {
        justify-content: center;
    }

    .view-toggle-btn {
        padding: 10px 14px;
        font-size: 12px;
        flex: 1;
    }

    .controls-filter {
        flex-wrap: wrap;
        justify-content: center;
        padding: 10px;
    }

    .controls-filter select {
        flex: 1;
        min-width: 100px;
    }

    /* ===== BOTONES TOUCH-FRIENDLY ===== */
    .btn {
        min-height: 48px;
        padding: 12px 20px;
        font-size: 15px;
        width: 100%;
        justify-content: center;
    }

    .btn-small {
        min-height: 40px;
        padding: 8px 14px;
        font-size: 13px;
    }

    /* ===== INPUTS MÓVIL ===== */
    input, select, textarea {
        font-size: 16px !important; /* Evita zoom en iOS */
        min-height: 48px;
        padding: 12px;
    }

    /* ===== CONTENEDOR DE TABLA CON SCROLL CONTROLADO ===== */
    .table-scroll-container {
        flex: 1;
        overflow: hidden;
        position: relative;
        border: 1px solid var(--line);
        border-radius: 10px;
        background: var(--bg);
    }

    .table-scroll-container table {
        border: none;
        border-radius: 0;
    }

    /* Scroll horizontal */
    .table-scroll-x {
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-x: contain;
    }

    /* Scroll vertical */
    .table-scroll-y {
        overflow-x: hidden;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-y: contain;
        max-height: 100%;
    }

    /* Scroll controlado - una direccion a la vez */
    .table-scroll-container > div {
        overflow: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        max-height: calc(100vh - 300px); /* Header + controls + nav + padding */
    }

    /* Clase para bloquear scroll horizontal */
    .table-scroll-container > div.scroll-lock-x {
        overflow-x: hidden;
    }

    /* Clase para bloquear scroll vertical */
    .table-scroll-container > div.scroll-lock-y {
        overflow-y: hidden;
    }

    /* ===== TABLAS RESPONSIVE ===== */
    table {
        min-width: 700px;
        font-size: 13px;
        border-collapse: collapse;
    }

    th, td {
        padding: 10px 8px;
        white-space: nowrap;
    }

    th {
        font-size: 11px;
        position: sticky;
        top: 0;
        z-index: 10;
        background: #f3f4f6;
    }

    /* ===== MODAL PANTALLA COMPLETA ===== */
    .modal-content {
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        margin: 0;
        border-radius: 0;
    }

    .modal-header-sticky {
        border-radius: 0;
    }

    .modal-header-content {
        grid-template-columns: auto 1fr auto;
        padding: 12px 16px;
        gap: 8px;
    }

    .modal-header-content h3 {
        font-size: 14px;
        min-width: auto;
    }

    .modal-header-actions {
        gap: 6px;
    }

    .icon-btn {
        padding: 8px 12px;
        font-size: 12px;
    }

    .modal-body-content {
        padding: 16px;
    }

    .modal-form-row {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .modal-form-group label {
        font-size: 11px;
    }

    /* ===== TABS EN MODAL ===== */
    .modal-header-sticky .tabs {
        position: static;
        box-shadow: none;
        border-top: 1px solid var(--line);
        padding: 4px;
    }

    .modal-header-sticky .tab {
        flex-direction: row;
        font-size: 11px;
        padding: 10px 8px;
    }

    .modal-header-sticky .tab::before {
        display: none;
    }

    /* ===== FORMULARIOS ===== */
    .form-section {
        padding: 14px;
        margin: 12px 0;
    }

    .form-section-top {
        padding: 14px;
        margin: 10px 0;
    }

    .form-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    /* ===== CARDS DE ESTATUS ===== */
    .status-view-grid {
        grid-template-columns: 1fr !important;
        gap: 12px;
    }

    /* ===== TOASTS ===== */
    #toastContainer {
        left: 10px;
        right: 10px;
        bottom: 100px; /* Encima de la navegación */
    }

    .toast {
        max-width: none;
    }

    /* ===== CALENDARIO MÓVIL ===== */
    .calendar-container {
        padding: 10px;
    }

    .calendar-header {
        flex-direction: column;
        gap: 10px;
    }

    .calendar-header h3 {
        font-size: 16px;
        text-align: center;
    }

    .calendar-days-grid {
        gap: 3px;
    }

    .calendar-day {
        min-height: 55px;
        padding: 4px;
    }

    .calendar-day-number {
        font-size: 11px;
    }

    .calendar-event {
        padding: 3px 4px;
        font-size: 8px;
    }

    .calendar-event-subtitle {
        display: none;
    }

    /* ===== BADGES ===== */
    .status-badge {
        font-size: 10px;
        padding: 3px 6px;
    }

    .dias-transito-muy-anticipado,
    .dias-transito-anticipado,
    .dias-transito-hoy,
    .dias-transito-leve,
    .dias-transito-moderado,
    .dias-transito-critico {
        font-size: 10px;
        padding: 3px 6px;
    }
}

/* Móviles muy pequeños */
@media (max-width: 380px) {
    .tab {
        font-size: 9px;
        padding: 8px 2px;
    }

    .tab::before {
        font-size: 16px;
    }

    .header-content h1 {
        font-size: 14px;
    }

    .btn {
        padding: 10px 16px;
        font-size: 14px;
    }

    .view-toggle-btn {
        padding: 8px 10px;
        font-size: 11px;
    }

    .modal-header-content h3 {
        font-size: 13px;
    }

    .icon-btn {
        padding: 6px 10px;
        font-size: 11px;
    }
}

/* Landscape en móviles */
@media (max-width: 768px) and (orientation: landscape) {
    .tabs {
        padding: 6px 4px;
    }

    .tab {
        padding: 8px 4px;
        font-size: 9px;
    }

    .tab::before {
        font-size: 14px;
    }

    .wrap {
        padding-bottom: 70px;
    }
}

/* Safe area para iPhone X y posteriores */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    @media (max-width: 768px) {
        .tabs {
            padding-bottom: calc(8px + env(safe-area-inset-bottom));
        }

        .wrap {
            padding-bottom: calc(85px + env(safe-area-inset-bottom));
        }

        .table-scroll-container > div {
            max-height: calc(100vh - 300px - env(safe-area-inset-bottom));
        }

        #toastContainer {
            bottom: calc(100px + env(safe-area-inset-bottom));
        }
    }
}

/* ================================================
   SELECTOR DE SECCION (Dropdown en header)
   ================================================ */

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.section-selector {
    position: relative;
}

.section-selector-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--accent);
    color: white;
    border: none;
    padding: 10px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(6,95,70,.25);
}

.section-selector-btn:hover {
    background: var(--success);
}

.section-selector-btn svg {
    transition: transform 0.2s ease;
}

.section-selector-btn.open svg {
    transform: rotate(180deg);
}

.section-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,.15);
    border: 1px solid var(--line);
    min-width: 280px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s ease;
    z-index: 1000;
    overflow: hidden;
}

.section-dropdown.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.section-option {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    width: 100%;
    padding: 14px 18px;
    border: none;
    background: transparent;
    cursor: pointer;
    text-align: left;
    transition: background 0.15s ease;
    font-size: 15px;
    font-weight: 500;
    color: var(--text);
}

.section-option:hover {
    background: var(--soft);
}

.section-option.active {
    background: linear-gradient(90deg, rgba(6,95,70,.08), transparent);
    border-left: 3px solid var(--accent);
}

.section-option .section-desc {
    font-size: 12px;
    color: var(--muted);
    font-weight: 400;
    margin-top: 4px;
}

.header-title h1 {
    margin: 0;
    font-size: clamp(16px, 2vw, 24px);
}

/* Tab disabled */
.tab.disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ================================================
   HOJA DE DEMANDA - Tooltips Dinámicos
   ================================================ */

.tooltip-trigger {
    cursor: help;
    border-bottom: 1px dashed var(--muted);
}

.tooltip-trigger small {
    font-size: 10px;
    color: var(--muted);
    margin-left: 4px;
}

/* Tooltip dinámico posicionado por JS */
.dynamic-tooltip {
    display: none;
    position: fixed;
    z-index: 9999;
    pointer-events: none;
}

.dynamic-tooltip .tooltip-content {
    background: #f3f4f6;
    color: #111827;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 12px;
    box-shadow: 0 4px 16px rgba(0,0,0,.15);
    border: 1px solid #e5e7eb;
    max-width: 300px;
}

/* Tabla dentro del tooltip */
.tooltip-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    min-width: 160px;
}

.tooltip-table th {
    background: #e5e7eb;
    padding: 6px 10px;
    text-align: left;
    font-weight: 600;
    font-size: 11px;
    border-bottom: 1px solid #d1d5db;
}

.tooltip-table td {
    padding: 5px 10px;
    border-bottom: 1px solid #e5e7eb;
}

.tooltip-table tr:last-child td {
    border-bottom: none;
}

.tooltip-table td:last-child,
.tooltip-table th:last-child {
    text-align: right;
}

/* Colores para estados de inventario */
.text-danger {
    color: #dc2626;
    font-weight: 600;
}

.text-warning {
    color: #d97706;
}

/* Hoja de demanda tabla */
.hoja-demanda-table th {
    background: var(--soft);
    position: sticky;
    top: 0;
}

.hoja-demanda-table td {
    vertical-align: middle;
}

/* ================================================
   HOJA DE DEMANDA - Layout de 3 tablas
   ================================================ */

.hoja-demanda-grid {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 10px;
}

.hoja-demanda-tabla {
    flex-shrink: 0;
}

.hoja-demanda-tabla:first-child {
    flex: 1;
    min-width: 500px;
}

.hoja-demanda-tabla table {
    font-size: 13px;
    border-collapse: collapse;
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
}

.hoja-demanda-tabla th {
    padding: 8px 10px;
    font-size: 11px;
    white-space: nowrap;
    height: 38px;
}

.hoja-demanda-tabla td {
    padding: 6px 10px;
    white-space: nowrap;
    height: 36px;
}

/* Descripcion puede truncarse */
.hoja-demanda-tabla .desc-cell {
    max-width: 130px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Tabla de proyección */
.tabla-proyeccion {
    background: #f0fdf4;
    min-width: 195px;
}

.tabla-proyeccion th {
    background: #dcfce7 !important;
    color: #166534;
}

.tabla-proyeccion td {
    min-width: 60px;
}

/* Tabla de pedido */
.tabla-pedido {
    background: #eff6ff;
    min-width: 90px;
}

.tabla-pedido th {
    background: #dbeafe !important;
    color: #1e40af;
}

.tabla-pedido tfoot td {
    background: #dbeafe !important;
    color: #1e40af;
    font-size: 14px;
}

/* Input de pedido */
.pedido-input {
    width: 70px;
    padding: 6px 8px !important;
    margin: 0 !important;
    text-align: center;
    font-size: 14px !important;
    min-height: auto !important;
    border: 1px solid #93c5fd !important;
    border-radius: 4px !important;
}

.pedido-input:focus {
    outline: none;
    border-color: #3b82f6 !important;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

/* Link del SKU */
.sku-link {
    color: var(--accent);
    text-decoration: none;
}

.sku-link:hover {
    text-decoration: underline;
}

/* Subgrupo section */
.subgrupo-section {
    margin-bottom: 25px;
}

.subgrupo-title {
    font-size: 16px;
    color: var(--accent);
    margin: 0 0 10px 0;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--line);
}

/* Responsive para hoja de demanda */
@media (max-width: 1024px) {
    .hoja-demanda-grid {
        flex-wrap: nowrap;
    }

    .hoja-demanda-tabla:first-child {
        min-width: 380px;
    }

    .hoja-demanda-tabla .desc-cell {
        max-width: 120px;
    }
}

@media (max-width: 768px) {
    .hoja-demanda-tabla:first-child {
        min-width: 320px;
    }

    .hoja-demanda-tabla .desc-cell {
        max-width: 100px;
    }

    .hoja-demanda-tabla th,
    .hoja-demanda-tabla td {
        padding: 4px 5px;
        font-size: 11px;
    }

    .tabla-proyeccion {
        min-width: 160px;
    }

    .pedido-input {
        width: 50px;
        font-size: 12px !important;
    }
}

/* Mobile adjustments para secciones */
@media (max-width: 768px) {
    .section-navigation {
        margin-bottom: 8px;
    }

    .section-tab {
        padding: 10px 12px;
        font-size: 14px;
    }

    .sub-navigation {
        flex-wrap: wrap;
    }

    .sub-navigation .tab {
        padding: 8px 12px;
        font-size: 12px;
    }
}
