:root {
    color-scheme: light;
    --ink: #182b25;
    --muted: #546660;
    --green: #245c47;
    --green-dark: #143b30;
    --green-soft: #e8f1eb;
    --border: #dce5de;
    --background: #f4f7f3;
    --red: #a22d36;
    font: 100%/1.5 "Segoe UI", system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { margin: 0; background: var(--background); color: var(--ink); }
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: var(--green); }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, [tabindex]:focus-visible {
    outline: 3px solid #367c60;
    outline-offset: 3px;
}
h1, h2, h3, p { margin: 0; overflow-wrap: anywhere; }
h1, h2, h3 { line-height: 1.18; letter-spacing: -.025em; }
h1 { font-size: clamp(2rem, 3.8vw, 3.125rem); }
h2 { font-size: 1.38rem; }
h3 { font-size: 1.12rem; }
.shell { width: min(100% - 3rem, 1200px); margin-inline: auto; min-width: 0; }
.panel, .hero-copy, .ingredient-field, .line-cost, .result { min-width: 0; }
.icon { width: 1.25rem; height: 1.25rem; flex: none; vertical-align: middle; }
.site-header { background: white; border-bottom: 1px solid var(--border); }
.header-inner { min-height: 74px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem; padding-block: 10px; }
.brand { display: inline-flex; align-items: center; color: var(--ink); font-size: 1.28rem; font-weight: 750; letter-spacing: -.045em; text-decoration: none; }
.brand > span:last-child { color: var(--green); }
.brand-mark { display: grid; place-items: center; width: 40px; height: 40px; margin-right: .65rem; border-radius: 12px; background: var(--green-dark); color: white; }
.brand-mark .icon { width: 23px; height: 23px; }
.nav-link, .button { display: inline-flex; align-items: center; justify-content: center; gap: .55rem; min-height: 46px; padding: .62rem 1rem; border-radius: 10px; font-size: .94rem; font-weight: 650; text-decoration: none; white-space: nowrap; }
.nav-link { color: var(--green-dark); }
.nav-link:hover, .nav-link[aria-current] { background: var(--green-soft); }
.header-inner nav { display: flex; align-items: center; gap: .55rem; }
.button { cursor: pointer; border: 1px solid transparent; max-width: 100%; white-space: normal; text-align: center; overflow-wrap: anywhere; }
.button:disabled { opacity: .6; cursor: wait; }
.button.primary { color: white; background: var(--green); }
.button.primary:hover { background: var(--green-dark); }
.button.secondary { color: var(--green-dark); background: white; border-color: #becfc4; }
.button.secondary:hover { background: var(--green-soft); }
.button.danger { color: var(--red); border-color: #ebbbc1; background: white; }
.button.danger:hover { background: #fcecef; }
main { padding-block: 32px 0; }
.hero { position: relative; overflow: hidden; min-height: 250px; display: flex; align-items: center; border-radius: 22px; background: linear-gradient(108deg, #133a2e 25%, #215741); color: white; }
.hero-copy { position: relative; z-index: 1; padding: 38px clamp(24px, 4vw, 52px); }
.hero p { margin: .7rem 0 1.4rem; color: #e0efe6; font-size: 1.04rem; }
.hero-button { background: #e5f1cf; color: #16392b; }
.hero-button:hover { background: white; }
.hero-button:focus-visible { outline-color: white; }
.hero-art { position: absolute; inset: 0 0 0 auto; width: 35%; display: grid; place-items: center; color: #cce8bf; opacity: .36; pointer-events: none; }
.plate-outline { display: grid; place-items: center; width: 240px; aspect-ratio: 1; border-radius: 50%; border: 1px solid currentColor; box-shadow: 0 0 0 22px #bddfb31b, 0 0 0 44px #bddfb313, 0 0 0 68px #bddfb30b; transform: translateX(10%); }
.plate-outline div { display: grid; place-items: center; width: 78%; aspect-ratio: 1; border: 1px solid currentColor; border-radius: 50%; }
.plate-outline .icon { width: 94px; height: 94px; stroke-width: .8; }
.panel { background: white; border: 1px solid var(--border); border-radius: 16px; box-shadow: 0 2px 6px #16392b05; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; margin-block: 20px; }
.stat { min-width: 0; display: flex; align-items: center; gap: .9rem; padding: 18px 22px; }
.feature-icon { flex: none; display: inline-grid; place-items: center; width: 46px; height: 46px; border-radius: 12px; color: var(--green); background: var(--green-soft); }
.feature-icon .icon { width: 22px; height: 22px; }
.stat div { display: grid; min-width: 0; overflow-wrap: anywhere; }
.stat strong { font-size: 1.55rem; line-height: 1.2; }
.stat div span, .section-heading p, .section-top p, .empty p, .editor-heading p { color: var(--muted); }
.section-heading { padding: 23px 24px 18px; }
.section-heading p, .section-top p { margin-top: .35rem; }
.dish-filters { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; padding: 0 24px 16px; }
.dish-filters .field:first-child { flex: 2 1 16rem; }
.dish-filters .field { flex: 1 1 12rem; }
.dish-count { padding: 0 24px 16px; color: var(--muted); font-size: .94rem; }
.dish-pagination { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 12px; padding: 18px 24px; border-top: 1px solid var(--border); }
.dish-pages { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px; }
.dish-pages .button { min-width: 44px; padding-inline: .7rem; }
.dish-pages [aria-current="page"] { color: white; background: var(--green); border-color: var(--green); }
.dish-pagination .button:disabled { cursor: default; }
.table-wrap { overflow-x: auto; max-width: 100%; min-width: 0; }
table { width: 100%; border-collapse: collapse; }
table th, table td { padding: 15px 20px; text-align: right; }
table th:first-child { padding-left: 24px; text-align: left; }
table th:last-child, table td:last-child { padding-right: 24px; }
thead th { border-block: 1px solid var(--border); background: #f7faf7; color: #40564c; font-size: .875rem; line-height: 1.35; }
thead span { display: block; color: var(--muted); font-weight: 400; }
.dish-sort { position: relative; min-height: 44px; padding: .3rem 1rem .3rem 0; border: 0; background: transparent; color: inherit; font: inherit; font-weight: 700; text-align: inherit; cursor: pointer; }
.dish-sort::after { content: ''; position: absolute; right: 0; top: 50%; border-left: 4px solid transparent; border-right: 4px solid transparent; border-bottom: 6px solid currentColor; opacity: .3; }
[aria-sort="ascending"] .dish-sort::after, [aria-sort="descending"] .dish-sort::after { opacity: 1; color: var(--green); }
[aria-sort="descending"] .dish-sort::after { transform: rotate(180deg); }
.dish-sort:hover { color: var(--green); }
tbody td, tbody th { border-bottom: 1px solid var(--border); }
tbody tr:last-child > * { border-bottom: 0; }
tbody tr:hover { background: #f8fbf8; }
tbody a { display: inline-flex; align-items: center; min-height: 44px; font-weight: 700; text-underline-offset: .2em; }
tbody td { white-space: nowrap; }
.margin-tag { display: inline-block; padding: .26rem .65rem; border-radius: 7px; color: #215940; background: var(--green-soft); font-weight: 650; }
.margin-tag.unavailable { color: var(--muted); background: #f2f4f2; }
.margin-tag.negative { background: #fcecef; }
.category-cell { text-align: left; }
tbody td.category-cell { white-space: normal; overflow-wrap: anywhere; min-width: 7rem; }
.negative { color: var(--red) !important; }
.empty { display: grid; gap: .65rem; justify-items: center; text-align: center; padding: 35px 20px; }
.empty.compact { padding: 22px 18px; margin-block: 1rem; background: #f8faf8; border: 1px dashed #cbd9ce; border-radius: 12px; }
.footnote { display: flex; align-items: flex-start; gap: .5rem; color: var(--muted); font-size: .875rem; margin-top: 16px; }
.footnote .icon { width: 1rem; height: 1rem; margin-top: .14rem; }
.site-footer { margin-top: 38px; padding: 17px 0 24px; border-top: 1px solid var(--border); color: var(--muted); font-size: .875rem; }
.site-footer span { margin-inline: .3rem; }
.editor-heading, .section-top, .form-actions { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.editor-heading { margin-bottom: 20px; flex-wrap: wrap; }
.editor-heading > *, .section-top > *, .form-actions > * { min-width: 0; }
.editor-save-actions { display: flex; flex-wrap: wrap; gap: .65rem; }
.editor-heading h1 { font-size: clamp(2rem, 3.6vw, 2.8rem); margin-block: .2rem; }
.back-link { display: inline-flex; align-items: center; min-height: 36px; text-underline-offset: .2em; font-weight: 650; }
.editor-section { padding: 23px 24px; margin-bottom: 16px; }
.dish-fields, .line-fields, .purchase-fields { display: grid; gap: 12px; }
.dish-fields { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1.4fr) minmax(0, .95fr); margin-top: 16px; }
.category-field { width: min(100%, 22rem); margin-top: 12px; }
.form-actions { flex-wrap: wrap; }
.form-actions .danger { margin-left: auto; }
.auth-panel { width: min(100%, 460px); margin: clamp(24px, 7vh, 80px) auto; padding: clamp(22px, 4vw, 34px); }
.auth-panel h1 { font-size: clamp(1.7rem, 3.5vw, 2.2rem); margin-bottom: .75rem; }
.auth-panel > p:not(.message) { color: var(--muted); }
.auth-form { display: grid; gap: 14px; margin-top: 20px; }
.field { display: grid; align-content: start; gap: .35rem; min-width: 0; color: #344a40; font-size: .875rem; font-weight: 650; }
.field input, .field select { display: block; width: 100%; min-width: 0; height: 46px; background-color: white; border: 1px solid #c5d3c9; border-radius: 8px; padding: 0 .7rem; color: var(--ink); font-size: 1rem; font-weight: 450; }
.field select { appearance: none; padding-right: 1.8rem; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='m1 1 5 5 5-5' fill='none' stroke='%23344a40' stroke-width='1.5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .65rem center; }
.field [aria-invalid="true"] { border-color: var(--red); }
.with-unit { position: relative; }
.with-unit input { padding-right: 1.8rem; }
.with-unit > span { position: absolute; top: 50%; right: .72rem; color: var(--muted); transform: translateY(-50%); pointer-events: none; }
.recipe-line { padding: 14px; margin-top: 12px; border: 1px solid var(--border); border-radius: 11px; background: #f9fbf9; }
.line-fields { grid-template-columns: minmax(0, 2.2fr) minmax(0, 1fr) minmax(0, .9fr) minmax(0, 1fr) 46px; }
.ingredient-dropdown { position: relative; min-width: 0; }
.ingredient-trigger { display: block; width: 100%; min-height: 46px; margin-top: .35rem; padding: .6rem 2rem .6rem .7rem; border: 1px solid #c5d3c9; border-radius: 8px; background: white; color: var(--ink); text-align: left; cursor: pointer; overflow-wrap: anywhere; }
.ingredient-trigger::after { content: ''; position: absolute; right: .85rem; top: 2.45rem; width: .5rem; height: .5rem; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(45deg); }
.ingredient-trigger[aria-expanded="true"] { border-color: var(--green); }
.ingredient-popup { position: absolute; top: calc(100% + 6px); left: 0; z-index: 30; width: max(100%, 280px); max-width: calc(100vw - 5rem); padding: 12px; border: 1px solid #becfc4; border-radius: 10px; background: white; box-shadow: 0 8px 24px #16392b26; }
.ingredient-options { max-height: min(280px, 40vh); overflow-y: auto; margin-top: .5rem; overscroll-behavior: contain; }
.ingredient-option-heading { padding: .6rem .5rem .3rem; color: var(--muted); font-size: .875rem; font-weight: 650; }
.ingredient-option { display: block; width: 100%; min-height: 44px; padding: .55rem .65rem; border: 0; border-radius: 6px; background: white; color: var(--ink); text-align: left; cursor: pointer; overflow-wrap: anywhere; }
.ingredient-option:hover, .ingredient-option.active { background: var(--green-soft); }
.ingredient-option[aria-selected="true"] { color: var(--green-dark); font-weight: 700; background: var(--green-soft); }
.ingredient-search-status { margin-top: .4rem; color: var(--muted); font-size: .875rem; }
.line-cost { display: grid; align-content: start; gap: .35rem; text-align: right; font-size: .875rem; color: #344a40; font-weight: 650; }
.line-cost strong { display: grid; align-items: center; height: 46px; font-size: 1.06rem; color: var(--ink); white-space: nowrap; }
.remove-line { width: 46px; height: 46px; margin-top: calc(1.3125rem + .35rem); border: 1px solid var(--border); border-radius: 8px; background: white; color: var(--red); cursor: pointer; }
.remove-line:hover { background: #fcecef; }
.text-button { display: inline-flex; gap: .32rem; align-items: center; min-height: 44px; border: 0; padding: .2rem 0; background: transparent; color: var(--green); font-size: .875rem; text-decoration: underline; text-underline-offset: .18em; cursor: pointer; }
.text-button .icon { width: 1rem; height: 1rem; }
.purchase { margin: .45rem 0 0; min-width: 0; padding: .8rem 1rem 1rem; border: 1px solid #cbd9ce; border-radius: 8px; }
.purchase legend { padding-inline: .35rem; font-weight: 700; }
.purchase-fields { grid-template-columns: minmax(0, 2fr) repeat(2, minmax(0, 1fr)) minmax(0, 1.15fr) repeat(2, minmax(0, 1fr)); }
.shared-notice, .line-error { display: flex; gap: .45rem; align-items: flex-start; margin-bottom: .75rem; color: var(--muted); font-size: .875rem; }
.shared-notice .icon { width: 1rem; height: 1rem; margin-top: .15rem; }
.line-error { margin: .35rem 0 0; color: var(--red); }
.recipe-total { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem; margin-top: 16px; padding: .85rem 1rem; border-radius: 8px; background: var(--green-soft); color: var(--green-dark); }
.recipe-total strong { font-size: 1.25rem; white-space: nowrap; }
.results { background: #fcfefb; }
.result-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 15px; }
.result { padding: 15px; display: grid; gap: .25rem; border: 1px solid #d5e5d8; border-radius: 11px; background: #edf5ed; color: var(--green-dark); }
.result span { font-size: .875rem; font-weight: 650; }
.result strong { font-size: clamp(1.25rem, 2.5vw, 1.85rem); line-height: 1.16; overflow-wrap: anywhere; }
.other-results { display: flex; flex-wrap: wrap; gap: .45rem 1.5rem; margin: 15px 0 0; font-size: .92rem; }
.other-results div { display: flex; flex-wrap: wrap; gap: .55rem; align-items: baseline; min-width: 0; }
.other-results dt { color: var(--muted); }
.other-results dd { margin: 0; font-weight: 700; white-space: nowrap; }
.message { margin-bottom: 12px; padding: .75rem 1rem; border: 1px solid #b8d2bf; border-radius: 10px; background: var(--green-soft); color: var(--green-dark); }
.message.error { background: #fcecef; color: var(--red); border-color: #ebbbc1; }
.pwa-install-help { padding: 20px; margin-bottom: 20px; }
.pwa-install-help p { margin-top: .75rem; }

@media (max-width: 1000px) {
    .dish-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .purchase-fields { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    table th, table td { padding-inline: 12px; }
    .line-fields { grid-template-columns: repeat(3, minmax(0, 1fr)) 46px; }
    .ingredient-field { grid-column: 1 / -1; min-width: 0; }
    .ingredient-popup { width: 100%; max-width: 100%; }
    .table-wrap { overflow: visible; }
    #dish-table, #dish-table thead, #dish-table tbody { display: block; }
    #dish-table thead tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); background: #f7faf7; padding: 8px 12px; gap: 4px; }
    #dish-table thead th { display: block; padding: 0; border: 0; text-align: left; min-width: 0; }
    #dish-table .dish-sort { width: 100%; padding-left: .4rem; overflow-wrap: anywhere; }
    #dish-table tbody { padding: 12px; }
    #dish-table tbody tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); margin-bottom: 12px; border: 1px solid var(--border); border-radius: 10px; padding: 12px; gap: 12px; }
    #dish-table tbody tr:last-child { margin-bottom: 0; }
    #dish-table tbody th, #dish-table tbody td { display: block; border: 0; padding: 0; min-width: 0; white-space: normal; text-align: left; overflow-wrap: anywhere; }
    #dish-table tbody th, #dish-table tbody .category-cell { grid-column: 1 / -1; }
    #dish-table tbody a { overflow-wrap: anywhere; }
    #dish-table tbody td::before { content: attr(data-label); display: block; margin-bottom: .2rem; color: var(--muted); font-size: .8rem; font-weight: 400; }
}

@media (max-width: 640px) {
    .shell { width: calc(100% - 1.5rem); }
    .header-inner { min-height: 62px; }
    .header-inner nav { flex-basis: 100%; flex-wrap: wrap; justify-content: flex-end; }
    .header-inner nav { gap: .25rem; }
    .header-inner nav .button, .header-inner nav .nav-link { padding-inline: .55rem; }
    .header-inner nav .nav-link .icon { display: none; }
    main { padding-top: 16px; }
    .hero { min-height: 210px; }
    .hero-copy { padding: 22px; }
    .hero-art { display: none; }
    .stats { gap: 8px; margin-block: 12px; }
    .stat { gap: .5rem; padding: 10px; }
    .stat div span { font-size: .875rem; }
    .stat .feature-icon { width: 34px; height: 34px; }
    .section-heading, .editor-section { padding: 16px; }
    .editor-heading { flex-wrap: wrap; }
    .dish-filters { padding-inline: 16px; }
    .dish-count { padding-inline: 16px; }
    .dish-pagination { gap: 8px; padding: 16px; }
    .dish-pages { order: 1; flex-basis: 100%; }
    .section-top { align-items: flex-start; flex-direction: column; gap: .7rem; }
    .line-fields { grid-template-columns: repeat(3, minmax(0, 1fr)) 46px; gap: 8px; }
    .ingredient-field { grid-column: 1 / -1; }
    .ingredient-popup { position: static; margin-top: 6px; }
    .ingredient-options { max-height: 35vh; max-height: 35dvh; }
    .purchase-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .purchase { padding-inline: .65rem; }
    .result-grid { grid-template-columns: 1fr; gap: 7px; }
    .result { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: center; gap: .75rem; }
    .result strong { text-align: right; }
    .editor-save-actions { width: 100%; }
    .editor-save-actions .button { flex: 1 1 9rem; }
    .form-actions .button { flex: 1 1 9rem; }
    .form-actions .danger { margin-left: 0; }
    .line-cost strong, .recipe-total strong, .other-results dd { white-space: normal; overflow-wrap: anywhere; height: auto; min-height: 46px; }
}

@media (max-width: 480px) {
    .dish-fields { grid-template-columns: 1fr; }
    .line-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .line-cost { text-align: left; }
    .remove-line { justify-self: end; }
}

@media (max-height: 500px) and (orientation: landscape) {
    .hero { min-height: 0; }
    .hero-copy { padding-block: 20px; }
    .ingredient-popup { position: static; margin-top: 6px; }
    .ingredient-options { max-height: 40vh; max-height: 40dvh; }
}
