/* ==== Базовое ==== */
* { box-sizing: border-box; }
body { font-family: system-ui, sans-serif; margin: 0; background: #faf7f2; color: #222; }
header { background: #e07a2c; color: white; padding: 12px 16px; }
header h1 { margin: 0 0 8px; font-size: 1.4rem; }
nav button { margin-right: 8px; padding: 6px 12px; border: 0; border-radius: 6px; cursor: pointer; }
main { padding: 16px; max-width: 1200px; margin: 0 auto; }
input, button { padding: 8px; font: inherit; border-radius: 6px; border: 1px solid #ccc; }
button { background: #e07a2c; color: white; border: 0; cursor: pointer; }
button:disabled { opacity: 0.6; cursor: not-allowed; }

/* ==== Чипы ингредиентов ==== */
.chip {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 3px 4px 3px 8px;
    border-radius: 12px;
    margin: 2px;
    font-size: 0.9em;
    border: 1px solid transparent;
    background: #f0ece6;
    color: #888;
    transition: background .15s, border-color .15s, color .15s;
}
.chip.is-selected {
    background: #fff1e0;
    border-color: #e07a2c;
    color: #7a3b0f;
}
.chip-check {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    user-select: none;
}
.chip-check input {
    margin: 0;
    width: 15px;
    height: 15px;
    accent-color: #e07a2c;
    cursor: pointer;
}
.chip-remove {
    background: transparent;
    border: 0;
    color: #999;
    padding: 0 2px;
    min-width: 24px;
    min-height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.05em;
    font-weight: 700;
    line-height: 1;
    border-radius: 50%;
    cursor: pointer;
}
.chip-remove:hover { color: #c0392b; background: rgba(192, 57, 43, .08); }
.pantry-tool:focus-visible,
.chip-check input:focus-visible,
.chip-remove:focus-visible {
    outline: 2px solid #e07a2c;
    outline-offset: 2px;
}

/* ==== Карточка блюда ==== */
#results {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 16px;
    align-items: start;
}
#results .dish { margin-top: 0; }
#results > .loading,
#results > .error { grid-column: 1 / -1; }

.dish { background: white; padding: 16px; border-radius: 8px; margin-top: 16px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
.dish h3 { margin: 0 0 6px; color: #b45a17; }
.dish .why { margin: 0 0 10px; color: #666; font-style: italic; }

details summary { cursor: pointer; color: #e07a2c; font-weight: bold; margin-top: 8px; }
details ol { margin: 8px 0 0; padding-left: 22px; }

/* ==== Рейтинг ==== */
.rating { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 0.85em; }

/* ==== Сохранённые рецепты ==== */
.saved { background: #fff3e6; padding: 12px; border-radius: 6px; margin-top: 8px; }

/* ==== Секции внутри карточки ==== */
.dish .section { margin: 8px 0; font-size: 0.95em; }
.dish .tags { margin-top: 4px; }

.tag {
    display: inline-block;
    padding: 3px 8px;
    background: #eef2f5;
    border-radius: 10px;
    margin: 2px 4px 2px 0;
    font-size: 0.85em;
}

.tag-missing {
    background: #fff3e6;
    color: #b45a17;
}

/* ==== Кнопка «Сохранить в рецепты» ==== */
.dish .actions {
    margin-top: 12px;
    display: flex;
    align-items: center;
    gap: 12px;
}
.dish .actions a { color: #e07a2c; }

/* ==== Состояния загрузки / ошибки ==== */
.loading {
    padding: 12px;
    background: #eef6ff;
    border-radius: 6px;
    color: #1e40af;
    margin-top: 16px;
}
.error {
    padding: 12px;
    background: #fee2e2;
    border-radius: 6px;
    color: #991b1b;
    margin-top: 16px;
}
.error pre {
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 240px;
    overflow: auto;
    font-size: 0.85em;
    margin: 8px 0 0;
}

/* ==== Единый блок "У меня есть" + ввод ==== */
.pantry-box {
    background: #fff8ef;
    border: 1px solid #f0d9b8;
    border-radius: 10px;
    padding: 10px 12px 12px;
    margin: 8px 0 14px;
}

.search-bottom {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    align-items: start;
    margin-bottom: 16px;
}
.search-bottom .pantry-box {
    margin: 0;
}
.search-bottom .search-controls {
    margin-bottom: 0;
}

.pantry-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    font-size: 0.95em;
}

.pantry-title {
    font-weight: 600;
    color: #b45a17;
}

.pantry-count {
    background: #e07a2c;
    color: #fff;
    border-radius: 10px;
    padding: 0 8px;
    font-size: 0.8em;
    line-height: 18px;
    min-width: 18px;
    white-space: nowrap;
    text-align: center;
}
.pantry-count[data-count="0"] { background: #d1c8bb; }

.pantry-tool {
    margin-left: auto;
    padding: 4px 10px;
    border-radius: 12px;
    border: 1px solid #e0d5c2;
    background: #fffdf9;
    color: #b45a17;
    font-size: 0.85em;
    cursor: pointer;
    white-space: nowrap;
    transition: all .15s;
}
.pantry-tool:hover { border-color: #e07a2c; background: #fff1e0; }
.pantry-tool:disabled {
    opacity: 0.45;
    cursor: default;
    background: #fffdf9;
    border-color: #e0d5c2;
}

.pantry-collapse-btn {
    display: none;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    min-height: 32px;
    padding: 2px 8px;
    border: 1px solid #e0d5c2;
    border-radius: 8px;
    background: #fffdf9;
    color: #b45a17;
    font-size: 1em;
    cursor: pointer;
}
.pantry-collapse-btn:hover { border-color: #e07a2c; background: #fff1e0; }
.ing-collapse-btn { display: inline-flex; }
#ing-box.is-collapsed #ing-body { display: none; }

.pantry-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 6px;
    max-height: 180px;
    overflow-y: auto;
    padding-right: 4px;
    overscroll-behavior: contain;
}
.pantry-chips:empty { display: none; margin: 0; }

.pantry-hint {
    margin: 2px 0 6px;
    font-size: 0.85em;
    color: #777;
    min-height: 1em;
}
.pantry-hint:empty { display: none; }
.pantry-hint-warn { color: #b45309; }

.pantry-empty {
    color: #999;
    font-style: italic;
    font-size: 0.9em;
    padding: 2px 0 6px;
}
.pantry-empty[hidden] { display: none; }

.pantry-input {
    width: 100%;
    border: 1px dashed #d9c3a3;
    background: #fffdf9;
    padding: 8px 10px;
    border-radius: 6px;
}
.pantry-input:focus {
    outline: none;
    border-color: #e07a2c;
    background: #fff;
}

.pantry-input-row {
    display: flex;
    gap: 8px;
    margin-top: 6px;
    align-items: stretch;
}
.pantry-input-row .pantry-input {
    flex: 1;
    width: auto;
    min-width: 0;
    margin: 0;
}
.add-ing-btn {
    flex-shrink: 0;
    width: 44px;
    height: auto;
    min-height: 44px;
    padding: 0;
    font-size: 1.4em;
    line-height: 1;
    border: none;
    border-radius: 6px;
    background: #e07a2c;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
}
.add-ing-btn:hover { background: #c96a20; }
.add-ing-btn:active { background: #c96a20; transform: scale(0.95); }

@media (max-width: 600px) {
    .pantry-chips { max-height: 38vh; }
    .chip { font-size: 0.9em; padding: 6px 6px 6px 8px; }
    .chip-remove { min-width: 28px; min-height: 28px; }
    .pantry-tool { min-height: 32px; }
    .pantry-collapse-btn { display: inline-flex; }
    #wish-box .pantry-collapse-btn { margin-left: auto; }
    .pantry-box.is-collapsed .pantry-body { display: none; }
}

/* ==== Блок поиска ==== */
.search-controls {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    align-items: start;
    margin-bottom: 14px;
}

.search-action {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: stretch;
    min-width: 250px;
}

.want-new-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9em;
    color: #555;
    white-space: nowrap;
}

.search-action button {
    padding: 10px 16px;
    font-weight: 600;
}

@media (max-width: 600px) {
    .search-controls {
        grid-template-columns: 1fr;
    }
    .search-action {
        min-width: 0;
    }
    input, textarea, select {
        font-size: 16px;
    }
}

/* ==== Кладовая: форма добавления ==== */
.ing-add-form {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin-bottom: 16px;
    padding: 12px;
    background: #fff8ef;
    border: 1px solid #f0d9b8;
    border-radius: 10px;
}
.ing-add-form input[type="text"],
.ing-add-form input:not([type]) {
    flex: 1 1 180px;
}
.ing-add-form input[type="number"] {
    width: 130px;
}
.avail-check {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9em;
    color: #555;
    white-space: nowrap;
}

/* ==== Кладовая: раскладка список + правая колонка ==== */
.pantry-layout {
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 16px;
    align-items: start;
}

/* Правая колонка: кнопка + панели */
.pantry-sidebar {
    display: flex;
    flex-direction: column;
    gap: 12px;
    position: sticky;
    top: 16px;
}

/* Кнопка «Список покупок» */
.shopping-new-btn {
    width: 100%;
    padding: 10px 14px;
    background: #e0edff;
    color: #146d65;
    border: 1px solid #b7d5f5;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.95em;
    cursor: pointer;
}
.shopping-new-btn:hover { background: #d0e2ff; }

@media (max-width: 760px) {
    .pantry-layout { grid-template-columns: 1fr; }
    .pantry-sidebar { position: static; }
    .search-bottom { grid-template-columns: 1fr; }
}

/* ==== Кладовая: список ингредиентов ==== */
.ing-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.ing-row {
    display: grid;
    grid-template-columns: 40px 110px 1fr 140px 100px 60px;
    gap: 10px;
    align-items: center;
    background: #fff;
    border: 1px solid #e5ddd2;
    border-radius: 8px;
    padding: 8px 12px;
}
.ing-row.off { opacity: 0.55; }

/* Переключатель «в наличии» */
.avail-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    user-select: none;
    font-family: inherit;
    font-size: 0.8em;
    font-weight: 600;
    line-height: 1.2;
    padding: 4px 8px;
    border-radius: 12px;
    border: 1px solid transparent;
    background: transparent;
    appearance: none;
    -webkit-appearance: none;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: all .15s;
}
.avail-toggle:disabled {
    cursor: default;
    opacity: 0.7;
}
.avail-toggle .dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #ccc;
    flex-shrink: 0;
}
.avail-toggle.on {
    background: #e6f6ec;
    color: #1e7a3e;
    border-color: #b8e2c8;
}
.avail-toggle.on .dot { background: #1e7a3e; }
.avail-toggle.off {
    background: #f2f2f2;
    color: #888;
    border-color: #ddd;
}
.avail-toggle.off .dot { background: #bbb; }

/* Название */
.ing-name {
    font-weight: 500;
}

/* Цена — inline-редактирование */
.ing-price {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.9em;
    color: #555;
}
.ing-price input {
    width: 90px;
    padding: 4px 6px;
    font-size: 0.95em;
    text-align: right;
    border: 1px dashed #ccc;
    border-radius: 4px;
    background: #fffdf9;
}
.ing-price input:focus {
    outline: none;
    border-color: #e07a2c;
    border-style: solid;
    background: #fff;
}
.ing-price .cur { color: #999; font-size: 0.85em; }

/* Кнопки в строке ингредиента (история, + в покупки) */
.hist-btn {
    background: transparent;
    color: #b45a17;
    border: 1px solid #f0d9b8;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.8em;
    cursor: pointer;
}
.hist-btn:hover { background: #fff3e0; }

.add-to-shopping {
    color: #1e40af;
    border-color: #b7d5f5;
}
.add-to-shopping:hover { background: #e0edff; }

/* Мобильная раскладка строки кладовой: вместо 6 колонок — 3 строки */
@media (max-width: 600px) {
    .ing-row {
        grid-template-columns: 36px 1fr auto;
        grid-template-areas:
            "del toggle price"
            "del name   name"
            "del hist   shopping";
        gap: 6px 8px;
        padding: 8px 10px;
    }
    .del-ing-btn { grid-area: del; align-self: start; }
    .avail-toggle {
        grid-area: toggle;
        justify-self: start;
        min-height: 40px;
        padding: 8px 12px;
        font-size: 0.9em;
    }
    .ing-name {
        grid-area: name;
        min-width: 0;
        overflow-wrap: anywhere;
    }
    .ing-price { grid-area: price; justify-self: end; }
    .hist-price-btn { grid-area: hist; justify-self: start; }
    .add-to-shopping { grid-area: shopping; justify-self: end; }
    .hist-btn { min-height: 36px; padding: 8px 12px; }
}

/* ==== Панель истории цен ==== */
.price-panel {
    background: #fff;
    border: 1px solid #e5ddd2;
    border-radius: 10px;
    padding: 12px 14px;
    max-height: 60vh;
    overflow: auto;
}
.price-panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}
.price-panel-head h3 {
    margin: 0;
    font-size: 1rem;
    color: #fafffb;
    word-break: break-word;
}
.price-panel-head a {
    cursor: pointer;
    color: #999;
    font-weight: 700;
    text-decoration: none;
}
.price-panel-head a:hover { color: #b45a17; }

.price-panel-body table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9em;
}
.price-panel-body th,
.price-panel-body td {
    text-align: left;
    padding: 6px 4px;
    border-bottom: 1px solid #f0ece5;
}
.price-panel-body th { color: #888; font-weight: 500; }
.price-panel-body td.num { text-align: right; font-variant-numeric: tabular-nums; }
.price-panel-body .empty { color: #999; font-style: italic; padding: 8px 0; }

/* ==== Список покупок ==== */
.shopping-panel {
    background: #f4f9ff;
    border: 1px solid #c9dff5;
    border-radius: 10px;
    padding: 12px 14px;
}

.shopping-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}
.shopping-head h3 {
    margin: 0;
    font-size: 1rem;
    color: #efefef;
    word-break: break-word;
}
.shopping-head a {
    cursor: pointer;
    color: #999;
    font-weight: 700;
    text-decoration: none;
}
.shopping-head a:hover { color: #1e40af; }

.shopping-total {
    background: #e0edff;
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 0.9em;
    margin-bottom: 10px;
}
.shopping-total b { color: #4caf50; font-size: 1.05em; }
.shopping-total-count { color: #6b7280; margin-left: 6px; }

.shopping-add-row {
    display: flex;
    gap: 6px;
    margin-bottom: 10px;
}
.shopping-add-row input { flex: 1; }
.shopping-add-row button {
    background: #dbeafe;
    color: #1e40af;
    border: 1px solid #b7d5f5;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 0.85em;
    cursor: pointer;
}
.shopping-add-row button:hover { background: #c9dff5; }

.shopping-items {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.shopping-item {
    display: grid;
    grid-template-columns: auto 60px 90px 1fr auto;  /* 5 колонок */
    gap: 6px;
    align-items: center;
    padding: 6px 8px;
    background: #fff;
    border: 1px solid #e5eaf2;
    border-radius: 6px;
}
.shopping-item.done {
    opacity: 0.65;
}
.shopping-item.done .sh-name {
    text-decoration: line-through;
    color: #888;
}

/* Галочка */
.sh-check {
    width: 22px;
    height: 22px;
    border-radius: 4px;
    border: 1px solid #b7d5f5;
    background: #fff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85em;
    color: transparent;
    transition: all .15s;
}
.sh-check.done {
    background: #22a35b;
    border-color: #22a35b;
    color: #fff;
}

/* Поле цены в списке покупок */
.sh-price {
    width: 80px;
    padding: 4px 6px;
    font-size: 0.9em;
    text-align: right;
    border: 1px dashed #ccc;
    border-radius: 4px;
    background: #fffdf9;
}
.sh-price:focus {
    outline: none;
    border-color: #1e40af;
    border-style: solid;
}

.sh-name { word-break: break-word; }
.sh-name.muted { color: #888; }

.sh-remove {
    background: transparent;
    color: #c33;
    border: 0;
    font-size: 1.1em;
    cursor: pointer;
    padding: 0 6px;
}
.sh-remove:hover { color: #f00; }

.shopping-footer {
    margin-top: 10px;
    display: flex;
    justify-content: flex-end;
}
.shopping-footer .danger {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fbcaca;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.85em;
    cursor: pointer;
}
.shopping-footer .danger:hover { background: #fecaca; }

.shopping-lists {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: -4px;
}
.shopping-list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px;
    background: #f7fafd;
    border: 1px solid #dbe8f5;
    border-radius: 6px;
    font-size: 0.85em;
    cursor: pointer;
}
.shopping-list-item:hover { background: #e8f1fc; }
.shopping-list-item.active {
    background: #e0edff;
    border-color: #b7d5f5;
    font-weight: 600;
}
.shopping-list-item .meta {
    color: #6b7280;
    font-size: 0.85em;
    margin-left: 8px;
}
.shopping-list-item .del {
    color: #c33;
    background: transparent;
    border: 0;
    font-size: 1em;
    cursor: pointer;
    padding: 0 4px;
}
.shopping-list-item .del:hover { color: #f00; }
.sh-qty {
    width: 60px;
    padding: 4px 6px;
    font-size: 0.9em;
    text-align: right;
    border: 1px dashed #ccc;
    border-radius: 4px;
    background: #fffdf9;
}
.sh-qty:focus {
    outline: none;
    border-color: #1e40af;
    border-style: solid;
}
/* Заголовок рецепта — кликабельный */
.saved-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    user-select: none;
}
.saved-head:hover .saved-title {
    color: #b45a17;
}
.saved-title {
    font-size: 1.02em;
    transition: color .15s;
}
.saved-toggle {
    color: #999;
    font-size: 0.9em;
    margin-left: 8px;
}

/* Раскрытый блок с деталями */
.saved-details {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px dashed #e5ddd2;
}
.saved-details .why {
    margin: 0 0 10px;
    color: #666;
    font-style: italic;
    font-size: 0.95em;
}
.saved-details .section {
    margin: 8px 0;
    font-size: 0.95em;
}
.saved-details .tags {
    margin-top: 4px;
}
.saved-details ol {
    margin: 6px 0 0;
    padding-left: 22px;
}

/* Кнопки внизу рецепта */
.saved-actions {
    margin-top: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.saved-actions .rating {
    margin-right: auto;
}
/* Заголовок рецепта — кликабельный */
.saved-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    user-select: none;
}
.saved-head:hover .saved-title { color: #b45a17; }
.saved-title { font-size: 1.02em; transition: color .15s; }
.saved-toggle { color: #999; font-size: 0.9em; margin-left: 8px; }

/* Раскрытый блок с деталями (без border) */
.saved-details {
    margin-top: 10px;
}
.saved-details .why {
    margin: 0 0 10px;
    color: #666;
    font-style: italic;
    font-size: 0.95em;
}
.saved-details .section { margin: 8px 0; font-size: 0.95em; }
.saved-details .tags { margin-top: 4px; }
.saved-details ol { margin: 6px 0 0; padding-left: 22px; }

/* Плашка с кнопками — отделена пунктиром */
.saved-actions {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px dashed #e5ddd2;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.saved-actions .rating { margin-right: auto; }

/* Кнопка "Приготовлено" — неактивная, но заметная */
.cooked-done {
    background: #e6f6ec;
    color: #1e7a3e;
    border: 1px solid #b8e2c8;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.85em;
    cursor: default;
    opacity: 1;   /* перебиваем общий button:disabled { opacity: .6 } */
}
.cooked-done:hover { background: #e6f6ec; }

/* Список рецептов без маркеров */
#saved-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.saved-details .muted {
    color: #999;
    font-style: italic;
    font-size: 0.9em;
}

.add-missing-btn {
    margin-top: 6px;
    padding: 4px 10px;
    background: #e0edff;
    color: #1e40af;
    border: 1px solid #b7d5f5;
    border-radius: 6px;
    font-size: 0.8em;
    cursor: pointer;
}
.add-missing-btn:hover { background: #d0e2ff; }
.add-missing-btn:disabled { opacity: 0.6; cursor: default; }
.use-ings-toggle {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 0.85em;
    color: #555;
    cursor: pointer;
    user-select: none;
    padding: 2px 8px;
    border-radius: 12px;
    border: 1px solid #e0d5c2;
    background: #fffdf9;
    transition: all .15s;
}
.use-ings-toggle:hover {
    border-color: #e07a2c;
}
.use-ings-toggle input {
    margin: 0;
    accent-color: #e07a2c;
}

/* Когда чекбокс снят — блок "приглушается" */
.pantry-box.ignore-ings .pantry-chips,
.pantry-box.ignore-ings .pantry-hint,
.pantry-box.ignore-ings .pantry-input {
    opacity: 0.45;
}
.pantry-box.ignore-ings .pantry-title {
    color: #999;
}
.dish-saved {
    border-left: 4px solid #e07a2c;
}

/* Метка "из ваших рецептов" */
.dish-source {
    font-size: 0.8em;
    color: #b45a17;
    background: #fff3e0;
    padding: 4px 10px;
    border-radius: 6px;
    margin-bottom: 8px;
    display: inline-block;
}
/* Фильтры */
.saved-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    padding: 10px 12px;
    background: #fff8ef;
    border: 1px solid #f0d9b8;
    border-radius: 10px;
    margin-bottom: 16px;
    font-size: 0.9em;
}
.saved-filters-label {
    color: #b45a17;
    font-weight: 600;
}
.filter-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    min-width: 0;
}
.filter-tags:empty { display: none; }
.filter-tags .chip {
    cursor: pointer;
    user-select: none;
}
.filter-tags .chip:hover {
    border-color: #e07a2c;
}
.saved-filters button {
    margin-left: auto;
    padding: 4px 12px;
    background: #e0edff;
    color: #1e40af;
    border: 1px solid #b7d5f5;
    border-radius: 6px;
    font-size: 0.9em;
    cursor: pointer;
}
.saved-filters button:hover { background: #d0e2ff; }

/* Метки пожелания/обстановки в карточке рецепта */
.saved-meta {
    margin: 4px 0 6px;
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.recipe-meta {
    display: inline-block;
    padding: 2px 8px;
    background: #eef2f5;
    color: #555;
    border-radius: 10px;
    font-size: 0.8em;
}
.search-sources {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.9em;
    color: #555;
}
.search-sources b {
    color: #333;
    margin-bottom: 2px;
}
.search-sources label {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}
.del-ing-btn {
    color: #c33;
    border-color: #fbcaca;
    padding: 4px 8px;
    font-size: 0.85em;
}
.del-ing-btn:hover {
    background: #fee2e2;
    color: #f00;
    border-color: #f88;
}
/* Тулбар над списком рецептов */
.saved-toolbar {
    margin: 0 0 12px;
}

/* Кнопки в карточке рецепта */
.recipe-edit-btn,
.recipe-del-btn {
    background: transparent;
    border: 1px solid #e5ddd2;
    color: #666;
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 0.9em;
    cursor: pointer;
    margin-left: 4px;
}
.recipe-edit-btn:hover { background: #f0f4f9; color: #1e40af; border-color: #b7d5f5; }
.recipe-del-btn:hover  { background: #fee2e2; color: #c33;   border-color: #fbcaca; }

/* ==== Модальное окно ==== */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    z-index: 1000;
    overflow-y: auto;
    padding: 40px 16px;
}
.modal-backdrop[hidden] { display: none; }

.modal {
    background: #fff;
    border-radius: 12px;
    max-width: 680px;
    width: 100%;
    box-shadow: 0 10px 40px rgba(0,0,0,0.15);
    display: flex;
    flex-direction: column;
    max-height: 90vh;
}

.modal-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px;
    border-bottom: 1px solid #eee;
}
.modal-head h3 {
    margin: 0;
    font-size: 1.1rem;
    color: #b45a17;
}
.modal-head a {
    cursor: pointer;
    color: #999;
    font-weight: 700;
    font-size: 1.1em;
}
.modal-head a:hover { color: #b45a17; }

.modal-body {
    padding: 16px 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.modal-body label {
    display: flex;
    flex-direction: column;
    gap: 3px;
    font-size: 0.9em;
    color: #555;
}
.modal-body input[type="text"],
.modal-body input[type="url"],
.modal-body input:not([type]),
.modal-body textarea {
    width: 100%;
    font: inherit;
    padding: 8px 10px;
    border: 1px solid #ccc;
    border-radius: 6px;
    background: #fffdf9;
}
.modal-body textarea { resize: vertical; }

.modal-body fieldset {
    border: 1px solid #eee;
    border-radius: 8px;
    padding: 10px 12px;
}
.modal-body legend {
    color: #b45a17;
    font-weight: 600;
    padding: 0 6px;
}

/* Строки ингредиентов/шагов */
.dynamic-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 6px;
    align-items: start;
    margin-bottom: 6px;
}
.dynamic-row .row-del {
    background: #fee2e2;
    color: #c33;
    border: 1px solid #fbcaca;
    padding: 4px 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9em;
}
.dynamic-row .row-del:hover { background: #fecaca; }

#recipe-add-ing,
#recipe-add-step {
    margin-top: 4px;
    background: #e0edff;
    color: #1e40af;
    border: 1px solid #b7d5f5;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.85em;
    cursor: pointer;
}
#recipe-add-ing:hover,
#recipe-add-step:hover { background: #d0e2ff; }

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding-top: 10px;
    border-top: 1px solid #eee;
    margin-top: 6px;
}
.modal-actions .primary {
    background: #e07a2c;
    color: #fff;
    border: 0;
    padding: 8px 16px;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
}
.modal-actions .primary:hover { background: #c96a20; }
.modal-actions button:not(.primary) {
    background: #f0f0f0;
    color: #333;
    border: 1px solid #ddd;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
}
.want-new-label {
    display: none;
}
/* ==== Страницы авторизации ==== */
.auth-page {
    max-width: 400px;
    margin: 60px auto;
    padding: 24px;
    background: #fff;
    border: 1px solid #e5ddd2;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}
.auth-page h1 {
    margin: 0 0 4px;
    font-size: 1.6rem;
    color: #e07a2c;
    text-align: center;
}
.auth-page h2 {
    margin: 0 0 20px;
    font-size: 1.1rem;
    color: #555;
    text-align: center;
    font-weight: 500;
}
.auth-page form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.auth-page label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.9em;
    color: #555;
}
.auth-page input {
    width: 100%;
    padding: 9px 12px;
    font: inherit;
    border: 1px solid #ccc;
    border-radius: 6px;
    background: #fffdf9;
}
.auth-page input:focus {
    outline: none;
    border-color: #e07a2c;
    background: #fff;
}
.auth-page .primary {
    margin-top: 6px;
    padding: 10px 16px;
    background: #e07a2c;
    color: #fff;
    border: 0;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
}
.auth-page .primary:hover { background: #c96a20; }
.auth-page .primary:disabled { opacity: 0.6; cursor: not-allowed; }

.auth-hint {
    margin: 6px 0 0;
    text-align: center;
    font-size: 0.9em;
    color: #666;
}
.auth-hint a {
    color: #e07a2c;
    text-decoration: none;
    font-weight: 600;
}
.auth-hint a:hover { text-decoration: underline; }

.auth-page .error {
    margin-top: 12px;
    padding: 10px 12px;
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fbcaca;
    border-radius: 6px;
    font-size: 0.9em;
}
.auth-page .error[hidden] { display: none; }
/* Шапка как flex-контейнер */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 10px 16px;
    background: #e07a2c;
    color: white;
    flex-wrap: wrap;  /* на узких экранах — перенос */
}

.app-header-left {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.app-header-left h1 {
    margin: 0;
    font-size: 1.3rem;
    white-space: nowrap;
}

.app-header-left nav {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

/* Блок пользователя — правый край */
.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;    /* ← прижимает к правому краю */
    font-size: 0.9em;
    white-space: nowrap;
}

.user-info .user-email {
    opacity: 0.9;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-info a,
.user-info button {
    color: #fff;
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.3);
    padding: 5px 10px;
    border-radius: 6px;
    cursor: pointer;
    text-decoration: none;
    font: inherit;
    font-size: 0.9em;
}

.user-info a:hover,
.user-info button:hover {
    background: rgba(255,255,255,0.25);
}

/* Кнопка настроек — иконка */
.user-info .settings-btn {
    font-size: 1.1em;
    padding: 4px 8px;
    line-height: 1;
}
.settings-hint {
    margin: 0 0 12px;
    font-size: 0.9em;
    color: #666;
    line-height: 1.4;
}

.settings-status {
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.9em;
}
.settings-status.ok {
    background: #e6f6ec;
    color: #1e7a3e;
    border: 1px solid #b8e2c8;
}
.settings-status.err {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fbcaca;
}
.settings-status[hidden] { display: none; }

/* ==== Кухни ==== */
.kitchen-switcher {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9em;
    color: #fff;
    white-space: nowrap;
}
.kitchen-switcher span { opacity: 0.9; }

#kitchen-select {
    max-width: 180px;
    padding: 5px 8px;
    border: 1px solid rgba(255,255,255,0.4);
    border-radius: 6px;
    background: rgba(255,255,255,0.15);
    color: #fff;
    font: inherit;
    font-size: 0.9em;
    cursor: pointer;
}
#kitchen-select option { color: #222; background: #fff; }

#kitchens-manage-btn {
    padding: 5px 10px;
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 6px;
    background: rgba(255,255,255,0.15);
    color: #fff;
    font: inherit;
    font-size: 0.9em;
    cursor: pointer;
}
#kitchens-manage-btn:hover { background: rgba(255,255,255,0.25); }

.kitchens-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 0 0 4px;
}
.kitchen-list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border: 1px solid #e5ddd2;
    border-radius: 8px;
    background: #fffdf9;
    cursor: pointer;
    transition: border-color .15s, background .15s;
}
.kitchen-list-item:hover { border-color: #e07a2c; }
.kitchen-list-item.active {
    border-color: #e07a2c;
    background: #fff1e0;
    box-shadow: inset 3px 0 0 #e07a2c;
}
.kitchen-list-name { font-weight: 600; }
.kitchen-list-meta {
    font-size: 0.85em;
    color: #777;
    white-space: nowrap;
}

.kitchen-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px 12px;
    border: 1px solid #eee;
    border-radius: 8px;
}
.kitchen-form label {
    display: flex;
    flex-direction: column;
    gap: 3px;
    font-size: 0.9em;
    color: #555;
}
.kitchen-form input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #ccc;
    border-radius: 6px;
    background: #fffdf9;
    font: inherit;
}
.kitchen-form button { align-self: flex-start; }

.kitchen-members {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 6px 0 0;
    padding: 0;
    list-style: none;
}
.kitchen-member {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    padding: 6px 10px;
    border-radius: 6px;
    background: #faf7f2;
    font-size: 0.9em;
}
.kitchen-member-email { font-weight: 500; }
.kitchen-member-name { color: #777; }
.kitchen-member-owner {
    margin-left: auto;
    padding: 1px 7px;
    border: 1px solid #f0c9a8;
    border-radius: 10px;
    color: #b45a17;
    font-size: 0.8em;
    white-space: nowrap;
}
.kitchen-member.muted { color: #999; }
.kitchen-member.err { color: #991b1b; }

.kitchens-page {
    display: flex;
    flex-direction: column;
    gap: 14px;
    max-width: 900px;
    padding-bottom: 24px;
}
.kitchens-hint {
    max-width: 900px;
    margin: 0 0 14px;
    color: #777;
    font-size: 0.92em;
}

@media (max-width: 600px) {
    .app-header-left { width: 100%; }
    .kitchen-switcher { width: 100%; }
    #kitchen-select { flex: 1; max-width: none; }
}
/* ==== Столы ==== */
.tables-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.table-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border: 1px solid #e5ddd2;
    border-radius: 8px;
    background: #fffdf9;
    cursor: pointer;
    transition: border-color .15s, background .15s;
}
.table-card:hover {
    border-color: #e07a2c;
    background: #fff7ec;
}
.table-card:active { background: #fff1e0; }
.table-card-name { font-weight: 600; }
.table-card-meta {
    font-size: 0.85em;
    color: #777;
    white-space: nowrap;
}

.table-detail {
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.table-detail[hidden] { display: none; }
.table-detail-head {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.table-name-input {
    flex: 1 1 220px;
    min-width: 160px;
    padding: 8px 10px;
    border: 1px solid #ccc;
    border-radius: 6px;
    background: #fffdf9;
    font: inherit;
}
.table-detail-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.table-section {
    border-top: 1px solid #eee;
    padding-top: 10px;
}
.table-section h3 {
    margin: 0 0 8px;
    font-size: 1.05rem;
    color: #b45a17;
}
.table-recipes {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.table-recipe {
    background: #fff3e6;
    border-radius: 8px;
    padding: 10px 12px;
}
.table-recipe-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}
.table-recipe-tags,
.table-recipe-ings { margin-top: 6px; }
.table-remove-recipe-btn {
    background: #fee2e2;
    color: #c33;
    border: 1px solid #fbcaca;
    padding: 5px 10px;
    border-radius: 6px;
    font-size: 0.85em;
    cursor: pointer;
}
.table-remove-recipe-btn:hover { background: #fecaca; }

.table-ingredients {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}
.table-ing-group {
    flex: 1 1 240px;
    min-width: 180px;
}
.table-ing-group h4 {
    margin: 0 0 6px;
    font-size: 0.95rem;
    color: #444;
}
.table-ing-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.table-price {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 10px 12px;
    background: #eef6ff;
    border-radius: 8px;
}
.table-price-note {
    font-size: 0.85em;
    color: #b45a17;
}

.table-recipes-picker {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 50vh;
    overflow-y: auto;
}
.table-picker-item {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    border: 1px solid #eee;
    border-radius: 6px;
    background: #fffdf9;
    color: #222;
    font-size: 1em;
    cursor: pointer;
}
.table-picker-item:hover { border-color: #e07a2c; }
.table-picker-item input { flex: none; }

.table-quick-ingredients {
    display: flex;
    flex-direction: column;
}
.table-quick-ing-input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #ccc;
    border-radius: 6px;
    background: #fffdf9;
    font: inherit;
}

.table-empty { padding: 10px; }

#table-quick-add-ing {
    margin-top: 4px;
    background: #e0edff;
    color: #1e40af;
    border: 1px solid #b7d5f5;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.85em;
    cursor: pointer;
}
#table-quick-add-ing:hover { background: #d0e2ff; }

@media (max-width: 600px) {
    .table-detail-head {
        flex-direction: column;
        align-items: stretch;
    }
    .table-name-input { width: 100%; }
    .table-detail-actions button { flex: 1 1 100%; }
}

.table-detail-head .danger {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fbcaca;
}
.table-detail-head .danger:hover { background: #fecaca; }

.dish-table-select {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9em;
    color: #555;
}
.dish-table-select select {
    padding: 5px 8px;
    border: 1px solid #ccc;
    border-radius: 6px;
    background: #fffdf9;
    font: inherit;
}
