/* --- DISPATCH (DESPACHO) STYLES --- */
:root {
    --dispatch-primary: var(--solvix-cyan);
    --dispatch-primary-dark: #0088cc;
    --dispatch-bg-gradient: linear-gradient(135deg, var(--solvix-navy) 0%, #041226 100%);

    --text-main: var(--solvix-silver);
    --text-sub: rgba(226, 232, 240, 0.7);
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --border: rgba(255, 255, 255, 0.1);

    --radius-lg: 20px;
    --radius-md: 12px;
}

#dispatch-content * {
    box-sizing: border-box;
    font-family: 'Segoe UI', system-ui, sans-serif;
    outline: none;
}

#dispatch-content {
    margin: 0;
    display: flex;
    flex-direction: column;
    overflow-y: auto; /* Allow vertical scroll */
    background: var(--dispatch-bg-gradient);
    color: var(--text-main);
    height: 100%;
    width: 100%;
    border-radius: 20px;
}

/* HEADER */
/* Note: Using specificity to override if needed, but scoped to #dispatch-content effectively */
.dispatch-header {
    height: 50px;
    margin: 15px 20px 0 20px;
    border-radius: var(--radius-lg);
    background: var(--solvix-metal);
    color: #020c1b;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 25px;
    box-shadow: var(--solvix-metal-shadow);
    font-weight: 800;
    border: 2px solid var(--solvix-metal-border);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    z-index: 10;
    flex-shrink: 0; /* Prevent header from shrinking */
}

/* LAYOUT */
.dispatch-main-grid {
    display: grid;
    grid-template-columns: minmax(350px, 1fr) 2fr;
    grid-template-rows: minmax(200px, auto) minmax(200px, auto) minmax(400px, auto);
    gap: 20px;
    padding: 20px;
    min-height: calc(100vh - 140px);
    align-items: start;
}

/* Asignación de Paneles al Grid */
.panel-pedidos {
    grid-column: 1 / 2;
    grid-row: 1 / 2;
    height: 100%;
}

.panel-validacion {
    grid-column: 2 / 3;
    grid-row: 1 / 2;
    height: 100%;
}

.panel-anden {
    grid-column: 1 / 3;
    grid-row: 2 / 3;
}

.panel-mapa {
    grid-column: 1 / 3;
    grid-row: 3 / 4;
    height: 100%;
}

.dispatch-panel {
    background: var(--solvix-glass);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-lg);
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    color: var(--solvix-silver);
}

.dispatch-panel-header {
    padding: 12px 20px;
    background: var(--theme-panel-header-bg);
    color: var(--theme-panel-header-text);
    font-weight: 800;
    border-bottom: 2px solid var(--solvix-metal-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* SIDEBAR IZQUIERDA / HORIZONTAL SCROLL */
.dispatch-queue-container {
    padding: 15px;
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--solvix-metal) !important;
    border-top: 2px solid #ffffff !important;
}

.horizontal-scroll {
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    align-items: stretch;
}

.horizontal-scroll .dispatch-list-card,
.horizontal-scroll .dispatch-dock-card {
    min-width: 280px;
    flex-shrink: 0;
}

.dispatch-section-title {
    padding: 10px 20px;
    background: #e2e8f0;
    font-weight: 700;
    font-size: 0.75rem;
    color: var(--text-sub);
    text-transform: uppercase;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Cards Generales */
.dispatch-list-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    padding: 15px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-left: 5px solid transparent;
    backdrop-filter: blur(5px);
}

.dispatch-list-card:hover {
    background: rgba(255, 255, 255, 0.08);
    transform: translateX(5px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    border-color: rgba(255, 255, 255, 0.2);
}

/* Cards de Pedidos (Pendientes) */
.dispatch-order-card {
    border-left-color: var(--warning);
}

/* Amarillo para Pendiente */
.dispatch-order-meta {
    font-size: 0.8rem;
    color: var(--text-sub);
    display: flex;
    justify-content: space-between;
    margin-top: 5px;
}

.dispatch-idl-tag {
    background: #fef3c7;
    color: #d97706;
    border: 1px dashed #fcd34d;
    padding: 4px;
    border-radius: 4px;
    text-align: center;
    font-family: monospace;
    font-weight: bold;
    font-size: 0.9rem;
    margin-top: 8px;
}

/* Cards de Manifiestos (En Ruta) */
.dispatch-manifest-card {
    border-left-color: var(--dispatch-primary);
    background: rgba(0, 136, 204, 0.1);
    border: 1px solid rgba(0, 136, 204, 0.2);
}

.dispatch-manifest-meta {
    font-size: 0.8rem;
    color: var(--text-sub);
    margin-top: 5px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.dispatch-manifest-status {
    font-size: 0.7rem;
    background: rgba(191, 219, 254, 0.2);
    color: #3b82f6;
    padding: 2px 8px;
    border-radius: 20px;
    width: fit-content;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border: 1px solid rgba(59, 130, 246, 0.3);
}

/* Historial (Completados) */
.dispatch-delivery-item {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    margin-bottom: 8px;
    border-left: 4px solid var(--success);
    padding: 12px;
    cursor: default;
    opacity: 0.7;
}

.dispatch-delivery-header {
    display: flex;
    justify-content: space-between;
    font-weight: bold;
    font-size: 0.85rem;
}

.dispatch-delivery-info {
    font-size: 0.75rem;
    color: var(--text-sub);
    margin-top: 4px;
    display: flex;
    justify-content: space-between;
}

/* CENTRO: ESCANEO */
.dispatch-scan-zone {
    flex: 1;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    overflow-y: auto;
    background: var(--solvix-glass) !important;
    border-top: 2px solid #ffffff !important;
}

.horizontal-layout {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
}

.horizontal-layout .scan-left {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.horizontal-layout .dispatch-input-wrapper {
    margin-bottom: 0;
}

.horizontal-layout .dispatch-scan-input {
    padding: 15px;
    font-size: 1.5rem;
}

.horizontal-feedback {
    flex-direction: row !important;
    gap: 15px;
    align-items: center;
    justify-content: flex-start !important;
    text-align: left !important;
    height: auto !important;
    padding: 15px;
    background: rgba(16, 185, 129, 0.1);
    border-radius: 12px;
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.horizontal-feedback .dispatch-big-check {
    margin-bottom: 0;
    font-size: 3.5rem;
}

.dispatch-scan-zone h2, .dispatch-scan-zone p {
    color: var(--solvix-header-text) !important;
}

.dispatch-input-wrapper {
    position: relative;
    width: 100%;
    max-width: 500px;
    margin-bottom: 40px;
}

.dispatch-scan-input {
    width: 100%;
    padding: 25px;
    font-size: 2rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--solvix-cyan);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    text-align: center;
    letter-spacing: 4px;
    font-family: 'Courier New', monospace;
    font-weight: 900;
    backdrop-filter: blur(10px);
    text-shadow: 0 0 15px var(--solvix-cyan-glow);
}

.dispatch-scan-input:focus {
    border-color: var(--solvix-cyan);
    background: rgba(255, 255, 255, 0.08);
    box-shadow: 0 0 30px var(--solvix-cyan-glow);
    outline: none;
    transform: scale(1.02);
}

.dispatch-scan-icon {
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 2rem;
    color: #cbd5e1;
}

.dispatch-feedback-box {
    text-align: center;
    opacity: 0.3;
    transition: opacity 0.3s;
    height: 150px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.dispatch-feedback-box.active {
    opacity: 1;
}

.dispatch-big-check {
    font-size: 5rem;
    color: var(--success);
    line-height: 1;
    margin-bottom: 10px;
    animation: pop 0.4s;
}

.dispatch-dock-text {
    font-size: 2.5rem;
    font-weight: 900;
    color: var(--text-main);
    margin: 10px 0;
}

/* DERECHA: MUELLES */
.dispatch-docks-list {
    padding: 15px;
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 15px;
    background: var(--solvix-glass) !important;
    border-top: 2px solid #ffffff !important;
}

.dispatch-dock-card {
    background: rgba(255, 255, 255, 0.03);
    padding: 20px;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(5px);
}

.dispatch-dock-card:hover {
    border-color: var(--solvix-cyan);
    background: rgba(255, 255, 255, 0.06);
    transform: translateY(-4px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.dispatch-dock-top {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
    align-items: center;
}

.dispatch-dock-name {
    font-weight: 800;
    font-size: 1rem;
}

.dispatch-dock-route {
    font-size: 0.75rem;
    color: var(--solvix-cyan);
    background: rgba(0, 242, 255, 0.1);
    padding: 4px 10px;
    border-radius: 20px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border: 1px solid rgba(0, 242, 255, 0.2);
}

.dispatch-progress-track {
    height: 12px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 6px;
    overflow: hidden;
    position: relative;
    margin-bottom: 20px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.dispatch-progress-fill {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 0.7rem;
    font-weight: bold;
    transition: width 0.5s ease;
}

.dispatch-btn-action {
    width: 100%;
    padding: 10px;
    border: none;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: 0.2s;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.dispatch-btn-manifest {
    background: var(--dispatch-primary);
    color: white;
}

.dispatch-btn-manifest:hover {
    background: var(--dispatch-primary-dark);
}

/* MODALES */
.dispatch-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(5px);
    z-index: 500;
    display: none;
    justify-content: center;
    align-items: center;
}

.dispatch-modal-card {
    background: var(--solvix-glass);
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    width: 90%;
    max-width: 800px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    animation: pop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    color: var(--solvix-silver);
}

.dispatch-modal-header {
    background: var(--solvix-metal);
    color: #020c1b;
    padding: 15px 25px;
    font-weight: 800;
    border-bottom: 2px solid var(--solvix-metal-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    box-shadow: var(--solvix-metal-shadow);
}

/* OPCIONES DE CARGA */
.dispatch-load-options-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 15px;
    padding: 25px;
    overflow-y: auto;
}

.dispatch-load-option-card {
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    padding: 20px;
    cursor: pointer;
    transition: all 0.3s;
    background: rgba(255, 255, 255, 0.03);
    color: var(--solvix-silver);
}

.dispatch-load-option-card:hover {
    border-color: var(--solvix-cyan);
    background: rgba(255, 255, 255, 0.08);
    transform: translateY(-2px);
}

.dispatch-load-option-card.selected-opt {
    border-color: var(--solvix-cyan);
    background: rgba(0, 242, 255, 0.05);
    transform: scale(1.02);
    box-shadow: 0 0 20px rgba(0, 242, 255, 0.1);
}

.dispatch-opt-title {
    font-weight: 800;
    font-size: 1.2rem;
    color: var(--solvix-cyan);
    margin-bottom: 5px;
    text-shadow: 0 0 10px var(--solvix-cyan-glow);
}

.dispatch-opt-desc {
    font-size: 0.85rem;
    color: var(--text-sub);
}

.dispatch-order-select-list {
    max-height: 200px;
    overflow-y: auto;
    margin-top: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: white;
    display: none;
}

.dispatch-order-select-list.open {
    display: block;
}

.dispatch-select-item {
    padding: 10px;
    border-bottom: 1px solid #eee;
    cursor: pointer;
    font-size: 0.9rem;
    display: flex;
    justify-content: space-between;
}

.dispatch-select-item:hover {
    background: #eff6ff;
}

.dispatch-select-item.selected {
    background: #dbeafe;
    font-weight: bold;
    border-left: 4px solid var(--dispatch-primary);
}

/* DOCUMENTOS */
.dispatch-doc-viewer {
    padding: 40px;
    background: white;
    overflow-y: auto;
    font-family: 'Arial', sans-serif;
    position: relative;
}

.dispatch-doc-header {
    border-bottom: 3px solid #000;
    padding-bottom: 20px;
    margin-bottom: 20px;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
}

.dispatch-doc-title {
    font-size: 2rem;
    font-weight: 900;
    text-transform: uppercase;
    margin: 0;
}

.dispatch-doc-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 30px;
}

.dispatch-doc-table th {
    background: #f3f4f6;
    text-align: left;
    padding: 12px;
    border-bottom: 2px solid #ddd;
}

.dispatch-doc-table td {
    padding: 12px;
    border-bottom: 1px solid #eee;
}

.dispatch-doc-actions {
    background: #f1f5f9;
    padding: 20px;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    border-top: 1px solid #ddd;
}

.dispatch-btn {
    padding: 10px 20px;
    border-radius: 6px;
    border: none;
    font-weight: 600;
    cursor: pointer;
}

.dispatch-btn-primary {
    background: var(--dispatch-primary);
    color: white;
}

.dispatch-btn-secondary {
    background: #e2e8f0;
    color: var(--text-main);
}

.dispatch-btn-success {
    background: var(--success);
    color: white;
}

/* POD / FIRMA */
.dispatch-delivery-card {
    width: 90%;
    max-width: 500px;
    background: white;
    border-radius: 16px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: pop 0.3s ease;
}

.dispatch-delivery-header {
    padding: 20px;
    background: var(--dispatch-primary);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.dispatch-delivery-tabs {
    display: flex;
    border-bottom: 1px solid #e5e7eb;
}

.dispatch-tab-btn {
    flex: 1;
    padding: 15px;
    background: none;
    border: none;
    font-weight: 600;
    color: var(--text-sub);
    cursor: pointer;
    border-bottom: 3px solid transparent;
}

.dispatch-tab-btn.active {
    color: var(--dispatch-primary);
    border-bottom-color: var(--dispatch-primary);
    background: #eff6ff;
}

.dispatch-tab-content {
    padding: 25px;
    display: none;
}

.dispatch-tab-content.active {
    display: block;
}

.dispatch-rut-input {
    width: 100%;
    padding: 15px;
    font-size: 1.5rem;
    text-align: center;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-family: monospace;
    letter-spacing: 2px;
    margin-bottom: 20px;
}

.dispatch-signature-pad {
    border: 2px dashed var(--border);
    border-radius: 8px;
    background: #fafafa;
    cursor: crosshair;
    touch-action: none;
    width: 100%;
    height: 200px;
    display: block;
}

.dispatch-signature-actions {
    display: flex;
    gap: 10px;
    margin-top: 10px;
    justify-content: flex-end;
}

@keyframes pop {
    0% {
        transform: scale(0.9);
    }

    100% {
        transform: scale(1);
    }
}

/* --- TRACKING MAP --- */
.truck-icon {
    background: transparent;
    text-align: center;
    line-height: 1;
    transition: all 1s linear;
    /* Smooth movement if position updates live */
}

/* Optional: Pulse effect for active tracking */
.truck-icon div {
    animation: bounceTruck 2s infinite;
}

@keyframes bounceTruck {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-3px);
    }
}

/* --- RESPONSIVE DESIGNS --- */

/* Tablet & Mobile (Collapse to single column) */
@media (max-width: 1024px) {
    .dispatch-main-grid {
        display: flex;
        flex-direction: column;
        height: auto;
        overflow-y: auto;
        padding-bottom: 20px;
    }

    .dispatch-panel {
        min-height: 400px;
        flex-shrink: 0;
        margin-bottom: 15px;
        max-height: 50vh;
    }

    /* Change Order: Map First (Main visual), then Queue, then Manifests */
    .dispatch-panel:nth-child(2) {
        order: -1;
        min-height: 50vh;
    }

    .dispatch-header {
        height: auto;
        flex-direction: column;
        padding: 10px;
        gap: 10px;
    }

    .dispatch-btn-group {
        width: 100%;
        justify-content: center;
    }

    /* Modal adjustments */
    #modal-tracking .modal-content,
    .modal-content {
        width: 95% !important;
        margin: 10px auto;
        max-height: 90vh;
    }

    .track-modal-body {
        flex-direction: column;
    }

    .track-list-sidebar {
        width: 100%;
        height: 200px;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .track-info-panel {
        padding: 15px;
    }
}