:root {
    --primary: #0f766e;
    --primary-dark: #115e59;
    --primary-soft: #ccfbf1;
    --accent: #f59e0b;
    --bg: #f1f5f9;
    --surface: #ffffff;
    --text: #0f172a;
    --muted: #64748b;
    --border: #e2e8f0;
    --income: #16a34a;
    --income-soft: #dcfce7;
    --expense: #dc2626;
    --expense-soft: #fee2e2;
    --radius: 14px;
    --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .06);
    --topbar-h: 56px;
    --bottomnav-h: 60px;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* ===== App shell ===== */
.sidebar {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 230px;
    background: var(--primary-dark);
    color: #fff;
    padding: 20px 14px;
    z-index: 40;
}

.sidebar .brand {
    font-size: 18px;
    font-weight: 700;
    padding: 4px 10px 16px;
    letter-spacing: .2px;
}

.sidebar nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    color: rgba(255, 255, 255, .85);
    padding: 11px 12px;
    border-radius: 10px;
    margin-bottom: 2px;
    font-size: 14px;
}

.sidebar nav a:hover {
    background: rgba(255, 255, 255, .1);
    text-decoration: none;
}

.sidebar nav a.active {
    background: rgba(255, 255, 255, .16);
    color: #fff;
    font-weight: 600;
}

.topbar {
    position: sticky;
    top: 0;
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 14px;
    z-index: 30;
}

.topbar .title {
    font-weight: 700;
    font-size: 16px;
}

.topbar .user {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: var(--muted);
}

.topbar .btn-logout {
    background: none;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 13px;
    color: var(--muted);
    cursor: pointer;
}

.content {
    max-width: 720px;
    margin: 0 auto;
    padding: 16px 14px calc(var(--bottomnav-h) + 24px);
}

/* ===== Bottom navigation (mobile) ===== */
.bottomnav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: var(--bottomnav-h);
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex;
    z-index: 40;
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.bottomnav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--muted);
    font-size: 11px;
    text-decoration: none;
}

.bottomnav a .ico {
    font-size: 20px;
    line-height: 1;
}

.bottomnav a.active {
    color: var(--primary);
    font-weight: 600;
}

.bottomnav a.center {
    position: relative;
    top: -12px;
}

.bottomnav a.center .fab {
    width: 52px;
    height: 52px;
    background: var(--primary);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    box-shadow: 0 4px 12px rgba(15, 118, 110, .35);
    margin-bottom: 4px;
}

/* ===== Cards ===== */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    margin-bottom: 14px;
}

.card h3 {
    margin: 0 0 6px;
    font-size: 15px;
}

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

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

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.stat {
    text-align: center;
}

.stat .num {
    font-size: 18px;
    font-weight: 700;
}

.stat .lbl {
    font-size: 12px;
    color: var(--muted);
}

.stat .num.income {
    color: var(--income);
}

.stat .num.expense {
    color: var(--expense);
}

/* ===== Year filter ===== */
.year-filter {
    display: flex;
    gap: 8px;
    align-items: center;
    margin: 14px 0;
}

.year-filter label {
    font-weight: 600;
    white-space: nowrap;
}

.year-filter select {
    width: auto;
    flex: 1;
    margin: 0;
}

/* ===== Report tools ===== */
.report-tools .year-filter {
    margin: 0 0 16px;
}

.report-tools .grid-3 {
    margin-bottom: 18px;
}

.balance-card {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: #fff;
    border: none;
}

.balance-card .lbl {
    color: rgba(255, 255, 255, .8);
    font-size: 13px;
}

.balance-card .amount {
    font-size: 30px;
    font-weight: 800;
    margin: 4px 0 2px;
}

.balance-card .sub {
    font-size: 13px;
    color: rgba(255, 255, 255, .85);
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: 1px solid transparent;
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    background: var(--primary);
    color: #fff;
    line-height: 1.2;
}

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

.btn.block {
    width: 100%;
}

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

.btn.ghost:hover {
    background: var(--bg);
}

.btn.danger {
    background: var(--expense);
}

.btn.danger:hover {
    background: #b91c1c;
}

.btn.sm {
    padding: 6px 10px;
    font-size: 13px;
}

.btn.light {
    background: var(--primary-soft);
    color: var(--primary-dark);
}

.btn.light:hover {
    background: #99f6e4;
}

/* ===== Forms ===== */
label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 5px;
    color: var(--text);
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 15px;
    font-family: inherit;
    background: #fff;
    color: var(--text);
    margin-bottom: 12px;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, .12);
}

.field {
    margin-bottom: 4px;
}

.hint {
    font-size: 12px;
    color: var(--muted);
    margin: -6px 0 12px;
}

/* ===== Flash ===== */
.flash {
    border-radius: 10px;
    padding: 11px 14px;
    margin-bottom: 12px;
    font-size: 14px;
}

.flash.success {
    background: var(--income-soft);
    color: #14532d;
    border: 1px solid #bbf7d0;
}

.flash.error {
    background: var(--expense-soft);
    color: #7f1d1d;
    border: 1px solid #fecaca;
}

/* ===== Tables ===== */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

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

th {
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .3px;
}

tr:last-child td {
    border-bottom: none;
}

/* ===== Badges ===== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}

.badge.income {
    background: var(--income-soft);
    color: var(--income);
}

.badge.expense {
    background: var(--expense-soft);
    color: var(--expense);
}

.badge.open {
    background: var(--income-soft);
    color: var(--income);
}

.badge.closed {
    background: var(--border);
    color: var(--muted);
}

.badge.active {
    background: var(--income-soft);
    color: var(--income);
}

.badge.inactive {
    background: var(--border);
    color: var(--muted);
}

.badge.void {
    background: var(--expense-soft);
    color: var(--expense);
}

.amount.income {
    color: var(--income);
    font-weight: 600;
}

.amount.expense {
    color: var(--expense);
    font-weight: 600;
}

/* ===== Lists ===== */
.list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.list-item:last-child {
    border-bottom: none;
}

.list-item .meta {
    color: var(--muted);
    font-size: 13px;
}

.avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--primary-soft);
    color: var(--primary-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 15px;
    flex-shrink: 0;
}

/* ===== Progress ===== */
.progress {
    height: 8px;
    background: var(--border);
    border-radius: 999px;
    overflow: hidden;
}

.progress .bar {
    height: 100%;
    background: var(--primary);
    border-radius: 999px;
}

/* ===== Quick input ===== */
.quick {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.quick a {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 18px 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--text);
    font-size: 13px;
    font-weight: 600;
}

.quick a .ico {
    font-size: 26px;
}

.quick a:hover {
    border-color: var(--primary);
}

/* ===== Section title ===== */
.section-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .4px;
    margin: 4px 0 8px;
}

/* ===== Auth ===== */
.auth-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: linear-gradient(160deg, var(--primary) 0%, var(--primary-dark) 100%);
}

.auth-card {
    width: 100%;
    max-width: 360px;
    background: #fff;
    border-radius: 18px;
    padding: 26px 22px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, .18);
}

.auth-card .brand {
    text-align: center;
    font-size: 22px;
    font-weight: 800;
    color: var(--primary-dark);
    margin-bottom: 2px;
}

.auth-card .sub {
    text-align: center;
    color: var(--muted);
    font-size: 13px;
    margin-bottom: 20px;
}

/* ===== Public ===== */
.public-header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: #fff;
    padding: 14px 16px;
}

.ph-inner {
    max-width: 860px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.ph-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.ph-logo {
    width: 42px;
    height: 42px;
    border-radius: 10px;
    flex-shrink: 0;
    background: #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .18);
}

.ph-titles {
    min-width: 0;
}

.ph-brand .brand {
    font-size: 18px;
    font-weight: 800;
    letter-spacing: .3px;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ph-brand .sub {
    font-size: 12px;
    color: rgba(255, 255, 255, .85);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ph-login {
    flex-shrink: 0;
    background: #fff;
    color: var(--primary-dark);
}

.ph-login:hover {
    background: var(--primary-soft);
}

/* ===== Chart ===== */
.chart {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
    margin-bottom: 14px;
}

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

.chart-head h3 {
    margin: 0;
    font-size: 15px;
}

.chart-legend {
    display: flex;
    gap: 12px;
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
}

.chart-legend .lg {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.chart-legend i {
    width: 10px;
    height: 10px;
    border-radius: 3px;
    display: inline-block;
}

.chart-legend .lg.income i {
    background: var(--income);
}

.chart-legend .lg.expense i {
    background: var(--expense);
}

.chart-bars {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    padding-top: 10px;
}

.chart-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.chart-pair {
    height: 140px;
    width: 100%;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 2px;
}

.chart-bar {
    width: 45%;
    max-width: 16px;
    min-width: 4px;
    border-radius: 3px 3px 0 0;
}

.chart-bar.income {
    background: var(--income);
}

.chart-bar.expense {
    background: var(--expense);
}

.chart-label {
    font-size: 10px;
    color: var(--muted);
    white-space: nowrap;
}

.public-tabs {
    display: flex;
    overflow-x: auto;
    gap: 6px;
    padding: 10px 14px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
}

.public-tabs a {
    white-space: nowrap;
    padding: 7px 14px;
    border-radius: 999px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
}

.public-tabs a.active {
    background: var(--primary);
    color: #fff;
}

.public-main {
    max-width: 720px;
    margin: 0 auto;
    padding: 16px 14px 40px;
}

.check {
    color: var(--income);
    font-weight: 700;
}

.cross {
    color: var(--expense);
    font-weight: 700;
}

/* ===== Desktop ===== */
@media (min-width: 768px) {
    .sidebar {
        display: block;
    }

    .bottomnav {
        display: none;
    }

    .topbar {
        left: 230px;
    }

    .content {
        margin-left: 230px;
        max-width: 860px;
        padding-bottom: 24px;
    }

    .public-main {
        max-width: 860px;
    }

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