:root {
    --bg: #f4f6fb;
    --surface: #ffffff;
    --border: #e2e6ee;
    --text: #1c2130;
    --text-muted: #6b7280;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-soft: #eaf1ff;
    --danger: #dc2626;
    --danger-soft: #fef2f2;
    --success: #16a34a;
    --success-soft: #ecfdf3;
    --warn: #d97706;
    --warn-soft: #fffbeb;
    --radius: 10px;
}

* { box-sizing: border-box; }

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

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

h1, h2, h3 { margin: 0 0 4px; }

/* ---------- Layout ---------- */

.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 230px;
    flex: none;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 20px 16px;
}

.brand {
    display: flex;
    align-items: center;
    padding: 4px 8px 20px;
}

.brand-logo {
    width: 100%;
    max-width: 176px;
    height: auto;
}

.nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
}

.nav a {
    display: block;
    padding: 10px 12px;
    border-radius: 8px;
    color: var(--text-muted);
    font-weight: 500;
    font-size: 14px;
}

.nav a:hover { background: var(--bg); text-decoration: none; }
.nav a.active { background: var(--primary-soft); color: var(--primary-dark); }

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 8px;
    border-top: 1px solid var(--border);
    margin-top: 12px;
}

.avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--bg);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    flex: none;
}

.who { display: flex; flex-direction: column; min-width: 0; }
.who strong { font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who span { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.content {
    flex: 1;
    padding: 32px 40px;
    max-width: 1100px;
}

.content-guest {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

/* ---------- Guest / auth pages ---------- */

.auth-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px;
    width: 100%;
    max-width: 380px;
}

.auth-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 24px;
}

.auth-logo-img {
    width: 100%;
    max-width: 220px;
    height: auto;
}

.auth-footer {
    text-align: center;
    margin-top: 18px;
    font-size: 14px;
    color: var(--text-muted);
}

/* ---------- Page header ---------- */

.page-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 24px;
}

.page-head p { color: var(--text-muted); margin: 4px 0 0; font-size: 14px; }

/* ---------- Buttons ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: 8px;
    border: 1px solid transparent;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
}

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

.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--bg); }

.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-block { width: 100%; justify-content: center; }

/* ---------- Cards / grid ---------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}

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

@media (max-width: 900px) {
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
    .app-shell { flex-direction: column; }
    .sidebar { width: 100%; flex-direction: row; align-items: center; flex-wrap: wrap; }
    .nav { flex-direction: row; flex-wrap: wrap; }
    .content { padding: 20px; }
}

.stat-label { font-size: 13px; color: var(--text-muted); }
.stat-value { font-size: 24px; font-weight: 700; margin-top: 4px; }
.stat-value.positive { color: var(--text); }
.stat-value.negative { color: var(--danger); }
.stat-value.income { color: var(--success); }
.stat-value.expense { color: var(--danger); }

/* ---------- Forms ---------- */

.form-group { margin-bottom: 14px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

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

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="month"], select, textarea {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid var(--border);
    border-radius: 7px;
    font-size: 14px;
    font-family: inherit;
    background: #fff;
    color: var(--text);
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

input[type="color"] { width: 60px; height: 38px; padding: 2px; border: 1px solid var(--border); border-radius: 7px; }

.help-text { font-size: 12.5px; color: var(--text-muted); margin-top: 4px; }
.field-error { font-size: 12.5px; color: var(--danger); margin-top: 4px; }

.checkbox-row { display: flex; align-items: center; gap: 8px; font-weight: 500; font-size: 14px; }
.checkbox-row input { width: auto; }

.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }

.type-toggle { display: flex; background: var(--bg); border-radius: 8px; padding: 4px; margin-bottom: 14px; }
.type-toggle label {
    flex: 1;
    text-align: center;
    padding: 8px 0;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13.5px;
    margin: 0;
    color: var(--text-muted);
}
.type-toggle input { display: none; }
.type-toggle label:has(input:checked) { background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.06); color: var(--text); }

/* ---------- Table ---------- */

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

table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th {
    text-align: left;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
}
tbody td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:hover { background: #fafbfd; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-danger { color: var(--danger); font-weight: 600; }
.empty-row td { text-align: center; padding: 40px 12px; color: var(--text-muted); }

/* ---------- Badges / pills ---------- */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12.5px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    font-family: inherit;
}
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-muted { background: var(--bg); color: var(--text-muted); }
.badge-info { background: var(--primary-soft); color: var(--primary-dark); }

.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* ---------- Progress ---------- */

.progress {
    height: 8px;
    border-radius: 999px;
    background: var(--bg);
    overflow: hidden;
}
.progress-bar { height: 100%; border-radius: 999px; background: var(--success); }
.progress-bar.warn { background: var(--warn); }
.progress-bar.danger { background: var(--danger); }

/* ---------- Flash messages ---------- */

.flash {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 14px;
}
.flash-success { background: var(--success-soft); color: var(--success); }
.flash-error { background: var(--danger-soft); color: var(--danger); }

/* ---------- Credit card visual ---------- */

.cc-card {
    border-radius: var(--radius);
    padding: 20px;
    color: #fff;
    position: relative;
    overflow: hidden;
}
.cc-card .cc-top { display: flex; justify-content: space-between; align-items: flex-start; }
.cc-card .cc-limit-label { font-size: 12px; opacity: .75; margin-top: 18px; }
.cc-card .cc-limit-value { font-size: 20px; font-weight: 700; }
.cc-card .cc-limit-total { font-size: 12px; opacity: .7; }
.cc-card .cc-days { display: flex; justify-content: space-between; font-size: 12px; opacity: .85; margin-top: 16px; }
.cc-card .cc-actions { display: flex; gap: 8px; margin-top: 14px; }
.cc-card .cc-actions a, .cc-card .cc-actions button {
    flex: 1;
    text-align: center;
    background: rgba(255,255,255,.15);
    color: #fff;
    border: none;
    padding: 8px;
    border-radius: 7px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}
.cc-card .cc-actions a:hover, .cc-card .cc-actions button:hover { background: rgba(255,255,255,.25); text-decoration: none; }

/* ---------- Filters bar ---------- */

.filters {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}
.filters select, .filters input { max-width: 200px; }

.month-nav { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.month-nav select { width: auto; }
.month-nav .btn-sm { padding: 9px 12px; font-size: 16px; line-height: 1; }

/* ---------- Pagination ---------- */

.pagination { display: flex; gap: 6px; margin-top: 16px; flex-wrap: wrap; }
.pagination a, .pagination span {
    padding: 6px 11px;
    border-radius: 6px;
    border: 1px solid var(--border);
    font-size: 13px;
    color: var(--text);
}
.pagination a:hover { background: var(--bg); text-decoration: none; }
.pagination .current { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ---------- Charts ---------- */

.chart-box { position: relative; height: 260px; }

/* ---------- Misc ---------- */

.section-title {
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 12px;
}
.mt-24 { margin-top: 24px; }
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
