:root {
    --fgs-blue-900: #073B67;
    --fgs-blue-800: #0B5B8F;
    --fgs-blue-700: #0B73B8;
    --fgs-blue-600: #1598D4;
    --fgs-blue-300: #8CC7E7;
    --fgs-blue-100: #EAF5FC;
    --fgs-blue-050: #F5FAFD;

    --fgs-gray-900: #2F3A43;
    --fgs-gray-700: #5F6972;
    --fgs-gray-500: #88929A;
    --fgs-gray-300: #DDE3E8;
    --fgs-gray-200: #E9EDF1;
    --fgs-gray-100: #F4F6F8;

    /* Acento corporativo/gerencial: ámbar obra + neutrales cálidos */
    --fgs-amber-600: #E88C2A;
    --fgs-amber-500: #EF9B41;
    --fgs-amber-100: #FCEBD9;
    --fgs-warm-gray: #A3A39B;

    --sidebar-width: 258px;
    --card-radius: 14px;
    --shadow-soft: 0 8px 24px rgba(7, 59, 103, 0.08);
    --shadow-card: 0 3px 12px rgba(35, 57, 77, 0.09);
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
}

body {
    margin: 0;
    background: #F8FAFC;
    color: var(--fgs-gray-900);
    font-family: Calibri, Carlito, "Segoe UI", Arial, sans-serif;
    font-size: 16px;
}

.app-shell {
    min-height: 100vh;
}

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-width);
    z-index: 1030;
    display: flex;
    flex-direction: column;
    background:
        linear-gradient(180deg, #E7F4FC 0%, #F1F8FD 58%, #E7F4FC 100%);
    border-right: 1px solid #BFD8E9;
}

.brand {
    min-height: 140px;
    padding: 26px 22px 18px;
    display: flex;
    align-items: flex-start;
    justify-content: center;
}

.brand-logo {
    display: block;
    width: 100%;
    max-width: 180px;
    height: auto;
    object-fit: contain;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 12px 12px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 46px;
    padding: 8px 14px;
    border-radius: 12px;
    color: var(--fgs-blue-900);
    text-decoration: none;
    font-size: 16px;
    font-weight: 600;
    transition: all 160ms ease;
}

.nav-item:hover {
    background: rgba(21, 152, 212, 0.08);
    color: var(--fgs-blue-700);
    transform: translateX(2px);
}

.nav-item.active {
    color: #fff;
    background: linear-gradient(135deg, var(--fgs-blue-700), #147FD1);
    box-shadow: 0 6px 16px rgba(11, 115, 184, 0.22);
}

.nav-icon {
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    flex: 0 0 32px;
}

.sidebar-footer {
    margin-top: auto;
    padding: 16px 22px 22px;
    color: var(--fgs-gray-700);
    border-top: 1px solid rgba(11, 91, 143, 0.08);
}

.main-content {
    min-height: 100vh;
    margin-left: var(--sidebar-width);
}

.topbar {
    min-height: 150px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 24px 34px;
    background: #FFFFFF;
    border-bottom: 1px solid var(--fgs-gray-200);
    box-shadow: 0 2px 7px rgba(47, 58, 67, 0.05);
}

.topbar h1 {
    margin: 0 0 4px;
    color: var(--fgs-blue-900);
    font-size: clamp(24px, 2.1vw, 34px);
    font-weight: 700;
    letter-spacing: -0.02em;
}

.page-subtitle {
    margin-bottom: 4px;
    color: var(--fgs-blue-700);
    font-size: 24px;
    font-weight: 700;
}

.page-source {
    color: var(--fgs-gray-700);
    font-size: 16px;
}

.sidebar-toggle {
    color: var(--fgs-blue-900);
    font-size: 28px;
    text-decoration: none;
}

.content-wrapper {
    padding: 24px 28px 32px;
}

.filters-card,
.dashboard-card {
    background: #FFFFFF;
    border: 1px solid var(--fgs-gray-200);
    border-radius: var(--card-radius);
    box-shadow: var(--shadow-card);
}

.filters-card {
    padding: 18px 20px 20px;
    margin-bottom: 18px;
}

.filters-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 14px;
}

.eyebrow {
    display: block;
    margin-bottom: 2px;
    color: var(--fgs-blue-600);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .12em;
    text-transform: uppercase;
}

.filters-heading h2 {
    margin: 0;
    color: var(--fgs-blue-900);
    font-size: 18px;
    font-weight: 700;
}

.form-label {
    margin-bottom: 5px;
    color: var(--fgs-gray-700);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
}

.form-select {
    min-height: 44px;
    border-color: var(--fgs-gray-300);
    font-size: 15px;
}

.form-select:focus {
    border-color: var(--fgs-blue-600);
    box-shadow: 0 0 0 .2rem rgba(21, 152, 212, .12);
}

.btn-outline-primary {
    --bs-btn-color: var(--fgs-blue-700);
    --bs-btn-border-color: var(--fgs-blue-300);
    --bs-btn-hover-bg: var(--fgs-blue-700);
    --bs-btn-hover-border-color: var(--fgs-blue-700);
}

.kpi-card {
    min-height: 108px;
    height: 100%;
    padding: 16px 18px;
    display: flex;
    align-items: center;
    gap: 14px;
}

.kpi-icon {
    width: 50px;
    height: 50px;
    flex: 0 0 50px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--fgs-blue-100), #FFFFFF);
    color: var(--fgs-blue-700);
    font-size: 28px;
}

.kpi-card.accent .kpi-icon {
    background: linear-gradient(135deg, var(--fgs-amber-100), #FFFFFF);
    color: var(--fgs-amber-600);
}

.kpi-card.accent .kpi-value {
    color: var(--fgs-amber-600);
}

.kpi-label {
    color: var(--fgs-gray-700);
    font-size: 15px;
    font-weight: 600;
    line-height: 1.1;
}

.kpi-value {
    margin-top: 5px;
    color: var(--fgs-blue-900);
    font-size: 38px;
    font-weight: 700;
    line-height: .95;
    letter-spacing: -0.02em;
}

.chart-card,
.detail-card {
    padding: 16px 18px 18px;
}

.card-heading {
    min-height: 36px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
}

.card-heading h3 {
    margin: 0;
    color: var(--fgs-blue-900);
    font-size: 18px;
    font-weight: 700;
}

.card-icon {
    color: var(--fgs-blue-700);
    font-size: 21px;
}

.chart-container {
    position: relative;
    width: 100%;
}

.chart-container-lg {
    min-height: 320px;
}

/* Evita que el canvas del donut se desborde fuera de su tarjeta */
#donutChartContainer {
    height: 320px;
    min-height: 320px;
    overflow: hidden;
}

/* Actas de entrega: pocos datos, se reducen las alturas de los gráficos */
body[data-section="actas"] .chart-container-lg {
    min-height: 250px;
}

body[data-section="actas"] #donutChartContainer {
    height: 210px;
    min-height: 210px;
    overflow: hidden;
}

.chart-container canvas {
    width: 100% !important;
    height: 100% !important;
}

.detail-card {
    min-height: 210px;
}

.ranking-list {
    display: grid;
    gap: 8px;
}

.ranking-row {
    display: grid;
    grid-template-columns: 34px minmax(165px, 220px) 1fr 48px;
    align-items: center;
    gap: 10px;
    min-height: 32px;
    border-top: 1px solid #EEF2F5;
}

.ranking-row:first-child {
    border-top: 0;
}

.ranking-position {
    color: var(--fgs-blue-700);
    font-weight: 700;
}

.ranking-label {
    overflow: hidden;
    color: #45515C;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 600;
}

.ranking-track,
.stack-track {
    position: relative;
    overflow: hidden;
    background: #EAF3F9;
    border-radius: 2px;
}

.ranking-track {
    height: 13px;
}

.ranking-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--fgs-blue-700), #1684CF);
}

.ranking-value {
    text-align: right;
    color: var(--fgs-gray-900);
    font-weight: 700;
}

.stack-legend {
    display: flex;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 18px;
    margin: 0 0 10px;
    padding: 0 2px;
}

.stack-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    color: var(--fgs-gray-700);
    font-size: 13px;
    font-weight: 600;
}

.stack-dot {
    width: 11px;
    height: 11px;
    border-radius: 2px;
}

.stack-table {
    display: grid;
    gap: 5px;
}

.stack-row {
    display: grid;
    grid-template-columns: minmax(190px, 245px) 1fr 46px;
    align-items: center;
    gap: 14px;
    min-height: 32px;
    border-top: 1px solid #EEF2F5;
}

.stack-label {
    overflow: hidden;
    color: #45515C;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.stack-track {
    display: flex;
    height: 22px;
}

.stack-segment {
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #FFFFFF;
    font-size: 12px;
    font-weight: 700;
    border-right: 1px solid rgba(255, 255, 255, .7);
}

.stack-segment:last-child {
    border-right: 0;
}

.stack-total {
    text-align: right;
    font-weight: 700;
}

/* --- Gerentes / personas --- */
.people-search {
    margin-bottom: 12px;
}

.people-search .form-control:focus {
    border-color: var(--fgs-blue-600);
    box-shadow: 0 0 0 .2rem rgba(21, 152, 212, .12);
}

.gerentes-list {
    display: grid;
    gap: 4px;
}

.gerente-row {
    border-top: 1px solid #EEF2F5;
}

.gerente-row:first-child {
    border-top: 0;
}

.gerente-head {
    display: grid;
    grid-template-columns: minmax(180px, 260px) 1fr 46px;
    align-items: center;
    gap: 14px;
    min-height: 36px;
    padding: 4px 2px;
    cursor: pointer;
    border-radius: 6px;
    transition: background 120ms ease;
}

.gerente-head:hover {
    background: var(--fgs-blue-050);
}

.gerente-name {
    display: flex;
    align-items: center;
    gap: 8px;
    overflow: hidden;
    color: #45515C;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.gerente-name i {
    color: var(--fgs-blue-600);
    font-size: 13px;
}

.gerente-track {
    display: flex;
    overflow: hidden;
    height: 20px;
    background: #EAF3F9;
    border-radius: 3px;
}

.gerente-total {
    text-align: right;
    font-weight: 700;
}

.people-panel {
    margin-top: 14px;
    padding-top: 4px;
    border-top: 1px dashed var(--fgs-gray-300);
}

.people-panel-title {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    color: var(--fgs-blue-900);
    font-size: 16px;
    font-weight: 700;
}

.people-table {
    display: grid;
    gap: 6px;
}

.person-row {
    display: grid;
    grid-template-columns: minmax(200px, 280px) 1fr minmax(180px, auto);
    gap: 14px;
    align-items: center;
    min-height: 34px;
    padding: 6px 8px;
    background: #FBFDFE;
    border: 1px solid var(--fgs-gray-200);
    border-radius: 8px;
}

.person-name {
    display: flex;
    align-items: center;
    gap: 8px;
    overflow: hidden;
    color: var(--fgs-gray-900);
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.person-status-dot {
    width: 10px;
    height: 10px;
    flex: 0 0 10px;
    border-radius: 50%;
}

.person-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    overflow: hidden;
    color: var(--fgs-gray-700);
    font-size: 13px;
    text-overflow: ellipsis;
}

.person-tools {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    justify-content: flex-end;
    align-items: center;
}

.tool-chip {
    padding: 2px 8px;
    border-radius: 20px;
    background: var(--fgs-blue-100);
    color: var(--fgs-blue-800);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .02em;
    text-transform: uppercase;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.chip-plan {
    padding: 1px 6px;
    border-radius: 20px;
    background: var(--fgs-gray-100);
    color: var(--fgs-gray-700);
    font-size: 10px;
    font-weight: 700;
    text-transform: capitalize;
    letter-spacing: .01em;
}

.chip-plan.paid {
    background: var(--fgs-amber-100);
    color: var(--fgs-amber-600);
}

.status-chip {
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .02em;
    text-transform: uppercase;
}

.os-label {
    color: var(--fgs-gray-700);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .03em;
    text-transform: uppercase;
}

.no-tool {
    color: var(--fgs-gray-500);
    font-size: 12px;
    font-style: italic;
}

.small-hint {
    color: var(--fgs-gray-500);
    font-size: 14px;
}

/* --- Inventario (matriz Obra x Tipo) --- */
.inv-search {
    margin-bottom: 12px;
}

.inv-search .form-control:focus {
    border-color: var(--fgs-blue-600);
    box-shadow: 0 0 0 .2rem rgba(21, 152, 212, .12);
}

.inv-table {
    display: grid;
    gap: 3px;
    overflow-x: auto;
}

.inv-row {
    display: grid;
    align-items: center;
    gap: 3px;
    min-height: 30px;
    grid-auto-columns: minmax(150px, 1fr);
    grid-template-columns: minmax(180px, 1.4fr) repeat(var(--inv-cols, 1), minmax(64px, 1fr)) minmax(64px, 1.2fr);
}

.inv-head .inv-cell,
.inv-foot .inv-cell {
    color: var(--fgs-gray-700);
    font-weight: 700;
}

.inv-head {
    color: var(--fgs-blue-900);
    font-size: 13px;
    font-weight: 700;
}

.inv-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px 6px;
    font-size: 13px;
    border-radius: 5px;
}

.inv-label {
    justify-content: flex-start;
    overflow: hidden;
    color: #45515C;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.inv-dot {
    width: 10px;
    height: 10px;
    flex: 0 0 10px;
    margin-right: 8px;
    border-radius: 3px;
}

.inv-zero {
    color: var(--fgs-gray-300);
}

.inv-count {
    position: relative;
    overflow: hidden;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 120ms ease;
}

.inv-count:hover {
    border-color: var(--fgs-blue-300);
    box-shadow: 0 0 0 2px rgba(21, 152, 212, .15);
}

.inv-count.open {
    border-color: var(--fgs-blue-700);
    box-shadow: 0 0 0 2px rgba(21, 152, 212, .25);
}

.inv-count-bar {
    position: absolute;
    inset: 0 auto 0 0;
    opacity: .22;
}

.inv-count-val {
    position: relative;
    z-index: 1;
    font-weight: 700;
}

.inv-total {
    color: var(--fgs-blue-900);
    font-weight: 700;
}

.inv-foot {
    border-top: 2px solid var(--fgs-gray-200);
}

.inv-detail {
    margin-top: 14px;
    padding-top: 4px;
    border-top: 1px dashed var(--fgs-gray-300);
}

.inv-detail-title {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    color: var(--fgs-blue-900);
    font-size: 16px;
    font-weight: 700;
}

.inv-detail-table {
    display: grid;
    gap: 5px;
}

.inv-detail-row {
    display: grid;
    grid-template-columns: minmax(200px, 1fr) 100px minmax(120px, .8fr) minmax(160px, 1fr) minmax(150px, .9fr);
    gap: 12px;
    align-items: center;
    min-height: 34px;
    padding: 6px 8px;
    background: #FBFDFE;
    border: 1px solid var(--fgs-gray-200);
    border-radius: 8px;
}

.inv-detail-name {
    overflow: hidden;
    color: var(--fgs-gray-900);
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.inv-detail-equipo {
    color: var(--fgs-blue-700);
    font-weight: 700;
    font-size: 12px;
}

.inv-detail-serie {
    overflow: hidden;
    color: var(--fgs-gray-700);
    font-size: 12px;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.inv-detail-meta {
    overflow: hidden;
    color: var(--fgs-gray-700);
    font-size: 13px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.inv-detail-arrendador {
    overflow: hidden;
    text-align: right;
    color: var(--fgs-gray-700);
    font-size: 13px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (max-width: 575.98px) {
    .inv-detail-row {
        grid-template-columns: 1fr;
        gap: 4px;
        text-align: left;
    }

    .inv-detail-arrendador {
        text-align: left;
    }
}

/* --- Actas de entrega --- */
.actas-table {
    display: grid;
    gap: 3px;
    overflow-x: auto;
}

.acta-row {
    display: grid;
    grid-template-columns: 90px minmax(180px, 1.3fr) minmax(150px, 1.1fr) minmax(150px, 1fr) 90px 90px minmax(200px, 1.6fr);
    gap: 10px;
    align-items: center;
    min-height: 34px;
    padding: 5px 8px;
    border-radius: 6px;
}

.acta-head {
    color: var(--fgs-blue-900);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    border-bottom: 1px solid var(--fgs-gray-200);
}

.acta-row:not(.acta-head):nth-child(odd) {
    background: #FBFDFE;
}

.acta-nombre {
    overflow: hidden;
    color: var(--fgs-gray-900);
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.acta-fecha {
    color: var(--fgs-gray-700);
    font-weight: 600;
    font-size: 13px;
}

.acta-cargo,
.acta-obra {
    overflow: hidden;
    color: var(--fgs-gray-700);
    font-size: 13px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.acta-obs {
    overflow: hidden;
    color: var(--fgs-gray-500);
    font-size: 12px;
    font-style: italic;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (max-width: 991.98px) {
    .acta-row {
        grid-template-columns: 80px minmax(160px, 1fr) 90px 90px;
    }

    .acta-cargo,
    .acta-obs {
        grid-column: 1 / -1;
    }
}

@media (max-width: 575.98px) {
    .acta-row {
        grid-template-columns: 1fr;
        gap: 4px;
        padding: 8px;
    }

    .acta-head {
        display: none;
    }
}

.dashboard-footer {
    padding: 24px 0 2px;
    text-align: center;
    color: var(--fgs-gray-700);
    font-size: 14px;
}

.loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, .62);
    backdrop-filter: blur(1px);
}

.loading-overlay.show {
    display: flex;
}

.empty-state {
    min-height: 160px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--fgs-gray-500);
    text-align: center;
}

@media (max-width: 1199.98px) {
    .chart-container-lg {
        min-height: 360px;
    }
}

@media (max-width: 991.98px) {
    :root {
        --sidebar-width: 240px;
    }

    .sidebar {
        transform: translateX(-100%);
        transition: transform 180ms ease;
        box-shadow: var(--shadow-soft);
    }

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

    .main-content {
        margin-left: 0;
    }

    .topbar {
        min-height: 132px;
        padding: 20px;
    }

    .content-wrapper {
        padding: 18px;
    }
}

@media (max-width: 575.98px) {
    .topbar h1 {
        font-size: 27px;
    }

    .page-subtitle {
        font-size: 20px;
    }

    .page-source {
        font-size: 14px;
    }

    .content-wrapper {
        padding: 14px 10px 24px;
    }

    .kpi-card {
        min-height: 106px;
        padding: 16px;
    }

    .kpi-icon {
        width: 50px;
        height: 50px;
        flex-basis: 50px;
        font-size: 28px;
    }

    .kpi-value {
        font-size: 37px;
    }

    .ranking-row {
        grid-template-columns: 28px minmax(120px, 1fr) 42px;
    }

    .ranking-track {
        display: none;
    }

    .stack-row {
        grid-template-columns: 1fr;
        gap: 4px;
        padding: 6px 0;
    }

    .stack-total {
        display: none;
    }

    .gerente-head {
        grid-template-columns: 1fr 46px;
    }

    .gerente-track {
        grid-column: 1 / -1;
        grid-row: 2;
    }

    .person-row {
        grid-template-columns: 1fr;
        gap: 6px;
    }

    .person-tools {
        justify-content: flex-start;
    }
}

/* --- Botón imprimir --- */
.print-btn {
    white-space: nowrap;
}

/* --- Vista imprimible / PDF --- */
@media print {
    @page {
        margin: 12mm;
    }

    body {
        background: #fff;
        font-size: 13px;
    }

    .sidebar,
    .filters-card,
    .loading-overlay,
    .toast-container,
    .sidebar-toggle,
    .print-btn {
        display: none !important;
    }

    .main-content {
        margin-left: 0 !important;
    }

    .topbar {
        min-height: auto;
        padding: 0 0 10px;
        background: #fff;
        border-bottom: 2px solid var(--fgs-blue-900);
        box-shadow: none;
    }

    .topbar h1 {
        font-size: 21px;
    }

    .page-subtitle {
        font-size: 16px;
    }

    .content-wrapper {
        padding: 12px 0 0;
    }

    .dashboard-card,
    .filters-card {
        box-shadow: none;
        border: 1px solid var(--fgs-gray-200);
        break-inside: avoid;
    }

    .col-xl-4 {
        width: 100% !important;
        flex: 0 0 100% !important;
        max-width: 100% !important;
    }

    .chart-container-lg {
        min-height: 300px;
    }

    body[data-section="actas"] .chart-container-lg {
        min-height: 260px;
    }

    body[data-section="actas"] #donutChartContainer {
        min-height: 240px;
    }

    .kpi-icon {
        width: 44px;
        height: 44px;
        flex-basis: 44px;
        font-size: 24px;
    }

    .kpi-value {
        font-size: 32px;
    }

    .kpi-label {
        font-size: 13px;
    }

    .people-search,
    .inv-search {
        display: none !important;
    }

    .acta-head {
        display: grid;
    }

    .acta-row {
        grid-template-columns: 80px minmax(160px, 1fr) minmax(130px, .9fr) minmax(130px, .9fr) 70px 70px minmax(180px, 1.4fr);
    }

    .dashboard-footer {
        text-align: left;
        padding-top: 14px;
    }
}
