/* ========================================================
   SANESCA PRO - SUITE DE AUDITORÍA Y CONTROL DE DESPACHO
   Archivo: css/despacho_ui.css
   ======================================================== */

:root {
    /* Identidad Sanesca */
    --sanesca-navy: #0f2b48;
    --sanesca-navy-dark: #0b192c;
    --sanesca-navy-light: #163d66;

    /* Superficies Dark Industrial */
    --sanesca-canvas: #0f172a;
    --sanesca-surface-dark: #0f172a;
    --sanesca-surface-card: #1e293b;
    --sanesca-surface-nested: #334155;
    --sanesca-surface-light: #f8fafc;
    --sanesca-surface-white: #ffffff;

    /* Bordes */
    --sanesca-border-subtle: #334155;
    --sanesca-border-medium: #475569;
    --sanesca-border-light: #e2e8f0;
    --sanesca-border-card: #cbd5e1;

    /* Tipografía */
    --sanesca-font-ui: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --sanesca-font-print: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

    /* Acentos Semánticos */
    --sanesca-emerald-500: #10b981;
    --sanesca-emerald-600: #059669;
    --sanesca-amber-500: #f59e0b;
    --sanesca-amber-600: #d97706;
    --sanesca-sky-400: #38bdf8;
    --sanesca-sky-600: #0284c7;
    --sanesca-rose-500: #ef4444;
    --sanesca-rose-600: #dc2626;
    --sanesca-pill-bg: #facc15;
    --sanesca-pill-text: #0f172a;
    --sanesca-pill-border: #eab308;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: var(--sanesca-font-ui);
}

html, body {
    background-color: #0f172a;
    background-color: var(--sanesca-canvas);
    color: #f8fafc;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Encabezado Superior */
.top-header {
    background-color: #1e293b;
    border-bottom: 2px solid #334155;
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 15px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.brand-section {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-contrast-plate {
    background: #ffffff;
    padding: 3px 8px;
    border-radius: 6px;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.15), 0 2px 8px rgba(0, 0, 0, 0.4);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.header-brand-logo {
    height: 20px;
    max-width: 95px;
    object-fit: contain;
    display: block;
}

.brand-logo-text, h1.brand-logo-text {
    margin: 0;
    font-size: 18px;
    font-weight: 900;
    letter-spacing: -0.5px;
    color: white;
    line-height: 1.2;
}

.brand-logo-text span, h1.brand-logo-text span {
    color: #38bdf8;
    font-weight: 700;
}

.badge-tag {
    background-color: #0369a1;
    color: white;
    font-size: 11.5px;
    font-weight: 800;
    padding: 3px 8px;
    border-radius: 4px;
    text-transform: uppercase;
}

.top-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.btn-header {
    min-height: 42px;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 800;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: none;
    transition: all 0.2s;
    touch-action: manipulation;
}

.btn-header:active {
    transform: scale(0.98);
}

.btn-header-more {
    display: none;
}

.btn-all-aboard {
    background-color: #047857;
    color: white;
}

.btn-all-aboard:hover {
    background-color: #065f46;
    transform: translateY(-1px);
}

.btn-print-manifest {
    background-color: #0369a1;
    color: white;
}

.btn-print-manifest:hover {
    background-color: #075985;
    transform: translateY(-1px);
}

.btn-sync-notion {
    background-color: #7c3aed;
    color: white;
}

.btn-sync-notion:hover {
    background-color: #6d28d9;
    transform: translateY(-1px);
}

.btn-back-empaque {
    background-color: #475569;
    color: #f1f5f9;
}

.btn-back-empaque:hover {
    background-color: #334155;
}

/* Cinta de Métricas en Tiempo Real */
.kpi-ribbon {
    background-color: #1e293b;
    margin: 15px 24px 0 24px;
    padding: 15px 20px;
    border-radius: 8px;
    border: 1px solid #334155;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

.kpi-card {
    background-color: #0f172a;
    padding: 14px 18px;
    border-radius: 8px;
    border: 1px solid #334155;
    position: relative;
    transition: all 0.2s ease;
}

.kpi-card.kpi-success {
    border-color: rgba(4, 120, 87, 0.6);
    background: linear-gradient(180deg, #0f172a 0%, rgba(4, 120, 87, 0.15) 100%);
}

.kpi-card.kpi-warning {
    border-color: rgba(217, 119, 6, 0.6);
    background: linear-gradient(180deg, #0f172a 0%, rgba(217, 119, 6, 0.15) 100%);
}

.kpi-card.kpi-analytics {
    border-color: rgba(15, 118, 110, 0.6);
    background: linear-gradient(180deg, #0f172a 0%, rgba(15, 118, 110, 0.15) 100%);
}

.kpi-card:hover {
    border-color: #475569;
    transform: translateY(-1px);
}

.kpi-title {
    font-size: 11.5px;
    color: #94a3b8;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.kpi-value {
    font-size: 20px;
    font-weight: 900;
    margin-top: 4px;
    color: white;
}

.kpi-sub {
    font-size: 11.5px;
    color: #94a3b8;
    margin-top: 2px;
}

/* Panel de Información del Lote y Asignación de Flota */
.control-panel {
    background-color: #1e293b;
    margin: 15px 24px;
    padding: 18px 20px;
    border-radius: 8px;
    border: 1px solid #334155;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

@media (max-width: 900px) {
    .control-panel {
        grid-template-columns: 1fr;
    }
}

.panel-block h2, .panel-block h3 {
    font-size: 13.5px;
    color: #38bdf8;
    font-weight: 800;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Collapsible Details para Asignación de Transporte */
.panel-block.panel-transport summary {
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    user-select: none;
    outline: none;
}

.panel-block.panel-transport summary::-webkit-details-marker {
    display: none;
}

.panel-block.panel-transport summary::after {
    content: '▾';
    font-size: 16px;
    color: #94a3b8;
    transition: transform 0.2s ease;
}

.panel-block.panel-transport[open] summary::after {
    transform: rotate(180deg);
}

.panel-block.panel-transport summary h2 {
    margin-bottom: 0;
}

.transport-quick-summary {
    font-size: 11.5px;
    font-weight: 700;
    color: #38bdf8;
    background: rgba(15, 23, 42, 0.7);
    padding: 3px 8px;
    border-radius: 4px;
    border: 1px solid #334155;
    margin-left: auto;
    margin-right: 12px;
}

.meta-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    font-size: 12px;
}

.meta-field label {
    display: block;
    color: #94a3b8;
    font-size: 11.5px;
    font-weight: 700;
}

.meta-field span {
    color: white;
    font-weight: 700;
    font-size: 12.5px;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.form-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.form-field label {
    color: #cbd5e1;
    font-size: 11.5px;
    font-weight: 700;
}

.form-field select, .form-field input, #select-chofer-flota {
    background-color: #0f172a;
    border: 1px solid #475569;
    color: white;
    min-height: 42px;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-field select:focus, .form-field input:focus, #select-chofer-flota:focus {
    border-color: #38bdf8;
    box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.2);
}

/* Grid de Tarjetas de Bulto para Rampa */
.audit-container {
    flex: 1;
    margin: 0 24px 24px 24px;
    background-color: #0f172a;
}

.audit-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.audit-header h2 {
    font-size: 15px;
    font-weight: 800;
    color: white;
}

.audit-filter-tools {
    display: flex;
    gap: 10px;
}

.btn-filter {
    background: transparent;
    border: 1px solid #475569;
    color: #cbd5e1;
    min-height: 38px;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 800;
    cursor: pointer;
    touch-action: manipulation;
    transition: all 0.15s ease;
}

.btn-filter.active {
    background: #0369a1;
    border-color: #38bdf8;
    color: white;
}

.bultos-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 14px;
}

/* Tarjeta de Bulto Individual */
.bulto-card {
    background-color: #1e293b;
    border-radius: 8px;
    padding: 14px;
    border: 2px solid #334155;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transition: all 0.2s;
}

.bulto-card.cargado {
    border-color: #047857;
    background: linear-gradient(180deg, #1e293b 0%, #064e3b 100%);
}

.bulto-card.quedado {
    border-color: #d97706;
    background: linear-gradient(180deg, #1e293b 0%, #78350f 100%);
}

.bulto-main {
    display: flex;
    gap: 12px;
}

.bulto-thumb {
    width: 75px;
    height: 75px;
    object-fit: contain;
    background-color: #f8fafc;
    color: #0f172a;
    border-radius: 6px;
    padding: 4px;
    border: 1px solid #475569;
}

.bulto-info {
    flex: 1;
    overflow: hidden;
}

.bulto-pill-num {
    display: inline-block;
    background-color: #facc15;
    color: #0f172a;
    font-size: 11.5px;
    font-weight: 900;
    padding: 3px 8px;
    border-radius: 4px;
    margin-bottom: 4px;
}

.bulto-code {
    font-size: 14px;
    font-weight: 900;
    color: white;
}

.bulto-desc {
    font-size: 12px;
    color: #cbd5e1;
    line-height: 1.3;
    margin-top: 2px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.bulto-qty {
    margin-top: 6px;
    font-size: 12.5px;
    color: #38bdf8;
    font-weight: 800;
}

.bulto-order-tag {
    font-size: 11.5px;
    color: #cbd5e1;
    background: #0f172a;
    padding: 3px 8px;
    border-radius: 4px;
    border: 1px solid #334155;
    display: inline-block;
    margin-top: 4px;
}

.btn-evidencia-bulto {
    min-height: 40px !important;
    padding: 8px 14px !important;
    font-size: 12px !important;
    font-weight: 800 !important;
    border-radius: 6px !important;
    touch-action: manipulation;
}

/* Botón Táctil de Estado de Bulto */
.btn-toggle-bulto {
    margin-top: 12px;
    width: 100%;
    min-height: 48px;
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 13.5px;
    font-weight: 900;
    letter-spacing: 0.3px;
    cursor: pointer;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.15s;
    touch-action: manipulation;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
}

.btn-toggle-bulto:active {
    transform: scale(0.98);
}

.btn-toggle-bulto.is-cargado {
    background-color: #047857;
    color: white;
}

.btn-toggle-bulto.is-cargado:hover {
    background-color: #065f46;
}

.btn-toggle-bulto.is-quedado {
    background-color: #d97706;
    color: #0f172a;
}

.btn-toggle-bulto.is-quedado:hover {
    background-color: #b45309;
}

/* Adaptabilidad Móvil y Tablet para Rampa */
@media (max-width: 1024px) {
    .top-header {
        padding: 12px 16px;
        gap: 12px;
    }

    .brand-section {
        width: 100%;
        justify-content: space-between;
        flex-wrap: wrap;
        gap: 8px;
    }

    .btn-header-secondary {
        display: none !important;
    }

    .btn-header-more {
        display: inline-flex !important;
        min-height: 44px;
        padding: 8px 14px;
    }

    .top-actions {
        width: 100%;
        overflow-x: visible;
        padding-bottom: 0;
        flex-wrap: wrap;
        gap: 6px;
        justify-content: flex-end;
    }

    .kpi-ribbon {
        margin: 12px 16px 0 16px;
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
        padding: 12px;
    }

    .control-panel {
        margin: 12px 16px;
        padding: 14px;
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .audit-container {
        margin: 0 16px 16px 16px;
    }

    .bultos-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }
}

@media (max-width: 640px) {
    .kpi-ribbon {
        grid-template-columns: 1fr;
    }

    .form-grid, .meta-grid {
        grid-template-columns: 1fr;
    }

    .audit-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .audit-filter-tools {
        width: 100%;
        display: flex;
    }

    .audit-filter-tools .btn-filter {
        flex: 1;
        text-align: center;
    }
}

/* ========================================================
   BOTTOM SHEET TÁCTIL (MÓVIL <= 768px)
   ======================================================== */
.bottom-sheet-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.75);
    backdrop-filter: blur(4px);
    z-index: 9998;
    opacity: 0;
    transition: opacity 0.25s ease;
}
.bottom-sheet-backdrop.active {
    display: block;
    opacity: 1;
}
.bottom-sheet-panel {
    display: block;
    position: fixed;
    bottom: -100%;
    left: 0;
    width: 100%;
    max-height: 80vh;
    background: #0f172a;
    border-top: 1px solid #334155;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -10px 25px rgba(0, 0, 0, 0.5);
    z-index: 9999;
    padding: 16px 20px 28px 20px;
    box-sizing: border-box;
    overflow-y: auto;
    transition: bottom 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
.bottom-sheet-panel.active {
    bottom: 0;
}
.bottom-sheet-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 12px;
    margin-bottom: 16px;
    border-bottom: 1px solid #334155;
}
.bottom-sheet-title {
    font-size: 15px;
    font-weight: 800;
    color: #38bdf8;
    letter-spacing: 0.5px;
}
.btn-close-bottom-sheet {
    background: transparent;
    border: none;
    color: #94a3b8;
    font-size: 20px;
    width: 44px;
    height: 44px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
}
.btn-close-bottom-sheet:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}
.bottom-sheet-body {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.btn-sheet-action {
    width: 100%;
    min-height: 48px;
    padding: 12px 16px;
    border-radius: 8px;
    border: 1px solid #334155;
    color: white;
    font-size: 14px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    transition: transform 0.1s, filter 0.2s;
    box-sizing: border-box;
}
.btn-sheet-action:active {
    transform: scale(0.98);
    filter: brightness(1.15);
}

/* ========================================================
   NOTIFICACIONES TOAST DESPACHO (PWA NO BLOQUEANTE)
   ======================================================== */
.toast-container-despacho {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 10001;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
    max-width: 90vw;
}
.toast-despacho {
    pointer-events: auto;
    background: #0f172a;
    border: 1px solid #334155;
    border-radius: 8px;
    padding: 12px 18px;
    color: white;
    font-size: 13px;
    font-weight: 600;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    gap: 10px;
    animation: toastFadeIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    transition: opacity 0.3s ease, transform 0.3s ease;
}
.toast-despacho.toast-exito {
    border-color: #10b981;
    background: rgba(6, 78, 59, 0.95);
}
.toast-despacho.toast-advertencia {
    border-color: #f59e0b;
    background: rgba(120, 53, 15, 0.95);
}
.toast-despacho.toast-error {
    border-color: #ef4444;
    background: rgba(127, 29, 29, 0.95);
}
@keyframes toastFadeIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ========================================================
   MODALES INDUSTRIALES DE DESPACHO Y AUDITORÍA
   ======================================================== */
.modal-despacho-overlay {
    position: fixed;
    top: 0;
    left: 0;
    inset: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.88);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    padding: 16px;
    box-sizing: border-box;
    overflow-y: auto;
    animation: modalFadeIn 0.25s ease-out;
}

.modal-despacho-card {
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 12px;
    padding: 24px;
    max-width: 560px;
    max-height: calc(100vh - 32px);
    overflow-y: auto;
    width: 100%;
    color: #f8fafc;
    box-shadow: 0 25px 35px -5px rgba(0, 0, 0, 0.6);
    box-sizing: border-box;
}

.modal-despacho-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #334155;
    padding-bottom: 12px;
    margin-bottom: 16px;
}

.modal-despacho-title {
    font-size: 17px;
    font-weight: 800;
    color: #38bdf8;
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
}

.btn-modal-close {
    background: transparent;
    border: none;
    color: #94a3b8;
    font-size: 20px;
    width: 40px;
    height: 40px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
}
.btn-modal-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.modal-despacho-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
    flex-wrap: wrap;
}

@keyframes modalFadeIn {
    from { opacity: 0; transform: scale(0.97); }
    to { opacity: 1; transform: scale(1); }
}

/* Accesibilidad y Clics Nativos en Inputs de Archivo (Remediación Desktop Chromium) */
.sr-only-file-input {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
    opacity: 0;
    pointer-events: none;
}

/* Modal de Rendimiento y Conciliación Operativa (Layout Responsivo) */
.analitica-kpi-container {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 20px;
    align-items: center;
    background: #0f172a;
    border: 1px solid #334155;
    border-radius: 8px;
    padding: 16px;
}

.analitica-donut-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    min-width: 120px;
}

.analitica-kpi-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.analitica-kpi-card {
    background: #1e293b;
    padding: 12px;
    border-radius: 6px;
    border: 1px solid #334155;
    min-width: 0;
}

.analitica-kpi-card .kpi-label {
    font-size: 11.5px;
    color: #94a3b8;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.analitica-kpi-card .kpi-number {
    font-size: 16px;
    font-weight: 900;
    color: white;
    margin-top: 2px;
}

.analitica-kpi-card .kpi-subtext {
    font-size: 11px;
    color: #94a3b8;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.analitica-table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.analitica-table-scroll table {
    width: 100%;
    min-width: 520px;
    border-collapse: collapse;
    font-size: 12px;
    text-align: left;
}

@media (max-width: 640px) {
    .analitica-kpi-container {
        grid-template-columns: 1fr;
        gap: 14px;
        padding: 12px;
    }

    .analitica-donut-wrapper {
        max-width: 120px;
        margin: 0 auto;
    }

    .analitica-kpi-grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .analitica-kpi-card {
        padding: 10px 12px;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    .analitica-kpi-card .kpi-label {
        font-size: 12px;
    }

    .analitica-kpi-card .kpi-number {
        font-size: 18px;
        margin-top: 0;
    }

    .analitica-kpi-card .kpi-subtext {
        display: none;
    }
}

/* Pestañas Semánticas del Historial de Despachos y Lotes */
.historial-tabs {
    display: flex;
    gap: 8px;
    padding: 10px 20px 0;
    background: #0f172a;
    border-bottom: 1px solid #334155;
}

.historial-tab-btn {
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    color: #94a3b8;
    font-size: 13px;
    font-weight: 700;
    padding: 8px 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.historial-tab-btn:hover {
    color: white;
    background: rgba(255, 255, 255, 0.04);
}

.historial-tab-btn.active {
    color: #38bdf8;
    border-bottom-color: #38bdf8;
    background: rgba(56, 189, 248, 0.08);
}

/* Contenedor Oculto para Impresión del Manifiesto */
#manifest-print-area {
    display: none;
}

@media print {
    body {
        background: white !important;
        color: black !important;
    }

    .top-header, .kpi-ribbon, .control-panel, .audit-container {
        display: none !important;
    }

    #manifest-print-area {
        display: block !important;
        width: 100%;
        background: white;
        padding: 0;
        margin: 0;
    }
}
