/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #f5f4f0;
    --surface: #ffffff;
    --surface2: #f0efe9;
    --border: rgba(0,0,0,0.1);
    --border2: rgba(0,0,0,0.06);
    --text: #1a1a18;
    --text2: #6b6b65;
    --text3: #a0a099;
    --green: #1D9E75;
    --green-bg: #e1f5ee;
    --red: #D85A30;
    --red-bg: #faece7;
    --blue: #378ADD;
    --blue-bg: #e6f1fb;
    --radius: 10px;
    --radius-lg: 14px;
    --shadow: 0 1px 3px rgba(0,0,0,0.07), 0 1px 2px rgba(0,0,0,0.04);
    --font: 'Inter', 'Helvetica Neue', system-ui, sans-serif;
}

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=IBM+Plex+Mono:wght@400;500&display=swap');

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
    min-height: 100vh;
}

/* ── Layout ── */
.app-shell { display: flex; flex-direction: column; min-height: 100vh; }

nav {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    gap: 0;
    height: 56px;
    position: sticky; top: 0; z-index: 50;
}
.nav-brand {
    font-size: 16px; font-weight: 600; color: var(--text);
    display: flex; align-items: center; gap: 8px;
    margin-right: 2rem; text-decoration: none;
}
.nav-brand .logo { font-size: 20px; }
.nav-links { display: flex; gap: 2px; }
.nav-link {
    padding: 6px 14px; border-radius: var(--radius);
    font-size: 14px; color: var(--text2);
    text-decoration: none; font-weight: 500;
    transition: all 0.15s;
}
.nav-link:hover { background: var(--surface2); color: var(--text); }
.nav-link.active { background: var(--text); color: var(--surface); }
.nav-right { margin-left: auto; font-size: 13px; color: var(--text3); }

main { max-width: 1100px; margin: 0 auto; padding: 2rem 1.5rem; width: 100%; }

/* ── Cards ── */
.card {
    background: var(--surface);
    border: 1px solid var(--border2);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}
.card-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border2);
    display: flex; align-items: center; justify-content: space-between;
}
.card-title { font-size: 14px; font-weight: 600; color: var(--text); }
.card-body { padding: 1.25rem; }

/* ── Balance Cards ── */
.balance-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-bottom: 1.5rem; }
.bal-card {
    background: var(--surface);
    border: 1px solid var(--border2);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    box-shadow: var(--shadow);
}
.bal-label { font-size: 12px; font-weight: 500; color: var(--text2); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 0.5rem; display: flex; align-items: center; gap: 6px; }
.bal-amount { font-size: 28px; font-weight: 600; font-family: 'IBM Plex Mono', monospace; letter-spacing: -0.5px; margin-bottom: 8px; }
.bal-amount.positive { color: var(--green); }
.bal-amount.negative { color: var(--red); }
.bal-edit { font-size: 12px; color: var(--text3); background: none; border: none; cursor: pointer; padding: 0; display: flex; align-items: center; gap: 4px; font-family: var(--font); }
.bal-edit:hover { color: var(--text2); }

/* ── Grid ── */
.two-col { display: grid; grid-template-columns: 1fr 1.6fr; gap: 1rem; }
.full-col { margin-top: 1rem; }

/* ── Form ── */
.form-section { margin-bottom: 1rem; }
.form-label { display: block; font-size: 12px; font-weight: 500; color: var(--text2); margin-bottom: 5px; }
.form-input, .form-select {
    width: 100%; padding: 8px 10px;
    border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--surface); color: var(--text);
    font-size: 14px; font-family: var(--font);
    transition: border-color 0.15s;
    appearance: none; -webkit-appearance: none;
}
.form-input:focus, .form-select:focus {
    outline: none; border-color: var(--text);
    box-shadow: 0 0 0 3px rgba(0,0,0,0.06);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }

.type-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 1rem; }
.type-btn {
    padding: 8px; border-radius: var(--radius);
    border: 1px solid var(--border);
    background: transparent; cursor: pointer;
    font-size: 14px; font-weight: 500; font-family: var(--font);
    color: var(--text2); transition: all 0.15s;
    display: flex; align-items: center; justify-content: center; gap: 6px;
}
.type-btn:hover { background: var(--surface2); }
.type-btn.active-ausgabe { background: var(--red-bg); border-color: var(--red); color: var(--red); }
.type-btn.active-einnahme { background: var(--green-bg); border-color: var(--green); color: var(--green); }

.btn-primary {
    width: 100%; padding: 9px 16px;
    background: var(--text); color: var(--surface);
    border: none; border-radius: var(--radius);
    font-size: 14px; font-weight: 500; cursor: pointer;
    font-family: var(--font); display: flex; align-items: center; justify-content: center; gap: 6px;
    transition: opacity 0.15s;
}
.btn-primary:hover { opacity: 0.85; }
.btn-sm {
    padding: 5px 12px; border: 1px solid var(--border);
    border-radius: var(--radius); background: transparent;
    font-size: 12px; color: var(--text2); cursor: pointer;
    font-family: var(--font); transition: all 0.15s;
}
.btn-sm:hover { background: var(--surface2); color: var(--text); }
.btn-danger { border-color: var(--red); color: var(--red); }
.btn-danger:hover { background: var(--red-bg); }

/* ── Transactions Table ── */
.tx-table { width: 100%; border-collapse: collapse; }
.tx-table th {
    font-size: 11px; font-weight: 500; color: var(--text3);
    text-transform: uppercase; letter-spacing: 0.05em;
    padding: 10px 14px; text-align: left;
    border-bottom: 1px solid var(--border2); white-space: nowrap;
}
.tx-table td { padding: 10px 14px; border-bottom: 1px solid var(--border2); vertical-align: middle; }
.tx-table tr:last-child td { border-bottom: none; }
.tx-table tr:hover td { background: var(--surface2); }

.tx-desc { font-size: 14px; color: var(--text); font-weight: 500; }
.tx-note { font-size: 12px; color: var(--text3); margin-top: 1px; }
.tx-date { font-size: 12px; color: var(--text2); white-space: nowrap; font-family: 'IBM Plex Mono', monospace; }
.tx-amount { font-size: 14px; font-weight: 600; font-family: 'IBM Plex Mono', monospace; white-space: nowrap; text-align: right; }
.tx-amount.out { color: var(--red); }
.tx-amount.in { color: var(--green); }

.badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 2px 8px; border-radius: 20px;
    font-size: 12px; font-weight: 500;
}
.method-badge {
    font-size: 11px; color: var(--text3);
    display: flex; align-items: center; gap: 4px; white-space: nowrap;
}

/* ── Categories ── */
.cat-list { display: flex; flex-direction: column; gap: 6px; }
.cat-row {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 10px; border-radius: var(--radius);
    background: var(--surface2);
}
.cat-icon { font-size: 18px; flex-shrink: 0; }
.cat-info { flex: 1; min-width: 0; }
.cat-name { font-size: 13px; font-weight: 500; color: var(--text); }
.cat-type { font-size: 11px; color: var(--text3); }
.cat-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.cat-del { background: none; border: none; color: var(--text3); cursor: pointer; font-size: 16px; padding: 2px 4px; border-radius: 4px; }
.cat-del:hover { color: var(--red); background: var(--red-bg); }

/* ── Modal ── */
.modal-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.35); z-index: 200;
    align-items: center; justify-content: center;
    backdrop-filter: blur(2px);
}
.modal-overlay.open { display: flex; }
.modal {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    width: 360px; max-width: 90vw;
    box-shadow: 0 20px 60px rgba(0,0,0,0.15);
    border: 1px solid var(--border2);
}
.modal h3 { font-size: 16px; font-weight: 600; margin-bottom: 1.25rem; }
.modal-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 1.25rem; }
.btn-cancel {
    padding: 9px; border: 1px solid var(--border); border-radius: var(--radius);
    background: transparent; font-size: 14px; cursor: pointer; font-family: var(--font);
}
.btn-cancel:hover { background: var(--surface2); }
.btn-save {
    padding: 9px; background: var(--text); color: var(--surface);
    border: none; border-radius: var(--radius);
    font-size: 14px; font-weight: 500; cursor: pointer; font-family: var(--font);
}
.btn-save:hover { opacity: 0.85; }

/* ── Toast ── */
.toast-container { position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 999; display: flex; flex-direction: column; gap: 8px; }
.toast {
    background: var(--text); color: var(--surface);
    padding: 10px 16px; border-radius: var(--radius);
    font-size: 13px; font-weight: 500;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
    animation: slideIn 0.2s ease; display: flex; align-items: center; gap: 8px;
}
.toast.error { background: var(--red); }
.toast.success { background: var(--green); }
@keyframes slideIn { from { transform: translateY(10px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ── Stats page ── */
.stats-period-tabs { display: flex; gap: 4px; }
.period-tab {
    padding: 6px 14px; border-radius: var(--radius);
    font-size: 13px; font-weight: 500; cursor: pointer;
    border: 1px solid var(--border); background: transparent;
    color: var(--text2); font-family: var(--font); transition: all 0.15s;
}
.period-tab.active { background: var(--text); color: var(--surface); border-color: var(--text); }
.period-nav { display: flex; align-items: center; gap: 8px; }
.period-nav button { width: 32px; height: 32px; border-radius: var(--radius); border: 1px solid var(--border); background: transparent; cursor: pointer; font-size: 16px; transition: all 0.15s; }
.period-nav button:hover { background: var(--surface2); }
.period-label { font-size: 15px; font-weight: 600; min-width: 120px; text-align: center; }

.stats-summary { display: grid; grid-template-columns: repeat(3,1fr); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card { background: var(--surface); border: 1px solid var(--border2); border-radius: var(--radius-lg); padding: 1.25rem; box-shadow: var(--shadow); }
.stat-label { font-size: 12px; font-weight: 500; color: var(--text2); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 6px; }
.stat-value { font-size: 26px; font-weight: 600; font-family: 'IBM Plex Mono', monospace; }
.stat-value.positive { color: var(--green); }
.stat-value.negative { color: var(--red); }
.stat-value.neutral { color: var(--text); }

.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1rem; }

.bar-chart { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: flex; align-items: center; gap: 10px; }
.bar-row-label { font-size: 13px; color: var(--text); width: 120px; flex-shrink: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 5px; }
.bar-track { flex: 1; height: 8px; background: var(--surface2); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 4px; transition: width 0.4s ease; }
.bar-val { font-size: 12px; font-family: 'IBM Plex Mono', monospace; color: var(--text2); width: 80px; text-align: right; flex-shrink: 0; }

.trend-chart { position: relative; height: 180px; }
canvas { width: 100% !important; }

.method-bars { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.method-card { background: var(--surface2); border-radius: var(--radius); padding: 1rem; }
.method-name { font-size: 13px; font-weight: 500; color: var(--text); margin-bottom: 8px; display: flex; align-items: center; gap: 6px; }
.method-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.method-row-label { font-size: 12px; color: var(--text2); }
.method-row-val { font-size: 12px; font-family: 'IBM Plex Mono', monospace; font-weight: 500; }
.method-row-val.out { color: var(--red); }
.method-row-val.in { color: var(--green); }

/* ── Filters ── */
.filter-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.filter-bar .form-select { width: auto; font-size: 13px; padding: 6px 28px 6px 10px; }

/* ── Empty state ── */
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--text3); }
.empty-state .empty-icon { font-size: 40px; margin-bottom: 0.75rem; }
.empty-state p { font-size: 14px; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Responsive ── */
@media (max-width: 768px) {
    .balance-grid, .stats-summary { grid-template-columns: 1fr 1fr; }
    .two-col, .stats-grid { grid-template-columns: 1fr; }
    .form-row-3 { grid-template-columns: 1fr 1fr; }
    main { padding: 1rem; }
}
@media (max-width: 480px) {
    .balance-grid { grid-template-columns: 1fr; }
}
