:root {
    --green: #41a541;
    --green-dark: #2f8632;
    --green-soft: #e7f6e7;
    --navy: #102a43;
    --navy-2: #243b53;
    --ink: #102a43;
    --muted: #627d98;
    --line: #d9e2ec;
    --bg: #f1f6ff;
    --card: #fff;
    --paid: #217a21;
    --partial: #b85e00;
    --overdue: #c23030;
    --info: #1d5fb8;
    --shadow: 0 1px 2px rgba(16, 42, 67, .06);
    --sidebar: 232px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: "Source Sans 3", "Segoe UI", sans-serif;
    color: var(--ink);
    background: var(--bg);
    font-size: 16px;
    line-height: 1.45;
}
a { color: var(--green-dark); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0 0 .4rem; line-height: 1.2; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }

.app { min-height: 100vh; }
.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar);
    background: var(--navy);
    color: #d9e2ec;
    display: flex;
    flex-direction: column;
    z-index: 20;
}
.brand {
    display: flex;
    gap: .7rem;
    align-items: center;
    padding: 1rem 1rem .8rem;
    color: #fff;
    font-weight: 700;
}
.mark {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--green);
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 700;
}
.brand small { display: block; font-weight: 500; color: #9fb3c8; font-size: .75rem; }
.nav { display: flex; flex-direction: column; padding: .2rem .6rem 1rem; gap: .15rem; overflow: auto; }
.nav a {
    color: #d9e2ec;
    text-decoration: none;
    padding: .48rem .7rem;
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-left: 3px solid transparent;
}
.nav a:hover { background: var(--navy-2); color: #fff; }
.nav a.active { background: #1a3d5c; color: #fff; border-left-color: var(--green); }
.badge {
    background: var(--green);
    color: #fff;
    border-radius: 99px;
    min-width: 1.3rem;
    text-align: center;
    font-size: .75rem;
    padding: 0 .35rem;
}
.main { margin-left: var(--sidebar); min-height: 100vh; }
.topbar {
    display: flex;
    align-items: center;
    gap: .8rem;
    background: #fff;
    border-bottom: 1px solid var(--line);
    padding: .7rem 1.2rem;
    position: sticky;
    top: 0;
    z-index: 10;
}
.topbar form { display: flex; gap: .4rem; align-items: center; margin-left: auto; }
.who { color: var(--muted); font-size: .92rem; }
.content { padding: 1.2rem; max-width: 1180px; }
button.menu-btn, button.sidebar-close { display: none; }
.backdrop { display: none; }
.guest .brand { color: var(--navy); }
.guest .brand small { color: var(--muted); }

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 1rem 1.1rem;
    margin-bottom: 1rem;
}
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: .8rem; margin-bottom: 1rem; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: .9rem 1rem; box-shadow: var(--shadow); }
.stat span { display: block; color: var(--muted); font-size: .78rem; letter-spacing: .04em; text-transform: uppercase; }
.stat strong { font-size: 1.55rem; }
.stat.paid strong { color: var(--paid); }
.stat.overdue strong { color: var(--overdue); }
.stat.partial strong { color: var(--partial); }
.currency-label { font-size: .8rem; color: var(--muted); margin: .2rem 0 .4rem; }

.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .95rem; }
table.data th {
    text-align: left;
    font-size: .75rem;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--muted);
    padding: .55rem .5rem;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}
table.data td { padding: .6rem .5rem; border-bottom: 1px solid #edf2f7; vertical-align: middle; }
table.data tr:hover td { background: #f7faff; }
.right { text-align: right; }
.money-good { color: var(--paid); font-weight: 600; }
.money-bad { color: var(--overdue); font-weight: 700; }
.muted { color: var(--muted); }
.tight { margin: 0; }

.status {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    border-radius: 99px;
    padding: .12rem .55rem;
    font-size: .82rem;
    font-weight: 600;
    background: var(--green-soft);
    color: var(--paid);
}
.status::before { content: ""; width: .45rem; height: .45rem; border-radius: 50%; background: currentColor; }
.status-partial, .status-due { background: #fff4e5; color: var(--partial); }
.status-overdue, .status-urgent, .status-failed, .status-denied, .status-fail { background: #fdecec; color: var(--overdue); }
.status-open, .status-info, .status-new, .status-pending, .status-submitted, .status-queued { background: #e8f1fc; color: var(--info); }
.status-void, .status-ended, .status-offline { background: #eef2f6; color: var(--muted); }
.status-in_progress, .status-progress { background: #fff4e5; color: var(--partial); }

.filters { display: flex; flex-wrap: wrap; gap: .4rem; margin: .6rem 0 1rem; }
.filters a, .chip {
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink);
    text-decoration: none;
    border-radius: 8px;
    padding: .35rem .7rem;
    font-size: .92rem;
}
.filters a.active, .chip.active { background: var(--navy); color: #fff; border-color: var(--navy); }

.btn, button.btn, a.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .35rem;
    background: var(--green);
    color: #fff;
    border: 0;
    border-radius: 8px;
    padding: .55rem .9rem;
    text-decoration: none;
    cursor: pointer;
    font-weight: 600;
}
.btn:hover { background: var(--green-dark); }
button.btn.menu-btn, button.btn.sidebar-close { display: none; }
.btn-navy { background: var(--navy); }
.btn-navy:hover { background: var(--navy-2); }
.btn-ghost { background: #fff; color: var(--navy); border: 1px solid var(--line); }
.btn-ghost:hover { background: var(--bg); }
.btn-danger { background: #fff; color: var(--overdue); border: 1px solid #f3c1c1; }
.btn-small { padding: .3rem .55rem; font-size: .85rem; }

.field { display: flex; flex-direction: column; gap: .25rem; margin-bottom: .75rem; }
.field span { font-size: .86rem; font-weight: 600; }
input[type="text"], input[type="email"], input[type="password"], input[type="date"], input[type="number"], select, textarea {
    width: 100%;
    border: 1px solid #bcccdc;
    border-radius: 8px;
    padding: .55rem .7rem;
    background: #fff;
}
textarea { min-height: 90px; resize: vertical; }
.grid-2, .grid-3 { display: grid; gap: .8rem; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.check { display: flex; gap: .45rem; align-items: center; margin: .4rem 0 .8rem; }
.check input { width: auto; }

.banner { border-radius: 10px; padding: .7rem .9rem; margin-bottom: .8rem; }
.banner-info { background: #e8f1fc; color: var(--info); }
.banner-paid { background: var(--green-soft); color: var(--paid); }
.banner-overdue { background: #fdecec; color: var(--overdue); }
.error { color: var(--overdue); font-size: .82rem; }
.empty { color: var(--muted); padding: .6rem 0; }

.ledger { display: grid; grid-template-columns: 2fr 1fr; gap: 1rem; }
.kv { display: flex; justify-content: space-between; gap: 1rem; padding: .35rem 0; border-bottom: 1px solid #edf2f7; }
.section-title { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: .6rem; }
details.panel { margin-top: .4rem; }
details.panel summary { cursor: pointer; font-weight: 700; }
.pad-wrap { border: 1px dashed #9fb3c8; border-radius: 10px; background: #fff; }
canvas#pad { width: 100%; height: 160px; touch-action: none; display: block; }
.hero-balance { font-size: 2rem; font-weight: 700; }
.guest {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1.5rem;
    background: linear-gradient(#102a43 0 180px, #f1f6ff 180px);
}
.guest .card { width: min(460px, 100%); }
.demo { display: flex; flex-wrap: wrap; gap: .4rem; }
.note { font-size: .9rem; color: var(--muted); }
.photo { max-width: 100%; border-radius: 8px; border: 1px solid var(--line); }
.message { padding: .6rem 0; border-bottom: 1px solid #edf2f7; }
.message strong { display: block; }

@media (max-width: 900px) {
    button.btn.menu-btn { display: inline-flex; }
    .sidebar { transform: translateX(-105%); transition: transform .18s ease; }
    .sidebar.open { transform: none; }
    .sidebar.open button.btn.sidebar-close { display: inline-flex; margin-left: auto; color: #fff; background: transparent; border-color: transparent; }
    .sidebar.open ~ .backdrop { display: block; position: fixed; inset: 0; background: rgba(16, 42, 67, .45); z-index: 15; }
    .main { margin-left: 0; }
    .stats, .grid-2, .grid-3, .ledger { grid-template-columns: 1fr; }
    .topbar { flex-wrap: wrap; }
    .topbar form { margin-left: 0; }
    .who { display: none; }
    .portfolio-switch { flex: 1 1 100%; }
    .portfolio-switch select { width: 100%; }
    .content { padding: .8rem; }
}
