/* Option B responsive/accessibility overrides. Load after workspace design CSS.
   Keep the document canvas and the shared recipe/label/print styles independent. */
@media screen {
.md-shell .md-sheet > header > div { min-width: 0; flex: 1; }
.md-shell .md-sheet > header p,
.md-shell .md-dialog strong,
.md-shell .md-section > header h3 { overflow-wrap: anywhere; }
.md-shell .md-sheet > header > button { flex-shrink: 0; min-width: 44px; min-height: 44px; }
.md-shell .md-sheet { max-height: 100dvh; min-width: 0; }
.md-shell .md-sheet > header { flex-shrink: 0; max-height: 40%; overflow: auto; }
.md-shell .md-sheet-body { min-width: 0; }
.md-shell .md-sheet-body .md-allergen-heading { font-size: 13px; font-weight: 650; line-height: 1.5; }
.md-shell .md-allergen-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-bottom: 16px; }
.md-shell .md-allergen { min-height: 56px; padding: 7px 10px; }
.md-shell .md-allergen > span:last-child { min-width: 0; overflow-wrap: anywhere; }
.md-shell .md-dialog footer { flex-wrap: wrap; }

/* The consent banner remains available after closing the menu dialog. Its
   preferences dialog and the shared removal confirmation keep their own layer. */
body:has(.md-shell [role="dialog"]) { overflow: hidden; }
body:has(.md-shell [role="dialog"]) > .ak-ck-banner { z-index: 100; }

}

@media screen and (max-width: 800px) {
  .md-shell .md-button,
  .md-shell input:not([type="checkbox"]):not([type="radio"]),
  .md-shell select { min-height: 44px; }
  .md-shell .md-section > header { min-width: 0; }
  .md-shell .md-section > header h3 { min-width: 0; max-width: 100%; }
  .md-shell .md-section > header > div { flex-wrap: wrap; gap: 6px; }
  .md-shell .md-section > header button { min-width: 44px; min-height: 44px; font-size: 12px; padding: 9px 10px; }
  .md-shell .md-mobile-outline > * { min-width: 0; flex-basis: 0; }
  .md-shell .md-mobile-outline select { max-width: none; }
  .md-shell .md-sheet > footer > div { min-width: 0; }
  .md-shell .md-sheet > footer > button { flex-shrink: 0; }
  .md-shell .menu-review-check { min-height: 44px; align-items: center; }
}

@media screen and (max-width: 380px) {
  .md-shell .md-section > header > div { margin-left: 0; }
  .md-shell .md-sheet > footer { gap: 8px; }
}

/* At high zoom or in a short landscape window, fixed headers and footers can
   leave less space than one allergen control. Scroll the complete dialog. */
@media screen and (max-height: 420px) {
  .md-shell .md-sheet,
  .md-shell .md-dialog.md-item-picker,
  .md-shell .md-dialog.md-deleted-dialog {
    display: block;
    overflow: auto;
    overscroll-behavior: contain;
  }

  .md-shell .md-dialog.md-item-picker,
  .md-shell .md-dialog.md-deleted-dialog { height: auto; }

  .md-shell .md-sheet > header { max-height: none; overflow: visible; }
  .md-shell .md-sheet-body,
  .md-shell .md-picker-body { overflow: visible; }
}

/* Keep the current menu and its next safe action together. Secondary document
   and section commands use native disclosures, so keyboard behavior stays native. */
@media screen {
  .md-shell [hidden] { display: none; }
  .md-shell .md-menu-header { align-items: center; padding: 18px 22px; gap: 14px 24px; }
  .md-shell .md-menu-header > .md-menu-heading { display: block; flex: 1 1 22rem; min-width: 0; margin: 0; }
  .md-shell .md-menu-header .md-document-name { font-size: 1.5rem; line-height: 1.25; letter-spacing: -.02em; }
  .md-shell .md-menu-header [data-menu-status] { max-width: 68ch; margin-top: 6px; font-size: .8125rem; line-height: 1.5; }
  .md-shell .md-menu-header > .md-menu-header-actions,
  .md-shell .md-stage-nav { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-width: 0; }
  .md-shell .md-menu-header > .md-menu-header-actions { flex: 0 1 auto; margin-left: auto; }
  .md-shell .md-stage-nav [aria-current="step"] { background: var(--md-sage); border-color: #849f87; color: var(--md-ink); opacity: 1; }
  .md-shell .md-canvas { padding-top: 24px; }
  .md-shell .md-switcher { min-height: 44px; }
  .md-shell .md-editor-toolbar { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 8px; }
  .md-shell .md-menu-context { margin-top: 12px; color: #526154; font-size: .8125rem; line-height: 1.5; }
  .md-shell .md-searchbar { margin: 18px 0; }
  .md-shell .md-section { margin-top: 22px; }
  .md-shell .md-section > header { gap: 4px 8px; padding: 0; border: 0; }
  .md-shell .md-section > header h3 { margin: 0; font-size: .8125rem; line-height: 1.5; font-weight: 650; }
  .md-shell .md-section-empty { color: #526154; font-size: .75rem; line-height: 1.5; }
  .md-shell .md-section-menu,
  .md-shell .md-menu-options { margin-left: auto; max-width: 100%; }
  .md-shell .md-section-menu > summary,
  .md-shell .md-menu-options > [data-md-dropdown],
  .md-shell .md-print-help > summary { min-height: 44px; padding: 12px 10px; color: var(--md-green); font-size: .8125rem; font-weight: 650; line-height: 1.5; cursor: pointer; }
  .md-shell .md-section-menu > div,
  .md-shell .md-menu-options > div { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 0; max-width: 100%; }
  .md-shell .md-section-menu:not([open]) > div,
  .md-shell .md-menu-options:not([open]) > div { display: none; }
  .md-shell .md-section-menu > summary:focus-visible,
  .md-shell .md-menu-options > [data-md-dropdown]:focus-visible,
  .md-shell .md-print-help > summary:focus-visible { outline: 3px solid #bc623b; outline-offset: 1px; }
  .md-shell .md-item-row { min-height: 76px; padding: 15px 4px; }
  .md-shell .md-item-state { max-width: 9rem; }
  .md-shell [data-menu-stage-heading] { font-size: 1.25rem; }
  .md-shell .md-proof-layout { margin-top: 18px; }
  .md-shell .md-review-panel > [data-menu-next-step] { margin: 14px 0; }
  .md-shell .md-print-help { margin-top: 14px; border-top: 1px solid var(--md-line); }
  .md-shell .md-print-help > p { font-size: .8125rem; line-height: 1.5; }
}

@media screen and (max-width: 800px) {
  .md-shell .md-menu-header { padding: 16px 20px; }
  .md-shell .md-menu-header > .md-menu-heading { flex-basis: 100%; }
  .md-shell .md-menu-header > .md-menu-header-actions { flex: 1 1 100%; width: 100%; margin: 0; }
  .md-shell .md-menu-header .md-stage-nav { flex: 1 1 auto; }
  .md-shell .md-menu-header .md-stage-nav > button { flex: 1 1 auto; }
  .md-shell .md-menu-header [data-menu-status] { font-size: .8125rem; }
  .md-shell .md-menu-options { margin-left: 0; }
  .md-shell .md-item-state { min-width: 0; flex: 0 0 7rem; }
  .md-shell .md-mobile-outline { margin-bottom: 18px; }
}

@media screen and (max-width: 380px) {
  .md-shell .md-menu-header { padding: 14px 15px; }
  .md-shell .md-menu-header > .md-menu-header-actions > button { width: 100%; }
  .md-shell .md-item-row { flex-wrap: wrap; gap: 6px; }
  .md-shell .md-item-state { flex-basis: 100%; max-width: none; text-align: left; }
}

@media screen {
  .md-shell .md-item-notes > summary,
  .md-shell .md-item-placement > summary,
  .md-shell .md-item-recovery > summary,
  .md-shell .md-item-usage > summary,
  .md-shell .md-review-items > summary {
    min-height: 44px;
    padding: 12px 4px;
    color: var(--md-green);
    font-size: .8125rem;
    font-weight: 650;
    line-height: 1.5;
    cursor: pointer;
  }
  .md-shell .md-item-notes > summary:focus-visible,
  .md-shell .md-item-placement > summary:focus-visible,
  .md-shell .md-item-recovery > summary:focus-visible,
  .md-shell .md-item-usage > summary:focus-visible,
  .md-shell .md-review-items > summary:focus-visible { outline: 3px solid #bc623b; outline-offset: 1px; }
  .md-shell .md-item-notes[open] > label,
  .md-shell .md-item-placement[open] > label { margin-top: 8px; }
}

@media screen {
  .md-shell .md-workspace-status { padding: 14px 22px; color: #526154; font-size: .8125rem; line-height: 1.5; }
}

/* One-menu edits need a scope note; shared edits retain the stronger warning. */
@media screen {
  .md-shell .md-shared-item-scope.is-compact {
    margin: 0 0 12px;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: #526154;
  }
  .md-shell .md-shared-item-scope.is-compact > strong { color: var(--md-ink); }
  .md-shell .md-shared-item-scope.is-compact > p { margin-top: 4px; }
  .md-shell .md-shared-item-scope.is-compact + h3 { margin-top: 16px; }
}

/* Direct editing: the menu is the working surface; optional tools stay nearby. */
@media screen {
  .md-shell .md-workspace { display: block; }
  .md-shell .md-canvas { min-width: 0; padding: 24px 28px 36px; }
  .md-shell .md-menu-header .md-document-name { margin: 0; }
  .md-shell .md-document-name > button {
    display: inline-flex; align-items: center; gap: 10px; max-width: 100%;
    min-height: 44px; padding: 0; border: 0; background: transparent;
    color: inherit; font: inherit; font-weight: 750; text-align: left; cursor: pointer;
    overflow-wrap: anywhere;
  }
  .md-shell .md-document-name > button > svg { flex: 0 0 18px; color: #667168; }
  .md-shell .md-document-name > button:hover { color: var(--md-green); }
  .md-shell .md-document-name > button:focus-visible { outline: 3px solid #bc623b; outline-offset: 4px; border-radius: 3px; }
  .md-shell [data-menu-save-state] { min-height: 20px; margin: 3px 0 0; font-size: .8125rem; line-height: 20px; color: #526154; }
  .md-shell .md-menu-header [data-menu-status] { margin: 5px 0 0; }
  .md-shell .md-editor-toolbar { align-items: center; }
  .md-shell .md-menu-options { margin-left: auto; position: relative; z-index: 3; }
  .md-shell .md-menu-options > div { position: absolute; top: 100%; right: 0; min-width: 180px; padding: 6px; flex-direction: column; background: var(--md-paper); border: 1px solid var(--md-line); border-radius: 8px; box-shadow: 0 8px 22px #1b2b211a; }
  .md-shell .md-menu-options > div > button { text-align: left; border: 0; }
  .md-shell .md-contents { position: relative; z-index: 2; }
  .md-shell .md-contents > [data-md-dropdown] { min-height: 44px; padding: 12px 10px; color: var(--md-green); font-size: .8125rem; line-height: 1.5; font-weight: 650; cursor: pointer; }
  .md-shell .md-contents > nav { position: absolute; top: 100%; left: 0; display: flex; flex-direction: column; width: min(280px, 65vw); max-height: 50vh; overflow: auto; padding: 6px; background: var(--md-paper); border: 1px solid var(--md-line); border-radius: 8px; box-shadow: 0 8px 22px #1b2b211a; }
  .md-shell .md-contents:not([open]) > nav { display: none; }
  .md-shell .md-contents > nav > button { display: flex; justify-content: space-between; gap: 16px; border: 0; text-align: left; }
  .md-shell .md-contents [aria-pressed="true"] { background: var(--md-sage); }
  .md-shell .md-menu-context { margin: 6px 0 0; }
  .md-shell .md-section { margin-top: 12px; }
  .md-shell .md-section-menu { position: relative; flex: 0 0 44px; }
  .md-shell .md-section-menu[open] { z-index: 4; }
  .md-shell .md-section-menu > summary { display: flex; align-items: center; justify-content: center; width: 44px; height: 44px; padding: 0; list-style: none; color: #526154; }
  .md-shell .md-section-menu > summary::-webkit-details-marker { display: none; }
  .md-shell .md-section-menu > div { position: absolute; top: 100%; right: 0; min-width: 180px; padding: 6px; background: var(--md-paper); border: 1px solid var(--md-line); border-radius: 8px; }
  .md-shell .md-section-menu > div > button { border: 0; min-height: 44px; }
  .md-shell .md-section-menu > div > button[data-md-action="rename-section"],
  .md-shell .md-section-menu > div > button[data-md-action="delete-section"] { flex-basis: 100%; text-align: left; }
  .md-shell .md-item-line { position: relative; display: flex; align-items: center; border-bottom: 1px solid var(--md-line); }
  .md-shell .md-item-row { flex: 1 1 auto; min-width: 0; width: auto; min-height: 82px; padding: 16px 12px 16px 0; border: 0; border-radius: 0; gap: 18px; }
  .md-shell .md-item-row:hover { background: #e9eee780; }
  .md-shell .md-item-copy { min-width: 0; flex: 1 1 auto; }
  .md-shell .md-item-copy > strong { font-size: 1rem; line-height: 1.5; }
  .md-shell .md-item-copy > span { font-size: .875rem; line-height: 1.5; }
  .md-shell .md-item-affordance { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex: 0 0 auto; }
  .md-shell .md-item-state { font-size: .75rem; flex: none; }
  .md-shell .md-item-edit { color: var(--md-green); font-size: .875rem; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
  .md-shell .md-row-options { flex: 0 0 44px; align-self: stretch; display: flex; align-items: center; }
  .md-shell .md-row-options > summary { display: flex; align-items: center; justify-content: center; width: 44px; height: 100%; min-height: 44px; cursor: pointer; list-style: none; color: #526154; }
  .md-shell .md-row-options > summary::-webkit-details-marker { display: none; }
  .md-shell .md-row-options > div { position: absolute; top: calc(100% - 8px); right: 0; z-index: 4; display: flex; flex-direction: column; min-width: 190px; padding: 6px; border: 1px solid var(--md-line); border-radius: 8px; background: var(--md-paper); box-shadow: 0 8px 22px #1b2b211a; }
  .md-shell .md-row-options:not([open]) > div { display: none; }
  .md-shell .md-row-options > div > button { border: 0; text-align: left; }
  .md-shell .md-row-options > summary:focus-visible,
  .md-shell .md-contents > [data-md-dropdown]:focus-visible { outline: 3px solid #bc623b; outline-offset: -3px; }
  .md-shell .md-editor-actions, .md-shell .menu-branding-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; padding-top: 18px; margin-top: 18px; border-top: 1px solid var(--md-line); }
  .md-shell .md-shared-appearance { margin-top: 28px; padding-top: 20px; border-top: 1px solid var(--md-line); }
  .md-shell .md-shared-appearance > p { margin: 6px 0 0; font-size: .8125rem; color: #526154; }
  .md-shell .md-branding-editor { max-width: 640px; margin: 0 auto; }
  .md-shell .md-item-version > summary,
  .md-shell .menu-branding-options > summary { min-height: 44px; padding: 12px 4px; color: var(--md-green); font-size: .8125rem; font-weight: 650; line-height: 1.5; cursor: pointer; }
  .md-shell .md-item-version > summary:focus-visible,
  .md-shell .menu-branding-options > summary:focus-visible { outline: 3px solid #bc623b; outline-offset: 1px; }
  .md-shell .md-item-version > p { margin: 6px 0; }
}
@media screen and (max-width: 800px) {
  .md-shell .md-canvas { padding: 20px 20px 30px; }
  .md-shell .md-menu-header-actions > [data-menu-header-save] { flex: 0 0 auto; width: auto; }
  .md-shell .md-menu-header .md-stage-nav > button { flex: 0 1 auto; }
  .md-shell .md-item-row { gap: 10px; }
  .md-shell .md-item-affordance { max-width: 6rem; }
  .md-shell .md-item-state { min-width: 0; text-align: right; }
}
@media screen and (max-width: 380px) {
  .md-shell .md-canvas { padding: 18px 15px 26px; }
  .md-shell .md-item-row { flex-wrap: nowrap; }
  .md-shell .md-item-state { flex-basis: auto; }
  .md-shell .md-document-name > button { font-size: 1.25rem; }
}
@media screen {
  .md-shell .md-menu-options-short { display: none; }
}
@media screen and (max-width: 600px) {
  .md-shell .md-editor-toolbar { gap: 6px; }
  .md-shell .md-menu-options-label { display: none; }
  .md-shell .md-menu-options-short { display: inline; }
  .md-shell .md-menu-options > [data-md-dropdown] { padding-right: 4px; padding-left: 6px; }
}

/* Equal columns keep the optional existing-item choice visually centred. */
@media screen {
  .md-shell .md-library-editor-actions.has-item-choice { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: stretch; gap: 10px; }
  .md-shell .md-library-editor-actions.has-item-choice > button { width: 100%; min-width: 0; margin: 0; }
}
@media screen and (max-width: 520px) {
  .md-shell .md-library-editor-actions.has-item-choice { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .md-shell .md-library-editor-actions.has-item-choice > .primary { grid-column: 1 / -1; }
}

/* Compact library rows keep food facts together and controls on one strip.
   Expanded details regain the full row; the item picker keeps its own layout. */
@media screen {
  .md-shell .md-items-library .md-library-toolbar { margin-bottom: 0; }
  .md-shell .md-items-library .md-picker-status { margin: 4px 0; }
  .md-shell .md-items-library .md-library-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 4px 24px; padding: 10px 8px; }
  .md-shell .md-items-library .md-library-item-summary { margin-top: 4px; }
  .md-shell .md-items-library .md-library-row-controls { display: flex; align-items: center; gap: 16px; min-width: 0; }
  .md-shell .md-items-library .md-picker-details { min-width: 0; margin-top: 0; }
  .md-shell .md-items-library .md-library-item-actions { margin: 0; gap: 8px; flex-wrap: nowrap; }
  .md-shell .md-items-library .md-library-item:has(.md-picker-details[open]) .md-library-row-controls { grid-column: 1 / -1; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: start; }
  .md-shell .md-items-library .md-picker-details > summary { display: flex; align-items: center; gap: 12px; padding: 8px 0; list-style: none; }
  .md-shell .md-items-library .md-picker-details > summary::-webkit-details-marker { display: none; }
  .md-shell .md-items-library .md-picker-details .md-picker-usage { margin: 0; font-weight: 400; color: #526154; }
  .md-shell .md-item-details-label { text-decoration: underline; text-underline-offset: 3px; }
}
@media screen and (max-width: 900px) {
  .md-shell .md-items-library .md-library-item { grid-template-columns: minmax(0, 1fr); }
  .md-shell .md-items-library .md-library-row-controls { justify-content: space-between; }
}
@media screen and (max-width: 600px) {
  .md-shell .md-items-library .md-library-heading { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 8px 12px; margin-bottom: 16px; }
  .md-shell .md-items-library .md-library-heading > div:first-child { display: contents; }
  .md-shell .md-items-library .md-library-heading h2 { grid-column: 1; grid-row: 1; margin: 0; }
  .md-shell .md-items-library .md-library-heading > button { grid-column: 2; grid-row: 1; }
  .md-shell .md-items-library .md-library-heading p { grid-column: 1 / -1; margin: 0; font-size: .8125rem; }
  .md-shell .md-items-library .md-library-toolbar { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 10px; margin-bottom: 0; }
  .md-shell .md-items-library .md-library-toolbar > label:first-child { grid-column: 1 / -1; }
  .md-shell .md-items-library .md-library-toolbar > label { min-width: 0; }
  .md-shell .md-items-library .md-library-toolbar > button { margin: 0; }
  .md-shell .md-items-library .md-picker-status { margin: 4px 0 0; }
  .md-shell .md-items-library .md-library-item { padding: 10px 0; }
  .md-shell .md-items-library .md-library-row-controls { gap: 8px; }
  .md-shell .md-items-library .md-picker-details > summary { display: grid; gap: 0; padding: 4px 0; }
  .md-shell .md-items-library .md-library-item:has(.md-picker-details[open]) .md-library-row-controls { grid-template-columns: minmax(0, 1fr); }
  .md-shell .md-items-library .md-library-item:has(.md-picker-details[open]) .md-library-item-actions { justify-self: end; }
  .md-shell .md-items-library .md-library-item-actions > button { padding: 8px 12px; }
  .md-shell .md-items-library .md-library-item-actions > button[data-mi-action="archive"],
  .md-shell .md-items-library .md-library-item-actions > button[data-mi-action="restore"] { padding-inline: 4px; border-color: transparent; background: transparent; box-shadow: none; }
}

/* Floating disclosure panels must leave both layout and hit testing when closed,
   including engines that retain positioned content from a closed <details>. */
@media screen {
  .md-shell .md-contents > nav[hidden],
  .md-shell .md-menu-options > div[hidden],
  .md-shell .md-section-menu > div[hidden],
  .md-shell .md-row-options > div[hidden] { display: none !important; }
}

@media screen {
  .md-shell [data-md-dropdown] { display: inline-flex; align-items: center; gap: 6px; border: 0; background: transparent; font-family: inherit; text-align: left; }
  .md-shell [data-md-dropdown]::before { content: ""; width: 0; height: 0; border-top: 4px solid transparent; border-bottom: 4px solid transparent; border-left: 5px solid currentColor; }
  .md-shell [data-md-dropdown][aria-expanded="true"]::before { transform: rotate(90deg); }
  .md-shell [data-md-dropdown]:focus-visible { outline: 3px solid #bc623b; outline-offset: 1px; }
}

@media screen {
  .md-shell .md-print-pending { display: flex; flex-wrap: wrap; gap: 0 16px; margin: 0; }
  .md-shell .md-print-pending[hidden], .md-shell .md-print-pending button[hidden] { display: none; }
  .md-shell .md-print-pending .md-button { min-height: 36px; padding: 4px 0; border: 0; background: transparent; box-shadow: none; font-size: 13px; font-weight: 500; color: var(--md-green); text-decoration: underline; text-underline-offset: 3px; }
}

/* Keep keyboard focus inside controls in the picker's scrolling viewport. */
@media screen {
  .md-shell .md-picker-controls input:focus-visible,
  .md-shell .md-picker-controls select:focus-visible {
    outline: 2px solid #bc623b;
    outline-offset: -2px;
  }
}
