:root {
    --p1: #B7DBE8;
    --p2: #01446B;
    --p3: #104D6F;
    --p4: #84A4B6;
    --p5: #5D87A0;
    --p2-dark: #002d4a;
    --bg: #f0f4f8;
    --border: #e2e8f0;
    --text: #1e293b;
    --sidebar-w: 260px;
    --sidebar-collapsed: 70px;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

body {
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    display: flex;
    overflow: hidden;
    font-size: 13px;
}

/* Login Screen */
#login-screen {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, var(--p2-dark) 0%, var(--p2) 100%);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.5s;
}

.login-box {
    background: #fff;
    padding: 40px;
    border-radius: 20px;
    width: 400px;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.3);
    text-align: center;
    animation: slideUp 0.6s ease-out;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    background: linear-gradient(180deg, var(--p2-dark) 0%, var(--p2) 40%, var(--p3) 100%);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    z-index: 100;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed);
    min-width: var(--sidebar-collapsed);
}

.sidebar-brand {
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    height: 60px;
}

.sidebar-brand img {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    flex-shrink: 0;
}

.sidebar-brand h2 {
    color: #fff;
    font-size: 15px;
    font-weight: 800;
    white-space: nowrap;
    transition: 0.2s;
}

.sidebar.collapsed .sidebar-brand h2 {
    opacity: 0;
    pointer-events: none;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 14px 25px;
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    transition: 0.2s;
    white-space: nowrap;
    overflow: hidden;
}

.nav-item i {
    width: 20px;
    text-align: center;
    font-size: 16px;
    flex-shrink: 0;
}

.nav-item span {
    margin-left: 15px;
    opacity: 1;
    transition: 0.2s;
}

.sidebar.collapsed .nav-item {
    padding: 14px 0;
    justify-content: center;
}

.sidebar.collapsed .nav-item span {
    opacity: 0;
    width: 0;
    margin: 0;
}

.nav-item:hover,
.nav-item.active {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border-left: 4px solid var(--p1);
}

/* Main Area */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg);
    position: relative;
    z-index: 10;
}

.topbar {
    background: #fff;
    height: 60px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 25px;
    flex-shrink: 0;
}

.top-left {
    display: flex;
    align-items: center;
    gap: 20px;
}

.toggle-btn {
    cursor: pointer;
    font-size: 18px;
    color: var(--p2);
    transition: 0.2s;
}

.page-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.card {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
    margin-bottom: 20px;
    overflow: hidden;
    border: 1px solid var(--border);
}

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    background: #f8fafc;
    color: #64748b;
    font-size: 10px;
    text-transform: uppercase;
    padding: 10px 10px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-weight: 700;
    white-space: nowrap;
}

td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    font-size: 12px;
}

.row-master:hover {
    background: #f8fafc;
}

.row-detail {
    display: none;
    background: #fafbfc;
    border-bottom: 2px solid var(--p1);
}

.row-detail.open {
    display: table-row;
}

.detail-container {
    padding: 25px 30px;
    border-left: 4px solid var(--p2);
}

/* Focus Mode: Hides other rows when one is expanded */
tbody.focus-mode .row-master:not(.active) {
    display: none !important;
}

tbody.focus-mode .row-detail:not(.open) {
    display: none !important;
}

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--p4);
    padding: 5px;
    transition: 0.2s;
    font-size: 14px;
}

.btn-icon:hover {
    color: var(--p2);
    transform: scale(1.1);
}

.btn-icon.del:hover {
    color: var(--danger);
}

.btn-add {
    background: var(--p2);
    color: #fff;
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-add:hover {
    background: var(--p2-dark);
    transform: translateY(-1px);
}

.badge {
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 9.5px;
    font-weight: 700;
    background: #f1f5f9;
    color: #475569;
    border: 1px solid var(--border);
    white-space: nowrap;
    display: inline-block;
}

/* Search bar */
.search-container {
    position: relative;
    width: 300px;
}

.search-container i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: #94a3b8;
    font-size: 14px;
}

.search-input {
    width: 100%;
    padding: 8px 12px 8px 35px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 12px;
    outline: none;
    transition: 0.2s;
    background: #f8fafc;
}

.search-input:focus {
    border-color: var(--p2);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(1, 68, 107, 0.05);
}

/* Page Headers */
.page-header-container {
    position: sticky;
    top: -25px;
    z-index: 100;
    background: #fff;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
}

.page-header-actions {
    display: flex;
    align-items: center;
    gap: 20px;
}

.page-title {
    font-weight: 800;
    color: var(--p2);
    font-size: 1.25em;
    margin: 0;
}

.search-group {
    display: flex;
    gap: 10px;
}


/* Loaders */
#init-loader {
    position: fixed;
    inset: 0;
    background: #fff;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.progress-bar {
    width: 200px;
    height: 4px;
    background: #f1f5f9;
    border-radius: 10px;
    margin-top: 20px;
    overflow: hidden;
}

.progress-fill {
    width: 0%;
    height: 100%;
    background: var(--p2);
    transition: 0.4s;
}

/* Modals */
.modal-bg {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 5000;
}

.modal-box {
    background: #fff;
    border-radius: 16px;
    width: 95%;
    max-width: 650px;
    padding: 30px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    border: 1px solid var(--border);
    position: relative;
    max-height: 95vh;
    overflow-y: auto;
    animation: slideUp 0.4s ease-out;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    font-size: 11px;
    font-weight: 700;
    color: #64748b;
    margin-bottom: 6px;
    text-transform: uppercase;
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 13px;
    outline: none;
    background: #f8fafc;
}

/* Misc */
.location-info {
    font-size: 10px;
    color: #64748b;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
}

.weather-chip {
    background: #f1f5f9;
    padding: 2px 8px;
    border-radius: 20px;
    color: var(--p2);
    display: flex;
    align-items: center;
    gap: 4px;
    border: 1px solid var(--border);
}

.danger-alert {
    background: #fef2f2;
    border: 1px solid #fee2e2;
    padding: 20px;
    border-radius: 12px;
    color: #991b1b;
    margin-bottom: 25px;
    display: flex;
    gap: 15px;
    align-items: center;
}

.order-number {
    color: var(--p2);
    font-weight: 800;
    font-family: 'Monaco', 'Consolas', monospace;
    letter-spacing: -0.5px;
}

.project-id {
    font-size: 9px;
    background: #e2e8f0;
    padding: 2px 5px;
    border-radius: 4px;
    margin-right: 5px;
    color: #64748b;
}

.row-master.active {
    background: #e0f2fe !important;
    border-left: 5px solid #0369a1 !important;
    transition: 0.2s;
}

.row-master.active td {
    color: #0369a1 !important;
    font-weight: 700 !important;
}

.row-master.active .order-number {
    color: #0369a1 !important;
}

.scroll-area {
    max-height: 350px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
}

.scroll-area thead {
    position: sticky;
    top: 0;
    background: #f8fafc;
    z-index: 5;
}

.scroll-area table {
    margin: 0 !important;
}

.scroll-area td {
    padding: 6px 12px;
    vertical-align: middle;
}

.scroll-area th {
    padding: 8px 12px;
}

/* Dashboard Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 25px;
}

.stat-card {
    background: #fff;
    padding: 20px;
    border-radius: 12px;
    border: 1px solid var(--border);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03);
    transition: 0.3s;
}

.stat-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.06);
}

.stat-label {
    font-size: 10px;
    font-weight: 700;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 8px;
}

.stat-value {
    font-size: 20px;
    font-weight: 800;
    color: var(--p2);
}

.stat-footer {
    font-size: 10px;
    margin-top: 8px;
    font-weight: 600;
}

.stat-footer.up {
    color: var(--success);
}

.stat-footer.down {
    color: var(--danger);
}

/* Dashboard Header */
.dash-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
}

.project-select-dash {
    padding: 10px 15px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: #fff;
    font-size: 13px;
    font-weight: 600;
    color: var(--p2);
    outline: none;
    cursor: pointer;
    min-width: 250px;
}

/* Custom Premium Multiselect */
.multiselect-container {
    position: relative;
    width: 100%;
}

.multiselect-selected-box {
    min-height: 42px;
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #f8fafc;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    cursor: pointer;
    transition: 0.2s ease;
}

.multiselect-selected-box:focus-within {
    border-color: var(--p2);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(1, 68, 107, 0.05);
}

.multiselect-tag {
    background: var(--p1);
    color: var(--p2-dark);
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    animation: fadeIn 0.2s ease-in-out;
}

.multiselect-tag i {
    cursor: pointer;
    font-size: 10px;
    color: var(--p5);
    transition: 0.2s;
}

.multiselect-tag i:hover {
    color: var(--danger);
    transform: scale(1.1);
}

.multiselect-placeholder {
    color: #94a3b8;
    font-size: 12.5px;
    pointer-events: none;
}

.multiselect-dropdown {
    position: absolute;
    top: calc(100% + 5px);
    left: 0;
    width: 100%;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    max-height: 220px;
    overflow-y: auto;
    display: none;
    animation: slideUp 0.2s ease-out;
}

.multiselect-search-container {
    padding: 8px 10px;
    position: sticky;
    top: 0;
    background: #fff;
    border-bottom: 1px solid var(--border);
    z-index: 5;
}

.multiselect-search {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 11.5px;
    outline: none;
    background: #f8fafc;
}

.multiselect-search:focus {
    border-color: var(--p2);
    background: #fff;
}

.multiselect-options-list {
    padding: 4px 0;
}

.multiselect-item {
    padding: 8px 12px;
    font-size: 12px;
    color: var(--text);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: 0.15s;
}

.multiselect-item:hover {
    background: var(--p1);
    color: var(--p2-dark);
    font-weight: 600;
}

.multiselect-item.selected {
    background: #f1f5f9;
    color: var(--p4);
    pointer-events: none;
}

.multiselect-custom-option {
    border-top: 1px solid var(--border);
    background: #f8fafc;
    font-weight: 600;
    color: var(--p2);
}

.multiselect-custom-option:hover {
    background: var(--p2);
    color: #fff;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* ============================================================
   RESPONSIVE MÓVIL — Solo aplica a pantallas ≤ 768px
   ============================================================ */
@media (max-width: 768px) {

    /* --- Layout --- */
    body {
        flex-direction: column;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 280px;
        transform: translateX(-100%);
        z-index: 10001;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .sidebar.mobile-open {
        transform: translateX(0);
    }

    .mobile-overlay {
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, 0.55);
        z-index: 10000;
        display: none;
        backdrop-filter: blur(3px);
    }

    .mobile-overlay.show {
        display: block;
    }

    .topbar {
        padding: 0 12px;
    }

    .page-content {
        padding: 12px;
    }

    /* --- Transforma tablas principales en TARJETAS --- */
    table {
        display: block;
        width: 100%;
        border-collapse: separate;
    }

    thead {
        display: none;
    }

    tbody {
        display: block;
        width: 100%;
    }

    /* Cada fila principal = una tarjeta */
    tr {
        display: block;
        width: 100%;
        margin-bottom: 10px;
        border: 1px solid var(--border);
        border-radius: 12px;
        background: #fff;
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
        overflow: hidden;
    }

    /* Cada celda = una línea compacta con etiqueta a la izquierda */
    td {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
        padding: 7px 12px;
        font-size: 12px;
        border: none;
        border-bottom: 1px solid #f1f5f9;
        min-height: 0;
        text-align: right;
    }

    td:last-child {
        border-bottom: none;
    }

    /* Etiqueta de columna (viene del data-label) */
    td::before {
        content: attr(data-label);
        font-size: 9px;
        font-weight: 800;
        color: #94a3b8;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        white-space: nowrap;
        flex-shrink: 0;
        text-align: left;
    }

    /* --- Fila de detalle (expansible) ---
       IMPORTANTE: ocultar cuando NO está abierta.
       Cuando está abierta se muestra como bloque plano. */
    .row-detail {
        display: none !important;
    }

    .row-detail.open {
        display: block !important;
        border-radius: 0 0 12px 12px;
        border: 1px solid var(--border);
        border-top: none;
        margin-top: -10px;
        margin-bottom: 10px;
    }

    .row-detail.open>td {
        display: block;
        padding: 0;
        border: none;
        text-align: left;
    }

    .row-detail.open>td::before {
        display: none;
    }

    .detail-container {
        border-left: none;
        border-top: 3px solid var(--p2);
        padding: 12px 10px;
    }

    /* --- .scroll-area: TABLA CON SCROLL HORIZONTAL ---
       Fuerza display tipo tabla con !important para ganar sobre las reglas globales */
    .scroll-area {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        max-height: none !important;
        border-radius: 8px;
    }

    .scroll-area table {
        display: table !important;
        width: auto !important;
        min-width: 680px;
        border-collapse: collapse !important;
    }

    .scroll-area thead {
        display: table-header-group !important;
    }

    .scroll-area tbody {
        display: table-row-group !important;
        width: auto !important;
    }

    .scroll-area tr {
        display: table-row !important;
        margin-bottom: 0 !important;
        border-radius: 0 !important;
        border: none !important;
        box-shadow: none !important;
        background: transparent !important;
        overflow: visible !important;
        width: auto !important;
    }

    .scroll-area th {
        display: table-cell !important;
        padding: 8px 10px !important;
        width: auto !important;
    }

    .scroll-area td {
        display: table-cell !important;
        padding: 7px 10px !important;
        border-bottom: 1px solid var(--border) !important;
        border-top: none !important;
        text-align: left !important;
        min-height: 0 !important;
        width: auto !important;
        flex: none !important;
    }

    .scroll-area td::before {
        display: none !important;
    }

    /* --- Ajustes varios --- */
    .page-header-container {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
        padding: 15px;
    }

    .page-header-actions {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        width: 100%;
    }

    .page-title {
        font-size: 1.1em;
        text-align: center;
        width: 100%;
        margin-bottom: 5px;
    }

    .search-group {
        flex-direction: column;
        width: 100%;
        gap: 10px;
    }

    .search-container {
        width: 100%;
    }

    .dash-header {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .hide-mobile {
        display: none;
    }

    /* --- Modal pantalla completa --- */
    .modal-box {
        width: 100%;
        max-height: 95vh;
        border-radius: 16px 16px 0 0;
        padding: 20px;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        top: auto;
        animation: slideUpModal 0.3s ease-out;
    }

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

@keyframes slideUpModal {
    from {
        transform: translateY(100%);
    }

    to {
        transform: translateY(0);
    }
}

/* ===== PANTALLA DE BIENVENIDA ===== */
.welcome-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(10px);
    z-index: 99998;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeIn 0.5s ease-out;
}

.welcome-box {
    background: #fff;
    border-radius: 24px;
    max-width: 800px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    padding: 40px;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.3);
    animation: slideUp 0.6s ease-out;
    position: relative;
}

.welcome-box h1 {
    font-size: 28px;
    font-weight: 800;
    color: var(--p2);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.welcome-box .subtitle {
    color: #64748b;
    font-size: 14px;
    margin-bottom: 30px;
    font-weight: 500;
}

.welcome-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin: 25px 0 30px;
}

.welcome-card {
    background: #f8fafc;
    border-radius: 16px;
    padding: 20px;
    border: 1px solid var(--border);
    transition: 0.3s;
    text-align: center;
}

.welcome-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.06);
    border-color: var(--p1);
}

.welcome-card i {
    font-size: 32px;
    color: var(--p2);
    margin-bottom: 12px;
    display: block;
}

.welcome-card h3 {
    font-size: 14px;
    font-weight: 700;
    color: var(--p2);
    margin-bottom: 6px;
}

.welcome-card p {
    font-size: 12px;
    color: #64748b;
    line-height: 1.5;
    margin: 0;
}

.welcome-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 10px;
    border-top: 1px solid var(--border);
    padding-top: 20px;
}

.welcome-footer .btn-add {
    padding: 10px 32px;
    font-size: 14px;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* Responsive */
@media (max-width: 768px) {
    .welcome-box {
        padding: 25px 20px;
    }

    .welcome-box h1 {
        font-size: 22px;
    }

    .welcome-grid {
        grid-template-columns: 1fr 1fr;
        gap: 12px;
    }

    .welcome-card {
        padding: 15px;
    }
}
/* Barra de progreso de los guardados (crearProgreso en app.js) */
.save-progress {
    margin-top: 18px;
    padding: 12px 14px;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 10px;
}

.save-progress .sp-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    font-size: 11px;
    font-weight: 700;
    color: var(--p2);
    margin-bottom: 8px;
}

.save-progress .sp-time {
    color: #64748b;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.save-progress .sp-track {
    height: 8px;
    background: #e2e8f0;
    border-radius: 999px;
    overflow: hidden;
}

.save-progress .sp-fill {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, var(--p2) 0%, #0284c7 100%);
    border-radius: 999px;
    transition: width 0.15s linear;
}

/* Avisos de la app (avisar / mostrarError en app.js): reemplazan al alert() del navegador */
.aviso-bg {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(4px);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.aviso-box {
    background: #fff;
    border-radius: 16px;
    width: 100%;
    max-width: 440px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 26px 26px 20px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.35);
    border-top: 5px solid var(--warning);
    text-align: center;
    animation: slideUp 0.25s ease-out;
}

.aviso-box.aviso-error { border-top-color: var(--danger); }
.aviso-box.aviso-info { border-top-color: var(--p2); }
.aviso-box.aviso-exito { border-top-color: var(--success); }

.aviso-icono { font-size: 34px; margin-bottom: 10px; color: var(--warning); }
.aviso-error .aviso-icono { color: var(--danger); }
.aviso-info .aviso-icono { color: var(--p2); }
.aviso-exito .aviso-icono { color: var(--success); }

.aviso-box h4 {
    font-size: 16px;
    font-weight: 800;
    color: var(--p2);
    margin-bottom: 10px;
}

.aviso-texto {
    font-size: 13px;
    color: #334155;
    line-height: 1.5;
    white-space: pre-line;
}

.aviso-sugerencia {
    margin-top: 14px;
    padding: 10px 12px;
    background: #f1f5f9;
    border-radius: 8px;
    font-size: 12px;
    color: #475569;
    line-height: 1.5;
    text-align: left;
}

.aviso-detalle {
    margin-top: 12px;
    font-size: 11px;
    color: #64748b;
    text-align: left;
}

.aviso-detalle summary { cursor: pointer; }

.aviso-detalle code {
    display: block;
    margin-top: 6px;
    padding: 8px;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 6px;
    word-break: break-word;
    white-space: pre-wrap;
}

.aviso-botones {
    display: flex;
    justify-content: center;
    margin-top: 18px;
}

.aviso-botones .btn-add { min-width: 140px; justify-content: center; }

/* ===== Cartera pendiente (abrirCartera en app.js) ===== */
.stat-card--accion { cursor: pointer; transition: box-shadow .15s, transform .15s; }
.stat-card--accion:hover, .stat-card--accion:focus-visible { box-shadow: 0 8px 24px -10px rgba(1, 68, 107, .35); transform: translateY(-2px); outline: none; }
.stat-ver { float: right; color: var(--p2); font-weight: 700; font-size: 11px; }

.cx-sub { font-size: 12px; color: #64748b; margin: -12px 0 16px; }
.cx-vacio { padding: 30px 10px; text-align: center; color: #475569; font-size: 14px; }
.cx-vacio i { color: var(--success); margin-right: 6px; }

.cx-tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.cx-tile { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; background: #fff; }
.cx-tile-l { font-size: 10px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: #64748b; }
.cx-tile-v { font-size: 20px; font-weight: 800; color: var(--p2); margin-top: 4px; }
.cx-tile-f { font-size: 11px; color: #64748b; margin-top: 2px; }

.cx-graficos { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; margin-bottom: 18px; }
.cx-grafico { border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; background: #fff; }
.cx-grafico h5 { font-size: 13px; font-weight: 800; color: var(--p2); margin: 0; }
.cx-nota { font-size: 11px; color: #64748b; margin: 2px 0 0; }

/* Columnas de antigüedad: barras finas que crecen desde una sola línea base */
.cx-cols { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-top: 12px; }
.cx-col { display: flex; flex-direction: column; align-items: center; border-radius: 8px; padding: 4px 0; cursor: default; outline: none; }
.cx-col:hover, .cx-col:focus-visible { background: #f1f5f9; }
.cx-col-valor { font-size: 12px; font-weight: 700; color: #0f172a; font-variant-numeric: tabular-nums; height: 18px; }
.cx-col-pista { height: 130px; width: 100%; display: flex; align-items: flex-end; justify-content: center; border-bottom: 1px solid #e2e8f0; }
.cx-col-barra { width: 24px; border-radius: 4px 4px 0 0; }
.cx-col-nombre { font-size: 11px; font-weight: 700; color: #334155; margin-top: 6px; text-align: center; }
.cx-col-n { font-size: 10px; color: #64748b; }

/* Barras horizontales por OC */
.cx-filas { display: flex; flex-direction: column; gap: 4px; margin-top: 12px; }
.cx-fila { display: grid; grid-template-columns: 110px minmax(0, 1fr); align-items: center; gap: 8px; padding: 3px 4px; border-radius: 6px; cursor: pointer; outline: none; }
.cx-fila:hover, .cx-fila:focus-visible { background: #f1f5f9; }
.cx-fila-nombre { font-size: 11px; font-weight: 700; color: #334155; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cx-fila-pista { display: flex; align-items: center; gap: 6px; min-width: 0; border-left: 1px solid #e2e8f0; }
.cx-fila-barra { height: 14px; background: var(--p2); border-radius: 0 4px 4px 0; flex: 0 0 auto; max-width: calc(100% - 60px); }
.cx-fila-valor { font-size: 11px; font-weight: 700; color: #0f172a; font-variant-numeric: tabular-nums; white-space: nowrap; }

.cx-tabla { border: 1px solid var(--border); border-radius: 10px; overflow: auto; max-height: 360px; }
.cx-tabla table { margin: 0; font-size: 12px; }
.cx-tabla thead th { position: sticky; top: 0; background: #f8fafc; z-index: 1; }
.cx-tabla tfoot td { background: #f8fafc; font-weight: 700; color: var(--p2); border-top: 2px solid var(--border); }
.cx-num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.cx-punto { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.cx-link { background: none; border: 0; padding: 0; color: var(--p2); font-weight: 700; cursor: pointer; font-size: 12px; }
.cx-link i { font-size: 9px; opacity: .6; }
.cx-link:hover { text-decoration: underline; }

.cx-tip {
    position: fixed; z-index: 100000; display: none; pointer-events: none;
    background: #0f172a; color: #fff; font-size: 11.5px; font-weight: 600;
    padding: 6px 10px; border-radius: 6px; box-shadow: 0 6px 16px rgba(0,0,0,.2); max-width: 280px;
}

@media (max-width: 768px) {
    .cx-tiles { grid-template-columns: 1fr; }
    .cx-graficos { grid-template-columns: 1fr; }
    .cx-fila { grid-template-columns: 90px minmax(0, 1fr); }
}

/* ===== Pagos sin comprobante (avisoComprobantes en app.js) ===== */
.aviso-comp {
    display: flex; align-items: center; gap: 14px; margin: 0 0 20px;
    padding: 12px 18px; border-radius: 12px; cursor: pointer;
    background: #fffbeb; border: 1px solid #fde68a; color: #78350f;
    transition: box-shadow .15s, transform .15s;
}
.aviso-comp:hover, .aviso-comp:focus-visible { box-shadow: 0 8px 20px -10px rgba(180, 83, 9, .45); transform: translateY(-1px); outline: none; }
.aviso-comp-icono { font-size: 20px; color: #d97706; }
.aviso-comp-texto { display: flex; flex-direction: column; gap: 2px; font-size: 13px; flex: 1; min-width: 0; }
.aviso-comp-texto span { font-size: 11.5px; color: #92400e; }
.aviso-comp-accion { font-size: 12px; font-weight: 800; color: #b45309; white-space: nowrap; }
.aviso-comp--ok {
    cursor: default; background: transparent; border: 0; padding: 0 4px; margin: -6px 0 18px;
    font-size: 11.5px; color: #64748b;
}
.aviso-comp--ok:hover { box-shadow: none; transform: none; }
.aviso-comp--ok i { color: var(--success); margin-right: 4px; }
@media (max-width: 768px) {
    .aviso-comp { flex-wrap: wrap; }
    .aviso-comp-accion { width: 100%; text-align: right; }
}

/* ===== Órdenes sin pedido (avisoSinPedido en app.js) ===== */
.aviso-comp--pedido { background: #eff6ff; border-color: #bfdbfe; color: #1e3a5f; }
.aviso-comp--pedido:hover, .aviso-comp--pedido:focus-visible { box-shadow: 0 8px 20px -10px rgba(1, 68, 107, .45); }
.aviso-comp--pedido .aviso-comp-icono { color: var(--p2); }
.aviso-comp--pedido .aviso-comp-texto span { color: #475569; }
.aviso-comp--pedido .aviso-comp-accion { color: var(--p2); }
.aviso-comp + .aviso-comp:not(.aviso-comp--ok) { margin-top: -8px; }
.cx-casilla { font-size: 11.5px; color: #475569; display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.cx-dias { font-weight: 700; color: #334155; }
.cx-dias--medio { color: #b45309; }
.cx-dias--alto { color: var(--danger); }
.cx-esp { font-size: 11px; white-space: normal; }
@media (min-width: 769px) { .cx-esp { max-width: 200px; } }

/* ===== Despacho desde inventario (bloqueInventario en app.js) ===== */
.inv-bloque { margin-top: 10px; padding: 10px 12px; border: 1px dashed var(--border); border-radius: 8px; background: #f8fafc; }
.inv-bloque .cx-casilla { align-items: flex-start; font-size: 12px; color: #334155; }
.inv-bloque .cx-casilla input { margin-top: 2px; }
.form-control:disabled { background: #f1f5f9; color: #94a3b8; cursor: not-allowed; }

/* ===== Visor de adjuntos (js/visor.js) — con los colores de SCOF ===== */
.visor-bg {
    position: fixed; inset: 0; z-index: 9500; display: none;
    align-items: center; justify-content: center; padding: 16px;
    background: rgba(15, 23, 42, 0.5); backdrop-filter: blur(8px);
}
.visor-bg.abierto { display: flex; }
.visor-caja {
    width: min(1100px, 100%); height: min(94vh, 100%); display: flex; flex-direction: column;
    background: #fff; border-radius: 16px; overflow: hidden; border: 1px solid var(--border);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25); animation: slideUp .25s ease-out;
}
.visor-cabeza { display: flex; align-items: center; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.visor-icono { font-size: 20px; color: var(--p2); flex: 0 0 auto; }
.visor-titulos { flex: 1; min-width: 0; }
.visor-nombre { font-size: 14px; font-weight: 800; color: var(--p2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.visor-meta { font-size: 11px; color: #64748b; margin-top: 2px; }
.visor-acciones { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.visor-btn {
    display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px;
    border: 1px solid var(--border); background: #f1f5f9; color: #475569;
    font-size: 12px; font-weight: 700; cursor: pointer; text-decoration: none;
}
.visor-btn:hover { background: #e2e8f0; }
.visor-btn--principal { background: var(--p2); border-color: var(--p2); color: #fff; }
.visor-btn--principal:hover { background: var(--p2-dark); }
.visor-btn:disabled { opacity: .45; cursor: not-allowed; }
.visor-cerrar { background: none; border: 0; color: #94a3b8; font-size: 18px; cursor: pointer; padding: 4px 8px; border-radius: 8px; }
.visor-cerrar:hover { background: #f1f5f9; color: var(--p2); }
.visor-cuerpo { flex: 1; min-height: 0; overflow: auto; background: #f1f5f9; }
.visor-paginas { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 16px; }
.visor-pagina { background: #fff; border-radius: 6px; border: 1px solid var(--border); box-shadow: 0 6px 18px -6px rgba(1, 68, 107, .25); max-width: 100%; }
.visor-pagina-n { font-size: 11px; font-weight: 700; color: #64748b; }
.visor-imagen { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 16px; }
.visor-imagen img { max-width: 100%; max-height: calc(94vh - 110px); object-fit: contain; border-radius: 6px; background: #fff; box-shadow: 0 6px 18px -6px rgba(1, 68, 107, .25); }
.visor-cargando {
    height: 100%; min-height: 260px; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 12px; color: #475569; font-size: 13px; text-align: center; padding: 24px;
}
.visor-cargando > i { font-size: 26px; color: var(--p2); }
.visor-error > i { color: var(--warning); }
.visor-impresion { position: fixed; width: 0; height: 0; border: 0; left: -9999px; top: 0; }
@media (max-width: 640px) {
    .visor-bg { padding: 0; }
    .visor-caja { height: 100%; border-radius: 0; }
    .visor-btn span { display: none; }
}

/* ===== Tendencia de cobro por mes (renderTendenciaCobro en app.js) ===== */
.tc { padding: 16px 20px 14px; margin-bottom: 20px; }
.tc-cabeza { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.tc-titulo { font-weight: 800; color: var(--p2); }
.tc-sub { font-size: 12px; color: #64748b; margin-top: 2px; }
.tc-controles { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.tc-ley { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: #334155; }
.tc-ley i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.tc-btn { border: 1px solid var(--border); background: #f8fafc; color: #475569; font-size: 11px; font-weight: 700; padding: 5px 10px; border-radius: 6px; cursor: pointer; }
.tc-btn:hover { background: #f1f5f9; }

.tc-grafico { padding: 8px 0 26px 54px; }
.tc-plano { position: relative; height: 200px; }
.tc-linea { position: absolute; left: 0; right: 0; border-top: 1px solid #eef2f6; }
.tc-linea:first-child { border-top-color: #cbd5e1; }
.tc-linea span {
    position: absolute; right: 100%; transform: translateY(-50%); margin-right: 8px;
    font-size: 10px; color: #64748b; font-variant-numeric: tabular-nums; white-space: nowrap;
}
.tc-meses { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); }
.tc-mes { position: relative; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; border-radius: 6px; outline: none; cursor: default; }
.tc-mes:hover, .tc-mes:focus-visible { background: rgba(1, 68, 107, .05); }
.tc-barras { height: 100%; width: 100%; display: flex; align-items: flex-end; justify-content: center; gap: 2px; }
.tc-barra { width: min(14px, 38%); border-radius: 4px 4px 0 0; }
.tc-etiqueta { position: absolute; top: 100%; margin-top: 6px; font-size: 10.5px; color: #64748b; white-space: nowrap; }
.tc-grafico + .tc-tabla { display: none; }
.tc-nota { font-size: 10.5px; color: #94a3b8; margin-top: 6px; }

.tc--tabla .tc-grafico { display: none; }
.tc--tabla .tc-tabla { display: block; }
.tc--tabla .tc-nota { margin-top: 10px; }
.tc-tabla { border: 1px solid var(--border); border-radius: 8px; overflow: auto; max-height: 320px; }
.tc-tabla table { margin: 0; font-size: 12px; }

@media (max-width: 768px) {
    .tc-grafico { padding-left: 44px; overflow-x: auto; overflow-y: hidden; }
    .tc-plano { min-width: 520px; }
    .tc-etiqueta { font-size: 9.5px; }
}
.tc-n { font-size: 10px; color: #94a3b8; }
