/* --- Google Fonts --- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

/* --- Basis Setup --- */
:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --bg-main: #f1f5f9;
    --sidebar-bg: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    margin: 0;
    padding: 0;
    background: var(--bg-main);
    color: var(--text-main);
    font-family: 'Inter', sans-serif;
    overflow: hidden;
}

/* --- App Layout --- */
.app-layout {
    display: flex;
    height: 100dvh;
    width: 100vw;
    overflow: hidden;
}

/* --- Modal & Editor Struktur --- */
.modal-bg {
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(8px);
}

/* --- Toolbar Styling (Kompakter & Responsive) --- */
.ql-toolbar.ql-snow {
    display: flex !important;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-start;
    border: none !important;
    border-bottom: 1px solid #e2e8f0 !important;
    /* Ersatz für var(--border-color) falls nicht definiert */
    background: #f8fafc;
    padding: 4px !important;
    /* Etwas weniger Padding außen */
    flex-shrink: 0 !important;
}

/* Button-Größe reduzieren */
.ql-snow.ql-toolbar button {
    width: 28px !important;
    /* Von 40px auf 28px reduziert */
    height: 28px !important;
    /* Von 40px auf 28px reduziert */
    border-radius: 6px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    margin: 1px !important;
    /* Engere Abstände */
    padding: 4px !important;
    transition: all 0.2s ease;
}

/* SVG Icons innerhalb der Buttons skalieren */
.ql-snow.ql-toolbar button svg {
    width: 16px !important;
    height: 16px !important;
}

/* Dropdowns (Picker) anpassen, damit sie nicht größer als die Buttons sind */
.ql-snow.ql-toolbar .ql-picker {
    height: 28px !important;
    margin: 1px !important;
}

.ql-snow.ql-toolbar .ql-picker-label {
    padding: 0 4px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 12px !important;
}

/* Mobile Optimierung: Touch-Bereich leicht vergrößern ohne das Layout zu sprengen */
@media (max-width: 640px) {
    .ql-snow.ql-toolbar button {
        width: 32px !important;
        /* Am Handy etwas größer für die Finger */
        height: 32px !important;
        margin: 2px !important;
    }

    .ql-toolbar.ql-snow {
        padding: 6px !important;
    }
}

.ql-snow.ql-toolbar button:hover {
    background: #e2e8f0 !important;
}

.ql-snow.ql-toolbar button.ql-active {
    color: #2563eb !important;
    /* Ersatz für var(--primary) */
    background: #eff6ff !important;
}

/* Icons für Custom Buttons */
.ql-snow.ql-toolbar button.ql-custom-color svg,
.ql-snow.ql-toolbar button.ql-custom-bg svg {
    width: 14px !important;
    height: 14px !important;
    stroke-width: 2px;
}

/* Verstecke unnötige Labels/Spans */
.ql-color-label,
.ql-custom-color span,
.ql-custom-bg span,
.ql-snow.ql-toolbar button svg+span {
    display: none !important;
}
.ql-snow .ql-picker.ql-header .ql-picker-item::before {
    font-size: 14px !important;
    line-height: 1.2;
}

.ql-snow .ql-picker.ql-header .ql-picker-options {
    padding: 8px !important;
    min-width: 150px !important;
}

/* --- Modernes Gruppen-Dropdown --- */
#note-group-select {
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
    padding: 0.6rem 2.5rem 0.6rem 1rem !important;
    border-radius: 12px !important;
    border: 1px solid var(--border-color) !important;
    font-size: 0.875rem;
    font-weight: 600;
    transition: all 0.2s ease;
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 1rem;
}

/* WICHTIG: Erpwingt weiße Liste für die Auswahlmöglichkeiten */
#note-group-select option {
    background-color: #ffffff !important;
    color: #1e293b !important;
    padding: 12px !important;
}

#note-group-select:hover {
    border-color: var(--primary) !important;
}

#note-group-select:focus {
    outline: none;
    border-color: var(--primary) !important;
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
}

/* --- Responsives Design --- */
@media (min-width: 641px) {
    #note-modal>div:not(.is-fullscreen) {
        width: 100% !important;
        max-width: 55rem !important;
        height: 85vh !important;
        margin: auto !important;
        border-radius: 2rem !important;
        overflow: hidden;
    }
}

/* Footer-Icons in der Note-Card */
.note-card-body .lucide {
    stroke-width: 3px;
    display: inline-block;
    vertical-align: middle;
}

/* Diese Regel überschreibt dein globales 1.5rem Padding NUR in der Vorschau */
.ql-editor.preview-mode {
    padding: 0 !important;
    margin: 0 !important;
    min-height: unset !important;
    line-height: 1.3 !important;
}

/* Fix für Aufzählungen in der Vorschau */
.ql-editor.preview-mode ul,
.ql-editor.preview-mode ol {
    padding-left: 1.2em !important;
    /* Bringt die Punkte zurück */
    margin: 4px 0 !important;
}

/* Fix für die Abstände der Paragraphen (verhindert die leere Zeile oben) */
.ql-editor.preview-mode p {
    margin: 0 !important;
    padding: 0 !important;
}

/* Falls du den Header noch näher am Text haben willst */
.note-card-header {
    padding-bottom: 0 !important;
    border-bottom: none !important;
    /* Optional: Entfernt die Linie für noch mehr Platz */
}

.note-card-body {
    padding-top: 0 !important;
}

@media (max-width: 640px) {
    #note-modal>div {
        width: 100% !important;
        height: 100% !important;
        border-radius: 0 !important;
    }

    .ql-toolbar.ql-snow {
        justify-content: center;
        padding: 8px 4px !important;
    }

    /* 1. Das Modal selbst schmaler machen, damit es nicht so verloren wirkt */
    #history-modal>div {
        max-width: 95vw !important;
        /* Fast volle Breite des Screens */
        height: 85vh !important;
        border-radius: 2.5rem !important;
    }

    /* 2. Sicherstellen, dass der Content-Bereich wirklich 100% nutzt */
    #history-content-area {
        width: 100% !important;
        display: block !important;
        /* Verhindert Flex-Seiteneffekte */
    }

    /* 3. Padding im Preview-Fenster vereinheitlichen */
    #history-preview {
        padding: 1.25rem !important;
        width: 100%;
    }

    /* 4. Den Header (Datum + Button) bündig machen */
    .preview-header-mobile {
        display: flex;
        justify-content: space-between;
        align-items: center;
        width: 100%;
        gap: 0.5rem;
    }

    #history-list {
        height: 100%;
        overflow-y: auto;
        scrollbar-width: thin;
    }

    #history-content-area {
        width: 100% !important;
    }

    /* Auf Desktop wollen wir die 80% Höhe, 
       aber auf Mobile soll es das ganze Screen-Feeling haben */
    #history-modal>div {
        width: 100% !important;
        height: 100% !important;
        max-width: 100% !important;
        border-radius: 0 !important;
    }

}

/* Fixierter Header im History-Preview */
.history-preview-header {
    position: sticky;
    top: 0;
    z-index: 10;
    background-color: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(8px);
    margin: -2rem -2rem 2rem -2rem;
    /* Gleicht das Padding des Parents aus */
    padding: 2rem 2rem 1.5rem 2rem;
    border-bottom: 1px solid #f1f5f9;
}

/* Sicherstellen, dass der Content-Bereich darunter scrollt */
#history-preview {
    display: flex;
    flex-direction: column;
    padding-top: 0 !important;
    /* Wird jetzt vom Header übernommen */
}

#history-selection-sheet {
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#history-list {
    display: block;
    /* Standardmäßig an */
    width: 33.333%;
}

/* Hilfsklassen */
.is-fullscreen {
    max-width: 100% !important;
    height: 100% !important;
    border-radius: 0 !important;
    width: 100% !important;
}

/* Entfernung alter UI-Elemente */
#floating-format-btn,
[onclick="toggleToolbar()"] {
    display: none !important;
}

.group-option-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    border-radius: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-bottom: 4px;
}

.group-option-item:hover {
    background-color: #f1f5f9;
}

.group-pill-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.05);
}

/* in style.css */
#group-sheet {
    transform: translateY(100%);
    transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
}

#group-sheet-overlay:not(.hidden) #group-sheet {
    transform: translateY(0);
}

#notes-grid,
#ungrouped-notes {
    align-items: start;
    grid-auto-rows: min-content;
}

/* Verhindert, dass das Modal den Content "abschneidet" und fixiert die Rundungen */
#history-modal .overflow-hidden {
    border-radius: 2rem;
    /* Erzwingt Rundung auch unten */
}

/* Sidebar Styling */
.history-item {
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

/* Styling für den Quill-Content in der Vorschau */
.preview-mode.ql-editor {
    height: auto !important;
    overflow: visible !important;
    font-size: 14px;
}

/* Fix für das Image-Generator Overlap aus dem Screenshot */
#history-preview img {
    max-width: 100%;
    height: auto;
    border-radius: 12px;
    margin: 10px 0;
}

/* Scrollbar für die Sidebar */
#history-list {
    scrollbar-width: thin;
    scrollbar-color: #e2e8f0 transparent;
}

.history-mobile-selector {
    display: none;
}

/* Fix für das mobile History Modal */
#mobile-history-modal:not(.hidden) {
    display: flex !important;
}

#mobile-history-preview-content {
    flex-grow: 1;
    height: auto !important;
    min-height: 10px;
}

#mobile-history-modal {
    background-color: white !important;
}

#mobile-content-wrapper {
    -webkit-overflow-scrolling: touch;
    height: 100% !important;
    display: flex !important;
    flex-direction: column !important;
    overflow-y: auto !important;
}



/* ============================================================
   EINKAUFSLISTE — CSS ADDITIONS für style.css
   Einfach ans Ende der bestehenden style.css anhängen
   ============================================================ */


/* --- Einkaufslisten-Card im Grid --- */
.shopping-card {
    background: white;
    cursor: pointer;
    position: relative;
    border: 1px solid #e2e8f0;
    border-radius: 0.5rem;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    height: fit-content;
    width: 100%;
    display: flex;
    flex-direction: column;
    transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.shopping-card:hover {
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.12);
    border-color: #6ee7b7;
}

/* Farbiger linker Rand — Emerald statt Slate */
.shopping-card .card-accent {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 4px;
    background: #e2e8f0;
    transition: background 0.2s ease;
}

.shopping-card:hover .card-accent {
    background: #10b981;
}

/* Header der Card */
.shopping-card-header {
    background: rgba(240, 253, 244, 0.6);
    border-bottom: 1px solid #d1fae5;
    padding: 6px 12px 6px 16px;
}

.shopping-card-header h5 {
    font-weight: 800;
    font-size: 13px;
    color: #1e293b;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Fortschrittsbalken in der Card */
.shopping-card-progress {
    padding: 8px 12px 4px 16px;
}

.shopping-card-progress-track {
    height: 4px;
    background: #f1f5f9;
    border-radius: 9999px;
    overflow: hidden;
}

.shopping-card-progress-fill {
    height: 100%;
    background: #10b981;
    border-radius: 9999px;
    transition: width 0.4s ease;
}

.shopping-card-progress-label {
    font-size: 9.5px;
    font-weight: 700;
    color: #64748b;
    margin-top: 3px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.shopping-card-progress-label .done {
    color: #10b981;
    font-weight: 800;
}

/* Item-Preview in der Card */
.shopping-card-items {
    padding: 6px 12px 4px 16px;
    flex-grow: 1;
}

.shopping-card-item-preview {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: #64748b;
    padding: 1px 0;
}

.shopping-card-item-preview.is-checked {
    text-decoration: line-through;
    color: #cbd5e1;
}

.shopping-card-item-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* Footer der Card */
.shopping-card-footer {
    padding: 6px 12px 8px 16px;
    margin-top: auto;
    border-top: 1px solid #f1f5f9;
    background: rgba(248, 250, 252, 0.4);
    display: flex;
    justify-content: space-between;
    align-items: center;
}


/* --- Checklist-Items im Modal --- */
.shopping-checklist-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 14px;
    border: 1px solid #f1f5f9;
    background: white;
    transition: all 0.15s ease;
    cursor: default;
    user-select: none;
}

.shopping-checklist-item:hover {
    border-color: #e2e8f0;
    background: #fafafa;
}

.shopping-checklist-item.is-checked {
    background: #f8fafc;
    border-color: #f1f5f9;
    opacity: 0.65;
}

/* Custom Checkbox */
.shopping-checkbox {
    width: 22px;
    height: 22px;
    border-radius: 7px;
    border: 2px solid #cbd5e1;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    cursor: pointer;
    transition: all 0.15s ease;
    background: white;
}

.shopping-checkbox:hover {
    border-color: #10b981;
    background: #f0fdf4;
}

.shopping-checkbox.checked {
    background: #10b981;
    border-color: #10b981;
}

.shopping-checkbox.checked svg {
    display: block;
}

.shopping-checkbox svg {
    display: none;
    width: 13px;
    height: 13px;
    color: white;
    stroke-width: 3;
}

/* Item-Farb-Pill */
.shopping-item-color-pill {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* Item-Text & Kategorie */
.shopping-item-title {
    flex-grow: 1;
    font-size: 13px;
    font-weight: 600;
    color: #334155;
    transition: color 0.15s ease;
}

.shopping-checklist-item.is-checked .shopping-item-title {
    text-decoration: line-through;
    color: #94a3b8;
}

.shopping-item-category {
    font-size: 9.5px;
    font-weight: 700;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.shopping-checklist-item.is-checked .shopping-item-category {
    color: #cbd5e1;
}

/* Löschen-Button am Item */
.shopping-item-remove {
    opacity: 0;
    width: 24px;
    height: 24px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #94a3b8;
    cursor: pointer;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

.shopping-checklist-item:hover .shopping-item-remove {
    opacity: 1;
}

.shopping-item-remove:hover {
    background: #fee2e2;
    color: #ef4444;
}

/* Kategorie-Trenner in der Checkliste */
.shopping-category-divider {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 12px 0 6px;
}

.shopping-category-divider span {
    font-size: 9px;
    font-weight: 900;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    white-space: nowrap;
}

.shopping-category-divider::before,
.shopping-category-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: #e2e8f0;
}


/* --- Bibliotheks-Such-Dropdown --- */
#shopping-library-results {
    scrollbar-width: thin;
    scrollbar-color: #e2e8f0 transparent;
}

.library-result-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.15s ease;
}

.library-result-item:hover {
    background: #f0fdf4;
}

.library-result-item .item-color {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.library-result-item .item-title {
    flex-grow: 1;
    font-size: 13px;
    font-weight: 600;
    color: #334155;
}

.library-result-item .item-category {
    font-size: 10px;
    font-weight: 700;
    color: #94a3b8;
    text-transform: uppercase;
}

.library-result-new {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.15s ease;
    border-top: 1px solid #f1f5f9;
    color: #10b981;
    font-size: 13px;
    font-weight: 700;
}

.library-result-new:hover {
    background: #f0fdf4;
}


/* --- Bibliotheks-Modal Items --- */
.library-item-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: 14px;
    border: 1px solid #f1f5f9;
    background: white;
    transition: all 0.15s ease;
}

.library-item-row:hover {
    border-color: #e2e8f0;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}

.library-item-color-swatch {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.05);
}

.library-item-info {
    flex-grow: 1;
    min-width: 0;
}

.library-item-info .title {
    font-size: 13px;
    font-weight: 700;
    color: #334155;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.library-item-info .category {
    font-size: 10px;
    font-weight: 600;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.library-item-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.library-item-action-btn {
    width: 30px;
    height: 30px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s ease;
    color: #94a3b8;
}

.library-item-action-btn:hover.edit {
    background: #eff6ff;
    color: #2563eb;
}

.library-item-action-btn:hover.delete {
    background: #fee2e2;
    color: #ef4444;
}


/* --- Einkaufslisten-Badge auf der Card --- */
.shopping-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 9px;
    font-weight: 800;
    color: #10b981;
    background: #f0fdf4;
    border: 1px solid #d1fae5;
    padding: 2px 6px;
    border-radius: 6px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}


/* --- Animationen --- */
.shopping-checklist-item {
    animation: slideInItem 0.18s ease-out;
}

@keyframes slideInItem {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Checked-Transition */
.shopping-checklist-item.checking {
    animation: checkBounce 0.25s ease-out;
}

@keyframes checkBounce {
    0% {
        transform: scale(1);
    }

    40% {
        transform: scale(0.97);
    }

    100% {
        transform: scale(1);
    }
}

body:has(#shopping-list-modal:not(.hidden)) .md\:hidden.fixed.bottom-6.right-6 {
    display: none !important;
}

@media (max-width: 768px) {
    #shopping-group-sheet {
        align-items: flex-end;
    }

    #shopping-sheet-content {
        border-bottom-left-radius: 0;
        border-bottom-right-radius: 0;
    }
}

/* Standard Zustand wenn ausgewählt */
.shopping-checklist-item.is-selected {
    background-color: #f0fdf4 !important;
    /* Hellgrün */
    border-color: #10b981 !important;
    box-shadow: inset 4px 0 0 0 #10b981 !important;
}

/* Wenn es ausgewählt UND bereits abgehakt ist */
.shopping-checklist-item.is-checked.is-selected {
    background-color: #f8fafc !important;
    /* Etwas neutraler, da erledigt */
    border-color: #cbd5e1 !important;
    opacity: 0.8;
}