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

/* --- RESET & BASE --- */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden; 
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    transition: background-color 0.3s ease, color 0.3s ease;
}

button, input, select, textarea {
    font-family: inherit;
}

/* --- LAYOUT --- */
.app-layout {
    display: grid;
    grid-template-columns: 280px 1fr; /* Fixed Sidebar Width */
    height: 100vh;
}

/* --- SIDEBAR --- */
.sidebar {
    background-color: var(--bg-sidebar);
    color: var(--text-sidebar);
    display: flex;
    flex-direction: column;
    padding: 24px 16px;
    border-right: 1px solid var(--border-color);
    z-index: 50;
    transition: background-color 0.3s ease;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 40px;
    padding-left: 12px;
}

/* NEU: LOGO BILD Container */
.brand-logo {
    width: 64px;
    height: 64px;
    background-image: var(--logo-image);
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    flex-shrink: 0;
}

/* NEU: Text Container */
.brand-text-container {
    display: flex; 
    flex-direction: column; 
    justify-content: center;
}

.brand h1 {
    font-size: 1.05rem; /* Etwas kleiner für den längeren Titel */
    font-weight: 700;
    letter-spacing: -0.5px;
    color: var(--text-main); 
    line-height: 1.2;
    margin: 0;
}

/* NEU: Slogan */
.brand-slogan {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
    letter-spacing: 0.5px;
    text-transform: none; /* normal */
  }
  

.nav-menu {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
    overflow-y: auto;
    padding-right: 4px;
}
.nav-menu::-webkit-scrollbar { width: 4px; }
.nav-menu::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 4px; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    border-radius: 8px;
    color: var(--text-sidebar);
    background: transparent;
    border: none;
    cursor: pointer;
    text-align: left;
    font-size: 0.95rem;
    font-weight: 500;
    transition: all 0.2s ease;
    width: 100%;
}

.nav-item:hover {
    background: var(--bg-hover);
    color: var(--text-main);
}

.nav-item.active {
    background: var(--primary);
    color: var(--primary-contrast);
    box-shadow: 0 4px 12px var(--primary-light);
}

/* --- SIDEBAR TREE --- */
.sidebar-dynamic-section {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-top: 12px;
    margin-bottom: 12px;
}

.tree-item {
    display: flex;
    align-items: center;
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text-sidebar);
    font-size: 0.9rem;
    transition: all 0.1s;
    user-select: none;
}
.tree-item:hover {
    background: var(--bg-hover);
    color: var(--text-main);
}
.tree-item.active {
    background: var(--bg-hover);
    color: var(--text-main);
    font-weight: 600;
}
.tree-item.active-list {
    color: var(--primary);
    background: var(--primary-light);
    font-weight: 500;
}

.tree-toggle {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 4px;
    border-radius: 4px;
    transition: background 0.2s;
    color: var(--text-muted);
}
.tree-toggle:hover { background: var(--bg-hover); color: var(--text-main); }
.tree-toggle svg { width: 14px; height: 14px; transition: transform 0.2s; }
.tree-toggle.expanded svg { transform: rotate(90deg); }
.tree-toggle.hidden { opacity: 0; pointer-events: none; }

.tree-icon {
    margin-right: 8px;
    opacity: 0.9;
    display: flex;
}
.tree-label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.tree-children {
    margin-left: 22px;
    display: none;
    flex-direction: column;
    gap: 1px;
    border-left: 1px solid var(--border-color);
}
.tree-children.visible { display: flex; }

.nav-spacer { flex: 1; }

/* --- MAIN CONTENT --- */
.main-content {
    overflow-y: auto;
    padding: 40px;
    position: relative;
    height: 100vh;
}

.view { display: none; padding-bottom: 80px; }
.view.active { display: block; animation: fadeIn 0.3s cubic-bezier(0.16, 1, 0.3, 1); }

@keyframes fadeIn { 
    from { opacity: 0; transform: translateY(10px); } 
    to { opacity: 1; transform: translateY(0); } 
}

/* --- BUTTONS & ICONS --- */
.icon-button {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    color: var(--text-secondary); 
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.icon-button:hover {
    background-color: var(--bg-hover);
    color: var(--primary);
    transform: scale(1.1);
}

.icon-btn-small {
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 6px;
    border-radius: 6px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.icon-btn-small:hover { 
    color: var(--text-main); 
    background: var(--bg-hover); 
}

/* --- TOP BAR --- */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 32px;
}

.nav-controls { display: flex; align-items: center; gap: 12px; }

.breadcrumbs {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1rem;
    color: var(--text-secondary);
    font-weight: 500;
}
.breadcrumb-item { cursor: pointer; transition: color 0.2s; }
.breadcrumb-item:hover { color: var(--text-main); text-decoration: underline; }
.breadcrumb-separator { opacity: 0.5; }

.top-bar-actions { display: flex; gap: 12px; }

/* INPUTS */
.search-box { position: relative; width: 280px; }
.search-box input {
    width: 100%;
    padding: 10px 16px 10px 42px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: var(--bg-input);
    color: var(--text-main);
    transition: all 0.2s;
    font-size: 0.95rem;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.search-box input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}
.search-box svg {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.sort-select {
    padding: 0 16px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: var(--bg-input);
    color: var(--text-main);
    cursor: pointer;
    font-size: 0.9rem;
    outline: none;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.sort-select:focus { border-color: var(--primary); }

/* --- ACTION BUTTONS --- */
.dashboard-actions-row {
    margin-bottom: 32px;
    display: flex;
    gap: 16px;
}

.action-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
}
.action-button.primary {
    background: var(--primary);
    color: var(--primary-contrast);
    box-shadow: 0 4px 14px var(--primary-light);
}
.action-button.primary:hover { 
    background: var(--primary-hover); 
    transform: translateY(-2px); 
    box-shadow: 0 6px 20px var(--primary-light); 
}
.action-button.outline {
    background: var(--bg-card);
    border-color: var(--border-color);
    color: var(--text-main);
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.action-button.outline:hover { 
    border-color: var(--text-secondary); 
    transform: translateY(-2px); 
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
}
.action-button.full-width { width: 100%; }

/* --- DASHBOARD GRID --- */
.grid-layout {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 24px;
}

.list-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 24px;
    position: relative;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    display: flex;
    flex-direction: column;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    overflow: hidden;
}

.list-card:not(.folder-card) {
    border-top: 4px solid var(--primary);
}
.list-card:not(.folder-card):hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1);
    border-color: var(--border-color);
}

.folder-card {
    background: linear-gradient(145deg, var(--folder-gradient-1) 0%, var(--folder-gradient-2) 100%);
}
/* FIX: Ecke (Folder Dog-ear) angepasst mit Variable */
.folder-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, var(--folder-corner) 50%, transparent 50%);
    pointer-events: none;
}
.folder-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1);
    border-color: var(--text-muted);
}

.list-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 16px;
    z-index: 1;
}

.list-card-header svg {
    width: 28px; height: 28px;
    color: var(--primary);
}

/* FIX: Folder Icon Farbe via Variable und Füllung sichtbar gemacht */
.folder-card .list-card-header svg {
    color: var(--folder-icon);
    fill: currentColor; 
    opacity: 0.9;
}

.list-card h2 {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 6px;
    color: var(--text-main);
    z-index: 1;
}
.list-card p {
    font-size: 0.9rem;
    color: var(--text-secondary);
    z-index: 1;
}

.list-card-actions {
    position: absolute;
    top: 16px;
    right: 16px;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 2;
}
.list-card:hover .list-card-actions { opacity: 1; }

.card-progress-mini {
    height: 4px;
    width: 100%;
    background: var(--bg-body);
    border-radius: 2px;
    margin-top: auto;
    overflow: hidden;
}
.card-progress-fill {
    height: 100%;
    background: var(--success);
    border-radius: 2px;
    transition: width 0.5s ease-out;
}

/* --- DETAIL VIEW --- */
.detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 32px;
}
.detail-title-wrapper { display: flex; align-items: center; gap: 12px; }
.detail-title-wrapper h1 { 
    font-size: 2rem; 
    font-weight: 800; 
    letter-spacing: -1px; 
    line-height: 1.2;
    color: var(--text-main);
}

.finance-overview {
    display: grid;
    grid-template-columns: repeat(3, 1fr) 1.5fr;
    gap: 20px;
    margin-bottom: 40px;
}
.finance-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    padding: 24px;
    border-radius: 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.finance-card.total { border-left: 5px solid var(--text-main); }
.finance-card.paid { border-left: 5px solid var(--success); }
.finance-card.open { border-left: 5px solid var(--primary); }

.finance-card .label { 
    font-size: 0.75rem; 
    text-transform: uppercase; 
    color: var(--text-muted); 
    font-weight: 700; 
    margin-bottom: 8px; 
    letter-spacing: 1px; 
}
.finance-card .value { 
    font-family: 'JetBrains Mono', monospace; 
    font-size: 1.5rem; 
    font-weight: 700; 
    color: var(--text-main); 
}

.progress-section {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    padding: 24px;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.progress-bar-bg { 
    height: 10px; 
    background: var(--bg-body); 
    border-radius: 5px; 
    overflow: hidden; 
    margin-bottom: 8px; 
}
.progress-bar-fill { 
    height: 100%; 
    background: var(--success); 
    width: 0%; 
    transition: width 0.6s cubic-bezier(0.22, 1, 0.36, 1); 
}
.progress-text { 
    font-size: 0.85rem; 
    color: var(--text-secondary); 
    text-align: right; 
    font-weight: 500;
}

/* --- SMART ADD & INPUTS --- */
.smart-add-container {
    background: var(--bg-card);
    padding: 12px;
    border-radius: 14px;
    border: 1px solid var(--border-color);
    margin-bottom: 32px;
    display: flex;
    gap: 12px;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
    align-items: stretch;
}

.input-group { flex: 2; display: flex; gap: 8px; }
.input-group input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: var(--bg-input);
    color: var(--text-main);
    font-size: 1rem;
    transition: background 0.2s, border-color 0.2s;
}
.input-group input:focus { 
    outline: none; 
    border-color: var(--primary); 
    box-shadow: 0 0 0 2px var(--primary-light);
}

.ai-btn {
    background: var(--primary);
    color: var(--primary-contrast);
    border: none;
    padding: 0 24px;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.2s, transform 0.1s;
    white-space: nowrap;
}
.ai-btn:hover { background: var(--primary-hover); }
.ai-btn:active { transform: scale(0.98); }
.ai-btn .spin { animation: spin 1s linear infinite; }
@keyframes spin { 100% { transform: rotate(360deg); } }

.filter-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: var(--bg-input);
    color: var(--text-main);
    transition: all 0.2s;
}
.filter-input:focus {
    border-color: var(--primary);
}

/* --- CATEGORIES & ITEMS --- */
.categories-list {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.category details {
    background: var(--bg-card);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    transition: box-shadow 0.2s;
}
.category details:hover { box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1); }

.category summary {
    padding: 16px 20px;
    background: var(--category-header-bg); 
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    list-style: none;
    border-bottom: 1px solid var(--border-color);
    transition: background 0.2s ease, color 0.2s;
    font-weight: 700;
    color: var(--category-header-text);
}
.category summary:hover { 
    filter: brightness(95%); /* Universell für Dark/Light */
}
.category summary::-webkit-details-marker { display: none; }

.category-title { 
    font-weight: 700; 
    font-size: 0.95rem; 
    color: inherit;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.category-chevron {
    transition: transform 0.2s;
    color: inherit; /* FIX: Erbt nun Farbe von Header Text */
}
.category details[open] .category-chevron { transform: rotate(90deg); }

.summary-actions { display: flex; gap: 4px; }

/* FIX: Icons im Header sollen Header Text Farbe haben */
.category summary .icon-button {
    color: inherit; 
}
.category summary .icon-button:hover {
    background: var(--category-header-btn-hover);
    color: inherit;
}

/* Item Rows */
.category ul { list-style: none; padding: 0; }

.category li {
    padding: 16px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    background: var(--bg-card);
    transition: background 0.1s;
    justify-content: space-between;
}
.category li:hover { background-color: var(--bg-hover); }

/* Checked State - FIX: Nutzt jetzt die rote Variable */
.category li.checked-item {
    background-color: var(--bg-checked-item);
}

.item-left { display: flex; align-items: center; gap: 16px; flex: 1; }

.item-text { 
    font-size: 1rem; 
    font-weight: 500; 
    color: var(--text-main); 
    line-height: 1.4;
}
.category li.checked-item .item-text { 
    text-decoration: line-through; 
    color: var(--text-muted); 
    opacity: 0.8; 
}

/* Checkbox */
.checkbox-real { display: none; }
.checkbox-custom {
    width: 24px; height: 24px;
    border: 2px solid var(--border-color);
    border-radius: 7px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    color: transparent;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    background: var(--bg-input);
    flex-shrink: 0;
}
/* FIX: Checkbox ist jetzt Rot wenn checked */
.checkbox-real:checked + .checkbox-custom {
    background: var(--primary); 
    border-color: var(--primary);
    color: white;
    transform: scale(1.05);
}

/* Price */
.item-price {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
    color: var(--text-main);
    background: var(--bg-body);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.9rem;
    white-space: nowrap;
    border: 1px solid var(--border-color);
}
.category li.checked-item .item-price { 
    background: transparent; 
    color: var(--text-muted); 
    text-decoration: line-through; 
    border-color: transparent;
}

.item-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: 16px;
}

/* Add Item Button Row */
.add-item-row { 
    background: var(--bg-body) !important; 
    padding: 0 !important; 
    border-bottom: none !important;
}
.add-item-btn-text {
    width: 100%; text-align: left; padding: 16px 24px;
    background: none; border: none; color: var(--text-secondary);
    font-weight: 600; cursor: pointer; display: flex; align-items: center; gap: 10px;
    transition: color 0.2s;
}
.add-item-btn-text:hover { color: var(--primary); }

/* --- SETTINGS & MODALS --- */
.settings-card {
    background: var(--bg-card);
    border-radius: 16px;
    border: 1px solid var(--border-color);
    padding: 24px;
    color: var(--text-main);
}
.settings-card h3 { margin-bottom: 16px; font-size: 1.1rem; }
.form-group label { display: block; margin-bottom: 8px; font-weight: 500; font-size: 0.9rem; color: var(--text-main); }

.switch { position: relative; display: inline-block; width: 48px; height: 26px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: var(--border-color); transition: .4s; }
.slider:before { position: absolute; content: ""; height: 20px; width: 20px; left: 3px; bottom: 3px; background-color: white; transition: .4s; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
input:checked + .slider { background-color: var(--primary); }
input:checked + .slider:before { transform: translateX(22px); }
.slider.round { border-radius: 34px; }
.slider.round:before { border-radius: 50%; }

.modal-overlay {
    position: fixed; inset: 0; background: rgba(0, 0, 0, 0.7); /* Darker overlay for better focus */
    display: none; align-items: center; justify-content: center; z-index: 1000;
    backdrop-filter: blur(4px);
    padding: 20px;
}
.modal-overlay.visible { display: flex; animation: fadeInModal 0.2s ease-out; }
@keyframes fadeInModal { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }

.modal-content {
    background: var(--bg-card);
    width: 100%;
    max-width: 420px;
    border-radius: 20px;
    padding: 32px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    border: 1px solid var(--border-color);
    color: var(--text-main);
}
.modal-header { display: flex; justify-content: space-between; margin-bottom: 24px; align-items: center; }
.modal-header h3 { font-size: 1.25rem; font-weight: 700; margin: 0; color: var(--text-main); }
.close-icon { font-size: 1.75rem; color: var(--text-muted); cursor: pointer; border: none; background: none; line-height: 1; }
.close-icon:hover { color: var(--primary); }

.modal-body input {
    width: 100%; padding: 12px 16px; margin-bottom: 16px;
    border: 1px solid var(--border-color); border-radius: 10px;
    background: var(--bg-input); color: var(--text-main);
    font-size: 1rem;
}
.modal-body input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }

/* Add utility classes for delete modal */
.modal-text {
    margin-bottom: 24px;
    color: var(--text-secondary);
    font-size: 1rem;
    line-height: 1.5;
}

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    width: 100%;
}

/* --- RESPONSIVE --- */
@media (max-width: 1024px) {
    .finance-overview {
        grid-template-columns: repeat(2, 1fr);
        grid-template-rows: auto auto;
    }
    .finance-card.total { grid-column: 1 / -1; }
    .progress-section { grid-column: 1 / -1; }
}

@media (max-width: 768px) {
    .app-layout { grid-template-columns: 1fr; }
    .sidebar { display: none; }
    .main-content { padding: 20px; }
    .top-bar { flex-direction: column; align-items: flex-start; gap: 16px; }
    .top-bar-actions { width: 100%; flex-direction: column; }
    .search-box { width: 100%; }
    .sort-select { width: 100%; }
    .smart-add-container { flex-direction: column; }
    .input-group { flex-direction: column; }
    .ai-btn { width: 100%; justify-content: center; }
    .item-actions { opacity: 1; }
}