.main-nav { width: min(1120px, calc(100% - 64px)); margin: 16px auto 0; display: flex; flex-wrap: wrap; gap: 6px; }
.main-nav a, .library-tabs a { text-decoration: none; padding: 10px 17px; border-radius: 9px; color: var(--muted); font-size: 14px; }
.main-nav a[aria-current], .library-tabs a[aria-current] { color: var(--ink); background: var(--soft); font-weight: 600; }
.main-nav a:hover, .library-tabs a:hover { background: var(--hover); }
main { padding-top: 32px; }
.library-heading { display: flex; justify-content: space-between; align-items: center; gap: 32px; margin: 18px 0 30px; }
.library-heading h1 { margin: 10px 0 16px; }
.library-heading p, .muted { color: var(--muted); }
.library-heading p { margin: 0; }
.product-title { font-size: clamp(32px, 4vw, 48px); overflow-wrap: anywhere; }
.button-row { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.library-heading > .button-row { max-width: 340px; justify-content: flex-end; flex-shrink: 0; }
.button.primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.button.primary:hover { filter: brightness(.94); }
.library-toolbar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 18px; padding: 20px 0; border-block: 1px solid var(--line); margin-bottom: 24px; }
.library-tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.library-search { display: flex; align-items: center; gap: 8px; }
input, select, textarea { max-width: 100%; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); color: var(--ink); padding: 11px 12px; font: inherit; min-width: 0; }
select { cursor: pointer; }
textarea { resize: vertical; }
input[type=checkbox] { accent-color: var(--accent); width: 20px; height: 20px; }
.library-search input { width: 100%; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.library-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.library-card { display: flex; flex-direction: column; min-width: 0; padding: 22px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); }
.library-card-top { display: flex; align-items: center; justify-content: space-between; color: var(--muted); }
.favourite-button { border: 0; background: transparent; color: var(--accent); font-size: 27px; min-width: 44px; min-height: 44px; border-radius: 8px; }
.favourite-button:hover { background: var(--hover); }
.library-card h2 { margin: 16px 0 12px; font-size: 20px; overflow-wrap: anywhere; }
.library-card h2 a { text-decoration: none; }
.library-card h2 a:hover { text-decoration: underline; }
.library-card p { color: var(--muted); margin: 0 0 10px; font-size: 13px; }
.card-actions { margin-top: auto; padding-top: 20px; }
.library-empty { grid-column: 1 / -1; background: var(--surface); border: 1px dashed var(--line); border-radius: 16px; padding: 65px 22px; }
.library-empty p { max-width: 540px; margin-inline: auto; }
.library-empty .button { margin-top: 16px; }
.library-footnote { color: var(--muted); font-size: 13px; margin: 26px 0 40px; }
.back-link { display: inline-block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.form-panel { padding: 26px; margin-bottom: 20px; }
.form-panel h2 { font-size: 21px; margin: 0 0 16px; }
.form-panel > p { font-size: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 24px; }
.form-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; margin-bottom: 12px; }
.form-field label, .portion-row label, .ingredient-row label { font-size: 13px; font-weight: 600; }
.form-field:has(textarea) { grid-column: 1 / -1; }
.checkbox-field { flex-direction: row; align-items: center; gap: 12px; }
.form-field small, .portion-row small { color: var(--muted); font-size: 12px; }
.errorlist { background: var(--soft); color: var(--ink); border-left: 3px solid #b87360; border-radius: 4px; padding: 10px 12px 10px 28px; margin: 4px 0 14px; font-size: 14px; }
.form-actions { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin: 24px 0 44px; }
.form-actions span { font-size: 13px; color: var(--muted); }
.lookup-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
.search-results article { display: flex; justify-content: space-between; align-items: center; gap: 20px; border-bottom: 1px solid var(--line); padding: 16px 0; }
.search-results h3 { font-size: 15px; margin: 0 0 6px; }
.search-results p { margin: 0; color: var(--muted); font-size: 12px; }
.ingredient-row { display: flex; flex-wrap: wrap; align-items: end; gap: 16px; border-bottom: 1px solid var(--line); margin-bottom: 16px; padding-bottom: 12px; }
.ingredient-row p { display: flex; flex-direction: column; gap: 6px; flex: 1 1 180px; min-width: 0; }
.ingredient-row p:first-of-type { flex: 3 1 240px; }
.ingredient-row p:has(input[type=checkbox]) { flex: 0 1 60px; }
.ingredient-row .ingredient-basis { flex: 1 1 100%; font-size: 13px; margin-top: 0; }
.ingredient-search { flex: 1 1 100%; min-width: 0; }
.ingredient-search-panel { margin-top: 12px; padding: 16px; border: 1px solid var(--line); border-radius: 12px; }
.ingredient-search-panel label { display: grid; gap: 8px; margin-bottom: 10px; }
.ingredient-search-panel input { width: 100%; min-width: 0; }
.ingredient-results { display: grid; gap: 12px; max-height: 540px; overflow: auto; }
.ingredient-results article { padding: 14px; border: 1px solid var(--line); border-radius: 10px; overflow-wrap: anywhere; }
.ingredient-results article p { display: block; font-size: 13px; margin: 8px 0; }
.ingredient-results details { margin-bottom: 12px; }
.ingredient-search-panel[hidden] { display: none; }
.portion-row { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; padding: 20px 0; border-top: 1px solid var(--line); }
.portion-row h3 { margin: 0; font-size: 17px; }
.portion-row p { margin: 6px 0; }
.portion-row > div:last-child { display: flex; flex-direction: column; gap: 6px; }
.undo-bar { display: flex; align-items: center; gap: 18px; color: var(--muted); font-size: 13px; margin-bottom: 20px; }
.product-macros { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; padding: 20px; background: var(--soft); border-radius: 10px; }
.product-macros dt { color: var(--muted); font-size: 13px; }
.product-macros dd { margin: 5px 0 0; font-size: 21px; }
.label-details summary { cursor: pointer; padding: 12px 0; }
.preserve-lines { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; }
.label-list > div { padding: 18px 0; border-bottom: 1px solid var(--line); }
.label-list dt { font-size: 14px; font-weight: 600; margin-bottom: 8px; }
.label-list dd { margin: 0; color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.recipe-parts > div { display: flex; justify-content: space-between; gap: 20px; padding: 16px 0; border-bottom: 1px solid var(--line); }
.recipe-parts small { display: block; color: var(--muted); font-size: 12px; }
.meal-group { padding-block: 0; }
.meal-group > summary { list-style: none; cursor: pointer; display: grid; grid-template-columns: 94px minmax(0, 1fr) 20px; gap: 6px 14px; align-items: start; padding: 24px 0; }
.meal-group > summary::-webkit-details-marker { display: none; }
.meal-category { font-size: 15px; }
.meal-title { font-size: 15px; overflow-wrap: anywhere; }
.meal-time { font-size: 12px; color: var(--muted); grid-row: 2; white-space: nowrap; }
.meal-total-macros { display: flex; flex-wrap: wrap; gap: 3px 13px; font-size: 12px; color: var(--muted); grid-column: 2; }
.meal-total-macros strong { color: var(--ink); font-weight: 500; }
.meal-quality { display: block; flex-basis: 100%; font-size: 11px; }
.meal-toggle { grid-column: 3; grid-row: 1 / 3; transition: transform .15s; }
.meal-group[open] > summary .meal-toggle { transform: rotate(180deg); }
.meal-contents { padding-left: 20px; border-left: 2px solid var(--line); margin-bottom: 20px; }
.meal-edit { display: inline-block; margin: 14px 0; font-size: 13px; }
@media (max-width: 960px) {
  .library-heading { flex-direction: column; align-items: stretch; gap: 22px; }
  .library-heading > .button-row { max-width: none; justify-content: flex-start; }
  .library-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 680px) {
  .main-nav { width: calc(100% - 36px); }
  .main-nav a { padding: 10px 12px; }
  .library-grid, .lookup-grid, .form-grid, .portion-row { grid-template-columns: 1fr; }
  .library-toolbar, .library-search { width: 100%; }
  .library-tabs { width: 100%; gap: 0; }
  .library-tabs a { padding: 10px 12px; }
  .library-heading h1 { font-size: 39px; }
  .library-heading .product-title { font-size: 32px; }
  .form-panel { padding: 20px; }
  .product-macros { grid-template-columns: 1fr 1fr; }
  .meal-group > summary { grid-template-columns: 76px minmax(0, 1fr) 16px; gap: 5px 8px; }
  .meal-category, .meal-title { font-size: 13px; }
  .meal-time, .meal-total-macros { font-size: 11px; }
  .meal-contents { padding-left: 12px; }
  .portion-row { gap: 10px; }
}

.button.danger { color: var(--ink); border-color: #b46363; }
.button.danger:hover { background: #a33d3d; color: #fff; }
