/* ========================================================================
   Haushaltsbuch — Design-Tokens & Komponenten
   Alles, was Seiten brauchen, landet hier. Kein <style>-Tag in PHP mehr.
   ======================================================================== */

/* -------- Design Tokens (Light) ---------------------------------------- */
:root {
    /* Farben */
    --hb-bg:            #f7f8fa;
    --hb-surface:       #ffffff;
    --hb-surface-alt:   #f1f3f5;
    --hb-border:        #e4e7eb;
    --hb-text:          #1f2937;
    --hb-text-muted:    #6b7280;

    --hb-primary:       #3b82f6;
    --hb-primary-soft:  #e0edff;
    --hb-success:       #10b981;
    --hb-success-soft:  #d1fae5;
    --hb-warning:       #f59e0b;
    --hb-warning-soft:  #fef3c7;
    --hb-danger:        #ef4444;
    --hb-danger-soft:   #fee2e2;

    /* Spacing */
    --hb-space-1: 0.25rem;
    --hb-space-2: 0.5rem;
    --hb-space-3: 0.75rem;
    --hb-space-4: 1rem;
    --hb-space-5: 1.25rem;
    --hb-space-6: 1.5rem;
    --hb-space-8: 2rem;

    /* Radien, Schatten, Transitions */
    --hb-radius-sm: 6px;
    --hb-radius:    8px;
    --hb-radius-lg: 12px;

    --hb-shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
    --hb-shadow:    0 4px 12px rgba(15, 23, 42, 0.06);
    --hb-shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.12);

    --hb-transition: 150ms ease;

    /* Bootstrap-Override-Variablen */
    --bs-primary: var(--hb-primary);
    --bs-body-bg: var(--hb-bg);
    --bs-body-color: var(--hb-text);
    --bs-border-color: var(--hb-border);
}

/* -------- Dark Mode ---------------------------------------------------- */
[data-theme="dark"] {
    --hb-bg:            #0f172a;
    --hb-surface:       #1e293b;
    --hb-surface-alt:   #273449;
    --hb-border:        #334155;
    --hb-text:          #e2e8f0;
    --hb-text-muted:    #94a3b8;

    --hb-primary:       #60a5fa;
    --hb-primary-soft:  #1e3a5f;
    --hb-success-soft:  #064e3b;
    --hb-warning-soft:  #713f12;
    --hb-danger-soft:   #7f1d1d;

    --hb-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --hb-shadow:    0 4px 12px rgba(0, 0, 0, 0.35);
    --hb-shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.45);
}

/* -------- Global Basics ------------------------------------------------ */
body {
    background: var(--hb-bg);
    color: var(--hb-text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

main {
    flex: 1 0 auto;
    padding-bottom: var(--hb-space-6);
}

.hb-footer {
    background: var(--hb-surface);
    border-top: 1px solid var(--hb-border);
}

a { color: var(--hb-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* -------- Navbar ------------------------------------------------------- */
.hb-navbar {
    background: var(--hb-surface);
    border-bottom: 1px solid var(--hb-border);
    box-shadow: var(--hb-shadow-sm);
    padding: var(--hb-space-3) 0;
}
.hb-navbar .nav-link { color: var(--hb-text); transition: color var(--hb-transition); }
.hb-navbar .nav-link:hover { color: var(--hb-primary); }
.hb-navbar .nav-link.active { color: var(--hb-primary); }
.hb-navbar .dropdown-menu {
    background: var(--hb-surface);
    border: 1px solid var(--hb-border);
    border-radius: var(--hb-radius);
}
.hb-navbar .dropdown-item { color: var(--hb-text); }
.hb-navbar .dropdown-item:hover { background: var(--hb-surface-alt); color: var(--hb-text); }

/* -------- Theme Toggle ------------------------------------------------ */
.hb-theme-btn .hb-theme-label-dark  { display: inline; }
.hb-theme-btn .hb-theme-label-light { display: none; }
.hb-theme-btn .hb-theme-icon-dark   { display: inline-block; }
.hb-theme-btn .hb-theme-icon-light  { display: none; }
[data-theme="dark"] .hb-theme-btn .hb-theme-label-dark  { display: none; }
[data-theme="dark"] .hb-theme-btn .hb-theme-label-light { display: inline; }
[data-theme="dark"] .hb-theme-btn .hb-theme-icon-dark   { display: none; }
[data-theme="dark"] .hb-theme-btn .hb-theme-icon-light  { display: inline-block; }

/* -------- Action Bar (Seiten-Header) ---------------------------------- */
.hb-action-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--hb-space-3);
    margin-bottom: var(--hb-space-4);
}
.hb-action-bar h1,
.hb-action-bar h2 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 600;
}
.hb-action-bar .hb-count {
    color: var(--hb-text-muted);
    font-weight: 400;
    font-size: 0.9em;
    margin-left: var(--hb-space-2);
}

/* -------- Stat Cards --------------------------------------------------- */
.hb-stat-grid {
    display: grid;
    gap: var(--hb-space-3);
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    margin-bottom: var(--hb-space-6);
}

.hb-stat {
    background: var(--hb-surface);
    border: 1px solid var(--hb-border);
    border-radius: var(--hb-radius);
    padding: var(--hb-space-4);
    transition: box-shadow var(--hb-transition);
}
.hb-stat:hover { box-shadow: var(--hb-shadow); }
.hb-stat-label {
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-size: 0.72rem;
    color: var(--hb-text-muted);
    margin-bottom: var(--hb-space-2);
}
.hb-stat-value {
    font-size: 1.6rem;
    font-weight: 600;
    line-height: 1.2;
    color: var(--hb-text);
}
.hb-stat-hint {
    font-size: 0.82rem;
    color: var(--hb-text-muted);
    margin-top: var(--hb-space-1);
}
.hb-stat--accent { border-top: 3px solid var(--hb-primary); }
.hb-stat--success { border-top: 3px solid var(--hb-success); }
.hb-stat--warning { border-top: 3px solid var(--hb-warning); }
.hb-stat--danger { border-top: 3px solid var(--hb-danger); }

/* -------- Card (generisch) -------------------------------------------- */
.hb-card {
    background: var(--hb-surface);
    border: 1px solid var(--hb-border);
    border-radius: var(--hb-radius);
    overflow: hidden;
    box-shadow: var(--hb-shadow-sm);
}
.hb-card-header {
    padding: var(--hb-space-3) var(--hb-space-4);
    border-bottom: 1px solid var(--hb-border);
    background: var(--hb-surface-alt);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--hb-space-3);
    font-weight: 600;
}
.hb-card-body { padding: var(--hb-space-4); }

/* -------- Data Table --------------------------------------------------- */
.hb-table {
    width: 100%;
    background: var(--hb-surface);
    border-collapse: separate;
    border-spacing: 0;
}
.hb-table thead th {
    background: var(--hb-surface-alt);
    color: var(--hb-text-muted);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: var(--hb-space-3) var(--hb-space-3);
    border-bottom: 1px solid var(--hb-border);
    position: sticky;
    top: 0;
    z-index: 1;
}
.hb-table tbody td {
    padding: var(--hb-space-3);
    border-bottom: 1px solid var(--hb-border);
    vertical-align: middle;
}
.hb-table tbody tr:last-child td { border-bottom: 0; }
.hb-table tbody tr { transition: background var(--hb-transition); }
.hb-table tbody tr:hover { background: var(--hb-surface-alt); }
.hb-table tr.hb-row--new { border-left: 3px solid var(--hb-warning); }
.hb-table .text-end { text-align: right; }
.hb-table .text-center { text-align: center; }

/* -------- Filter Bar --------------------------------------------------- */
.hb-filter-bar {
    background: var(--hb-surface);
    border: 1px solid var(--hb-border);
    border-radius: var(--hb-radius);
    padding: var(--hb-space-3);
    margin-bottom: var(--hb-space-4);
    display: flex;
    flex-wrap: wrap;
    gap: var(--hb-space-2);
    align-items: end;
}
.hb-filter-bar .hb-filter-item { flex: 1 1 180px; }
.hb-filter-bar label {
    display: block;
    font-size: 0.75rem;
    color: var(--hb-text-muted);
    margin-bottom: var(--hb-space-1);
}

/* -------- Empty State -------------------------------------------------- */
.hb-empty {
    padding: var(--hb-space-8);
    text-align: center;
    color: var(--hb-text-muted);
}
.hb-empty .hb-empty-icon { font-size: 2.5rem; margin-bottom: var(--hb-space-3); opacity: 0.5; }
.hb-empty .hb-empty-title { font-size: 1.1rem; font-weight: 500; color: var(--hb-text); margin-bottom: var(--hb-space-2); }

/* -------- Inline-Edit Helpers ----------------------------------------- */
.hb-inline-input,
.hb-inline-select {
    border: 1px solid transparent;
    background: transparent;
    color: var(--hb-text);
    width: 100%;
    padding: 2px 4px;
    border-radius: var(--hb-radius-sm);
    transition: border-color var(--hb-transition), background var(--hb-transition);
}
.hb-inline-input:hover,
.hb-inline-input:focus,
.hb-inline-select:hover,
.hb-inline-select:focus {
    border-color: var(--hb-border);
    background: var(--hb-surface);
    outline: none;
}
.hb-save-indicator {
    color: var(--hb-success);
    font-size: 0.8rem;
    opacity: 0;
    transition: opacity var(--hb-transition);
}
.hb-save-indicator.is-visible { opacity: 1; }

/* -------- Toasts ------------------------------------------------------- */
#hbToastContainer .hb-toast {
    min-width: 260px;
    background: var(--hb-surface);
    color: var(--hb-text);
    border: 1px solid var(--hb-border);
    border-left: 4px solid var(--hb-primary);
    border-radius: var(--hb-radius);
    box-shadow: var(--hb-shadow-lg);
    padding: var(--hb-space-3) var(--hb-space-4);
    margin-top: var(--hb-space-2);
    display: flex;
    gap: var(--hb-space-2);
    align-items: flex-start;
    animation: hb-toast-in 220ms ease;
}
.hb-toast.hb-toast--success { border-left-color: var(--hb-success); }
.hb-toast.hb-toast--warning { border-left-color: var(--hb-warning); }
.hb-toast.hb-toast--error   { border-left-color: var(--hb-danger); }
.hb-toast.hb-toast--info    { border-left-color: var(--hb-primary); }
.hb-toast-close {
    margin-left: auto;
    background: transparent;
    border: 0;
    color: var(--hb-text-muted);
    cursor: pointer;
    font-size: 1rem;
}
@keyframes hb-toast-in {
    from { transform: translateY(10px); opacity: 0; }
    to   { transform: translateY(0); opacity: 1; }
}

/* -------- Dropzone ---------------------------------------------------- */
.hb-dropzone {
    border: 2px dashed var(--hb-border);
    border-radius: var(--hb-radius);
    padding: var(--hb-space-6);
    text-align: center;
    color: var(--hb-text-muted);
    background: var(--hb-surface);
    transition: border-color var(--hb-transition), background var(--hb-transition);
}
.hb-dropzone--active {
    border-color: var(--hb-primary);
    background: var(--hb-primary-soft);
    color: var(--hb-primary);
}

/* -------- Floating Action Bar ----------------------------------------- */
.hb-action-float {
    position: fixed;
    bottom: var(--hb-space-6);
    left: 50%;
    transform: translateX(-50%);
    background: var(--hb-surface);
    border: 1px solid var(--hb-border);
    border-radius: var(--hb-radius-lg);
    box-shadow: var(--hb-shadow-lg);
    padding: var(--hb-space-3) var(--hb-space-4);
    display: flex;
    align-items: center;
    gap: var(--hb-space-3);
    z-index: 900;
}

/* -------- Chart-Card -------------------------------------------------- */
.hb-chart-card {
    background: var(--hb-surface);
    border: 1px solid var(--hb-border);
    border-radius: var(--hb-radius);
    padding: var(--hb-space-4);
    margin-bottom: var(--hb-space-4);
}
.hb-chart-canvas-wrap {
    position: relative;
    height: 320px;
}
.hb-chart-card-header {
    display: flex;
    gap: var(--hb-space-2);
    flex-wrap: wrap;
    margin-bottom: var(--hb-space-3);
    align-items: center;
}

/* -------- Tages-Gruppierung in Tabellen mit Limit-Warnung ------------- */
.hb-day-row {
    background: var(--hb-surface-alt);
    font-weight: 600;
}
.hb-day-row--over-limit {
    background: color-mix(in srgb, var(--hb-warning) 25%, var(--hb-surface));
}
.hb-limit-badge {
    display: inline-block;
    background: linear-gradient(135deg, var(--hb-warning), var(--hb-danger));
    color: #fff;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    margin-left: var(--hb-space-2);
}

/* -------- Badges / Status-Chips --------------------------------------- */
.hb-chip {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 500;
    background: var(--hb-surface-alt);
    color: var(--hb-text-muted);
}
.hb-chip--success { background: var(--hb-success-soft); color: var(--hb-success); }
.hb-chip--warning { background: var(--hb-warning-soft); color: var(--hb-warning); }
.hb-chip--danger  { background: var(--hb-danger-soft);  color: var(--hb-danger); }
.hb-chip--primary { background: var(--hb-primary-soft); color: var(--hb-primary); }

/* -------- Mobile Table → Cards ---------------------------------------- */
@media (max-width: 767.98px) {
    .hb-table-responsive { overflow: visible; }
    .hb-table,
    .hb-table thead,
    .hb-table tbody,
    .hb-table tr,
    .hb-table td { display: block; }
    .hb-table thead { display: none; }
    .hb-table tbody tr {
        border: 1px solid var(--hb-border);
        border-radius: var(--hb-radius);
        margin-bottom: var(--hb-space-3);
        padding: var(--hb-space-3);
        background: var(--hb-surface);
    }
    .hb-table tbody tr:hover { background: var(--hb-surface); }
    .hb-table tbody td {
        padding: var(--hb-space-1) 0;
        border: 0;
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: var(--hb-space-2);
    }
    .hb-table tbody td[data-label]::before {
        content: attr(data-label);
        font-size: 0.72rem;
        text-transform: uppercase;
        color: var(--hb-text-muted);
        flex-shrink: 0;
        min-width: 90px;
    }
}
