/* Estilos base + variables de tema (light/dark) y responsive */

:root {
    /* Light theme (por defecto) */
    --bg: #f8fafc;
    --panel: #ffffff;
    --panel2: #f1f5f9;
    --text: #0f172a;
    --muted: #475569;
    --accent: #16a34a;
    --blue: #2563eb;
    --blue-dark: #1d4ed8;
    --card: rgba(255, 255, 255, 0.8);
    --card2: rgba(255, 255, 255, 0.95);
    --border: #e2e8f0;
    --btn-bg: #f8fafc;
    --btn-border: #e2e8f0;
    --input-bg: #ffffff;
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --radius: 0.5rem;
    --radius-lg: 0.75rem;
}

/* Preferencia del sistema: dark */
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f172a;
        --panel: #1e293b;
        --panel2: #334155;
        --text: #f1f5f9;
        --muted: #94a3b8;
        --accent: #22c55e;
        --blue: #3b82f6;
        --blue-dark: #2563eb;
        --card: rgba(30, 41, 59, 0.8);
        --card2: rgba(30, 41, 59, 0.95);
        --border: #475569;
        --btn-bg: #1e293b;
        --btn-border: #475569;
        --input-bg: #0f172a;
        --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.3), 0 1px 2px -1px rgb(0 0 0 / 0.3);
        --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.3), 0 4px 6px -4px rgb(0 0 0 / 0.3);
    }
}

/* Forzar tema vía atributo en <html> */
:root[data-theme="dark"] {
    --bg: #0f172a;
    --panel: #1e293b;
    --panel2: #334155;
    --text: #f1f5f9;
    --muted: #94a3b8;
    --accent: #22c55e;
    --blue: #3b82f6;
    --blue-dark: #2563eb;
    --card: rgba(30, 41, 59, 0.8);
    --card2: rgba(30, 41, 59, 0.95);
    --border: #475569;
    --btn-bg: #1e293b;
    --btn-border: #475569;
    --input-bg: #0f172a;
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.3), 0 1px 2px -1px rgb(0 0 0 / 0.3);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.3), 0 4px 6px -4px rgb(0 0 0 / 0.3);
}

:root[data-theme="light"] {
    --bg: #f8fafc;
    --panel: #ffffff;
    --panel2: #f1f5f9;
    --text: #0f172a;
    --muted: #475569;
    --accent: #16a34a;
    --blue: #2563eb;
    --blue-dark: #1d4ed8;
    --card: rgba(255, 255, 255, 0.8);
    --card2: rgba(255, 255, 255, 0.95);
    --border: #e2e8f0;
    --btn-bg: #f8fafc;
    --btn-border: #e2e8f0;
    --input-bg: #ffffff;
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

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

html,
body {
    margin: 0;
    min-height: 100%;
    background-color: var(--bg);
    background-image: linear-gradient(rgba(15, 23, 42, 0.88), rgba(15, 23, 42, 0.94)), url(../img/PBFletes.webp);
    background-repeat: no-repeat;
    background-size: cover;
    background-position: center center;
    background-attachment: fixed;
    color: var(--text);
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    line-height: 1.6;
    overflow-x: hidden;
}

/* If a modern format (e.g., WebP) is available and detected, prefer it with high-contrast overlay */
:root[data-bg-modern="1"] body {
    background-image: linear-gradient(rgba(15, 23, 42, 0.88), rgba(15, 23, 42, 0.94)), url(../img/PBFletes.webp);
}

:root[data-theme="light"] body,
:root[data-theme="light"][data-bg-modern="1"] body {
    background-image: linear-gradient(rgba(248, 250, 252, 0.92), rgba(241, 245, 249, 0.96)), url(../img/PBFletes.webp);
}

a {
    color: var(--blue);
    text-decoration: none;
    transition: color 0.2s ease;
}

a:hover {
    color: var(--blue-dark);
    text-decoration: underline;
}

/* Loading Spinner */
.loading-spinner {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border);
    border-left: 4px solid var(--blue);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Topbar Modernizado */
.topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--card2);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
    width: 100%;
    overflow: visible;
}

.topbar nav {
    display: flex;
    align-items: center;
    gap: 1rem;
    max-width: 100%;
    margin: 0 auto;
    padding: 0.75rem 1rem;
    overflow: visible;
    position: relative;
}

/* Brand Modernizado */
.brand {
    font-weight: 700;
    text-decoration: none;
    color: var(--text);
    font-size: 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-right: auto;
    flex-shrink: 0;
}

.brand-content {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
}

.brand-icon {
    font-size: 1.5rem;
    color: var(--blue);
    flex-shrink: 0;
}

.brand-text {
    font-weight: 600;
    white-space: nowrap;
}

/* Nav Menu Modernizado - ESTRUCTURA SIMPLIFICADA */
.nav-menu {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex: 1;
    min-width: 0;
    overflow: visible;
}

.nav-main {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    min-width: 0;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    color: var(--text);
    font-weight: 500;
    transition: all 0.2s ease;
    text-decoration: none;
    white-space: nowrap;
    flex-shrink: 0;
}

.nav-link:hover {
    background: var(--btn-bg);
    text-decoration: none;
    transform: translateY(-1px);
}

.nav-link i {
    font-size: 1rem;
    opacity: 0.8;
    flex-shrink: 0;
}

/* Nav Actions */
.nav-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-left: auto;
    flex-shrink: 0;
}

/* Botones Mejorados */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    appearance: none;
    border: 1px solid var(--btn-border);
    background: var(--btn-bg);
    color: var(--text);
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    cursor: pointer;
    font-weight: 500;
    font-size: 0.875rem;
    transition: all 0.2s ease;
    text-decoration: none;
    white-space: nowrap;
    flex-shrink: 0;
    position: relative;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow);
    text-decoration: none;
}

.btn-icon {
    padding: 0.5rem;
    height: 2.5rem;
    justify-content: center;
    flex-shrink: 0;
    position: relative;
}

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

.btn-primary:hover {
    background: var(--blue-dark);
    border-color: var(--blue-dark);
    color: white;
}

.btn-secondary {
    background: var(--panel2);
    border-color: var(--border);
}

.btn-close {
    background: transparent;
    border: none;
    padding: 0.5rem;
}

/* Badge para notificaciones - POSICIÓN CORREGIDA */
.notif-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    background: #ef4444;
    color: white;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    font-size: 0.7rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    border: 2px solid var(--card2);
    z-index: 1;
    pointer-events: none;
}

/* User Menu Modernizado */
.user-menu {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.2s ease;
    flex-shrink: 0;
}

.user-menu:hover {
    background: var(--btn-bg);
}

.user-avatar {
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: var(--blue);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 0.875rem;
    flex-shrink: 0;
}

.user-info {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
    min-width: 0;
}

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

.user-role {
    font-size: 0.75rem;
    color: var(--muted);
    text-transform: capitalize;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--card2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 0.5rem;
    min-width: 200px;
    display: none;
    z-index: 1000;
}

.user-menu.active .user-dropdown {
    display: block;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    border-radius: var(--radius);
    color: var(--text);
    text-decoration: none;
    transition: background 0.2s ease;
    white-space: nowrap;
}

.dropdown-item:hover {
    background: var(--btn-bg);
    text-decoration: none;
}

.dropdown-item.logout {
    color: #ef4444;
}

.dropdown-item.logout:hover {
    background: #fef2f2;
}

/* Container - MEJORADO PARA EVITAR DESBORDAMIENTO */
.container {
    padding: 2rem 1rem;
    max-width: 100%;
    margin: 0 auto;
    min-height: calc(100vh - 120px);
    overflow-x: hidden;
    width: 100%;
    box-sizing: border-box;
}

/* Footer Modernizado */
.footer {
    background: var(--card2);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--border);
    padding: 1rem;
    position: relative;
    width: 100%;
    overflow: hidden;
}

.footer-content {
    max-width: 100%;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0 1rem;
}

.footer-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    white-space: nowrap;
}

.footer-icon {
    color: var(--blue);
}

.footer-copyright {
    color: var(--muted);
    font-size: 0.875rem;
    white-space: nowrap;
}

.version {
    background: var(--blue);
    color: white;
    padding: 0.125rem 0.5rem;
    border-radius: 1rem;
    font-size: 0.75rem;
    margin-left: 0.5rem;
}

/* Cards Modernizadas - CORREGIDO DESBORDAMIENTO */
.card {
    background: var(--card);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    width: 100%;
    box-sizing: border-box;
    overflow: hidden;
    /* Contener el contenido */
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

/* CORREGIDO: Regla incompleta para card img */
.card img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius);
    display: block;
}

/* Tablas mejoradas */
.table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card);
    min-width: 600px; /* Ancho mínimo para tablas grandes */
    table-layout: auto;
}

/* CORREGIDO: Estructura de tabla */
.table th,
.table td {
    padding: 0.75rem 1rem;
    text-align: center;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
    box-sizing: border-box;
}

.table th {
    background: var(--panel2);
    font-weight: 600;
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    position: sticky;
    top: 0;
    z-index: 10;
}

.table tbody tr {
    transition: background 0.2s ease;
}

.table tbody tr:hover {
    background: var(--btn-bg);
}

/* Para tablas dentro de cards - CORREGIDO */
.card .table-container {
    margin: 0;
    width: 100%;
    border-radius: var(--radius);
    background: transparent;
    box-shadow: none;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.card .table {
    background: transparent;
    min-width: 600px;
}

/* Status Pills Mejorados */
.status-pill {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.75rem;
    border-radius: 1rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: capitalize;
    white-space: nowrap;
}

.status-pill.creado { background: #f3f4f6; color: #374151; }
.status-pill.cobrado { background: #dcfce7; color: #166534; font-weight: 600; }
.status-pill.por_cobrar, .status-pill.por-cobrar { background: #fef3c7; color: #b45309; font-weight: 600; }
.status-pill.aprobado { background: #dbeafe; color: #1e40af; }
.status-pill.asignado { background: #fef3c7; color: #92400e; }
.status-pill.no_aprobado { background: #fee2e2; color: #991b1b; }
.status-pill.retirado { background: #e0f2fe; color: #0369a1; font-weight: 600; }
.status-pill.preparado { background: #f3f4f6; color: #374151; }
.status-pill.costeado { background: #e0e7ff; color: #3730a3; }
.status-pill.pagado { background: #dcfce7; color: #166534; }
.status-pill.reportado { background: #fae8ff; color: #86198f; }
.status-pill.completado { background: #dcfce7; color: #166534; }

/* Notificaciones Modal Mejorado */
.notif-modal {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(4px);
    z-index: 10000;
    padding: 1rem;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}

.notif-modal.show,
.notif-modal.active {
    display: flex;
    opacity: 1;
    visibility: visible;
}

.notif-panel {
    background: var(--panel);
    border-radius: var(--radius-lg);
    max-width: 700px;
    width: min(100%, 700px);
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    transform: scale(0.97);
    transition: transform 0.25s ease;
    overflow: hidden;
}

.notif-modal.show .notif-panel,
.notif-modal.active .notif-panel {
    transform: scale(1);
}

.notif-list {
    max-height: calc(90vh - 6rem);
    overflow-y: auto;
    padding: 1rem;
}

.notif-modal[aria-hidden="true"] {
    opacity: 0;
    visibility: hidden;
}

.notif-panel > .notif-footer,
.notif-panel > .notif-header {
    flex-shrink: 0;
}

.notif-panel form {
    width: 100%;
}

.notif-header {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    padding: 1.15rem 1.25rem;
    border-bottom: 1px solid var(--border);
    background: var(--panel);
    flex-shrink: 0;
    box-sizing: border-box;
    width: 100%;
}

.notif-header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    gap: 0.75rem;
}

.notif-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    font-size: 1.15rem;
    color: var(--text);
    margin: 0;
    min-width: 0;
}

.notif-subtitle {
    font-weight: 600;
    color: var(--blue);
    background: rgba(59, 130, 246, 0.15);
    border: 1px solid rgba(59, 130, 246, 0.3);
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    font-size: 0.75rem;
}

.btn-close {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--panel2);
    border: 1px solid var(--border);
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

.btn-close:hover,
.btn-close:active {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
    border-color: #ef4444;
}

.notif-header-bottom {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    width: 100%;
}

#notif-mark-all {
    font-size: 0.8rem;
    padding: 0.4rem 0.85rem;
    border-radius: 6px;
    font-weight: 600;
    background: var(--panel2);
    border: 1px solid var(--border);
    color: var(--text);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

#notif-mark-all:hover {
    background: rgba(59, 130, 246, 0.2);
    color: var(--blue);
    border-color: var(--blue);
}

.notif-list {
    max-height: 60vh;
    overflow-y: auto;
    padding: 0.75rem 1rem;
    background: var(--panel);
    flex: 1;
    box-sizing: border-box;
    width: 100%;
}

.notif-item {
    display: flex;
    gap: 0.85rem;
    padding: 0.85rem 1rem;
    border-radius: 10px;
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: background 0.2s ease;
    background: var(--panel2);
    border: 1px solid var(--border);
    box-sizing: border-box;
    width: 100%;
}

.notif-item:hover {
    background: var(--btn-bg);
    border-color: var(--blue);
}

.notif-item.unread {
    background: rgba(34, 197, 94, 0.05);
    border-left: 3px solid var(--accent);
}

.notif-icon {
    display: flex;
    align-items: flex-start;
    padding-top: 0.25rem;
    flex-shrink: 0;
}

.notif-icon i {
    font-size: 1rem;
    color: var(--muted);
}

.notif-item.unread .notif-icon i {
    color: var(--accent);
}

.notif-content {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.notif-header-inner {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.5rem;
    gap: 1rem;
}

.notif-title-inner {
    font-weight: 600;
    font-size: 0.875rem;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.notif-time {
    font-size: 0.75rem;
    color: var(--muted);
    white-space: nowrap;
    flex-shrink: 0;
}

.notif-message {
    font-size: 0.875rem;
    color: var(--text);
    margin: 0;
    line-height: 1.4;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.notif-actions-inner {
    margin-top: 0.5rem;
}

.btn-mark-read {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--muted);
    padding: 0.25rem 0.75rem;
    border-radius: var(--radius);
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.btn-mark-read:hover {
    background: var(--blue);
    color: white;
    border-color: var(--blue);
}

.notif-empty {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--muted);
}

.notif-empty i {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.notif-footer {
    padding: 1rem;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

#notif-btn {
    position: relative !important;
}

#notif-count.badge {
    position: absolute;
    top: -2px;
    right: -2px;
    background: #ef4444;
    color: #ffffff;
    border-radius: 999px;
    padding: 0 5px;
    font-size: 0.68rem;
    font-weight: 800;
    min-width: 18px;
    height: 18px;
    display: none;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--panel, #0f172a);
    box-shadow: 0 2px 6px rgba(239, 68, 68, 0.4);
    pointer-events: none;
    line-height: 1;
    z-index: 2;
}

/* Nav Toggle para móvil - CORREGIDO */
.nav-toggle {
    position: absolute;
    left: -9999px;
    width: 1px;
    height: 1px;
    opacity: 0;
}

.nav-toggle-label {
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 2.35rem;
    height: 2.35rem;
    cursor: pointer;
    padding: 0.35rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--btn-bg);
    flex-shrink: 0;
    position: relative;
    z-index: 1001;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.nav-toggle-label span {
    display: block;
    height: 2px;
    width: 1.25rem;
    background: var(--text);
    border-radius: 2px;
    transition: all 0.25s ease;
    transform-origin: center;
}

.nav-toggle-label span:nth-child(1) {
    transform: translateY(-4px);
}

.nav-toggle-label span:nth-child(3) {
    transform: translateY(4px);
}

/* Selector para el menú hamburguesa activo */
.nav-toggle:checked ~ .nav-toggle-label span:nth-child(1),
.nav-toggle-label.active span:nth-child(1) {
    transform: rotate(45deg) translate(4px, 4px);
}

.nav-toggle:checked ~ .nav-toggle-label span:nth-child(2),
.nav-toggle-label.active span:nth-child(2) {
    opacity: 0;
}

.nav-toggle:checked ~ .nav-toggle-label span:nth-child(3),
.nav-toggle-label.active span:nth-child(3) {
    transform: rotate(-45deg) translate(5px, -5px);
}

/* NOTA: El menú se controla con JavaScript para mejor compatibilidad */

/* Responsive Design - NAVBAR MOBILE CORREGIDO */
@media (max-width: 768px) {
    .container {
        padding: 1rem;
        overflow-x: hidden;
    }
    
    .topbar nav {
        flex-wrap: nowrap;
        padding: 0.5rem;
        gap: 0.5rem;
        position: relative;
    }
    
    /* Mostrar botón hamburguesa en móvil */
    .nav-toggle-label {
        display: flex;
        margin-left: auto;
    }
    
    /* Menú desplegable móvil bajo la barra superior */
    .nav-menu {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        width: 100vw;
        background: var(--panel) !important;
        border-bottom: 2px solid var(--blue);
        border-top: 1px solid var(--border);
        flex-direction: column;
        gap: 0.25rem;
        padding: 1rem 1.25rem 1.5rem 1.25rem;
        box-shadow: 0 20px 35px rgba(0, 0, 0, 0.4);
        z-index: 2000;
        max-height: calc(100vh - 65px);
        overflow-y: auto;
        box-sizing: border-box;
    }

    :root[data-theme="dark"] .nav-menu {
        background: #0f172a !important;
    }

    :root[data-theme="light"] .nav-menu {
        background: #ffffff !important;
        box-shadow: 0 15px 30px rgba(0, 0, 0, 0.12);
    }
    
    /* Mostrar menú cuando está activo vía CSS o JS */
    .nav-menu.active,
    .nav-toggle:checked ~ .nav-menu {
        display: flex;
        animation: mobileNavFadeIn 0.2s ease forwards;
    }

    @keyframes mobileNavFadeIn {
        from {
            opacity: 0;
            transform: translateY(-8px);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }
    
    .nav-main {
        display: flex;
        flex-direction: column;
        width: 100%;
        gap: 0.2rem;
    }
    
    .nav-link {
        width: 100%;
        display: flex;
        align-items: center;
        gap: 0.75rem;
        padding: 0.85rem 1rem;
        border-radius: 8px;
        color: var(--text);
        font-weight: 600;
        font-size: 0.95rem;
        box-sizing: border-box;
        transition: background 0.15s ease, color 0.15s ease;
    }

    .nav-link:hover,
    .nav-link:active {
        background: rgba(59, 130, 246, 0.15);
        color: #60a5fa;
    }
    
    /* Botón de campana directo en barra superior móvil */
    .btn-topbar-bell {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 2.35rem;
        height: 2.35rem;
        border-radius: var(--radius);
        background: var(--btn-bg);
        border: 1px solid var(--border);
        color: var(--text);
        cursor: pointer;
        position: relative;
        font-size: 1rem;
        flex-shrink: 0;
        margin-left: auto;
        margin-right: 0.4rem;
        transition: background 0.2s ease;
    }

    .btn-topbar-bell:hover,
    .btn-topbar-bell:active {
        background: rgba(59, 130, 246, 0.2);
        color: #60a5fa;
    }

    .btn-topbar-bell #mobile-notif-count.badge {
        position: absolute;
        top: -3px;
        right: -3px;
        background: #ef4444;
        color: #ffffff;
        border-radius: 999px;
        padding: 0 4px;
        font-size: 0.65rem;
        font-weight: 800;
        min-width: 16px;
        height: 16px;
        display: none;
        align-items: center;
        justify-content: center;
        border: 2px solid var(--panel, #0f172a);
        box-shadow: 0 2px 5px rgba(239, 68, 68, 0.4);
        line-height: 1;
    }

    /* Acciones inferiores del menú desplegable móvil */
    .nav-actions {
        display: flex;
        flex-direction: column;
        width: 100%;
        gap: 0.65rem;
        margin-left: 0;
        padding-top: 1rem;
        margin-top: 0.5rem;
        border-top: 1px solid var(--border);
        box-sizing: border-box;
    }

    .btn-theme-toggle,
    .btn-notif-toggle {
        display: flex !important;
        align-items: center;
        gap: 0.75rem;
        width: 100%;
        padding: 0.85rem 1rem;
        border-radius: 8px;
        background: var(--panel2) !important;
        border: 1px solid var(--border) !important;
        color: var(--text) !important;
        font-size: 0.95rem;
        font-weight: 600;
        cursor: pointer;
        justify-content: flex-start;
        box-sizing: border-box;
        transition: all 0.15s ease;
    }

    .btn-theme-toggle:hover,
    .btn-theme-toggle:active,
    .btn-notif-toggle:hover,
    .btn-notif-toggle:active {
        background: rgba(59, 130, 246, 0.15) !important;
        color: #60a5fa !important;
        border-color: #60a5fa !important;
    }

    .nav-action-label {
        display: inline !important;
        font-weight: 600;
    }

    .btn-notif-toggle #notif-count {
        margin-left: auto;
        position: static !important;
        background: #ef4444;
        color: #ffffff;
        border-radius: 999px;
        padding: 2px 8px;
        font-size: 0.72rem;
        font-weight: 800;
    }

    /* Tarjeta de usuario en el menú móvil */
    .user-menu {
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 100%;
        padding: 0.75rem 1rem;
        background: var(--panel2) !important;
        border: 1px solid var(--border) !important;
        border-radius: 10px;
        box-sizing: border-box;
        margin-top: 0.25rem;
        gap: 0.75rem;
    }

    .user-info .user-name {
        color: var(--text) !important;
        font-weight: 700;
    }

    .user-info .user-role {
        color: var(--muted) !important;
    }

    .user-dropdown {
        display: none !important;
    }

    .mobile-logout-link {
        display: inline-flex !important;
        align-items: center;
        gap: 0.35rem;
        padding: 0.45rem 0.85rem;
        background: rgba(239, 68, 68, 0.15);
        color: #ef4444;
        border: 1px solid rgba(239, 68, 68, 0.3);
        border-radius: 6px;
        font-size: 0.82rem;
        font-weight: 600;
        text-decoration: none;
        flex-shrink: 0;
        transition: background 0.15s ease;
    }

    .mobile-logout-link:hover,
    .mobile-logout-link:active {
        background: #ef4444;
        color: #ffffff;
    }

    /* Modal de Notificaciones en Pantallas Móviles */
    .notif-modal {
        padding: 0;
        align-items: flex-end;
    }

    .notif-panel {
        width: 100vw;
        max-width: 100vw;
        max-height: 88vh;
        border-radius: 20px 20px 0 0;
        box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.5);
        background: var(--panel) !important;
        border: 1px solid var(--border);
        border-bottom: none;
        border-left: none;
        border-right: none;
        margin: 0;
        box-sizing: border-box;
    }

    .notif-header {
        padding: 0.85rem 1rem;
        gap: 0.5rem;
    }

    .notif-title {
        font-size: 1.05rem;
    }

    #notif-mark-all {
        font-size: 0.75rem;
        padding: 0.35rem 0.75rem;
    }

    #push-status-bar {
        padding: 8px 12px !important;
        font-size: 0.8rem;
    }

    .notif-list {
        max-height: calc(88vh - 11rem);
        padding: 0.65rem 0.75rem;
    }

    .notif-item {
        padding: 0.75rem;
        gap: 0.65rem;
        margin-bottom: 0.4rem;
    }

    .notif-title-inner {
        font-size: 0.82rem;
    }

    .notif-message {
        font-size: 0.78rem;
    }

    .btn-mark-read {
        padding: 0.3rem 0.65rem;
        font-size: 0.72rem;
    }
    
    .footer-content {
        flex-direction: column;
        text-align: center;
        gap: 0.5rem;
        padding: 0 0.5rem;
    }
    
    .grid.two {
        grid-template-columns: 1fr !important;
    }
    .grid.two-fixed {
        grid-template-columns: 1fr !important;
    }
    
    form .row {
        grid-template-columns: 1fr !important;
    }
    
    /* Cards en móvil - EVITAR DESBORDAMIENTO */
    .card {
        padding: 1rem;
        margin: 0.5rem 0;
        border-radius: var(--radius);
        width: 100%;
        box-sizing: border-box;
    }
    
    /* Tablas en móvil - scroll horizontal funcionando */
    .table-container {
        margin: 0.5rem 0;
        border-radius: var(--radius);
        width: 100%;
    }
    
    .table {
        min-width: 600px; /* Forzar scroll horizontal en móvil */
    }

    /* Ajustar badge de notificaciones en móvil */
    .notif-badge {
        top: -3px;
        right: -3px;
        width: 16px;
        height: 16px;
        font-size: 0.6rem;
    }
}

/* TABLAS RESPONSIVE CORREGIDAS - ENFOQUE MEJORADO */
@media (max-width: 480px) {
    .brand-text {
        font-size: 1.05rem;
        font-weight: 700;
        white-space: nowrap;
    }
    
    .container {
        padding: 0.5rem;
    }
    
    .card {
        padding: 0.75rem;
        margin: 0.25rem 0;
    }
    
    /* TABLAS EN MÓVIL - ENFOQUE CON SCROLL HORIZONTAL */
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0.5rem 0;
        border-radius: var(--radius);
        border: 1px solid var(--border);
    }
    
    .table {
        min-width: 600px !important;
        width: 100%;
        background: var(--card);
    }
    
    /* Mantener las cabeceras visibles */
    .table thead {
        display: table-header-group;
    }
    
    .table th,
    .table td {
        padding: 0.5rem 0.75rem;
        white-space: nowrap;
    }
    
    /* Alternativa para mostrar datos en móvil con cards */
    .table-mobile-cards .table {
        min-width: 100% !important;
        display: block;
    }
    
    .table-mobile-cards .table thead {
        display: none;
    }
    
    .table-mobile-cards .table tbody,
    .table-mobile-cards .table tr {
        display: block;
        width: 100%;
    }
    
    .table-mobile-cards .table tr {
        margin-bottom: 1rem;
        border: 1px solid var(--border);
        border-radius: var(--radius);
        padding: 0.75rem;
        background: var(--card);
        box-shadow: var(--shadow);
    }
    
    .table-mobile-cards .table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.5rem 0;
        border: none;
        border-bottom: 1px solid var(--border);
        width: 100%;
        box-sizing: border-box;
        white-space: normal;
        text-overflow: unset;
        max-width: none;
    }
    
    .table-mobile-cards .table td:last-child {
        border-bottom: none;
    }
    
    /* Añadir etiquetas usando data-label */
    .table-mobile-cards .table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--muted);
        margin-right: 1rem;
        flex-shrink: 0;
        min-width: 100px;
    }
    
    /* Ajustar botones dentro de tablas en móvil */
    .table-mobile-cards .table td .btn {
        width: 100%;
        justify-content: center;
        margin: 0.25rem 0;
    }
    
    .table-mobile-cards .table td .status-pill {
        margin-left: auto;
    }
}

/* Estados de carga mejorados */
.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
}

/* Scrollbar personalizado */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: var(--btn-bg);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--muted);
}

/* Auth layout */
.auth-shell {
    min-height: calc(100vh - 64px);
    display: flex;
    flex-direction: column;
}

.auth-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem 0;
}

@media (max-width: 768px) {
    .auth-shell {
        min-height: calc(100vh - 56px);
    }
    .auth-wrapper {
        padding: 0.75rem 0;
    }
}

.auth-card {
    margin: 0 auto;
    width: 100%;
    max-width: 420px;
}

/* Utilidades para prevenir desbordamiento */
.no-overflow {
    overflow: hidden;
}

.text-ellipsis {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.min-width-0 {
    min-width: 0;
}

/* Estilo para botón de exportación PDF */
.btn-pdf {
    background-color: #dc2626 !important;
    color: #ffffff !important;
    border-color: #dc2626 !important;
}

.btn-pdf:hover {
    background-color: #b91c1c !important;
    border-color: #b91c1c !important;
}

/* Grid Utilities - Asegurar que existan */
.grid {
    display: grid;
    gap: 1rem;
}

.grid.two {
    grid-template-columns: 1fr 1fr;
}

.grid.two-fixed {
    grid-template-columns: 1fr 1fr;
}

@media (max-width: 768px) {
    .grid.two,
    .grid.two-fixed,
    #trips-list.grid.two {
        grid-template-columns: 1fr !important;
    }
}

/* Form Row */
form .row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1rem;
}

@media (max-width: 768px) {
    form .row {
        grid-template-columns: 1fr !important;
    }
}

/* Table Container */
.table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius);
    background: var(--card);
    box-shadow: var(--shadow);
    margin: 1rem 0;
    padding: 0;
}

/* Asegurar que los inputs respeten el tema */
input,
select,
textarea {
    background: var(--input-bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.5rem 0.75rem;
    font-family: inherit;
    font-size: 0.875rem;
    transition: border-color 0.2s ease;
    width: 100%;
    box-sizing: border-box;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Mejoras de accesibilidad para móvil */
@media (max-width: 768px) {
    input,
    select,
    textarea {
        font-size: 16px; /* Prevenir zoom en iOS */
    }
    
    .btn {
        padding: 0.6rem 1rem;
        min-height: 44px; /* Área de toque mínima */
    }
    
    .btn-icon {
        min-height: 44px;
        min-width: 44px;
    }
}

/* ============================================================
   ESTILOS PREMIUM PARA TABLA DE REPORTES CON SCROLL HORIZONTAL
   ============================================================ */
.reportes-scroll-container {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: #0f172a;
    margin-top: 0.75rem;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3);
}

.reportes-scroll-container::-webkit-scrollbar {
    height: 10px;
    width: 10px;
}

.reportes-scroll-container::-webkit-scrollbar-track {
    background: #0b1120;
    border-radius: 6px;
}

.reportes-scroll-container::-webkit-scrollbar-thumb {
    background: #3b82f6;
    border-radius: 6px;
    border: 2px solid #0b1120;
}

.reportes-scroll-container::-webkit-scrollbar-thumb:hover {
    background: #60a5fa;
}

.reportes-table {
    width: 100%;
    min-width: 1580px;
    border-collapse: separate !important;
    border-spacing: 0 !important;
    background: transparent !important;
    font-size: 0.82rem;
}

.reportes-table th {
    background: #0b1324 !important;
    color: #94a3b8 !important;
    font-weight: 700;
    font-size: 0.74rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding: 12px 14px;
    border-bottom: 2px solid rgba(59, 130, 246, 0.35) !important;
    border-top: none !important;
    border-left: none !important;
    border-right: none !important;
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 10;
    text-align: center;
}

.reportes-table td {
    padding: 10px 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06) !important;
    border-top: none !important;
    border-left: none !important;
    border-right: none !important;
    white-space: nowrap;
    vertical-align: middle;
    color: #e2e8f0;
    font-size: 0.82rem;
}

.reportes-table tbody tr:nth-child(even) {
    background: rgba(15, 23, 42, 0.65);
}

.reportes-table tbody tr:nth-child(odd) {
    background: rgba(30, 41, 59, 0.55);
}

.reportes-table tbody tr:hover {
    background: rgba(59, 130, 246, 0.15) !important;
}

/* Fijar primera columna (#ID) durante el scroll horizontal */
.reportes-table th.sticky-col,
.reportes-table td.sticky-col {
    position: sticky;
    left: 0;
    z-index: 5;
    box-shadow: 3px 0 6px -1px rgba(0, 0, 0, 0.35);
}

.reportes-table th.sticky-col {
    background: #0b1324 !important;
    z-index: 15;
}

.reportes-table td.sticky-col {
    background: #152238 !important;
    font-weight: 700;
    color: #60a5fa;
}

.reportes-table tbody tr:hover td.sticky-col {
    background: #1e3a5f !important;
}