:root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --text: #1e2430;
    --text-muted: #6b7280;
    --border: #e2e5ea;
    --primary: #e05d38;
    --primary-hover: #c94e2c;
    --primary-soft: #fdeee8;
    --success: #2f9e6e;
    --danger: #d94a4a;
    --radius: 14px;
    --shadow: 0 1px 3px rgba(20, 24, 40, .07), 0 8px 24px rgba(20, 24, 40, .06);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: .75rem;
    padding: 1rem 1.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}

header h1 {
    margin: 0;
    font-size: 1.35rem;
    letter-spacing: -.02em;
}

.app-version {
    font-size: .8rem;
    font-weight: 500;
    color: var(--text-muted);
    vertical-align: middle;
}

.header-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ------------------------------------------------ buttons */
.btn {
    border: 1px solid transparent;
    border-radius: 10px;
    padding: .55rem 1rem;
    font-size: .92rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s, border-color .15s, transform .05s;
}

.btn:active { transform: scale(.97); }

.btn-primary {
    background: var(--primary);
    color: #fff;
}
.btn-primary:hover { background: var(--primary-hover); }

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border-color: var(--border);
}
.btn-ghost:hover { background: var(--bg); color: var(--text); }

.btn.small { padding: .35rem .7rem; font-size: .82rem; }

.btn-danger {
    background: transparent;
    color: var(--danger);
    border: none;
    padding: .3rem .5rem;
    font-size: 1rem;
}
.btn-danger:hover { background: #fdecec; border-radius: 8px; }

/* ------------------------------------------------ layout */
main {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
    padding: 1.25rem 1.5rem;
    max-width: 1400px;
    margin: 0 auto;
    align-items: start;
}

.panel {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem;
}

.panel h2 {
    margin: 0 0 1rem;
    font-size: 1.05rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .06em;
    font-weight: 700;
}

/* ------------------------------------------------ dishes */
.dish {
    display: flex;
    align-items: flex-start;
    gap: .75rem;
    padding: .8rem .9rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: .6rem;
    cursor: pointer;
    transition: border-color .15s, background .15s, box-shadow .15s;
}

.dish:hover { border-color: var(--primary); }

.dish.selected {
    border-color: var(--primary);
    background: var(--primary-soft);
    box-shadow: inset 0 0 0 1px var(--primary);
}

.dish input[type="checkbox"] {
    width: 1.25rem;
    height: 1.25rem;
    margin-top: .15rem;
    accent-color: var(--primary);
    cursor: pointer;
    flex-shrink: 0;
}

.dish-body { flex: 1; min-width: 0; }

.dish-name { font-weight: 600; }

.dish-meta {
    margin-top: .15rem;
    font-size: .78rem;
    color: var(--text-muted);
}

.dish-ingredients {
    margin: .35rem 0 0;
    padding: 0;
    list-style: none;
    font-size: .85rem;
    color: var(--text-muted);
    display: flex;
    flex-wrap: wrap;
    gap: .35rem;
}

.dish-ingredients li {
    background: var(--bg);
    padding: .15rem .55rem;
    border-radius: 999px;
    white-space: nowrap;
}

.dish-actions {
    display: flex;
    gap: .25rem;
    align-items: center;
}
.dish-actions .btn-ghost {
    opacity: 0;
    transition: opacity .15s;
}
.dish:hover .dish-actions .btn-ghost { opacity: 1; }

.fav-btn {
    background: transparent;
    border: none;
    padding: .2rem .4rem;
    font-size: 1.15rem;
    line-height: 1;
    color: #c3c8d1;
    cursor: pointer;
    transition: color .15s, transform .1s;
    flex-shrink: 0;
}
.fav-btn:hover { color: var(--danger); transform: scale(1.15); }
.fav-btn.active { color: var(--danger); }

/* ------------------------------------------------ shopping list */
.shopping-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.shopping-item {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .7rem .6rem;
    border-bottom: 1px solid var(--border);
}

.shopping-item:last-child { border-bottom: none; }

.shopping-item input[type="checkbox"] {
    width: 1.3rem;
    height: 1.3rem;
    accent-color: var(--success);
    cursor: pointer;
    flex-shrink: 0;
}

.shopping-item .item-name { flex: 1; font-weight: 500; }

.item-qty-box {
    display: flex;
    align-items: center;
    gap: .3rem;
    flex-shrink: 0;
}

.qty-btn {
    padding: .1rem .45rem;
    font-size: .95rem;
    line-height: 1.2;
    border-radius: 8px;
}

.qty-btn:disabled {
    opacity: .3;
    cursor: default;
    background: transparent;
    color: var(--text-muted);
}

.progress-badge {
    color: var(--primary);
    font-weight: 700;
    font-size: .85rem;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.dish-badge {
    color: var(--primary);
    font-size: .95rem;
    font-weight: 700;
    white-space: nowrap;
}

.legend {
    color: var(--primary);
    font-weight: 700;
}

.legend-note {
    font-size: .78rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: none;
    letter-spacing: normal;
}

.shopping-item .item-qty {
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    font-size: .92rem;
    white-space: nowrap;
}

.shopping-item.checked .item-name {
    text-decoration: line-through;
    color: var(--text-muted);
}
.shopping-item.checked .item-qty { opacity: .55; }
.shopping-item.checked .progress-badge { display: none; }

.shopping-count {
    margin-top: 1rem;
    font-size: .85rem;
    color: var(--text-muted);
    text-align: right;
}

/* ------------------------------------------------ empty state */
.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 2rem 1rem;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    margin: 0;
}

/* ------------------------------------------------ dialog */
.dialog {
    border: none;
    border-radius: var(--radius);
    box-shadow: 0 20px 60px rgba(20, 24, 40, .25);
    padding: 1.5rem;
    width: min(640px, calc(100vw - 2rem));
    height: min(85vh, 760px);
    overflow-y: auto;
}

.dialog::backdrop { background: rgba(20, 24, 40, .4); }

.dialog form {
    display: flex;
    flex-direction: column;
    height: 100%;
    gap: .25rem;
}

.dialog form label { flex-shrink: 0; }
.dialog form h3 { flex-shrink: 0; }
.dialog form input#dish-name { flex-shrink: 0; }
.dialog form .btn-ghost.small { flex-shrink: 0; margin-top: .5rem; }
.dialog form .dialog-actions { flex-shrink: 0; }

.dialog h3 { margin: 0 0 1rem; font-size: 1.15rem; }

.dialog label {
    display: block;
    font-size: .82rem;
    font-weight: 600;
    color: var(--text-muted);
    margin: .9rem 0 .35rem;
}

.dialog input[type="text"], .dialog input[type="number"] {
    width: 100%;
    padding: .55rem .7rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: .95rem;
    font-family: inherit;
}

.dialog input:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }

.ingredient-rows {
    display: flex;
    flex-direction: column;
    gap: .5rem;
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.ingredient-row {
    display: grid;
    grid-template-columns: 1fr 110px 90px 34px;
    gap: .5rem;
    align-items: center;
}

.ingredient-row .btn-danger { padding: .2rem .45rem; }

.ingredient-row { position: relative; }

.suggestion-list {
    position: absolute;
    top: calc(100% + 2px);
    left: 0;
    width: calc(100% - 174px);
    margin: 0;
    padding: .25rem;
    list-style: none;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow);
    z-index: 20;
    max-height: 320px;
    overflow-y: auto;
}

.suggestion-list li {
    padding: .4rem .6rem;
    border-radius: 8px;
    cursor: pointer;
    font-size: .92rem;
}

.suggestion-list li:hover,
.suggestion-list li.active {
    background: var(--primary-soft);
    color: var(--primary-hover);
}

.dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: .6rem;
    margin-top: 1.5rem;
}

/* ------------------------------------------------ toast */
.toast {
    position: fixed;
    bottom: 1.25rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text);
    color: #fff;
    padding: .7rem 1.2rem;
    border-radius: 10px;
    box-shadow: var(--shadow);
    font-size: .9rem;
    z-index: 100;
    animation: toast-in .2s ease-out;
}

@keyframes toast-in {
    from { opacity: 0; transform: translate(-50%, 8px); }
    to   { opacity: 1; transform: translate(-50%, 0); }
}

.hidden { display: none !important; }

/* ------------------------------------------------ responsive */
@media (max-width: 800px) {
    header { padding: .8rem 1rem; }
    header h1 { font-size: 1.15rem; }
    main {
        grid-template-columns: 1fr;
        padding: 1rem;
        gap: 1rem;
    }

    /* Einkaufsliste (zweite Sektion) unter die Gerichte */
    .shopping-panel { order: 2; }
    .dishes-panel { order: 1; }

    .dish-actions .btn-ghost { opacity: 1; }

    .shopping-item {
        position: relative;
    }
}

/* Sehr kleine Screens: Zutaten-Zeilen im Dialog kompakter */
@media (max-width: 480px) {
    .ingredient-row {
        grid-template-columns: 1fr 80px 70px 30px;
        gap: .35rem;
    }
    .dialog {
        padding: 1rem;
        height: min(90vh, 760px);
    }
}