:root {
    --azul-oscuro: #082d5c;
    --azul-menu: #0d436f;
    --azul: #1976c9;
    --verde: #35a853;
    --morado: #8e44cc;
    --rojo: #e53935;
    --amarillo: #f4c542;
    --gris-fondo: #f5f8fc;
    --gris-borde: #dce6f2;
    --texto: #001b44;
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}

body {
    margin: 0;
    font-family: "Segoe UI", Arial, sans-serif;
    background: var(--gris-fondo);
    color: var(--texto);
}

body.modal-open {
    overflow: hidden;
}

.app {
    display: flex;
    min-height: 100vh;
    width: 100%;
    max-width: 100%;
}

.sidebar {
    width: 58px;
    min-width: 58px;
    background: linear-gradient(180deg, #123f67, #0a3155);
    color: white;
    padding-top: 42px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 38px;
    border-radius: 0 0 8px 0;
}

.sidebar .icon {
    font-size: 22px;
    cursor: pointer;
}

.main {
    flex: 1;
    padding: 14px 18px 18px 18px;
    min-width: 0;
    width: calc(100% - 58px);
    max-width: calc(100% - 58px);
}

.header {
    display: grid;
    grid-template-columns: minmax(260px, 1fr) minmax(340px, 420px) max-content minmax(210px, 260px);
    align-items: stretch;
    gap: 14px;
    margin-bottom: 10px;
    width: 100%;
}

.header>* {
    min-width: 0;
}

.title h1 {
    margin: 0;
    font-size: 27px;
    color: var(--azul-oscuro);
}

.title p {
    margin: 2px 0 0;
    font-size: 16px;
    color: var(--azul-oscuro);
}

.budget-filter {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    align-items: stretch;
    width: 100%;
    height: 100%;
    min-width: 0;
}

.budget-control,
.date-filter {
    background: white;
    border: 1px solid var(--gris-borde);
    border-radius: 8px;
    padding: 8px 10px;
    box-shadow: 0 2px 8px rgba(10, 50, 100, 0.05);
    min-width: 0;
    min-height: 64px;
    height: 100%;
}

.compact-control {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.budget-control label,
.date-filter label {
    display: block;
    font-size: 12px;
    font-weight: 700;
    color: var(--azul-oscuro);
    margin-bottom: 5px;
}

.budget-row {
    display: flex;
    align-items: center;
    gap: 5px;
}

.budget-row input[type="number"] {
    width: 76px;
    height: 30px;
    border: 1px solid var(--gris-borde);
    border-radius: 5px;
    padding: 0 6px;
    color: var(--texto);
    font-weight: 600;
}

.budget-row span {
    font-size: 12px;
    font-weight: 700;
    color: var(--azul-oscuro);
}

.date-filter {
    width: fit-content;
    max-width: 100%;
    justify-self: start;
}

.date-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
    width: max-content;
    max-width: 100%;
}

.date-row input {
    width: 145px;
    height: 32px;
    border: 1px solid var(--gris-borde);
    border-radius: 5px;
    padding: 0 8px;
    background: white;
    color: var(--texto);
}

.update {
    text-align: right;
    font-size: 12px;
    color: var(--azul-oscuro);
    padding-top: 10px;
}

.layout {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr) 330px;
    gap: 10px;
    min-width: 0;
    width: 100%;
}

.filters,
.panel,
.side-panel,
.narrative,
.metric-card {
    background: white;
    border: 1px solid var(--gris-borde);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(10, 50, 100, 0.06);
    min-width: 0;
}

.filters {
    padding: 16px;
    min-width: 0;
}

.filter-group {
    margin-bottom: 18px;
}

.filter-group label {
    display: block;
    font-weight: 700;
    font-size: 12px;
    color: var(--azul-oscuro);
    margin-bottom: 8px;
}

select {
    width: 100%;
    height: 30px;
    border: 1px solid var(--gris-borde);
    border-radius: 4px;
    background: white;
    padding: 0 8px;
    color: var(--texto);
}

select.multi-select {
    height: 118px;
    padding: 6px 8px;
    overflow-y: auto;
}

select.multi-select option {
    padding: 4px 6px;
}

.filter-help {
    display: block;
    margin-top: 5px;
    font-size: 10px;
    line-height: 1.25;
    color: #5d6f86;
}

.check {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 9px 0;
    font-size: 12px;
}

.check input {
    width: 16px;
    height: 16px;
}

.switch-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    font-size: 12px;
    color: var(--texto);
}

.switch {
    position: relative;
    display: inline-block;
    width: 42px;
    height: 22px;
    flex-shrink: 0;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.switch-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: #c8d4e3;
    border-radius: 999px;
    transition: 0.2s;
}

.switch-slider:before {
    content: "";
    position: absolute;
    height: 18px;
    width: 18px;
    left: 2px;
    top: 2px;
    background: white;
    border-radius: 50%;
    transition: 0.2s;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}

.switch input:checked+.switch-slider {
    background: var(--azul);
}

.switch input:checked+.switch-slider:before {
    transform: translateX(20px);
}

.clear-btn {
    width: 100%;
    height: 42px;
    border: 1px solid var(--gris-borde);
    border-radius: 5px;
    background: white;
    color: var(--azul-oscuro);
    font-weight: 600;
    margin-top: 30px;
    cursor: pointer;
}

.clear-btn:hover {
    background: #eef6ff;
}

.content {
    display: grid;
    gap: 10px;
    min-width: 0;
}

.metrics-panel {
    padding: 10px;
    min-height: auto;
}

.metrics-panel.panel {
    min-height: auto;
}

.metrics-header {
    display: grid;
    grid-template-columns: 2fr 3fr 2fr;
    gap: 8px;
    margin-bottom: 4px;
}

.metrics {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 8px;
    min-width: 0;
    align-items: stretch;
}

.metric-card {
    min-height: 72px;
    padding: 8px 8px;
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.metric-card.is-loading::after {
    content: "";
    position: absolute;
    top: 8px;
    right: 8px;
    width: 14px;
    height: 14px;
    border: 2px solid #dce6f2;
    border-top-color: var(--azul);
    border-radius: 50%;
    animation: holo-spin 0.8s linear infinite;
}

.metric-card.is-loading .value {
    opacity: 0.72;
}

@keyframes holo-spin {
    to {
        transform: rotate(360deg);
    }
}

.metric-card h4 {
    margin: 0 0 6px;
    font-size: 11px;
    color: #001b44;
}

.metric-card .value {
    font-size: 22px;
    line-height: 1.1;
    font-weight: 800;
    margin: 0;
}

.green {
    color: var(--verde);
}

.blue {
    color: var(--azul);
}

.purple {
    color: var(--morado);
}

.red {
    color: var(--rojo);
}

.section-title {
    text-align: center;
    font-weight: 800;
    font-size: 13px;
    margin-bottom: 4px;
}

.ingresos-title {
    color: var(--verde);
}

.gastos-title {
    color: var(--azul);
}

.resultado-title {
    color: var(--morado);
}

.dashboard-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 10px;
    min-width: 0;
}

.panel {
    padding: 12px;
    min-height: auto;
    overflow: hidden;
}

.panel h3 {
    margin: 0;
    font-size: 15px;
    color: var(--azul-oscuro);
}

.panel .subtitle {
    font-size: 12px;
    margin-bottom: 8px;
}

.panel-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.panel-title-row h3 {
    margin: 0;
}

.toggle-btn {
    border: 1px solid var(--gris-borde);
    background: #f8fbff;
    color: var(--azul-oscuro);
    border-radius: 6px;
    padding: 6px 9px;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
}

.toggle-btn:hover {
    background: #eef6ff;
}

.panel-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.expand-chart-btn {
    border: 1px solid var(--gris-borde);
    background: #ffffff;
    color: var(--azul-oscuro);
    border-radius: 6px;
    padding: 6px 9px;
    font-size: 11px;
    font-weight: 800;
    cursor: pointer;
    white-space: nowrap;
    box-shadow: 0 1px 4px rgba(10, 50, 100, 0.05);
}

.expand-chart-btn:hover {
    background: #eef6ff;
    border-color: #b8d3f2;
}

.expand-chart-btn:focus,
.toggle-btn:focus,
.chart-modal-close:focus {
    outline: 2px solid rgba(25, 118, 201, 0.35);
    outline-offset: 2px;
}

.panel-flex {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    min-width: 0;
}

.chart {
    width: 100%;
    height: 245px;
    min-width: 0;
}

.narrative {
    background: #f8fbff;
    padding: 10px 12px;
    font-size: 12px;
    line-height: 1.4;
    min-height: 54px;
    position: relative;
    overflow: hidden;
}

.narrative.narrative-loading {
    color: transparent;
}

.narrative.narrative-loading::before,
.ai-list-loading::before {
    content: "";
    position: absolute;
    top: 12px;
    left: 12px;
    width: 14px;
    height: 14px;
    border: 2px solid #dce6f2;
    border-top-color: var(--azul);
    border-radius: 50%;
    animation: holo-spin 0.8s linear infinite;
}

.narrative.narrative-loading::after {
    content: "";
    display: block;
    height: 34px;
    margin-left: 28px;
    border-radius: 5px;
    background:
        linear-gradient(90deg, rgba(220, 230, 242, 0.45) 25%, rgba(238, 246, 255, 0.9) 38%, rgba(220, 230, 242, 0.45) 63%),
        linear-gradient(#dce6f2 0 0),
        linear-gradient(#dce6f2 0 0);
    background-size: 220% 100%, 100% 10px, 72% 10px;
    background-position: 100% 0, 0 3px, 0 23px;
    background-repeat: no-repeat;
    animation: holo-skeleton 1.1s ease-in-out infinite;
}

@keyframes holo-skeleton {
    to {
        background-position: -100% 0, 0 3px, 0 23px;
    }
}

.chart-modal {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 22px;
    z-index: 9999;
}

.chart-modal.is-open {
    display: flex;
}

.chart-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 27, 68, 0.45);
    backdrop-filter: blur(3px);
}

.chart-modal-content {
    position: relative;
    width: min(1320px, 96vw);
    height: min(860px, 92vh);
    background: #ffffff;
    border: 1px solid var(--gris-borde);
    border-radius: 14px;
    box-shadow: 0 22px 70px rgba(0, 27, 68, 0.35);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chart-modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    padding: 14px 18px;
    background: #f8fbff;
    border-bottom: 1px solid var(--gris-borde);
}

.chart-modal-header h3 {
    margin: 0;
    color: var(--azul-oscuro);
    font-size: 18px;
}

.chart-modal-header p {
    margin: 3px 0 0;
    color: #5d6f86;
    font-size: 12px;
}

.chart-modal-close {
    width: 34px;
    height: 34px;
    border: 1px solid var(--gris-borde);
    border-radius: 50%;
    background: #ffffff;
    color: var(--azul-oscuro);
    font-size: 24px;
    line-height: 28px;
    font-weight: 700;
    cursor: pointer;
    flex-shrink: 0;
}

.chart-modal-close:hover {
    background: #eef6ff;
}

.chart-modal-body {
    flex: 1;
    min-height: 0;
    padding: 14px;
}

.chart-modal-chart {
    width: 100%;
    height: 100%;
    min-height: 520px;
}

.side {
    display: grid;
    gap: 10px;
    min-width: 0;
}

.side-panel {
    padding: 14px;
    min-width: 0;
}

.ai-list-loading {
    position: relative;
    min-height: 118px;
    overflow: hidden;
}

.ai-list-loading::before {
    top: 2px;
    left: 0;
}

.ai-list-loading::after {
    content: "";
    display: block;
    height: 102px;
    margin-left: 28px;
    border-radius: 5px;
    background:
        linear-gradient(90deg, rgba(220, 230, 242, 0.45) 25%, rgba(238, 246, 255, 0.95) 38%, rgba(220, 230, 242, 0.45) 63%),
        linear-gradient(#dce6f2 0 0),
        linear-gradient(#dce6f2 0 0),
        linear-gradient(#dce6f2 0 0),
        linear-gradient(#dce6f2 0 0);
    background-size: 220% 100%, 100% 10px, 88% 10px, 96% 10px, 74% 10px;
    background-position: 100% 0, 0 2px, 0 31px, 0 60px, 0 89px;
    background-repeat: no-repeat;
    animation: holo-skeleton 1.1s ease-in-out infinite;
}

.side-panel h3 {
    margin: 0 0 12px;
    color: var(--azul-oscuro);
    font-size: 16px;
}

.insight,
.model-item,
.action {
    display: grid;
    grid-template-columns: 34px 1fr;
    gap: 10px;
    margin-bottom: 14px;
    align-items: start;
    font-size: 12px;
    line-height: 1.35;
}

.insight .i,
.model-item .i {
    font-size: 25px;
    text-align: center;
}

.model-item b {
    color: var(--azul-oscuro);
}

.action {
    grid-template-columns: 18px 1fr;
    margin-bottom: 9px;
}

.action input {
    margin-top: 1px;
}

@media (max-width: 1500px) {
    .header {
        grid-template-columns: 1fr 1fr;
    }

    .update {
        text-align: left;
    }

    .layout {
        grid-template-columns: 210px minmax(0, 1fr);
    }

    .side {
        grid-column: 1 / -1;
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .metrics {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

@media (max-width: 1000px) {
    .app {
        display: block;
    }

    .sidebar {
        display: none;
    }

    .main {
        width: 100%;
        max-width: 100%;
    }

    .header,
    .layout,
    .dashboard-grid,
    .panel-flex,
    .side,
    .budget-filter {
        grid-template-columns: 1fr;
    }

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

    .date-filter {
        width: 100%;
        justify-self: stretch;
    }

    .date-row {
        width: 100%;
        flex-wrap: wrap;
    }
}


@media (max-width: 1000px) {
    .panel-title-row {
        align-items: flex-start;
        flex-wrap: wrap;
    }

    .panel-actions {
        width: 100%;
        justify-content: flex-start;
    }

    .chart-modal {
        padding: 10px;
    }

    .chart-modal-content {
        width: 98vw;
        height: 92vh;
        border-radius: 10px;
    }

    .chart-modal-header {
        padding: 12px;
    }

    .chart-modal-body {
        padding: 10px;
    }

    .chart-modal-chart {
        min-height: 420px;
    }
}
