/*
 * AlpacaSpar Design System
 * Token-Layer ueber Bootstrap 5 - vereinheitlicht Farben, Radien, Schatten,
 * Buttons und mobile Patterns. Wird auf jeder Seite NACH Bootstrap geladen.
 */

:root {
    /* Farben */
    --as-cream: rgb(252, 247, 235);
    --as-cream-soft: rgb(255, 249, 240);
    --as-page-bg: #faf8f3;
    --as-surface: #ffffff;
    --as-border: #e9e2d4;
    --as-border-soft: #f0ebe0;
    --as-text: #212529;
    --as-text-muted: #6c757d;
    --as-green: #2e7d46;
    --as-green-dark: #256639;
    --as-green-soft: #edfaf4;
    --as-red: #b02a37;
    --as-red-soft: #fdefe9;
    --as-accent: #5a9dad;

    /* Form - Koppel: sehr runde Ecken, weiche Schatten */
    --as-radius: 1.25rem;
    --as-radius-sm: 0.875rem;
    --as-radius-pill: 999px;
    --as-shadow: 0 1px 2px rgba(33, 37, 41, 0.04), 0 6px 18px rgba(33, 37, 41, 0.06);
    --as-shadow-raised: 0 2px 6px rgba(33, 37, 41, 0.06), 0 12px 32px rgba(33, 37, 41, 0.09);

    /* Typo - Koppel: gerundeter Font-Stack fuer Headings/Kennzahlen */
    --as-font-rounded: ui-rounded, -apple-system, 'SF Pro Rounded', system-ui, sans-serif;

    /* Bottom-Tab-Bar */
    --as-bottom-nav-height: 60px;

    /* Bootstrap-Variablen ueberschreiben */
    --bs-body-bg: var(--as-page-bg);
    --bs-body-color: var(--as-text);
}

body {
    background-color: var(--as-page-bg);
}

/* ---------- Typografie (Koppel: gerundet-freundlich) ---------- */

h1, h2, h3, h4, h5, h6,
.h1, .h2, .h3, .h4, .h5, .h6,
.navbar-brand,
.card-title {
    font-family: var(--as-font-rounded);
    font-weight: 700;
}

/* ---------- Karten ---------- */

.card {
    border: 1px solid var(--as-border);
    border-radius: var(--as-radius);
    box-shadow: var(--as-shadow);
    background-color: var(--as-surface);
}

/* Gestrichelte Rahmen (Sparziel-Karten) durch ruhige Flaechen ersetzen */
.card[style*="dashed"],
.card.border-dashed {
    border-style: solid !important;
}

.card .card-body {
    padding: 1rem 1.25rem;
}

/* Investment-Karten: dezenter Akzent statt Vollrahmen */
.card-accent-invest {
    border-left: 4px solid #1d4e77;
}

/* ---------- Buttons ---------- */

/* Koppel: Buttons als freundliche Pillen */
.btn {
    border-radius: var(--as-radius-pill);
    font-weight: 600;
}

/* Primaeraktion (.btn-dark): gefuellt in Gruen statt Schwarz.
   Bootstrap 5.1 kennt keine --bs-btn-*-Variablen, daher klassische Overrides. */
.btn-dark {
    background-color: var(--as-green);
    border-color: var(--as-green);
    color: #ffffff;
}

.btn-dark:hover,
.btn-dark:focus {
    background-color: var(--as-green-dark);
    border-color: var(--as-green-dark);
    color: #ffffff;
}

.btn-dark:active,
.btn-dark.active,
.btn-check:checked + .btn-dark {
    background-color: var(--as-green-dark);
    border-color: var(--as-green-dark);
    color: #ffffff;
}

/* Outline-Buttons: Creme-Hover, Pill erbt vom .btn */
.btn-outline-dark:hover,
.btn-outline-dark:focus,
.btn-outline-secondary:hover,
.btn-outline-secondary:focus {
    background-color: var(--as-cream);
}

/* Cyan-Outline-Buttons (Quill-Speichern etc.) auf ruhiges Grau-Outline ziehen.
   Bootstrap 5.1 nutzt noch keine --bs-btn-Variablen, daher klassische Overrides. */
.btn-outline-info {
    color: var(--as-text-muted);
    border-color: #ced4da;
    background-color: transparent;
}

.btn-outline-info:hover,
.btn-outline-info:focus {
    color: var(--as-text);
    background-color: var(--as-cream-soft);
    border-color: #adb5bd;
    box-shadow: none;
}

.btn-outline-info:active,
.btn-check:checked + .btn-outline-info,
.btn-outline-info.active {
    color: var(--as-text);
    background-color: var(--as-cream);
    border-color: #adb5bd;
}

/* Submit-Buttons konsistent kapitalisiert */
input[type="submit"].btn,
button[type="submit"].btn {
    text-transform: capitalize;
}

/* ---------- Progress ---------- */

/* Koppel: dicke, komplett gerundete Fortschrittsbalken */
.progress {
    height: 1rem;
    border-radius: var(--as-radius-pill);
    background-color: #ece7db;
    overflow: hidden;
}

.progress-bar {
    background-color: var(--as-green);
    border-radius: var(--as-radius-pill);
    font-weight: 700;
    font-size: 0.7rem;
}

/* Bootstraps .bg-success (!important) auf Markengruen ziehen */
.progress-bar.bg-success {
    background-color: var(--as-green) !important;
}

/* Koppel: solide Balken statt Streifen */
.progress-bar-striped {
    background-image: none;
}

/* ---------- KPI-Tiles (ersetzen stat-figure Blockquotes) ---------- */

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem 1rem;
    margin-bottom: 0.75rem;
}

@media (min-width: 576px) {
    .kpi-grid {
        grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    }
}

.kpi-tile {
    min-width: 0;
}

.kpi-value {
    font-family: var(--as-font-rounded);
    font-size: 1.25rem;
    font-weight: 700;
    line-height: 1.2;
    color: var(--as-text);
    /* Beträge stehen im kpi-grid untereinander und müssen an der Ziffer ausgerichtet sein */
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.kpi-label {
    font-size: 0.75rem;
    color: var(--as-text-muted);
    line-height: 1.3;
}

.kpi-hint {
    font-size: 0.7rem;
    color: var(--as-text-muted);
    opacity: 0.8;
    line-height: 1.3;
}

/* ---------- Zeitraum-Chips ---------- */

.range-chip {
    border-radius: 999px !important;
    padding-inline: 0.75rem;
    background-color: var(--as-surface);
    border-color: var(--as-border);
    color: var(--as-text-muted);
    font-weight: 600;
}

/* Hover: Gruen-Akzent. Hoehere Spezifitaet (0,3,0) schlaegt den
   .btn-outline-secondary:hover-Override weiter oben in dieser Datei. */
.btn.range-chip:hover,
.btn.range-chip:focus {
    background-color: var(--as-green-soft);
    border-color: var(--as-green);
    color: var(--as-green);
}

/* Aktiv: gefuellter gruener Chip. Spezifitaet 0,3,0 schlaegt Bootstraps
   .btn-outline-secondary.active (0,2,0), design-system.css laedt nach Bootstrap. */
.btn.range-chip.active,
.btn-check:checked + .btn.range-chip {
    background-color: var(--as-green);
    border-color: var(--as-green);
    color: #ffffff;
}

.range-custom-form {
    display: inline-flex;
    align-items: center;
    min-height: 31px;
    padding: 0.15rem 0.2rem 0.15rem 0.65rem;
    border: 1px solid var(--as-border);
    border-radius: var(--as-radius-pill);
    background-color: var(--as-surface);
    color: var(--as-text-muted);
    font-family: var(--as-font-rounded);
    font-size: 0.8rem;
    font-weight: 600;
    transition: border-color 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease;
}

.range-custom-form:hover,
.range-custom-form:focus-within {
    border-color: var(--as-green);
    background-color: var(--as-green-soft);
    box-shadow: 0 0 0 0.2rem rgba(46, 125, 70, 0.1);
    color: var(--as-green);
}

.range-custom-label {
    margin-right: 0.35rem;
    cursor: text;
    white-space: nowrap;
}

.range-custom-input {
    width: 2.8rem;
    min-width: 0;
    padding: 0.05rem 0.25rem;
    border: 0;
    border-radius: 0.45rem;
    outline: 0;
    background-color: var(--as-page-bg);
    color: var(--as-text);
    font: inherit;
    text-align: center;
    appearance: textfield;
}

.range-custom-input::-webkit-inner-spin-button,
.range-custom-input::-webkit-outer-spin-button {
    margin: 0;
    appearance: none;
}

.range-custom-input::placeholder {
    color: var(--as-text-muted);
    opacity: 0.65;
}

.range-custom-unit {
    margin: 0 0.3rem 0 0.2rem;
}

.range-custom-submit {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 23px;
    height: 23px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background-color: var(--as-green-soft);
    color: var(--as-green);
}

.range-custom-submit:hover,
.range-custom-submit:focus {
    background-color: var(--as-green);
    color: #ffffff;
}

.range-custom-submit .material-icons {
    font-size: 16px;
}

.range-custom-form.active {
    border-color: var(--as-green);
    background-color: var(--as-green);
    color: #ffffff;
}

.range-custom-form.active .range-custom-input {
    background-color: rgba(255, 255, 255, 0.18);
    color: #ffffff;
}

.range-custom-form.active .range-custom-submit {
    background-color: #ffffff;
    color: var(--as-green);
}

.range-custom-form.active:focus-within {
    background-color: var(--as-green-dark);
}

/* ---------- Sticker-Badge (Koppel) ---------- */
/* Kleine Pille: weisser Grund, Gruen-Border, gruener fetter Text, weicher Schatten.
   Fuer Status-Hinweise wie Monats-Delta auf Karten. */
.sticker {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    padding: 0.15rem 0.55rem;
    border-radius: var(--as-radius-pill);
    background-color: var(--as-surface);
    border: 1px solid var(--as-green);
    color: var(--as-green);
    font-family: var(--as-font-rounded);
    font-size: 0.7rem;
    font-weight: 700;
    line-height: 1.2;
    white-space: nowrap;
    box-shadow: 0 1px 3px rgba(33, 37, 41, 0.08);
}

/* Negativ-Variante fuer ruecklaeufige Werte */
.sticker-down {
    border-color: var(--as-red);
    color: var(--as-red);
}

/* ===== Top-Navbar ===== */
.navbar-top {
    background-color: var(--as-cream);
    border-bottom: 1px solid var(--as-border-soft);
}
/* Creme-Hover ist auf Creme unsichtbar -> weisser Hover */
.navbar-top .btn-outline-dark:hover, .navbar-top .btn-outline-dark:focus,
.navbar-top .btn-outline-secondary:hover, .navbar-top .btn-outline-secondary:focus {
    background-color: var(--as-surface);
}
/* Desktop: Links als Pills, aktiv = gefuellter gruener Chip (wie Bottom-Nav) */
@media (min-width: 768px) {
    .navbar-top .navbar-nav { gap: 0.25rem; }
    .navbar-top .navbar-nav .nav-link {
        padding: 0.3rem 0.85rem;
        border-radius: var(--as-radius-pill);
        font-weight: 600;
    }
    .navbar-top .navbar-nav .nav-link:hover,
    .navbar-top .navbar-nav .nav-link:focus {
        color: var(--as-green);
        background-color: var(--as-green-soft);
    }
    .navbar-top .navbar-nav .nav-link.active {
        background-color: var(--as-green);
        color: #ffffff;
    }
}

/* ---------- Navbar (mobil) ---------- */

@media (max-width: 767.98px) {
    .navbar-collapse .navbar-nav {
        padding-top: 0.5rem;
        border-top: 1px solid var(--as-border);
        margin-top: 0.5rem;
    }

    .navbar-collapse .nav-link {
        padding: 0.625rem 0.5rem;
        border-radius: var(--as-radius-sm);
    }

    .navbar-collapse .nav-link.active {
        background-color: rgba(46, 125, 70, 0.08);
        font-weight: 600;
        color: var(--as-green);
    }

    /* User-Bereich: eigene Zeile, sauber getrennt */
    .navbar-collapse .navbar-user-area {
        border-top: 1px solid var(--as-border);
        margin-top: 0.5rem;
        padding: 0.75rem 0.5rem 0.375rem;
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 0.5rem;
    }
}

/* ---------- Bottom-Tab-Bar (Koppel, nur Mobile) ---------- */
/*
 * Haupt-Navigation auf Mobile: fixierte Leiste am unteren Rand mit 4 Tabs.
 * Auf Desktop (>=768px) komplett ausgeblendet - dort bleibt die Navbar.
 */

.bottom-nav {
    display: none;
}

@media (max-width: 767.98px) {
    .bottom-nav {
        display: flex;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1030;
        justify-content: space-around;
        align-items: stretch;
        background-color: rgb(252, 247, 235);
        border-top: 1px solid var(--as-border);
        padding: 0.375rem 0.25rem calc(0.375rem + env(safe-area-inset-bottom));
        box-shadow: 0 -2px 12px rgba(33, 37, 41, 0.05);
    }

    .bottom-nav-item {
        flex: 1 1 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 0.15rem;
        padding: 0.15rem 0.25rem;
        text-decoration: none;
        color: var(--as-text-muted);
        min-width: 0;
    }

    .bottom-nav-item .bottom-nav-icon {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 30px;
        border-radius: var(--as-radius-pill);
        transition: background-color 0.15s ease, color 0.15s ease;
    }

    .bottom-nav-item svg {
        width: 20px;
        height: 20px;
    }

    .bottom-nav-label {
        font-size: 0.65rem;
        font-weight: 600;
        font-family: var(--as-font-rounded);
        line-height: 1;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 100%;
    }

    /* Aktiver Tab: gefuellter runder Chip in Gruen, weisses Icon */
    .bottom-nav-item.active {
        color: var(--as-green);
    }

    .bottom-nav-item.active .bottom-nav-icon {
        background-color: var(--as-green);
        color: #ffffff;
    }

    /* Platz fuer die Bar schaffen, damit nichts verdeckt wird */
    body {
        padding-bottom: calc(var(--as-bottom-nav-height) + env(safe-area-inset-bottom));
    }
}

/* ---------- Footer: auf Mobile nicht fixiert ---------- */

@media (max-width: 767.98px) {
    footer .navbar.fixed-bottom {
        position: static;
    }
}

/* ---------- Quill-Editor kompakt ---------- */

.ql-container {
    min-height: 90px;
    border-bottom-left-radius: var(--as-radius-sm);
    border-bottom-right-radius: var(--as-radius-sm);
}

.ql-toolbar {
    border-top-left-radius: var(--as-radius-sm);
    border-top-right-radius: var(--as-radius-sm);
}

/* ---------- Tabellen mobil ---------- */

@media (max-width: 575.98px) {
    .table {
        font-size: 0.875rem;
    }

    .table td,
    .table th {
        padding: 0.375rem 0.375rem;
    }
}

/* ---------- Import-Stepper (mobil) ---------- */
/*
 * Der CSV-Import-Fortschritts-Stepper (Upload -> Vorschau -> Review -> Fertig)
 * laeuft auf schmalen Viewports horizontal aus dem Bild (feste Connector-Breite
 * 60px + Labels). Auf <=575.98px werden die Labels aller nicht-aktiven Schritte
 * ausgeblendet, nur der aktive Schritt zeigt sein Text-Label. Die Verbindungslinien
 * werden flexibel und fuellen den Restplatz, sodass die Zeile immer in den Viewport
 * passt und kein horizontaler Scroll entsteht. design-system.css wird auf allen
 * Import-Seiten NACH den Inline-Styles geladen, daher gewinnen diese Regeln.
 */

@media (max-width: 575.98px) {
    .step-indicator {
        justify-content: space-between;
        width: 100%;
        margin-bottom: 1.5rem;
    }

    .step {
        flex: 0 0 auto;
        min-width: 0;
    }

    .step .step-number {
        margin-right: 0;
    }

    /* Labels der nicht-aktiven Schritte ausblenden */
    .step > span:not(.step-number) {
        display: none;
    }

    /* Nur der aktive Schritt zeigt sein Text-Label */
    .step.active > span:not(.step-number) {
        display: inline;
        margin-left: 0.4rem;
        font-size: 0.8rem;
        white-space: nowrap;
    }

    /* Verbindungslinien fuellen den verfuegbaren Platz statt fester 60px */
    .step-connector {
        flex: 1 1 0;
        width: auto;
        min-width: 6px;
        margin: 0 0.4rem;
    }
}

/* ---------- Buchungs-Tabelle (Koppel) ---------- */
/*
 * Ersetzt die alten Vollzeilen-Tints (.table-plus/.table-minus) durch eine
 * ruhige weisse Karte. Die Zeilen bleiben klickbar (Edit-Modal), Farbe steckt
 * nur noch im Betrag und in der Konto-Pille. Passt zu den .card-Regeln oben.
 */

.buchungs-card {
    background-color: var(--as-surface);
    border: 1px solid var(--as-border-soft);
    border-radius: var(--as-radius);
    padding: 1rem 1.25rem;
}

.buchungs-table {
    margin-bottom: 0;
    --bs-table-bg: transparent;
    /* Hover-Tint dezent gruen statt Bootstrap-Grau */
    --bs-table-hover-bg: var(--as-green-soft);
}

/* Bootstraps harte 2px-Linie unter dem thead abschalten */
.buchungs-table > :not(:first-child) {
    border-top: 0;
}

/* Kopfzeile: kleine, ruhige Label-Optik */
.buchungs-table thead th {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--as-text-muted);
    font-weight: 600;
    border-top: none;
    border-bottom: 1px solid var(--as-border);
}

/* Datenzellen: luftig, weiche Trennlinien */
.buchungs-table tbody td {
    padding: 0.6rem 0.5rem;
    border-bottom: 1px solid var(--as-border-soft);
    vertical-align: middle;
}

/* Letzte Zeile ohne Trennlinie */
.buchungs-table tbody tr:last-child td {
    border-bottom: none;
}

/* Ganze Zeile klickbar (oeffnet das Edit-Modal) */
.buchungs-table tbody tr {
    cursor: pointer;
}

/* Dezente Vorzeichen-Tints auf ganzer Zeile */
.buchungs-table tbody tr.row-plus > td {
    background-color: var(--as-green-soft);
}

.buchungs-table tbody tr.row-minus > td {
    background-color: var(--as-red-soft);
}

/* Hover: etwas tiefere Variante des jeweiligen Tints statt globalem Gruen */
.buchungs-table tbody tr.row-plus {
    --bs-table-hover-bg: #ddf2e7;
}

.buchungs-table tbody tr.row-minus {
    --bs-table-hover-bg: #f9e2d9;
}

/* Betrag: fette Ziffern, tabellarisch ausgerichtet */
.buchung-amount {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.amount-plus {
    color: var(--as-green);
}

.amount-minus {
    color: var(--as-red);
}

.buchung-date {
    color: var(--as-text-muted);
}

/* Konto-Pille: Farbe kommt als --konto-color aus dem Template.
   Fallback-Zeile zuerst fuer Browser ohne color-mix. */
.konto-badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 0.15rem 0.55rem;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    background: #f1f3f5;
    color: #495057;
    border: 1px solid #dee2e6;
    background: color-mix(in srgb, var(--konto-color, #6c757d) 16%, #ffffff);
    color: color-mix(in srgb, var(--konto-color, #6c757d) 55%, #1a1a1a);
    border: 1px solid color-mix(in srgb, var(--konto-color, #6c757d) 35%, #ffffff);
}

/* Aktions-Icons in Verwaltungs-Tabellen: ruhig grau, farbiger Hover */
.buchungs-table .action-icon {
    color: var(--as-text-muted);
    text-decoration: none;
    vertical-align: middle;
}

.buchungs-table .action-icon.action-edit:hover,
.buchungs-table .action-icon.action-edit:focus {
    color: var(--as-green);
}

.buchungs-table .action-icon.action-delete:hover,
.buchungs-table .action-icon.action-delete:focus {
    color: var(--as-red);
}

/* Mobil: Zellen etwas kompakter */
@media (max-width: 576px) {
    .buchungs-table tbody td {
        padding: 0.5rem 0.4rem;
        font-size: 0.8rem;
    }
}

/* Drag & Drop: Karten-Sortierung */
.drag-handle {
    color: var(--as-text-muted);
    opacity: .45;
    cursor: grab;
    z-index: 2;
    padding: .25rem .5rem;
    touch-action: none;
}

.drag-handle:active {
    cursor: grabbing;
}

.sortable-chosen .card {
    box-shadow: var(--as-shadow-raised);
}

.sortable-ghost {
    opacity: .4;
}

.sortable-ghost .card {
    border: 2px dashed var(--as-green);
}
