/* ==========================================================================
   HANBURG QR MENU — Multi-Device & Foldable Adaptive Layout
   1. Foldable Cover Screen (<= 365px / [data-posture="fold-cover"])
   2. Phone (366px - 679px)
   3. Foldable Unfolded Dual-Pane (@media horizontal-viewport-segments: 2 / near-square / [data-posture="fold-dual"])
   4. Foldable Flex Tabletop (@media vertical-viewport-segments: 2 / [data-posture="fold-flex"])
   5. Tablet Portrait (680px - 1023px) & Landscape (1024px - 1279px)
   6. Desktop / PC (1280px+)
   ========================================================================== */

.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
}

.flex-stage,
.hinge-divider-h,
.hinge-divider-v {
  display: none;
}

/* ==========================================================================
   TOPBAR (Phone, Cover, Foldable Dual, Tablet)
   ========================================================================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--header-h);
  padding: 0 clamp(10px, 2.8vw, 24px);
  padding-top: var(--safe-top);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--bg-glass);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-bottom: 2px solid var(--frame-ring);
}

@media (max-width: 560px) {
  .topbar .brand-subtitle,
  .topbar .hide-xs {
    display: none;
  }

  .topbar .brand-mark {
    width: 34px;
    height: 34px;
  }

  .topbar .brand-name {
    font-size: 1rem;
  }

  .topbar-actions {
    gap: 5px;
  }

  .topbar .channel-switch-btn {
    padding: 5px 8px;
    font-size: 0.7rem;
  }

  .topbar .icon-btn {
    min-width: 32px;
    height: 32px;
    padding: 0 7px;
    font-size: 0.74rem;
  }
}

/* ==========================================================================
   MAIN WORKSPACE — MOBILE-FIRST DEFAULT
   ========================================================================== */
.workspace {
  flex: 1;
  display: block;
  width: 100%;
  position: relative;
}

.sidebar {
  display: none;
}

.menu-pane {
  width: 100%;
  padding: 14px clamp(12px, 3vw, 24px) calc(84px + var(--safe-bottom));
  container-type: inline-size;
  container-name: menu-area;
}

/* Container-Responsive Menu Grid */
.menu-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

@container menu-area (min-width: 500px) {
  .menu-grid:not(.is-compact-list) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
  }
}

@container menu-area (min-width: 840px) {
  .menu-grid:not(.is-compact-list) {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 18px;
  }
}

/* Default List View (1 column mobile/tablet narrow, 2 columns wide desktop) */
.menu-grid.is-compact-list {
  grid-template-columns: 1fr;
  gap: 10px;
}

@container menu-area (min-width: 740px) {
  .menu-grid.is-compact-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }
}

/* ==========================================================================
   COMPANION PANE — Mobile Bottom Sheet Default
   ========================================================================== */
.companion-pane {
  position: fixed;
  inset: 0;
  z-index: 80;
  pointer-events: none;
  visibility: hidden;
  transition: visibility 0s linear var(--dur-med);
}

.companion-pane.is-open {
  pointer-events: auto;
  visibility: visible;
  transition: visibility 0s linear 0s;
}

.companion-backdrop {
  position: absolute;
  inset: 0;
  background: var(--bg-scrim);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  opacity: 0;
  transition: opacity var(--dur-med) var(--ease-out);
}

.companion-pane.is-open .companion-backdrop {
  opacity: 1;
}

.companion-sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 90dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border-top: 2px solid var(--brand-gold);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  box-shadow: var(--shadow-float);
  transform: translateY(102%);
  transition: transform var(--dur-med) var(--ease-out);
  padding-bottom: var(--safe-bottom);
  overflow: hidden;
}

.companion-pane.is-open .companion-sheet {
  transform: translateY(0);
}

.companion-body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 18px 22px;
}

.companion-body.has-sticky-footer {
  padding-bottom: 0;
}

.floating-tray-bar {
  position: fixed;
  left: 50%;
  bottom: calc(14px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 50;
  width: min(calc(100% - 24px), 460px);
}

.floating-tray-bar[hidden] {
  display: none !important;
}

/* ==========================================================================
   1. FOLDABLE COVER SCREEN (<= 365px / Galaxy Z Fold Outer)
   ========================================================================== */
@media (max-width: 365px) {
  :root {
    --header-h: 54px;
  }

  .topbar {
    padding: 0 8px;
    gap: 4px;
  }

  .topbar .brand-link {
    gap: 6px;
  }

  .topbar .brand-mark {
    width: 30px;
    height: 30px;
  }

  .topbar .brand-name {
    font-size: 0.9rem;
    letter-spacing: 0.01em;
  }

  .topbar .channel-switch {
    padding: 2px;
  }

  .topbar .channel-switch-btn {
    padding: 4px 6px;
    font-size: 0.64rem;
    gap: 3px;
  }

  .topbar .icon-btn {
    min-width: 28px;
    height: 28px;
    padding: 0 5px;
    font-size: 0.68rem;
  }

  .menu-pane {
    padding: 10px 10px calc(72px + var(--safe-bottom));
  }

  .sticky-controls {
    top: var(--header-h);
    margin: 0 -10px 12px;
    padding: 8px 10px;
  }

  .dish-card {
    flex-direction: row-reverse !important;
    align-items: center;
    padding: 10px !important;
    gap: 10px !important;
  }

  .dish-card .dish-media {
    width: 82px !important;
    height: 82px !important;
    aspect-ratio: 1 / 1 !important;
    border-radius: var(--radius-sm) !important;
    flex-shrink: 0;
    border-bottom: none !important;
  }

  .dish-card .dish-badges-overlay {
    display: none;
  }

  .dish-card .dish-content {
    padding: 0 !important;
  }

  .dish-card .dish-desc {
    -webkit-line-clamp: 2;
    font-size: 0.75rem;
  }
}

[data-posture="fold-cover"] .topbar .brand-subtitle {
  display: none;
}

/* ==========================================================================
   2. TABLET PORTRAIT (680px - 1023px)
   ========================================================================== */
@media (min-width: 680px) {
  .menu-pane {
    padding: 18px 24px calc(88px + var(--safe-bottom));
  }

  .companion-sheet {
    left: auto;
    top: 0;
    bottom: 0;
    width: min(430px, 88vw);
    max-height: 100dvh;
    border-top: none;
    border-left: 2px solid var(--brand-gold);
    border-radius: var(--radius-lg) 0 0 var(--radius-lg);
    transform: translateX(102%);
  }

  .companion-pane.is-open .companion-sheet {
    transform: translateX(0);
  }

  .sheet-drag-handle {
    display: none;
  }
}

/* ==========================================================================
   3. TABLET LANDSCAPE (1024px - 1279px)
   ========================================================================== */
@media (min-width: 1024px) {
  .workspace {
    display: grid;
    grid-template-columns: 248px minmax(0, 1fr);
    align-items: start;
    max-width: 1640px;
    margin: 0 auto;
  }

  .sidebar {
    display: flex;
    flex-direction: column;
    position: sticky;
    top: var(--header-h);
    height: calc(100dvh - var(--header-h));
    overflow-y: auto;
    padding: 18px 14px 24px;
    border-right: 1px solid var(--border-subtle);
    background: var(--bg-canvas);
  }

  .category-pills {
    display: none;
  }

  .menu-pane {
    padding: 20px 28px 80px;
  }
}

/* ==========================================================================
   4. DESKTOP / PC (1280px+) — Full 3-Column Layout
   ========================================================================== */
@media (min-width: 1280px) {
  :root {
    --sticky-top: 0px;
  }

  .topbar {
    display: none;
  }

  .workspace {
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--tray-w);
    min-height: 100dvh;
  }

  .sidebar {
    top: 0;
    height: 100dvh;
    padding: 18px 16px 20px;
    border-right: 1.5px solid var(--border-subtle);
  }

  .sidebar .sidebar-brand-block {
    display: flex;
  }

  .menu-pane {
    padding: 0 28px 56px;
  }

  .sticky-controls {
    top: 0;
    margin-left: -28px;
    margin-right: -28px;
    padding: 16px 28px 12px;
  }

  .companion-pane {
    position: sticky;
    top: 0;
    inset: auto;
    height: 100dvh;
    visibility: visible;
    pointer-events: auto;
    z-index: 20;
    border-left: 2px solid var(--frame-ring);
    background: var(--bg-surface);
  }

  .companion-backdrop,
  .companion-close,
  .sheet-drag-handle,
  .floating-tray-bar {
    display: none !important;
  }

  .companion-sheet {
    position: relative;
    width: 100%;
    height: 100%;
    max-height: none;
    border: none;
    border-radius: 0;
    box-shadow: none;
    transform: none !important;
    background: transparent;
  }

  .companion-body {
    padding: 18px 20px 22px;
  }

  .companion-body.has-sticky-footer {
    padding-bottom: 0;
  }
}

/* ==========================================================================
   5. FOLDABLE UNFOLDED — DUAL-PANE BOOK POSTURE
   ========================================================================== */
@media (horizontal-viewport-segments: 2),
       (min-width: 640px) and (max-width: 940px) and (min-aspect-ratio: 4/5) and (max-aspect-ratio: 6/5) {
  .app-shell:not([data-posture="standard"]):not([data-posture="fold-flex"]) {
    height: 100dvh;
    overflow: hidden;
  }

  .app-shell:not([data-posture="standard"]):not([data-posture="fold-flex"]) .topbar {
    display: flex;
    flex-shrink: 0;
  }

  .app-shell:not([data-posture="standard"]):not([data-posture="fold-flex"]) .sidebar {
    display: none;
  }

  .app-shell:not([data-posture="standard"]):not([data-posture="fold-flex"]) .workspace {
    display: grid;
    grid-template-columns: minmax(0, 1fr) var(--fold-hinge-w) minmax(0, 1fr);
    height: calc(100dvh - var(--header-h));
    max-width: none;
    overflow: hidden;
  }

  .app-shell:not([data-posture="standard"]):not([data-posture="fold-flex"]) .menu-pane {
    height: 100%;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 14px 14px 32px;
  }

  .app-shell:not([data-posture="standard"]):not([data-posture="fold-flex"]) .category-pills {
    display: flex;
  }

  .app-shell:not([data-posture="standard"]):not([data-posture="fold-flex"]) .sticky-controls {
    top: -14px;
    margin: 0 -14px 12px;
    padding: 10px 14px;
  }

  .app-shell:not([data-posture="standard"]):not([data-posture="fold-flex"]) .hinge-divider-v {
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(90deg, rgba(255, 184, 0, 0.04), rgba(240, 106, 0, 0.16) 50%, rgba(255, 184, 0, 0.04));
    border-left: 1.5px solid var(--frame-ring);
    border-right: 1.5px solid var(--frame-ring);
    user-select: none;
  }

  .app-shell:not([data-posture="standard"]):not([data-posture="fold-flex"]) .companion-pane {
    position: relative;
    inset: auto;
    height: 100%;
    visibility: visible;
    pointer-events: auto;
    z-index: 10;
    background: var(--bg-surface);
  }

  .app-shell:not([data-posture="standard"]):not([data-posture="fold-flex"]) .companion-backdrop,
  .app-shell:not([data-posture="standard"]):not([data-posture="fold-flex"]) .companion-close,
  .app-shell:not([data-posture="standard"]):not([data-posture="fold-flex"]) .sheet-drag-handle,
  .app-shell:not([data-posture="standard"]):not([data-posture="fold-flex"]) .floating-tray-bar {
    display: none !important;
  }

  .app-shell:not([data-posture="standard"]):not([data-posture="fold-flex"]) .companion-sheet {
    position: relative;
    width: 100%;
    height: 100%;
    max-height: none;
    border: none;
    border-radius: 0;
    box-shadow: none;
    transform: none !important;
    background: transparent;
  }
}

@media (horizontal-viewport-segments: 2) {
  .app-shell:not([data-posture="standard"]):not([data-posture="fold-flex"]) .workspace {
    grid-template-columns:
      env(viewport-segment-width 0 0)
      max(16px, calc(env(viewport-segment-left 1 0) - env(viewport-segment-right 0 0)))
      env(viewport-segment-width 1 0);
  }
}

.app-shell[data-posture="fold-dual"] {
  height: 100dvh;
  overflow: hidden;
}

.app-shell[data-posture="fold-dual"] .topbar {
  display: flex;
  flex-shrink: 0;
}

.app-shell[data-posture="fold-dual"] .sidebar {
  display: none !important;
}

.app-shell[data-posture="fold-dual"] .workspace {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) var(--fold-hinge-w) minmax(0, 1fr) !important;
  height: calc(100dvh - var(--header-h));
  max-width: none;
  overflow: hidden;
}

.app-shell[data-posture="fold-dual"] .menu-pane {
  height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px 14px 28px;
}

.app-shell[data-posture="fold-dual"] .category-pills {
  display: flex !important;
}

.app-shell[data-posture="fold-dual"] .sticky-controls {
  top: -12px;
  margin: 0 -14px 12px;
  padding: 10px 14px;
}

.app-shell[data-posture="fold-dual"] .hinge-divider-v {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(90deg, rgba(255, 184, 0, 0.05), rgba(240, 106, 0, 0.18) 50%, rgba(255, 184, 0, 0.05));
  border-left: 1.5px solid var(--frame-ring);
  border-right: 1.5px solid var(--frame-ring);
}

.app-shell[data-posture="fold-dual"] .companion-pane {
  position: relative !important;
  inset: auto !important;
  height: 100% !important;
  visibility: visible !important;
  pointer-events: auto !important;
  z-index: 10;
  background: var(--bg-surface);
  border-left: none;
}

.app-shell[data-posture="fold-dual"] .companion-backdrop,
.app-shell[data-posture="fold-dual"] .companion-close,
.app-shell[data-posture="fold-dual"] .sheet-drag-handle,
.app-shell[data-posture="fold-dual"] .floating-tray-bar {
  display: none !important;
}

.app-shell[data-posture="fold-dual"] .companion-sheet {
  position: relative !important;
  width: 100% !important;
  height: 100% !important;
  max-height: none !important;
  border: none !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  transform: none !important;
  background: transparent;
}

/* ==========================================================================
   6. FOLDABLE FLEX / TABLETOP POSTURE
   ========================================================================== */
@media (vertical-viewport-segments: 2) {
  .app-shell:not([data-posture="standard"]) {
    height: 100dvh;
    overflow: hidden;
    display: grid;
    grid-template-rows:
      env(viewport-segment-height 0 0)
      max(18px, calc(env(viewport-segment-top 1 0) - env(viewport-segment-bottom 0 0)))
      minmax(0, 1fr);
  }

  .app-shell:not([data-posture="standard"]) .topbar { display: none; }
  .app-shell:not([data-posture="standard"]) .flex-stage { display: flex; }
  .app-shell:not([data-posture="standard"]) .hinge-divider-h { display: flex; }
  .app-shell:not([data-posture="standard"]) .workspace { display: block; overflow: hidden; height: 100%; }
  .app-shell:not([data-posture="standard"]) .sidebar,
  .app-shell:not([data-posture="standard"]) .hero-card { display: none !important; }
  .app-shell:not([data-posture="standard"]) .menu-pane { height: 100%; overflow-y: auto; padding: 8px 12px 76px; }
  .app-shell:not([data-posture="standard"]) .companion-pane { top: env(viewport-segment-top 1 0); }
  .app-shell:not([data-posture="standard"]) .companion-sheet { max-height: 100%; }
}

.app-shell[data-posture="fold-flex"] {
  height: 100dvh;
  overflow: hidden;
  display: grid;
  grid-template-rows: 46dvh var(--fold-hinge-h) minmax(0, 1fr);
}

.app-shell[data-posture="fold-flex"] .topbar { display: none !important; }
.app-shell[data-posture="fold-flex"] .flex-stage { display: flex; }
.app-shell[data-posture="fold-flex"] .hinge-divider-h { display: flex; }
.app-shell[data-posture="fold-flex"] .workspace { display: block !important; overflow: hidden; height: 100%; max-width: none; }
.app-shell[data-posture="fold-flex"] .sidebar,
.app-shell[data-posture="fold-flex"] .hero-card { display: none !important; }
.app-shell[data-posture="fold-flex"] .menu-pane { height: 100%; overflow-y: auto; overscroll-behavior: contain; padding: 6px 12px 74px; }
.app-shell[data-posture="fold-flex"] .sticky-controls { top: -6px; margin: 0 -12px 10px; padding: 6px 12px 8px; }

.app-shell[data-posture="fold-flex"] .dish-card {
  flex-direction: row-reverse !important;
  align-items: center;
  padding: 10px !important;
  gap: 10px !important;
}

.app-shell[data-posture="fold-flex"] .dish-card .dish-media {
  width: 72px !important;
  height: 72px !important;
  aspect-ratio: 1 / 1 !important;
  border-radius: var(--radius-sm) !important;
  flex-shrink: 0;
  border-bottom: none !important;
}

.app-shell[data-posture="fold-flex"] .dish-card .dish-badges-overlay { display: none; }
.app-shell[data-posture="fold-flex"] .dish-card .dish-content { padding: 0 !important; }
.app-shell[data-posture="fold-flex"] .companion-pane { top: calc(46dvh + var(--fold-hinge-h)); }
.app-shell[data-posture="fold-flex"] .companion-sheet { max-height: 100%; border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
