/* Retro Layout Overrides (pairs with style-retro.css)
   - Desktop: drawer & insights | grid (centered grid)
   - Mobile: stack controls -> grid -> veg shelf, hide insights
   - Veg shelf: non-sticky by default
   Breakpoints align to Elementor: tablet <= 1024px, mobile <= 767px
*/

/* 1) Grid shell: 3 columns on desktop */
html,
body{
  height: 100%;
  overflow: hidden;
}

#appShell{
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 340px;
  grid-template-rows: minmax(0, 1fr);
  column-gap: var(--planner-gap);
  row-gap: var(--planner-gap);
  align-items: stretch;
  min-height: 100vh;
  height: 100vh;
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
}
@supports (height: 100dvh){
  #appShell{ height: 100dvh; }
}

/* Left column container */
#leftPanel{
  grid-column: 1;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  gap: var(--planner-gap);
  min-height: 0; /* allow children to shrink for scrolling */
  height: 100%;
  align-self: stretch;
  margin: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

/* Controls stay sized to content */
#controlsDrawer{
  flex: 0 0 auto;
}

/* Insights flexes to fill leftover space */
#insightsPanel,
.insights-panel{
  flex: 1 1 auto;
  min-height: 0;
  align-self: stretch;
  position: static;          /* no sticky now that it’s under the drawer */
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.insights-header{ flex: 0 0 auto; }

.insights-body{
  flex: 1 1 auto;
  min-height: 0;
  margin-top: 0.5rem;
  overflow-y: auto;
}

/* Work area (grid) in the right column, top row */
#workArea{
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* 3) Center the grid and constrain its max width */
#grid-area{
  display: flex;
  flex-direction: column;
  align-items: center;   /* center the grid wrapper */
  gap: 8px;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  padding-top: 14px;
}
.grid-wrapper{
  width: max-content;
  max-width: none;
  margin: 0 auto;
  min-height: 0;
}

/* 4) Who owns the scroll? The grid, not the page */
html, body{
  overflow-x: hidden;  /* prevent page-wide sideways scroll */
}
.grid-scroll-container{
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  overflow-x: auto;    /* grid can scroll horizontally if needed */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  touch-action: pan-x pan-y;
}
@supports (height: 1dvh){
  .grid-scroll-container{
    height: 100%;
  }
}
#grid-container{
  overflow: visible;   /* avoid nested scrollbars inside the grid */
}

/* 5) Veg menu lives in the right panel and is non-sticky */
#rightPanel{
  grid-column: 3;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  align-self: stretch;
  margin: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

#veg-menu{
  position: static !important;
  bottom: auto !important;
  z-index: auto !important;
  height: 100%;
  align-self: stretch;
  min-height: 0;
  width: 100%;
}

@media (max-width: 1024px){
  #appShell{
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    width: 100%;
    height: 100dvh;
    min-height: 100dvh;
    padding: 0 var(--planner-pad);
    overflow-y: auto;
  }
  #leftPanel,
  #workArea,
  #rightPanel,
  #insightsPanel{ grid-column: 1; }
  #leftPanel{
    grid-row: 1;
    width: 100%;
    height: auto;
    min-height: 0;
  }
  #workArea{
    grid-row: 2;
    position: relative;
    z-index: 0;
  }
  #rightPanel{
    grid-row: 3;
    height: auto;
    overflow: visible;
  }
  #insightsPanel{
    grid-row: auto;
    position: relative;
    z-index: 1;
  }
  #insightsPanel{ display: none; }
  body.insights-open #insightsPanel,
  #insightsPanel.is-open{ display: flex; }
  #insightsToggle{
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
  }
  #veg-menu{ height: auto; }
  #grid-area{
    align-items: stretch;
    padding-top: var(--planner-gap);
  }
  .grid-wrapper{
    max-width: none;
    margin: 0;
    min-height: 0;
  }
  .grid-scroll-container{
    height: auto;
    max-height: 70dvh;
  }
}

@media (min-width: 1025px){
  #leftPanel{
    gap: 0;
  }
  #leftPanel :is(#controlsDrawer, #insightsPanel){
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
  }
  #leftPanel #controlsDrawer{
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
  }
  #leftPanel :is(#controlsDrawer, #insightsPanel){
    margin: 0;
  }
  #leftPanel #insightsPanel{
    border-top: 0;
    border-top-left-radius: 0;
    border-top-right-radius: 0;
  }
  #rightPanel #veg-menu{
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
  }
}

@media (max-width: 767px){
  #appShell{
    padding: 0 max(var(--planner-gap), 10px);
  }
  .grid-scroll-container{
    height: auto;
    max-height: 70dvh;
  }
  #rightPanel{ order: 3; }
  #veg-menu{ display: block; }
  #vegTabs button{ padding: 6px 12px; }
  #insightsToggle{ display: none; }
  #insightsPanel{ display: none !important; }
}

@media (max-width: 480px){
  .grid-scroll-container{ max-height: 70dvh; }
  .grid-wrapper{ min-height: 0; }
}
