:root {
    --bg: #f4f7fb;
    --surface: #ffffff;
    --ink: #111827;
    --muted: #64748b;
    --line: #dbe3f0;

    --brand: #31579a;
    --brand-dark: #243f73;

    --blue: #3168c9;
    --green: #6ba844;
    --orange: #ff7a1a;
    --red: #ff1717;
    --purple: #7c3aed;

    --ok: #5da13b;
    --bad: #d91f1f;

    --shadow: 0 24px 70px rgba(15, 23, 42, .12);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background:
        radial-gradient(circle at top left, rgba(49, 87, 154, .14), transparent 34rem),
        linear-gradient(180deg, #f8fafc 0%, var(--bg) 100%);
    color: var(--ink);
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

button,
input,
select {
    font: inherit;
}

.topbar {
    background: linear-gradient(135deg, #0f172a, #31579a);
    color: #fff;
    box-shadow: 0 15px 35px rgba(15, 23, 42, .18);
    position: sticky;
    top: 0;
    z-index: 30;
}

.topbar-inner {
    width: min(1120px, calc(100% - 2rem));
    min-height: 74px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.brand {
    display: flex;
    align-items: center;
    gap: .75rem;
}

.brand-icon {
    width: 42px;
    height: 42px;
    border-radius: 15px;
    background: rgba(255, 255, 255, .14);
    display: flex;
    align-items: center;
    justify-content: center;
}

.brand strong {
    display: block;
    font-size: 1rem;
}

.brand small {
    color: rgba(255, 255, 255, .75);
}

.topbar-actions,
.form-actions,
.login-row,
.card-title-row {
    display: flex;
    align-items: center;
    gap: .7rem;
    flex-wrap: wrap;
}

.page {
    width: min(1120px, calc(100% - 2rem));
    margin: 0 auto;
    padding: 2rem 0 3rem;
}

.public-wrapper {
    display: flex;
    justify-content: center;
    margin-bottom: 2rem;
}

.expense-card {
    width: min(420px, 100%);
    background: #fff;
    border: 3px solid #31579a;
    border-radius: 66px;
    padding: 30px 31px 38px;
    box-shadow: var(--shadow);
}

.document-header {
    text-align: center;
    margin-bottom: 13px;
}

.document-header h1 {
    font-size: 14px;
    line-height: 1.25;
    margin: 0 0 12px;
    font-weight: 900;
    letter-spacing: -.01em;
}

.document-header p {
    margin: 0;
    font-size: 15px;
    color: #111;
}

.sections-list {
    display: grid;
    gap: 9px;
}

.expense-section {
    border-top: 1.7px solid #3f70d8;
}

.section-title {
    border-bottom: 1.7px solid #3f70d8;
    padding: 3px 7px 2px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
}

.section-title strong {
    font-size: 14px;
    font-weight: 900;
    text-transform: uppercase;
}

.section-title small {
    font-size: 10px;
    color: #64748b;
    white-space: nowrap;
}

.section-blue .section-title strong {
    color: var(--blue);
}

.section-green .section-title strong {
    color: var(--green);
}

.section-orange .section-title strong {
    color: var(--orange);
}

.section-red .section-title strong {
    color: var(--red);
}

.section-purple .section-title strong {
    color: var(--purple);
}

.mini-table {
    padding: 0 7px 8px;
}

.mini-head,
.mini-row {
    display: grid;
    grid-template-columns: 65px minmax(0, 1fr) 104px;
    align-items: center;
    column-gap: 8px;
}

.mini-head {
    font-size: 8px;
    font-weight: 900;
    color: #111;
    text-transform: uppercase;
    padding-top: 2px;
}

.mini-row {
    font-size: 14px;
    line-height: 1.25;
    padding: 4px 0 0;
}

.mini-date {
    white-space: nowrap;
}

.mini-concept {
    min-width: 0;
    overflow-wrap: anywhere;
}

.mini-amount {
    text-align: right;
    white-space: nowrap;
}

.empty-section {
    color: var(--muted);
    font-size: 12px;
    padding: 8px 7px;
}

.total-box {
    border-top: 4px solid #4268b7;
    margin: 8px 7px 0;
    padding: 8px 7px 0;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
}

.total-box div > strong {
    color: var(--red);
    display: block;
    font-size: 13px;
}

.total-box small {
    display: block;
    margin-top: 3px;
    font-size: 11px;
    color: #111;
}

#publicTotal {
    font-size: 18px;
    line-height: 1.1;
    text-align: right;
    white-space: nowrap;
}

.total-positive {
    color: var(--ok);
}

.total-negative {
    color: var(--bad);
}

.loading {
    color: var(--muted);
    text-align: center;
}

.admin-panel {
    display: grid;
    gap: 1rem;
}

.admin-card {
    background: rgba(255, 255, 255, .9);
    border: 1px solid rgba(226, 232, 240, .95);
    border-radius: 24px;
    padding: 1.25rem;
    box-shadow: 0 20px 50px rgba(15, 23, 42, .08);
    backdrop-filter: blur(14px);
}

.admin-card h2 {
    margin: .15rem 0 0;
    font-size: 1.1rem;
}

.eyebrow {
    color: var(--brand);
    font-size: .76rem;
    font-weight: 900;
    letter-spacing: .12em;
    text-transform: uppercase;
    margin: 0;
}

.muted {
    color: var(--muted);
    line-height: 1.55;
}

.hidden {
    display: none !important;
}

.admin-content {
    display: grid;
    gap: 1rem;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}

.span-2 {
    grid-column: span 2;
}

.form-group label {
    display: block;
    font-weight: 800;
    color: #334155;
    font-size: .85rem;
    margin-bottom: .45rem;
}

.form-control,
.form-select {
    width: 100%;
    min-height: 44px;
    border: 1px solid #d9e2ef;
    border-radius: 14px;
    background: #fff;
    color: #111827;
    padding: .7rem .85rem;
    outline: none;
}

.form-control:focus,
.form-select:focus {
    border-color: #0ea5e9;
    box-shadow: 0 0 0 .2rem rgba(14, 165, 233, .13);
}

.btn {
    min-height: 42px;
    border-radius: 13px;
    border: 1px solid transparent;
    padding: .65rem .95rem;
    font-weight: 900;
    cursor: pointer;
    transition: transform .16s ease, box-shadow .16s ease;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn-primary {
    background: var(--brand);
    border-color: var(--brand);
    color: #fff;
    box-shadow: 0 12px 24px rgba(49, 87, 154, .22);
}

.btn-primary:hover {
    background: var(--brand-dark);
}

.btn-light {
    background: rgba(255, 255, 255, .93);
    color: #1e293b;
    border-color: rgba(255, 255, 255, .55);
}

.btn-secondary {
    background: #f1f5f9;
    color: #334155;
    border-color: #e2e8f0;
}

.btn-warning {
    background: #fef3c7;
    color: #92400e;
    border-color: #fde68a;
}

.btn-danger {
    background: #fee2e2;
    color: #991b1b;
    border-color: #fecaca;
}

.btn-mini {
    min-height: 34px;
    padding: .4rem .6rem;
    border-radius: 10px;
    font-size: .84rem;
}

.table-responsive {
    width: 100%;
    overflow-x: auto;
    margin-top: 1rem;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
}

.admin-table th {
    text-align: left;
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: #475569;
    border-bottom: 1px solid var(--line);
    padding: .75rem .65rem;
}

.admin-table td {
    border-bottom: 1px solid var(--line);
    padding: .75rem .65rem;
    vertical-align: middle;
}

.badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: .28rem .6rem;
    font-size: .78rem;
    font-weight: 900;
}

.badge-blue {
    background: #dbeafe;
    color: #1d4ed8;
}

.badge-green {
    background: #dcfce7;
    color: #15803d;
}

.badge-orange {
    background: #ffedd5;
    color: #c2410c;
}

.badge-red {
    background: #fee2e2;
    color: #b91c1c;
}

.badge-purple {
    background: #ede9fe;
    color: #6d28d9;
}

.action-group {
    display: flex;
    gap: .35rem;
    flex-wrap: nowrap;
}

.toast {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 100;
    max-width: min(420px, calc(100% - 2rem));
    background: #0f172a;
    color: #fff;
    border-radius: 16px;
    padding: .9rem 1rem;
    box-shadow: 0 20px 50px rgba(15, 23, 42, .25);
    transform: translateY(1rem);
    opacity: 0;
    pointer-events: none;
    transition: .18s ease;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

.toast.ok {
    background: #15803d;
}

.toast.bad {
    background: #b91c1c;
}

.toast.warn {
    background: #b45309;
}

@media (max-width: 760px) {
    .topbar-inner,
    .page {
        width: min(100% - 1rem, 1120px);
    }

    .topbar-inner {
        align-items: flex-start;
        flex-direction: column;
        padding: .8rem 0;
    }

    .expense-card {
        border-radius: 42px;
        padding: 26px 22px 32px;
    }

    .mini-head,
    .mini-row {
        grid-template-columns: 58px minmax(0, 1fr) 92px;
        column-gap: 6px;
    }

    .mini-row {
        font-size: 12.5px;
    }

    #publicTotal {
        font-size: 15px;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .span-2 {
        grid-column: auto;
    }
}

@media print {
    .no-print,
    .topbar,
    .admin-panel,
    .toast {
        display: none !important;
    }

    body {
        background: #fff !important;
    }

    .page {
        width: 100%;
        padding: 0;
    }

    .expense-card {
        box-shadow: none;
        margin: 0 auto;
    }
}