:root {
    --bg: #f5f7fb;
    --panel: #ffffff;
    --ink: #172033;
    --muted: #657083;
    --line: #dde3ee;
    --primary: #2754c5;
    --primary-dark: #1d3f94;
    --danger: #c62828;
    --danger-soft: #fff0f0;
    --success: #18844a;
    --success-soft: #eefaf3;
    --warning: #b56b00;
    --shadow: 0 12px 28px rgba(21, 31, 56, 0.10);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: Arial, Helvetica, sans-serif;
}

a {
    color: inherit;
    text-decoration: none;
}

.topbar {
    align-items: center;
    background: #101828;
    color: white;
    display: flex;
    gap: 18px;
    justify-content: space-between;
    padding: 14px 22px;
    position: sticky;
    top: 0;
    z-index: 20;
}

.topbar,
.page,
.account-card,
.panel,
.login-card {
    max-width: 100%;
}

.brand {
    align-items: center;
    display: flex;
    font-size: 21px;
    font-weight: 800;
    gap: 10px;
}

.brand img {
    background: white;
    border-radius: 6px;
    display: block;
    height: 42px;
    object-fit: contain;
    padding: 4px 8px;
    width: 150px;
}

.brand span,
.brand-mark {
    align-items: center;
    background: var(--primary);
    border-radius: 8px;
    display: inline-flex;
    height: 34px;
    justify-content: center;
    width: 34px;
}

.brand-mark {
    color: white;
    font-size: 24px;
    font-weight: 800;
    margin: 0 auto 12px;
}

.login-logo {
    display: block;
    margin: 0 auto 26px;
    max-width: 430px;
    width: 100%;
}

.nav {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.nav a {
    border-radius: 6px;
    color: #dce4f4;
    padding: 8px 10px;
}

.nav a:hover,
.download-link {
    background: rgba(255, 255, 255, 0.12);
}

.page {
    margin: 0 auto;
    max-width: 1240px;
    padding: 24px;
}

.page-head {
    align-items: center;
    display: flex;
    gap: 18px;
    justify-content: space-between;
    margin-bottom: 18px;
}

h1,
h2,
p {
    margin-top: 0;
}

h1 {
    font-size: 30px;
    margin-bottom: 6px;
}

h2 {
    font-size: 19px;
}

p {
    color: var(--muted);
}

.grid {
    display: grid;
    gap: 18px;
}

.grid.two {
    grid-template-columns: minmax(280px, 0.8fr) minmax(420px, 1.2fr);
}

.panel,
.login-card,
.account-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.panel {
    padding: 20px;
}

.panel.narrow {
    max-width: 520px;
}

.form-grid,
.stack {
    display: grid;
    gap: 14px;
}

label {
    color: var(--muted);
    display: grid;
    font-size: 14px;
    gap: 7px;
}

input,
select {
    background: white;
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--ink);
    font: inherit;
    min-height: 42px;
    padding: 9px 10px;
    width: 100%;
}

.btn {
    align-items: center;
    background: white;
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--ink);
    cursor: pointer;
    display: inline-flex;
    font: inherit;
    font-weight: 700;
    justify-content: center;
    min-height: 40px;
    padding: 9px 13px;
}

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

.btn.primary:hover {
    background: var(--primary-dark);
}

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

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

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

.btn.ghost {
    background: #f7f9fc;
}

.btn.small {
    font-size: 13px;
    min-height: 34px;
    padding: 6px 9px;
}

.actions,
.row-actions {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.table-wrap {
    overflow-x: auto;
}

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

th,
td {
    border-bottom: 1px solid var(--line);
    padding: 11px 9px;
    text-align: left;
    vertical-align: middle;
}

th {
    color: var(--muted);
    font-size: 13px;
}

.account-grid {
    display: grid;
    gap: 18px;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
}

.account-card {
    border-top: 6px solid var(--danger);
    overflow: hidden;
    padding: 16px;
    position: relative;
}

.add-item-btn {
    margin: 2px 0 16px;
    width: 100%;
}

.account-card.paid {
    border-top-color: var(--success);
}

.account-card.pending {
    background: linear-gradient(180deg, var(--danger-soft), #fff 80px);
}

.account-card.paid {
    background: linear-gradient(180deg, var(--success-soft), #fff 80px);
}

.account-card.saving::after {
    background: rgba(255, 255, 255, 0.72);
    content: 'Guardando...';
    display: grid;
    inset: 0;
    place-items: center;
    position: absolute;
}

.account-head,
.account-foot {
    align-items: center;
    display: flex;
    justify-content: space-between;
    gap: 12px;
}

.account-head h2 {
    margin: 4px 0 0;
}

.status-dot {
    color: var(--danger);
    font-size: 13px;
    font-weight: 800;
    text-transform: uppercase;
}

.paid .status-dot {
    color: var(--success);
}

.icon-btn {
    align-items: center;
    background: #eef2f8;
    border: 0;
    border-radius: 999px;
    cursor: pointer;
    display: inline-flex;
    font-size: 24px;
    height: 34px;
    justify-content: center;
    line-height: 1;
    width: 34px;
}

.consumption-list {
    display: grid;
    gap: 9px;
    margin: 16px 0;
}

.consumption-row {
    align-items: center;
    display: grid;
    gap: 8px;
    grid-template-columns: minmax(0, 1fr) 76px minmax(78px, auto);
}

.line-total {
    text-align: right;
}

.account-total span {
    color: var(--muted);
    display: block;
    font-size: 13px;
}

.account-total strong {
    font-size: 24px;
}

.quick-stats {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin-bottom: 18px;
}

.quick-stats div {
    background: white;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
}

.quick-stats strong {
    display: block;
    font-size: 22px;
}

.quick-stats span {
    color: var(--muted);
    font-size: 13px;
}

.empty,
.empty-state {
    color: var(--muted);
    text-align: center;
}

.empty-state {
    background: white;
    border: 1px dashed var(--line);
    border-radius: 8px;
    margin-top: 18px;
    padding: 32px;
}

.alert {
    border-radius: 8px;
    margin-bottom: 16px;
    padding: 12px 14px;
}

.alert.error {
    background: var(--danger-soft);
    color: var(--danger);
}

.alert.success {
    background: var(--success-soft);
    color: var(--success);
}

.alert.warning {
    background: #fff6e5;
    color: var(--warning);
}

.login-body {
    align-items: center;
    display: grid;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 24px;
    place-items: center;
}

.login-card {
    border-radius: 10px;
    max-width: 560px;
    padding: clamp(32px, 5vw, 48px);
    text-align: center;
    width: min(94vw, 560px);
}

.login-card p {
    font-size: 18px;
    margin-bottom: 20px;
}

.login-card label {
    font-size: 17px;
    text-align: left;
}

.login-card .btn {
    font-size: 18px;
    min-height: 54px;
}

.password-field {
    display: grid;
    position: relative;
}

.password-field input {
    font-size: 20px;
    min-height: 56px;
    padding-right: 58px;
}

.password-toggle {
    align-items: center;
    background: #eef2f8;
    border: 1px solid var(--line);
    border-radius: 7px;
    color: var(--ink);
    cursor: pointer;
    display: inline-flex;
    font-size: 22px;
    height: 42px;
    justify-content: center;
    position: absolute;
    right: 7px;
    top: 7px;
    width: 44px;
}

.password-toggle.is-visible {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.muted-link {
    color: var(--muted);
    display: inline-block;
    font-size: 14px;
    margin-top: 16px;
}

.modal-backdrop {
    background: rgba(16, 24, 40, 0.52);
    display: grid;
    inset: 0;
    padding: 18px;
    place-items: center;
    position: fixed;
    z-index: 50;
}

.modal-backdrop[hidden] {
    display: none;
}

.modal {
    background: white;
    border-radius: 8px;
    max-width: 420px;
    padding: 22px;
    position: relative;
    width: 100%;
}

.modal-close {
    position: absolute;
    right: 12px;
    top: 12px;
}

@media (max-width: 820px) {
    .topbar,
    .page-head {
        align-items: stretch;
        flex-direction: column;
    }

    .account-foot {
        align-items: stretch;
    }

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

    .page {
        padding: 16px;
    }
}

@media (max-width: 620px) {
    body {
        background: #f7f9fc;
    }

    .login-body {
        align-items: center;
        padding: 14px;
    }

    .login-card {
        box-shadow: 0 14px 34px rgba(21, 31, 56, 0.14);
        padding: 28px 18px;
        width: 100%;
    }

    .login-logo {
        margin-bottom: 22px;
        max-width: 360px;
    }

    .topbar {
        gap: 12px;
        padding: 12px;
        position: static;
    }

    .brand img {
        height: 38px;
        width: 138px;
    }

    .nav {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .nav a {
        background: rgba(255, 255, 255, 0.08);
        text-align: center;
    }

    .page {
        padding: 12px;
    }

    .page-head {
        gap: 10px;
        margin-bottom: 12px;
    }

    .page-head h1 {
        font-size: 24px;
        margin-bottom: 2px;
    }

    .page-head p {
        font-size: 14px;
        margin-bottom: 0;
    }

    .page-head .actions,
    .account-foot .actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        width: 100%;
    }

    .quick-stats {
        gap: 8px;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        margin-bottom: 12px;
    }

    .quick-stats div {
        padding: 10px 8px;
    }

    .quick-stats strong {
        font-size: 17px;
        overflow-wrap: anywhere;
    }

    .quick-stats span {
        font-size: 11px;
    }

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

    .account-card {
        border-radius: 8px;
        padding: 12px;
    }

    .account-head {
        align-items: flex-start;
        flex-direction: row;
    }

    .account-head h2 {
        font-size: 24px;
        line-height: 1.1;
    }

    .icon-btn {
        flex: 0 0 auto;
        height: 42px;
        width: 42px;
    }

    .consumption-row {
        grid-template-columns: minmax(0, 1fr) 70px;
        gap: 7px;
    }

    input,
    select {
        font-size: 16px;
        min-height: 44px;
        padding: 8px 9px;
    }

    .line-total {
        grid-column: 1 / -1;
        border-bottom: 1px solid var(--line);
        padding-bottom: 6px;
        text-align: right;
    }

    .consumption-list {
        gap: 8px;
        margin: 12px 0;
    }

    .account-foot {
        display: grid;
        grid-template-columns: 1fr;
    }

    .account-total strong {
        font-size: 30px;
    }

    .btn {
        min-height: 46px;
        padding: 10px;
    }
}

@media (max-width: 380px) {
    .quick-stats {
        grid-template-columns: 1fr;
    }
}
