:root {
    --pc-primary: #2f6b4f;
    --pc-primary-dark: #24543e;
    --pc-primary-soft: #e6f0eb;
    --pc-sidebar: #17322a;
    --pc-bg: #f5f7f6;
    --pc-surface: #ffffff;
    --pc-border: #e3e8e5;
    --pc-hover: #eef2f0;
    --pc-text: #1d2a25;
    --pc-muted: #6b7a73;
    --pc-warn: #b7791f;
    --pc-warn-soft: #fbf3e4;
    --pc-radius: 12px;

    --bs-primary: var(--pc-primary);
    --bs-primary-rgb: 47, 107, 79;
    --bs-link-color: var(--pc-primary);
    --bs-link-color-rgb: 47, 107, 79;
    --bs-link-hover-color: var(--pc-primary-dark);
    --bs-body-font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --bs-body-color: var(--pc-text);
    --bs-body-bg: var(--pc-bg);
    --bs-border-radius: 8px;
}

html, body {
    font-family: var(--bs-body-font-family);
    background: var(--pc-bg);
    color: var(--pc-text);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { font-weight: 700; letter-spacing: -.01em; }
h1:focus { outline: none; }

.btn-primary {
    --bs-btn-bg: var(--pc-primary);
    --bs-btn-border-color: var(--pc-primary);
    --bs-btn-hover-bg: var(--pc-primary-dark);
    --bs-btn-hover-border-color: var(--pc-primary-dark);
    --bs-btn-active-bg: var(--pc-primary-dark);
    --bs-btn-active-border-color: var(--pc-primary-dark);
    font-weight: 600;
}

.form-control:focus, .form-check-input:focus, .btn:focus-visible {
    border-color: var(--pc-primary);
    box-shadow: 0 0 0 .2rem rgba(47, 107, 79, .2);
}
.form-check-input:checked { background-color: var(--pc-primary); border-color: var(--pc-primary); }

/* ---------- Menú lateral ---------- */
.nav-toggle { display: none; }

.brand {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: 1.25rem 1.25rem 1.5rem;
}
.brand-mark {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: #3f8a66;
    color: #fff;
    display: grid;
    place-items: center;
    font-size: 1.15rem;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { color: #fff; font-size: .98rem; }
.brand-text small { color: #9db8ab; font-size: .75rem; }

.nav-list { display: flex; flex-direction: column; padding: 0 .75rem 1.5rem; gap: 2px; }

.nav-section {
    text-transform: uppercase;
    font-size: .68rem;
    letter-spacing: .08em;
    color: #7f9c8f;
    padding: 1.1rem .75rem .4rem;
    font-weight: 600;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: .55rem .75rem;
    border-radius: 8px;
    color: #cfded6;
    text-decoration: none;
    font-size: .92rem;
    font-weight: 500;
}
.nav-item i { font-size: 1.05rem; width: 1.2rem; text-align: center; }
.nav-item:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-item.active { background: rgba(255,255,255,.12); color: #fff; }
.nav-item.disabled { opacity: .5; cursor: default; }
.nav-item.disabled:hover { background: transparent; color: #cfded6; }
.nav-item em {
    margin-left: auto;
    font-style: normal;
    font-size: .65rem;
    background: rgba(255,255,255,.1);
    padding: .1rem .45rem;
    border-radius: 999px;
}

/* ---------- Componentes ---------- */
.page-header { margin-bottom: 1.5rem; }
.page-header h1 { font-size: 1.6rem; margin: 0; }
.page-header p { color: var(--pc-muted); margin: .25rem 0 0; }

.card-pc {
    background: var(--pc-surface);
    border: 1px solid var(--pc-border);
    border-radius: var(--pc-radius);
    padding: 1.25rem;
}

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1.75rem; }
.stat-label { color: var(--pc-muted); font-size: .8rem; font-weight: 500; }
.stat-value { font-size: 1.7rem; font-weight: 700; margin-top: .15rem; }

.section-title { font-size: 1.05rem; font-weight: 600; margin: 0 0 .9rem; }

.edificios { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; }
.edificio-head { display: flex; align-items: center; gap: .75rem; margin-bottom: 1rem; }
.edificio-code {
    width: 44px; height: 44px; border-radius: 10px;
    background: var(--pc-primary-soft); color: var(--pc-primary);
    display: grid; place-items: center; font-weight: 700;
}
.edificio-head small { color: var(--pc-muted); }

.badge-pc {
    display: inline-flex; align-items: center; gap: .3rem;
    font-size: .72rem; font-weight: 600; white-space: nowrap;
    padding: .2rem .55rem; border-radius: 999px;
    background: var(--pc-warn-soft); color: var(--pc-warn);
}

.aptos { display: grid; grid-template-columns: repeat(4, 1fr); gap: .45rem; }
.apto {
    border: 1px solid var(--pc-border);
    border-radius: 8px;
    padding: .45rem .3rem;
    text-align: center;
    font-size: .85rem;
    font-weight: 600;
    background: var(--pc-bg);
}

.empty {
    text-align: center;
    padding: 2.5rem 1rem;
    color: var(--pc-muted);
}
.empty i { font-size: 2rem; display: block; margin-bottom: .5rem; }

/* ---------- Pantalla de acceso ---------- */
.auth-wrap {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1.5rem 1rem;
    background: linear-gradient(160deg, #17322a 0%, #2f6b4f 100%);
}
.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--pc-surface);
    border-radius: 16px;
    padding: 2rem 1.75rem;
    box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
.auth-brand { text-align: center; margin-bottom: 1.5rem; }
.auth-brand .brand-mark { margin: 0 auto .75rem; width: 52px; height: 52px; font-size: 1.5rem; background: var(--pc-primary); }
.auth-brand h1 { font-size: 1.3rem; margin: 0; }
.auth-brand p { color: var(--pc-muted); margin: .25rem 0 0; font-size: .9rem; }

/* ---------- Validación / errores (Blazor) ---------- */
.valid.modified:not([type=checkbox]) { outline: 1px solid #26b050; }
.invalid { outline: 1px solid #e50000; }
.validation-message { color: #c53030; font-size: .85rem; }

#blazor-error-ui {
    background: #fff4e5;
    color: #7a4b00;
    bottom: 0;
    box-shadow: 0 -1px 4px rgba(0,0,0,.15);
    display: none;
    left: 0;
    padding: .7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: .75rem; top: .5rem; }

.blazor-error-boundary { background: #b32121; padding: 1rem; color: white; border-radius: 8px; }
.blazor-error-boundary::after { content: "Ocurrió un error."; }

.darker-border-checkbox.form-check-input { border-color: #929292; }

.apto small { display: block; font-size: .68rem; font-weight: 500; color: var(--pc-warn); }
.apto-especial { border-color: #ecd5a8; background: var(--pc-warn-soft); }

/* ---------- Tablas ---------- */
.table-pc { --bs-table-bg: transparent; font-size: .92rem; }
.table-pc thead th {
    font-size: .74rem; text-transform: uppercase; letter-spacing: .05em;
    color: var(--pc-muted); font-weight: 600; background: var(--pc-bg);
    border-bottom: 1px solid var(--pc-border); padding: .65rem 1rem;
}
.table-pc td { padding: .7rem 1rem; vertical-align: middle; border-color: var(--pc-border); }
.table-pc tbody tr:last-child td { border-bottom: 0; }
.row-link { cursor: pointer; }
.row-link:hover td { background: var(--pc-hover); }
tr.inactivo td { color: var(--pc-muted); }
.fila-edicion td { background: var(--pc-primary-soft); }
.edificio-code.sm { width: 34px; height: 34px; font-size: .8rem; border-radius: 8px; }
.icon-btn-sm { border: 0; background: transparent; color: var(--pc-muted); padding: .25rem .45rem; border-radius: 6px; }
.icon-btn-sm:hover { background: var(--pc-hover); color: var(--pc-text); }
.back-link { color: var(--pc-muted); text-decoration: none; font-size: .88rem; font-weight: 500; }
.back-link:hover { color: var(--pc-primary); }

/* ---------- Personas ---------- */
.filtros { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; margin-bottom: 1rem; }
.filtros .input-icon { flex: 1 1 260px; }
.filtros .form-select { width: auto; min-width: 180px; }
.input-icon { position: relative; }
.input-icon i { position: absolute; left: .75rem; top: 50%; transform: translateY(-50%); color: var(--pc-muted); }
.input-icon .form-control { padding-left: 2.2rem; }
.avatar.sm { width: 30px; height: 30px; font-size: .8rem; flex-shrink: 0; }
.chip {
    display: inline-flex; align-items: center; gap: .3rem;
    font-size: .78rem; font-weight: 600;
    padding: .15rem .5rem; border-radius: 6px;
    background: var(--pc-bg); border: 1px solid var(--pc-border);
}
.chip small { color: var(--pc-muted); font-weight: 500; }
.chip i { color: #d69e2e; font-size: .7rem; }
.chip-prop { background: var(--pc-primary-soft); border-color: #cfe1d7; }
.nuevo-vinculo { background: var(--pc-primary-soft); padding: .9rem 1rem; border-top: 1px solid var(--pc-border); }
.avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: var(--pc-primary); color: #fff;
    display: grid; place-items: center; font-weight: 600; font-size: .9rem;
}

/* ---------- Cobros ---------- */
.seg { display: inline-flex; background: var(--pc-surface); border: 1px solid var(--pc-border); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: .35rem .9rem; border-radius: 7px; font-weight: 600; font-size: .88rem; color: var(--pc-muted); }
.seg button.on { background: var(--pc-primary); color: #fff; }
.mes-nav { display: inline-flex; align-items: center; gap: .25rem; background: var(--pc-surface); border: 1px solid var(--pc-border); border-radius: 10px; padding: 3px 6px; }
.mes-nav span { min-width: 140px; text-align: center; font-weight: 600; font-size: .92rem; }
.aviso { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; background: var(--pc-warn-soft); color: #7a5212; border: 1px solid #ecd5a8; border-radius: 10px; padding: .7rem 1rem; font-size: .9rem; }
.saldo { font-weight: 600; font-size: .85rem; padding: .15rem .55rem; border-radius: 999px; white-space: nowrap; }
.saldo.debe { background: #fdecec; color: #b42318; }
.saldo.favor { background: #e7f4ec; color: #1f7a45; }
.saldo.al-dia { color: #1f7a45; }
.stat-value .saldo { font-size: 1.3rem; }

/* ---------- Informe ---------- */
.table-pc tfoot td { background: var(--pc-bg); border-top: 1px solid var(--pc-border); }
.informe-head h2 { font-size: 1.25rem; margin: .1rem 0 1rem; }
.balance { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; background: var(--pc-surface); border: 1px solid var(--pc-border); border-radius: var(--pc-radius); padding: 1rem 1.25rem; margin-bottom: 1rem; }
.balance > div:not(.op) { display: flex; flex-direction: column; }
.balance span { font-size: .78rem; color: var(--pc-muted); font-weight: 500; }
.balance strong { font-size: 1.35rem; }
.balance .op { font-size: 1.3rem; color: var(--pc-muted); }
.balance .total { margin-left: auto; background: var(--pc-primary-soft); padding: .4rem .9rem; border-radius: 10px; }
.balance .total strong { color: var(--pc-primary); }
h3.section-title { font-size: 1rem; }

@media print {
    .sidebar, .topbar, .no-print, #blazor-error-ui { display: none !important; }
    body, .main { background: #fff; }
    .content { padding: 0; max-width: none; }
    .card-pc, .balance { border-color: #ccc; break-inside: avoid; }
}

/* ---------- Gas ---------- */
.input-lectura { max-width: 110px; min-width: 84px; }
.fila-error td { background: #fdecec; }
.foto-medidores { display: block; flex-grow: 1; }
.foto-medidores img { width: 100%; max-height: 220px; object-fit: cover; border-radius: 8px; border: 1px solid var(--pc-border); }

/* Editor de recuadros */
.foto-editor { position: relative; touch-action: none; user-select: none; cursor: crosshair; border-radius: 8px; overflow: hidden; border: 1px solid var(--pc-border); }
.foto-editor img { display: block; width: 100%; pointer-events: none; }
.recuadro { position: absolute; border: 2px solid #22c55e; background: rgba(34,197,94,.15); pointer-events: none; }
.recuadro span { position: absolute; top: -1.35rem; left: -2px; background: #22c55e; color: #fff; font-size: .7rem; font-weight: 700; padding: 0 .3rem; border-radius: 4px 4px 0 0; }
.recuadro.activo { border-color: #f59e0b; background: rgba(245,158,11,.18); }
.recuadro.activo span { background: #f59e0b; }
.recuadro.dibujando { border: 2px dashed #f59e0b; background: rgba(245,158,11,.12); }
.chip-btn { border: 1px solid var(--pc-border); background: var(--pc-surface); border-radius: 999px; padding: .2rem .7rem; font-size: .82rem; font-weight: 600; }
.chip-btn.hecho { border-color: #9fd3b4; color: #1f7a45; }
.chip-btn.on { background: #f59e0b; border-color: #f59e0b; color: #fff; }

/* Contador ampliado junto a cada lectura */
.celda-contador { width: 1%; }
.contador-zoom { width: 170px; background-repeat: no-repeat; border-radius: 6px; border: 1px solid var(--pc-border); background-color: #222; }
@media (max-width: 560px) { .contador-zoom { width: 120px; } }
.sug-alta { color: #2f8a5b; }
.sug-media { color: #d69e2e; }
.sug-baja { color: #c53030; }

/* Conceptos a pagar */
.conceptos-pago { background: var(--pc-surface); border: 1px solid var(--pc-border); border-radius: 8px; padding: .6rem .75rem; }
.concepto-item { display: flex; align-items: center; gap: .6rem; padding: .3rem 0; border-top: 1px dashed var(--pc-border); font-size: .9rem; cursor: pointer; margin: 0; }
.estado-cargo { font-size: .7rem; font-weight: 600; padding: .05rem .45rem; border-radius: 999px; margin-left: .3rem; white-space: nowrap; }
.estado-cargo.pagado { background: #e7f4ec; color: #1f7a45; }
.estado-cargo.parcial { background: var(--pc-warn-soft); color: var(--pc-warn); }
.estado-cargo.pendiente { background: #fdecec; color: #b42318; }

/* ---------- Móvil y tabletas ---------- */
/* Las tablas anchas se desplazan dentro de su tarjeta en lugar de cortarse. */
.card-pc.overflow-hidden:has(> .table), .card-pc.overflow-hidden:has(> table) { overflow-x: auto !important; -webkit-overflow-scrolling: touch; }
.card-pc > .table-pc { min-width: 100%; }

@media (max-width: 860px) {
    .page-header { margin-bottom: 1rem; }
    .page-header h1 { font-size: 1.35rem; }
    .page-header .btn { width: 100%; }

    /* Indicadores en dos columnas y más compactos. */
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem; margin-bottom: 1rem; }
    .stats .card-pc { padding: .75rem .9rem; }
    .stats .stat-value { font-size: 1.25rem; }

    /* Filtros: edificio y mes en una fila completa cada uno. */
    .filtros { gap: .5rem; }
    .filtros .seg { max-width: 100%; overflow-x: auto; }
    .filtros .mes-nav { flex: 1 1 auto; justify-content: space-between; }
    .filtros .form-select, .filtros .input-icon { flex: 1 1 100%; min-width: 0; }

    /* Balance (saldo anterior + ingresos − gastos = saldo) en cuadrícula. */
    /* Balance: una línea por concepto (etiqueta a la izquierda, monto a la derecha). */
    .balance { flex-direction: column; align-items: stretch; gap: .35rem; padding: .8rem 1rem; }
    .balance > div:not(.op) { flex-direction: row !important; justify-content: space-between; align-items: baseline; gap: 1rem; }
    .balance strong { font-size: 1.05rem; }
    .balance .op { display: none; }
    .balance .total { margin-left: 0; margin-top: .2rem; }

    /* Tablas más compactas. */
    .table-pc { font-size: .85rem; }
    .table-pc td, .table-pc th { padding: .55rem .6rem; }
    .table-pc thead th, .table-pc td.text-end, .table-pc td .btn { white-space: nowrap; }

    /* Formularios en tarjetas: botones a lo ancho y fáciles de tocar. */
    .card-pc .d-flex.gap-2 > .btn { flex: 1 1 auto; }
    .btn-sm { padding: .4rem .65rem; }
    .form-control-sm, .form-select-sm { font-size: 16px; } /* evita el zoom automático de iOS */
    .alert { font-size: .9rem; }
    .alert.d-flex { flex-wrap: wrap; }

    .edificios { grid-template-columns: 1fr !important; }
    .informe-head h2 { font-size: 1.15rem; }
}

@media (max-width: 400px) {
    .stats { grid-template-columns: 1fr 1fr; }
    .seg button { padding: .35rem .65rem; }
}

/* ---------- Directorio de vecinos ---------- */
.vecinos { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; }
.vecinos .card-pc { padding: 1rem; }
.vecino-mio { border-color: var(--pc-primary); }
.vecino-persona { display: flex; align-items: center; gap: .4rem; padding: .45rem 0; border-top: 1px solid var(--pc-border); }
@media (max-width: 860px) { .vecinos { grid-template-columns: 1fr; gap: .6rem; } .vecino-persona .btn { flex: 0 0 auto !important; } }

/* ---------- Gráfico de barras por mes ---------- */
.barras-meses { background: var(--pc-surface); border: 1px solid var(--pc-border); border-radius: var(--pc-radius); padding: 1rem 1.25rem; margin-bottom: 1rem; }
.bm-titulo { font-weight: 600; font-size: .95rem; margin-bottom: .75rem; }
/* Cada columna lleva su valor, su barra y su mes: siempre alineados. */
.bm-area { display: grid; column-gap: 0; }
.bm-col { display: flex; flex-direction: column; align-items: center; min-width: 0; }
.bm-valor { font-size: .82rem; color: var(--pc-text); margin-bottom: .25rem; white-space: nowrap; }
.bm-pista { height: 160px; width: 100%; display: flex; align-items: flex-end; justify-content: center; border-bottom: 1px solid var(--pc-border); }
.bm-barra { width: 56%; max-width: 64px; background: var(--pc-primary-soft); border: 1px solid var(--pc-primary); border-bottom: 0; border-radius: 4px 4px 0 0; min-height: 2px; transition: filter .15s; }
.bm-barra.actual { background: var(--pc-primary); }
.bm-col:hover .bm-barra { filter: brightness(.92); }
.bm-etiqueta { font-size: .78rem; color: var(--pc-muted); margin-top: .35rem; text-align: center; white-space: nowrap; }
.bm-nota { font-size: .8rem; color: var(--pc-muted); margin-top: .6rem; }
@media print { .barras-meses { break-inside: avoid; border-color: #ccc; } }
@media (max-width: 860px) {
    .barras-meses { padding: .8rem .75rem; }
    .bm-pista { height: 130px; }
    .bm-barra { width: 64%; }
    .bm-valor { font-size: .68rem; }
    .bm-etiqueta { font-size: .68rem; white-space: normal; line-height: 1.15; }
}
