/* ==========================================================================
   CAEXPORT LOGÍSTICA - SISTEMA WEB DE CORRESPONDENCIA Y PAQUETERÍA
   Paleta extraída: #CC0001 (Rojo), #AE0001 (Rojo Profundo), #003A6C (Azul Océano),
   #09264E (Azul Marino), #061735 (Azul Medianoche)
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&family=Outfit:wght@500;600;700;800&display=swap');

:root {
    --c-red: #CC0001;
    --c-dark-red: #AE0001;
    --c-blue: #003A6C;
    --c-navy: #09264E;
    --c-midnight: #061735;
    
    --c-red-rgb: 204, 0, 1;
    --c-blue-rgb: 0, 58, 108;
    --c-navy-rgb: 9, 38, 78;
    --c-midnight-rgb: 6, 23, 53;

    --bg-page: #f1f5f9;
    --bg-surface: #ffffff;
    --bg-surface-alt: #f8fafc;
    --border: #e2e8f0;
    --border-focus: #003A6C;

    --text-title: #061735;
    --text-body: #334155;
    --text-muted: #64748b;
    --text-light: #94a3b8;

    --font-sans: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
    --font-heading: 'Outfit', 'Plus Jakarta Sans', sans-serif;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --radius-xl: 28px;
    --radius-full: 9999px;

    --shadow-subtle: 0 2px 4px rgba(6, 23, 53, 0.04);
    --shadow-card: 0 10px 25px -5px rgba(6, 23, 53, 0.06), 0 8px 10px -6px rgba(6, 23, 53, 0.04);
    --shadow-elevated: 0 20px 30px -10px rgba(6, 23, 53, 0.12);
    --shadow-glow-red: 0 0 25px rgba(204, 0, 1, 0.3);
    --shadow-glow-blue: 0 0 25px rgba(0, 58, 108, 0.25);
    
    --transition: all 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-sans);
    background-color: var(--bg-page);
    color: var(--text-body);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-heading);
    color: var(--text-title);
    letter-spacing: -0.02em;
    font-weight: 700;
}

a {
    color: var(--c-blue);
    text-decoration: none;
    transition: var(--transition);
}

a:hover {
    color: var(--c-red);
}

/* ==========================================================================
   APP LAYOUT (SIDEBAR + TOPBAR + CONTENT)
   ========================================================================== */

.app-wrapper {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.app-sidebar {
    width: 280px;
    background: linear-gradient(180deg, var(--c-midnight) 0%, var(--c-navy) 100%);
    color: #ffffff;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 100;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
    transition: var(--transition);
}

.sidebar-brand {
    padding: 1.75rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.85rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand-icon-box {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--c-red), var(--c-dark-red));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.35rem;
    color: #fff;
    box-shadow: var(--shadow-glow-red);
}

.brand-info h2 {
    font-size: 1.25rem;
    color: #ffffff;
    font-weight: 800;
    letter-spacing: -0.03em;
    line-height: 1.1;
}

.brand-info span {
    font-size: 0.72rem;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-weight: 600;
}

.sidebar-menu {
    flex: 1;
    padding: 1.25rem 0.9rem;
    overflow-y: auto;
}

.sidebar-menu::-webkit-scrollbar {
    width: 5px;
}

.sidebar-menu::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-menu::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.18);
    border-radius: 4px;
}

.sidebar-menu::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.35);
}

.menu-category {
    font-size: 0.7rem;
    text-transform: uppercase;
    color: #94a3b8;
    letter-spacing: 0.08em;
    font-weight: 700;
    padding: 0.6rem 0.8rem;
    margin-top: 0.8rem;
}

.nav-link-item {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    color: #cbd5e1;
    font-weight: 500;
    font-size: 0.92rem;
    margin-bottom: 0.3rem;
    transition: var(--transition);
}

.nav-link-item i {
    font-size: 1.1rem;
    width: 22px;
    text-align: center;
    color: #94a3b8;
    transition: var(--transition);
}

.nav-link-item:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #ffffff;
    transform: translateX(4px);
}

.nav-link-item:hover i {
    color: #ff6b6b;
}

.nav-link-item.active {
    background: linear-gradient(90deg, rgba(204, 0, 1, 0.25) 0%, rgba(0, 58, 108, 0.2) 100%);
    color: #ffffff;
    border-left: 4px solid var(--c-red);
    font-weight: 600;
}

.nav-link-item.active i {
    color: var(--c-red);
}

.sidebar-footer {
    padding: 1.25rem 1.25rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(0, 0, 0, 0.2);
}

.user-mini-card {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    background: var(--c-blue);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1rem;
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.user-details {
    flex: 1;
    overflow: hidden;
}

.user-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: #ffffff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role-badge {
    font-size: 0.7rem;
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: var(--radius-full);
    background: rgba(204, 0, 1, 0.3);
    color: #ff9999;
    font-weight: 600;
}

/* Main Content Area */
.app-main {
    flex: 1;
    margin-left: 280px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Topbar */
.app-topbar {
    height: 72px;
    background: #ffffff;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    position: sticky;
    top: 0;
    z-index: 90;
    box-shadow: var(--shadow-subtle);
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.topbar-title h1 {
    font-size: 1.35rem;
    margin: 0;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.btn-quick-new {
    background: linear-gradient(135deg, var(--c-red), var(--c-dark-red));
    color: #ffffff !important;
    padding: 0.6rem 1.25rem;
    border-radius: var(--radius-md);
    font-size: 0.88rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(204, 0, 1, 0.25);
    transition: var(--transition);
}

.btn-quick-new:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(204, 0, 1, 0.35);
}

.btn-topbar-link {
    background: var(--bg-surface-alt);
    color: var(--text-body);
    border: 1px solid var(--border);
    padding: 0.55rem 1rem;
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    transition: var(--transition);
}

.btn-topbar-link:hover {
    background: #ffffff;
    border-color: var(--c-blue);
    color: var(--c-blue);
}

/* Content Container */
.app-content {
    flex: 1;
    padding: 2rem;
}

/* ==========================================================================
   CARDS, KPI STATS & GRIDS
   ========================================================================== */

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.kpi-card {
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-card);
    position: relative;
    overflow: hidden;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.kpi-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-elevated);
}

.kpi-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
}

.kpi-card.accent-red::before { background: linear-gradient(90deg, var(--c-red), var(--c-dark-red)); }
.kpi-card.accent-blue::before { background: linear-gradient(90deg, var(--c-blue), #0284c7); }
.kpi-card.accent-navy::before { background: linear-gradient(90deg, var(--c-navy), var(--c-midnight)); }
.kpi-card.accent-green::before { background: linear-gradient(90deg, #16a34a, #22c55e); }

.kpi-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.kpi-label {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.kpi-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

.accent-red .kpi-icon { background: rgba(204, 0, 1, 0.1); color: var(--c-red); }
.accent-blue .kpi-icon { background: rgba(0, 58, 108, 0.1); color: var(--c-blue); }
.accent-navy .kpi-icon { background: rgba(9, 38, 78, 0.1); color: var(--c-navy); }
.accent-green .kpi-icon { background: rgba(22, 163, 74, 0.1); color: #16a34a; }

.kpi-value {
    font-size: 2.1rem;
    font-weight: 800;
    color: var(--text-title);
    font-family: var(--font-heading);
    line-height: 1.1;
    margin-bottom: 0.35rem;
}

.kpi-subtext {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Card Components */
.card {
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-card);
    margin-bottom: 2rem;
    overflow: hidden;
}

.card-header {
    padding: 1.25rem 1.75rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #ffffff;
}

.card-title {
    font-size: 1.15rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.65rem;
}

.card-title i {
    color: var(--c-blue);
}

.card-body {
    padding: 1.75rem;
}

/* ==========================================================================
   TABLES & BADGES
   ========================================================================== */

.table-responsive {
    overflow-x: auto;
    width: 100%;
}

.custom-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.custom-table th {
    background: var(--bg-surface-alt);
    padding: 0.9rem 1.25rem;
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.custom-table td {
    padding: 1.1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
    vertical-align: middle;
}

.custom-table tr:hover td {
    background: #f8fafc;
}

/* Status Badges */
.badge-status {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.3rem 0.75rem;
    border-radius: var(--radius-full);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.badge-status::before {
    content: '';
    width: 7px;
    height: 7px;
    border-radius: 50%;
}

.badge-registrado { background: #e0f2fe; color: #0369a1; }
.badge-registrado::before { background: #0284c7; }

.badge-recibido_sucursal { background: #ede9fe; color: #5b21b6; }
.badge-recibido_sucursal::before { background: #7c3aed; }

.badge-en_transito { background: #e0e7ff; color: #3730a3; }
.badge-en_transito::before { background: #4f46e5; }

.badge-en_reparto { background: #fef3c7; color: #92400e; }
.badge-en_reparto::before { background: #d97706; }

.badge-entregado { background: #dcfce7; color: #166534; }
.badge-entregado::before { background: #22c55e; }

.badge-intento_fallido { background: #fee2e2; color: #991b1b; }
.badge-intento_fallido::before { background: #ef4444; }

.badge-cancelado { background: #f1f5f9; color: #475569; }
.badge-cancelado::before { background: #64748b; }

.badge-type {
    display: inline-block;
    white-space: nowrap;
    padding: 0.2rem 0.6rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 600;
    background: #f1f5f9;
    color: var(--c-navy);
    border: 1px solid var(--border);
}

.guia-pill {
    display: inline-block;
    white-space: nowrap;
    font-family: monospace;
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--c-blue);
    letter-spacing: 0.04em;
    background: rgba(0, 58, 108, 0.06);
    padding: 0.22rem 0.55rem;
    border-radius: var(--radius-sm);
    border: 1px dashed rgba(0, 58, 108, 0.25);
}

/* ==========================================================================
   BUTTONS & CONTROLS
   ========================================================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.65rem 1.35rem;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    transition: var(--transition);
}

.btn-primary {
    background: linear-gradient(135deg, var(--c-blue) 0%, var(--c-navy) 100%);
    color: #ffffff !important;
    box-shadow: 0 4px 12px rgba(0, 58, 108, 0.25);
}

.btn-primary:hover {
    box-shadow: 0 6px 18px rgba(0, 58, 108, 0.35);
    transform: translateY(-2px);
}

.btn-danger {
    background: linear-gradient(135deg, var(--c-red) 0%, var(--c-dark-red) 100%);
    color: #ffffff !important;
    box-shadow: 0 4px 12px rgba(204, 0, 1, 0.25);
}

.btn-danger:hover {
    box-shadow: 0 6px 18px rgba(204, 0, 1, 0.35);
    transform: translateY(-2px);
}

.btn-secondary {
    background: var(--bg-surface-alt);
    color: var(--text-body);
    border-color: var(--border);
}

.btn-secondary:hover {
    background: #ffffff;
    border-color: var(--text-body);
}

.btn-sm {
    padding: 0.4rem 0.8rem;
    font-size: 0.82rem;
    border-radius: var(--radius-sm);
}

/* Form Styles */
.form-group {
    margin-bottom: 1.25rem;
}

.form-label {
    display: block;
    font-size: 0.84rem;
    font-weight: 600;
    color: var(--text-title);
    margin-bottom: 0.4rem;
}

.form-control, .form-select {
    width: 100%;
    padding: 0.7rem 1rem;
    font-size: 0.92rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background-color: #ffffff;
    color: var(--text-body);
    font-family: inherit;
    transition: var(--transition);
}

.form-control:focus, .form-select:focus {
    outline: none;
    border-color: var(--c-blue);
    box-shadow: 0 0 0 3px rgba(0, 58, 108, 0.15);
}

/* ==========================================================================
   TRACKING TIMELINE (MODERN INTERACTIVE)
   ========================================================================== */

.tracking-milestones {
    display: flex;
    justify-content: space-between;
    position: relative;
    margin: 2.5rem 0 3.5rem;
}

.tracking-milestones::before {
    content: '';
    position: absolute;
    top: 24px;
    left: 40px;
    right: 40px;
    height: 4px;
    background: #e2e8f0;
    z-index: 1;
}

.tracking-milestone-step {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 120px;
    text-align: center;
}

.milestone-icon {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: #ffffff;
    border: 3px solid #cbd5e1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: #94a3b8;
    margin-bottom: 0.85rem;
    transition: var(--transition);
}

.milestone-label {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
}

.milestone-date {
    font-size: 0.72rem;
    color: var(--text-light);
    margin-top: 0.2rem;
}

/* Completed Step */
.tracking-milestone-step.completed .milestone-icon {
    border-color: var(--c-blue);
    background: var(--c-blue);
    color: #ffffff;
    box-shadow: var(--shadow-glow-blue);
}

.tracking-milestone-step.completed .milestone-label {
    color: var(--c-blue);
    font-weight: 700;
}

/* Active Current Step */
.tracking-milestone-step.current .milestone-icon {
    border-color: var(--c-red);
    background: var(--c-red);
    color: #ffffff;
    box-shadow: var(--shadow-glow-red);
    animation: pulseRed 2s infinite;
}

.tracking-milestone-step.current .milestone-label {
    color: var(--c-red);
    font-weight: 800;
}

@keyframes pulseRed {
    0% { box-shadow: 0 0 0 0 rgba(204, 0, 1, 0.5); }
    70% { box-shadow: 0 0 0 14px rgba(204, 0, 1, 0); }
    100% { box-shadow: 0 0 0 0 rgba(204, 0, 1, 0); }
}

/* Vertical Timeline */
.timeline-vertical {
    position: relative;
    padding-left: 2rem;
    border-left: 2px solid #e2e8f0;
    margin-left: 1rem;
}

.timeline-item {
    position: relative;
    margin-bottom: 2rem;
}

.timeline-item:last-child {
    margin-bottom: 0;
}

.timeline-dot {
    position: absolute;
    left: -2.6rem;
    top: 0.15rem;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #ffffff;
    border: 4px solid var(--c-blue);
}

.timeline-item.active .timeline-dot {
    border-color: var(--c-red);
    background: var(--c-red);
}

.timeline-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.35rem;
}

.timeline-title {
    font-size: 0.98rem;
    font-weight: 700;
    color: var(--text-title);
}

.timeline-time {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.timeline-desc {
    font-size: 0.88rem;
    color: var(--text-body);
    margin-bottom: 0.35rem;
}

.timeline-location {
    font-size: 0.78rem;
    color: var(--c-blue);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

/* ==========================================================================
   FLASH MESSAGES & ALERTS
   ========================================================================== */

.alert {
    padding: 1rem 1.25rem;
    border-radius: var(--radius-md);
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.85rem;
    font-size: 0.9rem;
}

.alert-success {
    background: #dcfce7;
    color: #14532d;
    border: 1px solid #bbf7d0;
}

.alert-danger {
    background: #fee2e2;
    color: #7f1d1d;
    border: 1px solid #fecaca;
}

.alert-info {
    background: #e0f2fe;
    color: #075985;
    border: 1px solid #bae6fd;
}

/* ==========================================================================
   PRINT / WAYBILL (GUÍA DE ENVÍO TÉRMICA / ESTÁNDAR)
   ========================================================================== */

.waybill-wrapper {
    background: #fff;
    max-width: 800px;
    margin: 2rem auto;
    padding: 2.5rem;
    border: 2px solid #000;
    border-radius: 4px;
    font-family: var(--font-sans);
    color: #000;
}

@media print {
    body * {
        visibility: hidden;
    }
    .waybill-wrapper, .waybill-wrapper * {
        visibility: visible;
    }
    .waybill-wrapper {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        max-width: 100%;
        margin: 0;
        padding: 1.5cm;
        border: 2px solid #000;
    }
    .no-print {
        display: none !important;
    }
}

/* ==========================================================================
   ESTILOS PERSONALIZADOS SWEETALERT2
   ========================================================================== */
div:where(.swal2-container) .swal2-popup {
    border-radius: var(--radius-lg) !important;
    font-family: var(--font-sans) !important;
    padding: 1.75rem !important;
    box-shadow: 0 20px 40px rgba(6, 23, 53, 0.25) !important;
    border: 1px solid var(--border) !important;
}

div:where(.swal2-container) .swal2-title {
    font-family: var(--font-heading) !important;
    font-weight: 800 !important;
    color: var(--text-title) !important;
    letter-spacing: -0.02em;
    font-size: 1.35rem !important;
}

div:where(.swal2-container) .swal2-html-container {
    font-size: 0.95rem !important;
    color: var(--text-body) !important;
    line-height: 1.5 !important;
}

div:where(.swal2-container) .swal2-styled.swal2-confirm {
    background: linear-gradient(135deg, var(--c-red) 0%, var(--c-dark-red) 100%) !important;
    border-radius: var(--radius-md) !important;
    font-weight: 700 !important;
    font-size: 0.9rem !important;
    padding: 0.65rem 1.4rem !important;
    box-shadow: 0 4px 12px rgba(204, 0, 1, 0.25) !important;
}

div:where(.swal2-container) .swal2-styled.swal2-cancel {
    background: #64748b !important;
    border-radius: var(--radius-md) !important;
    font-weight: 600 !important;
    font-size: 0.9rem !important;
    padding: 0.65rem 1.4rem !important;
}

/* ==========================================================================
   RESPONSIVE DESIGN Y SOPORTE PARA MÓVILES Y TABLETS
   ========================================================================== */

/* Encabezado móvil interno del Sidebar */
.sidebar-mobile-header {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.15rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(0, 0, 0, 0.2);
}

.mobile-header-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #94a3b8;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Botón de apertura de menú móvil (Hamburger) */
.sidebar-toggle-btn {
    display: none;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    color: var(--text-title);
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    font-size: 1.15rem;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    flex-shrink: 0;
    box-shadow: var(--shadow-subtle);
}

.sidebar-toggle-btn:hover {
    background: #ffffff;
    color: var(--c-blue);
    border-color: var(--c-blue);
}

/* Botón de cierre dentro del Sidebar en Móviles */
.sidebar-close-btn {
    display: none;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #ffffff;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    font-size: 0.95rem;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.sidebar-close-btn:hover {
    background: var(--c-red);
    border-color: var(--c-red);
    color: #ffffff;
}

/* Telón / Backdrop semitransparente para móvil */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(6, 23, 53, 0.65);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 1040;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.28s ease;
}

.sidebar-backdrop.show {
    opacity: 1;
    pointer-events: auto;
}

/* Soporte Universal para Tablas Responsivas */
.table-responsive,
.card-table,
.card-body:has(> table),
.card:has(> .custom-table),
.card:has(> table) {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.custom-table,
table.table {
    min-width: 620px;
}

/* ==========================================================================
   PATRÓN DE TABLAS RESPONSIVAS A TARJETAS (MOBILE CARDS)
   ========================================================================== */
@media (max-width: 768px) {
    /* Desactivar scroll horizontal forzado cuando la tabla se convierte a tarjetas */
    .table-responsive:has(> .table-card-mobile),
    .card-table:has(> .table-card-mobile),
    .card:has(> .table-card-mobile),
    .card-body:has(> .table-card-mobile) {
        overflow-x: visible !important;
    }

    .table-card-mobile {
        min-width: 0 !important;
        width: 100% !important;
        display: block !important;
        border-collapse: separate !important;
    }

    .table-card-mobile thead {
        display: none !important;
    }

    .table-card-mobile tbody {
        display: flex !important;
        flex-direction: column !important;
        gap: 0.85rem !important;
        width: 100% !important;
        padding: 0.25rem 0 !important;
    }

    .table-card-mobile tr {
        display: block !important;
        background: #ffffff !important;
        border: 1px solid var(--border) !important;
        border-radius: var(--radius-md) !important;
        padding: 1rem !important;
        box-shadow: 0 2px 8px rgba(6, 23, 53, 0.05) !important;
        transition: var(--transition) !important;
    }

    .table-card-mobile tr:hover td {
        background: transparent !important;
    }

    .table-card-mobile td {
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        padding: 0.45rem 0 !important;
        border-bottom: 1px dashed #f1f5f9 !important;
        font-size: 0.88rem !important;
        text-align: right !important;
        white-space: normal !important;
        gap: 0.75rem !important;
    }

    .table-card-mobile td:last-child {
        border-bottom: none !important;
        padding-top: 0.75rem !important;
        margin-top: 0.35rem !important;
        border-top: 1px solid var(--border) !important;
        justify-content: flex-end !important;
    }

    .table-card-mobile td::before {
        content: attr(data-label);
        font-weight: 700;
        font-size: 0.72rem;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        color: var(--text-muted);
        text-align: left;
        flex-shrink: 0;
    }

    .table-card-mobile td:empty::before,
    .table-card-mobile td[data-label=""]::before {
        display: none !important;
    }

    /* Mensaje de tabla vacía sin etiquetas falsas */
    .table-card-mobile td[colspan] {
        display: block !important;
        text-align: center !important;
        border-bottom: none !important;
        padding: 2rem 1rem !important;
    }
    .table-card-mobile td[colspan]::before {
        display: none !important;
    }

    /* Acciones expandidas para fácil pulsación táctil */
    .table-card-mobile td:last-child .btn {
        padding: 0.5rem 0.85rem !important;
        font-size: 0.85rem !important;
    }

    .table-card-mobile td:last-child div {
        flex-wrap: wrap;
        justify-content: flex-end;
    }
}

/* Estilos de Barra de Desplazamiento Suave en Tablas */
.table-responsive::-webkit-scrollbar,
.card-table::-webkit-scrollbar {
    height: 6px;
}

.table-responsive::-webkit-scrollbar-thumb,
.card-table::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

/* --------------------------------------------------------------------------
   BREAKPOINT 1: TABLETS Y PANTALLAS MEDIANAS (<= 991.98px)
   -------------------------------------------------------------------------- */
@media (max-width: 991.98px) {
    /* Activación del encabezado móvil y botón de menú */
    .sidebar-mobile-header {
        display: flex;
    }

    .sidebar-toggle-btn {
        display: inline-flex;
    }

    .sidebar-close-btn {
        display: inline-flex;
    }

    .sidebar-backdrop {
        display: block !important;
    }

    /* Transformación de la barra lateral en menú flotante (Off-Canvas Drawer) */
    .app-sidebar {
        position: fixed !important;
        top: 0 !important;
        bottom: 0 !important;
        left: 0 !important;
        width: 290px !important;
        max-width: 85vw !important;
        transform: translateX(-100%) !important;
        z-index: 1050 !important;
        box-shadow: 12px 0 35px rgba(0, 0, 0, 0.45) !important;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    }

    .app-sidebar.show {
        transform: translateX(0) !important;
    }

    /* El contenido principal ocupa el 100% del ancho */
    .app-main {
        margin-left: 0 !important;
        width: 100% !important;
        min-width: 0 !important;
    }

    .app-topbar {
        padding: 0.75rem 1.25rem;
        height: auto;
        min-height: 64px;
    }

    .app-content {
        padding: 1.5rem 1.25rem;
    }

    /* Colapso de layouts de 2 columnas principales a 1 columna apilada */
    div[style*="grid-template-columns: 2fr"],
    div[style*="grid-template-columns: 1fr 2fr"],
    div[style*="grid-template-columns: 2fr 1.05fr"],
    div[style*="grid-template-columns: 2fr 1.15fr"],
    div[style*="grid-template-columns: 2fr 1fr"] {
        grid-template-columns: 1fr !important;
        gap: 1.25rem !important;
    }

    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1.25rem;
    }
}

/* --------------------------------------------------------------------------
   BREAKPOINT 2: SMARTPHONES (<= 767.98px)
   -------------------------------------------------------------------------- */
@media (max-width: 767.98px) {
    .app-topbar {
        padding: 0.6rem 0.85rem;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .topbar-left {
        gap: 0.5rem;
    }

    .topbar-title h1 {
        font-size: 1.15rem;
    }

    .topbar-right {
        gap: 0.4rem;
        flex-wrap: wrap;
    }

    .btn-quick-new, 
    .btn-topbar-link {
        padding: 0.5rem 0.85rem;
        font-size: 0.82rem;
    }

    .app-content {
        padding: 1rem 0.75rem;
    }

    .card {
        border-radius: var(--radius-md);
        margin-bottom: 1.25rem;
    }

    .card-header {
        padding: 1rem 1.15rem;
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .card-header .btn,
    .card-header a {
        align-self: flex-start;
    }

    .card-body {
        padding: 1.25rem 1rem;
    }

    /* Formularios y columnas en 1 sola columna vertical */
    div[style*="grid-template-columns: 1fr 1fr"],
    div[style*="grid-template-columns: 1fr 1.5fr"],
    div[style*="grid-template-columns: 1fr 1fr 1fr 1fr"],
    div[style*="grid-template-columns: repeat(4, 1fr)"],
    div[style*="grid-template-columns: repeat(3, 1fr)"] {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }

    .kpi-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }

    /* Diálogos modales y SweetAlert adaptados a teléfonos */
    .modal-dialog,
    div:where(.swal2-container) .swal2-popup {
        width: 95vw !important;
        padding: 1.25rem 1rem !important;
        margin: 10px auto !important;
    }

    /* Timeline de rastreo responsivo */
    .tracking-milestones {
        overflow-x: auto;
        padding-bottom: 1rem;
        justify-content: flex-start;
        gap: 1rem;
        -webkit-overflow-scrolling: touch;
    }

    .tracking-milestones::before {
        min-width: 500px;
    }

    .tracking-milestone-step {
        flex-shrink: 0;
        width: 100px;
    }
}

/* --------------------------------------------------------------------------
   BREAKPOINT 3: SMARTPHONES PEQUEÑOS (<= 480px)
   -------------------------------------------------------------------------- */
@media (max-width: 480px) {
    .btn-topbar-link span {
        display: none;
    }

    .btn-topbar-link {
        padding: 0.5rem 0.65rem;
    }

    .topbar-title h1 {
        font-size: 1.05rem;
    }

    .btn-quick-new {
        padding: 0.5rem 0.85rem;
        font-size: 0.8rem;
    }
}


