:root {
    --bg: #f3f5f9;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --text: #152033;
    --muted: #6b7280;
    --line: #e5e7eb;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --positive: #15803d;
    --negative: #c2410c;
    --warning: #a16207;
    --shadow: 0 12px 36px rgba(15, 23, 42, .08);
    --radius: 18px;
    --sidebar: 270px;
}
* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body { margin: 0; min-height: 100vh; font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--text); background: var(--bg); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.positive { color: var(--positive) !important; }
.negative { color: var(--negative) !important; }
.hidden { display: none !important; }
.auth-view { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at top left, #dbeafe 0, transparent 35%), linear-gradient(145deg, #eff6ff, #f8fafc 55%, #eef2ff); }
.auth-card { width: min(430px, 100%); background: rgba(255,255,255,.95); border: 1px solid rgba(255,255,255,.85); border-radius: 28px; padding: 34px; box-shadow: 0 24px 70px rgba(37,99,235,.14); }
.auth-card h1 { margin: 14px 0 6px; font-size: 30px; }
.auth-card > p { margin: 0 0 24px; color: var(--muted); }
.brand-mark { width: 58px; height: 58px; border-radius: 18px; display: grid; place-items: center; color: #fff; font-weight: 800; letter-spacing: -.04em; background: linear-gradient(135deg, #2563eb, #7c3aed); box-shadow: 0 10px 25px rgba(37,99,235,.28); }
.brand-mark.small { width: 42px; height: 42px; border-radius: 13px; font-size: 14px; flex: 0 0 auto; }
.auth-tabs, .segment-tabs { display: flex; gap: 6px; overflow-x: auto; background: #eef2f7; border-radius: 14px; padding: 5px; scrollbar-width: none; }
.auth-tabs { margin-bottom: 18px; }
.auth-tabs button, .segment-tabs button { border: 0; background: transparent; color: var(--muted); padding: 10px 14px; border-radius: 10px; white-space: nowrap; font-weight: 700; }
.auth-tabs button.active, .segment-tabs button.active { color: var(--text); background: #fff; box-shadow: 0 3px 10px rgba(15,23,42,.08); }
.auth-form, .form-grid { display: grid; gap: 14px; }
label { display: grid; gap: 7px; color: #475569; font-size: 13px; font-weight: 700; }
input, select, textarea { width: 100%; border: 1px solid #d9dee8; border-radius: 12px; background: #fff; padding: 11px 12px; color: var(--text); outline: none; transition: border-color .18s, box-shadow .18s; }
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.primary-btn, .secondary-btn { border: 0; border-radius: 12px; padding: 11px 16px; font-weight: 800; }
.primary-btn { color: #fff; background: var(--primary); box-shadow: 0 8px 20px rgba(37,99,235,.2); }
.primary-btn:hover { background: var(--primary-dark); }
.secondary-btn { color: var(--text); background: #e9eef7; }
.wide { width: 100%; margin-top: 4px; }
.app-shell { min-height: 100vh; padding-left: var(--sidebar); }
.side-drawer { position: fixed; z-index: 40; inset: 0 auto 0 0; width: var(--sidebar); padding: 22px 16px; background: #111827; color: #fff; display: flex; flex-direction: column; }
.drawer-brand { display: flex; align-items: center; gap: 12px; padding: 2px 8px 24px; }
.drawer-brand strong { display: block; font-size: 15px; }
.drawer-brand small { color: #94a3b8; display: block; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; max-width: 165px; }
.side-drawer nav { display: grid; gap: 5px; }
.drawer-link, .drawer-logout { width: 100%; border: 0; border-radius: 12px; color: #cbd5e1; background: transparent; padding: 12px 13px; display: flex; align-items: center; gap: 12px; text-align: left; font-weight: 700; }
.drawer-link span { width: 22px; text-align: center; font-size: 20px; }
.drawer-link:hover, .drawer-link.active { color: #fff; background: rgba(255,255,255,.1); }
.drawer-logout { margin-top: auto; color: #fca5a5; }
.topbar { position: sticky; z-index: 20; top: 0; min-height: 76px; display: flex; align-items: center; gap: 15px; padding: 12px 26px; border-bottom: 1px solid rgba(229,231,235,.85); background: rgba(243,245,249,.88); backdrop-filter: blur(14px); }
.topbar h1 { margin: 0; font-size: 21px; }
.topbar small { color: var(--muted); }
.icon-btn { width: 42px; height: 42px; border: 0; border-radius: 12px; background: #fff; color: var(--text); font-size: 21px; box-shadow: 0 4px 14px rgba(15,23,42,.06); }
#menuBtn { display: none; }
.round-add { margin-left: auto; width: 43px; height: 43px; border-radius: 50%; border: 0; color: #fff; background: var(--primary); font-size: 24px; box-shadow: 0 8px 20px rgba(37,99,235,.25); }
.main-content { padding: 26px; max-width: 1500px; margin: 0 auto; }
.app-view { display: none; animation: fadeIn .2s ease; }
.app-view.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: translateY(0); } }
.period-row, .toolbar, .section-heading, .inline-control { display: flex; gap: 12px; align-items: end; }
.period-row { margin-bottom: 18px; flex-wrap: wrap; }
.period-row label { min-width: 160px; }
.toolbar { margin-bottom: 18px; }
.toolbar select { max-width: 230px; }
.toolbar input { max-width: 360px; }
.toolbar .primary-btn { margin-left: auto; }
.summary-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 14px; margin-bottom: 18px; }
.summary-card { position: relative; overflow: hidden; min-height: 120px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.summary-card::after { content: ""; position: absolute; width: 70px; height: 70px; right: -18px; bottom: -24px; border-radius: 50%; background: rgba(37,99,235,.08); }
.summary-card small { color: var(--muted); display: block; margin-bottom: 9px; font-weight: 700; }
.summary-card strong { display: block; font-size: 24px; letter-spacing: -.03em; }
.summary-card .sub { margin-top: 8px; color: var(--muted); font-size: 12px; }
.summary-card.positive strong { color: var(--positive); }
.summary-card.negative strong { color: var(--negative); }
.dashboard-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 16px; }
.panel { min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.span-2 { grid-column: span 2; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.panel h2, .section-heading h2 { margin: 0; font-size: 17px; }
.panel p, .section-heading p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.chart-panel canvas { width: 100%; max-height: 280px; }
.worth-list, .advice-list { display: grid; gap: 10px; }
.worth-row { display: flex; justify-content: space-between; gap: 16px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.worth-row:last-child { border: 0; padding-bottom: 0; font-weight: 800; }
.progress { height: 9px; background: #edf1f6; border-radius: 999px; overflow: hidden; margin: 8px 0 4px; }
.progress span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg,#2563eb,#7c3aed); }
.guide-block { padding: 12px; border-radius: 14px; background: #f8fafc; margin-bottom: 10px; }
.guide-line { display: flex; justify-content: space-between; gap: 12px; }
.advice-item { border-left: 4px solid var(--primary); border-radius: 10px; background: #eff6ff; color: #1e3a5f; padding: 11px 12px; font-size: 13px; line-height: 1.5; }
.record-list, .card-list { display: grid; gap: 11px; }
.record-item, .entity-card { min-width: 0; background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px; box-shadow: 0 6px 20px rgba(15,23,42,.04); }
.record-item { display: grid; grid-template-columns: minmax(0,1fr) auto auto; align-items: center; gap: 14px; }
.record-item h3, .entity-card h3 { margin: 0 0 4px; font-size: 15px; }
.record-item p, .entity-card p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.record-amount { font-weight: 850; white-space: nowrap; }
.record-amount.income { color: var(--positive); }
.record-actions { display: flex; gap: 7px; }
.mini-btn { border: 0; border-radius: 9px; background: #eef2f7; color: #334155; padding: 7px 10px; font-size: 12px; font-weight: 800; }
.mini-btn.danger { color: #b91c1c; background: #fef2f2; }
.compact .record-item { grid-template-columns: minmax(0,1fr) auto; }
.empty-state { text-align: center; padding: 42px 18px; border: 1px dashed #cbd5e1; border-radius: 16px; color: var(--muted); background: rgba(255,255,255,.55); }
.segment-tabs { margin-bottom: 18px; }
.section-heading { justify-content: space-between; margin-bottom: 16px; }
.entity-card { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 12px; }
.entity-meta { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.pill { display: inline-flex; align-items: center; border-radius: 999px; padding: 5px 8px; background: #eef2ff; color: #4338ca; font-size: 11px; font-weight: 800; }
.pill.warn { background: #fff7ed; color: #c2410c; }
.pill.good { background: #ecfdf5; color: #15803d; }
.entity-value { text-align: right; font-weight: 850; font-size: 18px; }
.entity-actions { display: flex; gap: 7px; justify-content: flex-end; margin-top: 12px; }
.inline-control label { width: 90px; }
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; min-width: 960px; }
.data-table th, .data-table td { border-bottom: 1px solid var(--line); padding: 12px 10px; text-align: right; white-space: nowrap; font-size: 13px; }
.data-table th:first-child, .data-table td:first-child { text-align: left; }
.data-table th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.muted-note { color: var(--muted); font-size: 12px; line-height: 1.5; }
.settings-panel { max-width: 850px; }
.form-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
.form-grid .full { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: flex-end; gap: 9px; padding-top: 7px; }
.checkbox-field { display: flex; align-items: center; gap: 9px; min-height: 43px; }
.checkbox-field input { width: 18px; height: 18px; }
.modal { position: fixed; z-index: 100; inset: 0; display: none; }
.modal.open { display: grid; place-items: center; padding: 18px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(15,23,42,.58); backdrop-filter: blur(3px); }
.modal-card { position: relative; width: min(760px,100%); max-height: min(88vh,900px); overflow-y: auto; background: #fff; border-radius: 22px; padding: 20px; box-shadow: 0 30px 80px rgba(0,0,0,.25); }
.modal-head { display: flex; justify-content: space-between; align-items: start; gap: 12px; margin-bottom: 18px; }
.modal-head h2 { margin: 0; }
.modal-head p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.toast { position: fixed; z-index: 150; left: 50%; bottom: 28px; transform: translate(-50%,30px); opacity: 0; pointer-events: none; background: #111827; color: #fff; border-radius: 12px; padding: 11px 16px; box-shadow: 0 10px 30px rgba(0,0,0,.22); transition: .22s; max-width: min(90vw,520px); font-size: 13px; }
.toast.show { transform: translate(-50%,0); opacity: 1; }
.toast.error { background: #991b1b; }
.drawer-overlay { display: none; }
.bottom-nav { display: none; }
.loading { opacity: .55; pointer-events: none; }
@media (max-width: 1050px) {
    :root { --sidebar: 240px; }
    .summary-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
}
@media (max-width: 820px) {
    .app-shell { padding-left: 0; padding-bottom: 82px; }
    .side-drawer { transform: translateX(-105%); transition: transform .22s ease; width: min(84vw,300px); }
    .side-drawer.open { transform: translateX(0); }
    .drawer-overlay { position: fixed; z-index: 35; inset: 0; background: rgba(15,23,42,.45); }
    .drawer-overlay.open { display: block; }
    #menuBtn { display: inline-grid; place-items: center; }
    .bottom-nav { position: fixed; z-index: 30; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(5,1fr); padding: 7px max(8px,env(safe-area-inset-left)) calc(7px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: rgba(255,255,255,.96); backdrop-filter: blur(14px); }
    .bottom-nav button { border: 0; background: transparent; color: #64748b; padding: 4px; display: grid; place-items: center; gap: 2px; }
    .bottom-nav button span { font-size: 20px; line-height: 1; }
    .bottom-nav button small { font-size: 10px; }
    .bottom-nav button.active { color: var(--primary); }
    .main-content { padding: 18px; }
    .topbar { padding: 10px 16px; min-height: 68px; }
    .dashboard-grid { grid-template-columns: 1fr; }
    .span-2 { grid-column: auto; }
}
@media (max-width: 600px) {
    .auth-card { padding: 24px; border-radius: 22px; }
    .summary-grid { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 10px; }
    .summary-card { min-height: 108px; padding: 14px; }
    .summary-card strong { font-size: 19px; }
    .period-row { display: grid; grid-template-columns: 1fr 1fr; align-items: end; }
    .period-row label { min-width: 0; }
    .period-row button { grid-column: 1/-1; }
    .toolbar { display: grid; grid-template-columns: 1fr 1fr; }
    .toolbar select, .toolbar input { max-width: none; }
    .toolbar input { grid-column: 1/-1; grid-row: 2; }
    .toolbar .primary-btn { margin: 0; }
    .form-grid { grid-template-columns: 1fr; }
    .form-grid .full { grid-column: auto; }
    .record-item { grid-template-columns: minmax(0,1fr) auto; }
    .record-actions { grid-column: 1/-1; justify-content: flex-end; }
    .section-heading { align-items: center; }
    .section-heading p { display: none; }
    .inline-control { width: 100%; justify-content: end; }
    .entity-card { grid-template-columns: 1fr; }
    .entity-value { text-align: left; }
    .entity-actions { justify-content: flex-start; }
    .modal.open { padding: 0; align-items: end; }
    .modal-card { width: 100%; max-height: 92vh; border-radius: 22px 22px 0 0; padding-bottom: calc(22px + env(safe-area-inset-bottom)); }
}

/* Offline-first edition extensions */
.lead { color: var(--muted); margin-top: -4px; }
.privacy-note { background: #eef6ff; border: 1px solid #bfdbfe; border-radius: 14px; color: #1e3a5f; font-size: 13px; line-height: 1.55; padding: 12px 14px; }
.auth-footnote { color: var(--muted); font-size: 12px; line-height: 1.45; margin: 14px 0 0; }
.side-drawer { overflow-y: auto; }
.side-drawer nav { padding-bottom: 8px; }
.catalog-badge { background: #172033; border: 1px solid #334155; border-radius: 10px; color: #cbd5e1; font-size: 11px; margin: auto 16px 10px; padding: 9px 10px; }
.tool-grid, .settings-grid { display: grid; gap: 18px; grid-template-columns: minmax(0, 1.15fr) minmax(300px, .85fr); }
.result-panel { display: flex; flex-direction: column; }
.result-panel #targetResult { flex: 1; }
.result-hero { background: linear-gradient(135deg, #eff6ff, #f8fafc); border: 1px solid #dbeafe; border-radius: 16px; margin-bottom: 12px; padding: 18px; }
.result-hero small { color: var(--muted); display: block; font-weight: 700; margin-bottom: 6px; text-transform: uppercase; }
.result-hero strong { color: var(--primary); display: block; font-size: clamp(24px, 4vw, 38px); line-height: 1.1; }
.result-grid { display: grid; gap: 10px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.result-stat { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 12px; }
.result-stat small { color: var(--muted); display: block; margin-bottom: 4px; }
.result-stat strong { font-size: 15px; }
.section-heading.minor { margin-top: 24px; }
.report-controls { align-items: end; display: grid; gap: 12px; grid-template-columns: repeat(3, minmax(160px, 1fr)) auto auto auto; margin-bottom: 18px; }
.report-controls label { min-width: 0; }
.compact-grid { grid-template-columns: repeat(4, minmax(130px, 1fr)); margin-bottom: 16px; }
.toolbar.wrap { flex-wrap: wrap; }
.file-button { align-items: center; cursor: pointer; display: inline-flex; justify-content: center; position: relative; }
.file-button input { height: 1px; opacity: 0; overflow: hidden; position: absolute; width: 1px; }
.stack-actions { display: grid; gap: 10px; }
.danger-btn { background: #fff1f2; border: 1px solid #fecdd3; border-radius: 10px; color: #be123c; cursor: pointer; font: inherit; font-weight: 750; padding: 11px 15px; }
.danger-btn:hover { background: #ffe4e6; }
.category-description { color: var(--muted); font-size: 12px; margin-top: 5px; max-width: 760px; }
.category-source { border-radius: 999px; display: inline-block; font-size: 10px; font-weight: 800; margin-left: 6px; padding: 3px 7px; text-transform: uppercase; }
.category-source.server { background: #e0f2fe; color: #075985; }
.category-source.custom { background: #ede9fe; color: #5b21b6; }
.category-source.override { background: #fef3c7; color: #92400e; }
.status-dot { border-radius: 50%; display: inline-block; height: 8px; margin-right: 5px; width: 8px; }
.status-dot.active { background: #16a34a; }
.status-dot.inactive { background: #94a3b8; }
.entity-actions { flex-wrap: wrap; }
.record-item { grid-template-columns: minmax(0, 1fr) auto auto; }
.data-table td, .data-table th { white-space: nowrap; }
.data-table td:first-child, .data-table td:nth-child(2) { white-space: normal; }
.local-only-chip { background: #dcfce7; border-radius: 999px; color: #166534; display: inline-flex; font-size: 11px; font-weight: 800; padding: 5px 9px; }
.form-hint { color: var(--muted); font-size: 11px; line-height: 1.45; margin-top: 4px; }
.entry-category-hint {
    padding: 10px 12px;
    border-radius: 10px;
    background: #f8fafc;
    border-left: 3px solid var(--primary);
}

.entry-category-hint strong {
    color: var(--primary);
}
.full-width-note { grid-column: 1 / -1; }

@media (max-width: 1100px) {
    .report-controls { grid-template-columns: repeat(3, minmax(140px, 1fr)); }
    .report-controls button { width: 100%; }
}

@media (max-width: 820px) {
    .tool-grid, .settings-grid { grid-template-columns: 1fr; }
    .report-controls { grid-template-columns: 1fr 1fr; }
    .compact-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 600px) {
    .report-controls { grid-template-columns: 1fr; }
    .result-grid { grid-template-columns: 1fr; }
    .record-item { grid-template-columns: minmax(0, 1fr) auto; }
    .record-item .record-actions { grid-column: 1 / -1; justify-content: flex-end; }
    .compact-grid { grid-template-columns: 1fr 1fr; }
}

/* Add money entry direction tabs */
.entry-flow-tabs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    padding: 5px;
    border: 1px solid var(--line);
    border-radius: 15px;
    background: #eef2f7;
}
.entry-flow-tab {
    border: 0;
    border-radius: 11px;
    background: transparent;
    color: var(--muted);
    padding: 11px 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    font-weight: 800;
}
.entry-flow-tab.active {
    background: #fff;
    color: var(--text);
    box-shadow: 0 3px 10px rgba(15,23,42,.08);
}
.entry-flow-tab[data-entry-flow="funds"].active .entry-flow-sign { color: var(--positive); }
.entry-flow-tab[data-entry-flow="deductions"].active .entry-flow-sign { color: var(--negative); }
.entry-flow-sign { font-size: 19px; line-height: 1; }
