/* =========================================
   1. GLOBAL RESET & TYPOGRAPHY
   ========================================= */
* { box-sizing: border-box; }

body {
    margin: 0; padding: 0;
    font-family: var(--font-body);
    font-size: 16px;
    background-color: var(--bg-body);
    color: var(--text-main);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, .brand-text {
    font-family: var(--font-heading);
    letter-spacing: 1px;
}
h1 {
    font-size: 1.3rem;
}

button, .btn-primary, .btn-secondary, .nav-links a {
    font-family: var(--font-ui);
    font-weight: 600;
}

a { text-decoration: none; color: inherit; }
a.btn-primary, a.btn-secondary, .dashboard-grid a, .btn { text-decoration: none !important; }


/* =========================================
   2. HEADER & TOPBAR
   ========================================= */
.topbar {
    position: sticky; top: 0; left: 0; right: 0;
    z-index: 1000;
    background: var(--bg-header);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-color);
    height: var(--header-height);
    display: flex; align-items: center;
    transition: background-color 0.3s, border-color 0.3s;
    width: 100%;
}

.topbar-inner {
    width: 100%; max-width: 1200px; margin: 0 auto; padding: 0 20px;
    display: flex; justify-content: space-between; align-items: center;
}

.brand {
    font-weight: 700; font-size: 1.3rem;
    display: flex; align-items: center; gap: 10px; color: var(--primary);
}
.brand-text { display: inline-block; }
@media (max-width: 400px) { .brand-text { display: none; } }
.brand-logo-link img { height: 35px; width: auto; vertical-align: middle; }

.icon-btn {
    background: transparent; border: none; cursor: pointer;
    font-size: 1.2rem; padding: 8px; border-radius: 50%;
    transition: transform 0.2s, background-color 0.2s;
    color: var(--text-main); display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover { transform: scale(1.1); background-color: var(--bg-body); }

[data-theme="light"] .icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: none; }

.topbar-actions { display: flex; align-items: center; }
.dropdown-container { position: relative; display: inline-block; }

.topbar-new-btn {
    padding: 8px 16px; border-radius: 20px;
    display: flex; align-items: center; gap: 5px;
    font-weight: 600; transition: all 0.2s;
}
@media (max-width: 500px) {
    .desktop-text { display: none; }
    .topbar-new-btn { padding: 8px; border-radius: 50%; }
}

.dropdown-menu {
    display: none; position: absolute; right: 0; top: 120%;
    background-color: var(--bg-card); min-width: 160px;
    box-shadow: 0 8px 16px rgba(0,0,0,0.2);
    border-radius: var(--radius); border: 1px solid var(--border-color);
    z-index: 2000; overflow: hidden; animation: fadeIn 0.2s;
}
.dropdown-menu.show { display: block; }
.dropdown-menu a {
    color: var(--text-main); padding: 12px 16px; text-decoration: none;
    display: flex; align-items: center; gap: 10px;
    font-size: 0.95rem; transition: background 0.1s;
}
.dropdown-menu a:hover { background-color: var(--bg-body); color: var(--primary); }


/* =========================================
   3. SIDEBAR NAVIGATION
   ========================================= */
.nav-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5); z-index: 2000;
    opacity: 0; visibility: hidden; transition: opacity 0.3s;
}
.nav-overlay.open { opacity: 1; visibility: visible; }

.side-nav {
    position: fixed; top: 0; left: 0;
    width: 280px; height: 100%;
    background: var(--bg-card); z-index: 2001;
    transform: translateX(-100%); transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 4px 0 15px rgba(0,0,0,0.1);
    display: flex; flex-direction: column; overflow-y: auto;
}
.side-nav.open { transform: translateX(0); }

.nav-header {
    padding: 30px 20px 10px 20px;
    display: flex; flex-direction: column; align-items: center; position: relative;
}
.sidebar-logo-container { width: 100%; text-align: center; margin-bottom: 0px; }
.sidebar-logo-container img { max-width: 120px; height: auto; margin: 0 auto; }

.logo-dark { display: none !important; }
.logo-light { display: block !important; }
[data-theme="dark"] .logo-dark { display: block !important; }
[data-theme="dark"] .logo-light { display: none !important; }

.sidebar-controls {
    padding: 20px; border-bottom: 1px solid var(--border-color);
    display: flex; flex-direction: column; gap: 15px; margin-bottom: 10px;
}
.sidebar-search input {
    width: 100%; padding: 10px; border-radius: var(--radius);
    border: 1px solid var(--border-color);
    background: var(--bg-body); color: var(--text-main);
}
.theme-switcher-row {
    display: flex; justify-content: space-between; align-items: center;
    font-size: 0.9rem; color: var(--text-muted);
}

.nav-links { list-style: none; padding: 10px; }
.nav-links li { margin-bottom: 5px; }
.nav-links a {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 10px;
    text-decoration: none; color: var(--text-main);
    font-size: 0.95rem; border-radius: var(--radius);
    transition: background-color 0.2s, color 0.2s;
}
.nav-links a:hover { background-color: var(--bg-body); color: var(--primary); }
.nav-links a svg { flex-shrink: 0; width: 20px; height: 20px; }
.nav-links li.separator { height: 1px; background: var(--border-color); margin: 15px 0; }


/* =========================================
   4. MAIN LAYOUT & GRID
   ========================================= */
.app-container {
    max-width: 1200px; margin: 20px auto; padding: 0 8px;
    min-height: calc(100vh - var(--header-height) - 100px);
}

.dashboard-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px; margin-bottom: 40px;
}

.card {
    background: var(--bg-card); padding: 12px;
    border-radius: var(--radius); box-shadow: var(--shadow);
    transition: background-color 0.3s; display: block; color: inherit;
}
.card h2 { font-size: 1rem; margin-bottom: 10px; color: var(--text-muted); }


/* =========================================
   5. TRANSACTION LIST & SPLITS
   ========================================= */
.transaction-list { display: flex; flex-direction: column; gap: 15px; margin-top: 15px; }

.trans-item {
    display: flex;
    align-items: center; /* WICHTIG: Zentriert Items vertikal */
    justify-content: space-between;
    padding-bottom: 15px; border-bottom: 1px solid var(--border-color);
}
.trans-item:last-child { border-bottom: none; padding-bottom: 0; }

/* Haupt-Icon (52px) */
.trans-icon {
    width: 52px; height: 52px; min-width: 52px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    color: white; font-weight: bold; font-size: 1.3rem;
    margin-right: 15px;
    flex-shrink: 0;
    aspect-ratio: 1/1; /* Kreise erzwingen */
}

/* Unter-Icon (36px) */
.trans-icon.small {
    width: 36px; height: 36px; min-width: 36px;
    font-size: 0.9rem;
    /* margin-right bleibt 15px, damit der Text bündig ist */
}

.trans-details { flex-grow: 1; overflow: hidden; }
.trans-title {
    font-weight: 500; font-size: 0.95rem;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.trans-meta { font-size: 0.8rem; color: var(--text-muted); }
.trans-amount { font-weight: bold; font-size: 0.95rem; white-space: nowrap; }

/* Split Container (Akkordeon) */
.split-details {
    display: none;
    background-color: var(--bg-body);
    /* Zentrierung Berechnung:
       Mitte Großes Icon (52px) = 26px
       Mitte Kleines Icon (36px) = 18px
       Differenz = 8px.
       -> Padding-Left 8px sorgt dafür, dass die Mitten übereinander liegen.
    */
    padding-left: 8px;
    border-top: 1px dashed var(--border-color);
}

.split-toggle-container {
    background: var(--bg-body); padding: 15px;
    border-radius: var(--radius); margin-bottom: 20px;
    display: flex; justify-content: space-between; align-items: center;
    border: 1px solid var(--border-color);
}
.split-rows { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }
.split-row {
    background: var(--bg-body); padding: 10px;
    border-radius: var(--radius); border: 1px solid var(--border-color);
    position: relative; animation: fadeIn 0.2s ease-out;
}
.split-summary {
    background: var(--bg-card); padding: 15px; margin-top: 20px;
    text-align: center; font-weight: bold;
    border: 1px solid var(--border-color); border-radius: var(--radius);
}
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-5px); } to { opacity: 1; transform: translateY(0); } }


/* =========================================
   6. UI ELEMENTS
   ========================================= */
.toast-container {
    position: fixed; top: 25px; left: 50%; transform: translateX(-50%);
    z-index: 3000; pointer-events: none;
    width: 90%; max-width: 400px;
    display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.toast {
    background: rgba(255, 255, 255, 0.95); backdrop-filter: blur(10px);
    color: #333; padding: 12px 20px; border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.15); border: 1px solid rgba(0,0,0,0.05);
    display: flex; align-items: center; gap: 12px;
    opacity: 0; transform: translateY(-20px) scale(0.95);
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    font-weight: 500; font-size: 0.95rem; pointer-events: auto;
}
[data-theme="dark"] .toast {
    background: rgba(30, 30, 30, 0.9); color: #fff;
    border: 1px solid rgba(255,255,255,0.1);
}
.toast.show { opacity: 1; transform: translateY(0) scale(1); }
.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }

.modal-backdrop {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.6); z-index: 4000;
    display: none; align-items: center; justify-content: center;
    opacity: 0; transition: opacity 0.2s;
}
.modal-backdrop.visible { opacity: 1; }
.modal {
    background: var(--bg-card); width: 90%; max-width: 400px;
    padding: 25px; border-radius: var(--radius);
    box-shadow: 0 10px 25px rgba(0,0,0,0.3);
    transform: scale(0.9); transition: transform 0.2s; text-align: center;
}
.modal-backdrop.visible .modal { transform: scale(1); }
.modal-actions { display: flex; gap: 10px; justify-content: center; }
.modal-actions button {
    flex: 1; padding: 10px; border-radius: var(--radius);
    border: none; font-weight: bold; cursor: pointer;
}
.btn-cancel { background: transparent; border: 1px solid var(--border-color) !important; color: var(--text-main); }
.btn-confirm { background: var(--danger); color: white; }

.scroll-top-btn {
    position: fixed; bottom: 30px; right: 30px;
    width: 45px; height: 45px;
    background-color: var(--bg-card); color: var(--primary);
    border: 1px solid var(--border-color); border-radius: 50%;
    font-size: 1.2rem; cursor: pointer; box-shadow: var(--shadow);
    display: none; align-items: center; justify-content: center;
    z-index: 90; transition: all 0.3s;
}
.scroll-top-btn.visible { display: flex; }
.scroll-top-btn:hover { background-color: var(--primary); color: white; transform: translateY(-3px); }

.main-footer {
    text-align: center; padding: 20px;
    color: var(--text-muted); font-size: 0.85rem; margin-top: 20px;
}

/* =========================================
   7. DASHBOARD & STATS
   ========================================= */
.dashboard-header {
    display: flex; justify-content: center; align-items: center; margin-bottom: 20px;
}
.month-nav {
    display: flex; align-items: center; gap: 10px;
    background: var(--bg-card); padding: 8px 15px;
    border-radius: 50px; box-shadow: var(--shadow);
}
.month-title {
    margin: 0 10px; font-size: 1rem;
    font-weight: 700; white-space: nowrap;
}
.btn-current-month {
    display: flex; align-items: center; justify-content: center;
    width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--border-color);
    background: var(--bg-body); color: var(--text-muted); transition: all 0.2s;
}
.btn-current-month.active {
    background-color: var(--primary); color: white; border-color: var(--primary);
}

.stats-grid {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 25px;
}
.stat-card {
    background: var(--bg-card); padding: 15px;
    border-radius: var(--radius); box-shadow: var(--shadow);
    display: flex; flex-direction: column; justify-content: center; text-align: center;
}
.stat-card h2 {
    font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.5px;
    margin-bottom: 5px; color: var(--text-muted);
}
.stat-card .big-number { font-size: 1.3rem; font-weight: 800; }
@media (max-width: 500px) {
    .stat-card { padding: 10px 5px; }
    .stat-card h2 { font-size: 0.7rem; }
    .stat-card .big-number { font-size: 1.0rem; word-break: break-all; }
}

.action-btn {
    background: transparent; border: none; cursor: pointer;
    color: var(--text-muted); padding: 8px; border-radius: 8px;
    transition: color 0.2s, background 0.2s; display: flex; align-items: center;
}
.action-btn:hover { background: var(--bg-body); color: var(--text-main); }
.action-btn.delete:hover { color: var(--danger); background: rgba(230, 57, 70, 0.1); }

/* =========================================
   8. CATEGORY FILTER (Redesign)
   ========================================= */
.cat-filter-container {
    border: 1px solid var(--border-color); border-radius: var(--radius);
    background: var(--bg-card); padding: 10px;
    max-height: 300px; overflow-y: auto;
}
.cat-group {
    margin-bottom: 15px; border-bottom: 1px solid var(--border-color); padding-bottom: 10px;
}
.cat-group:last-child { border-bottom: none; margin-bottom: 0; }

.cat-parent-row {
    display: flex; align-items: center; gap: 10px;
    background-color: rgba(0,0,0,0.03); padding: 8px 10px; border-radius: 4px;
    font-weight: bold; font-family: var(--font-ui);
    cursor: pointer; transition: background 0.2s;
}
.cat-parent-row:hover { background-color: rgba(0,0,0,0.06); }

.cat-children-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 8px; padding: 10px 0 0 25px;
}
.cat-child-item {
    display: flex; align-items: center; gap: 8px;
    font-size: 0.9rem; cursor: pointer; padding: 4px; border-radius: 4px;
}
.cat-child-item:hover { background: var(--bg-body); }
input[type="checkbox"] {
    width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer;
}
