/* Planner layout overrides (loaded after base.css)
   - Desktop: crop chooser and Layout tools | grid (centered grid)
   - Compact landscape: narrower sidebar | independently scrolling grid
   - Veg shelf: non-sticky by default
   Breakpoints align to Elementor: tablet <= 1024px, mobile <= 767px
*/

/* 1) App shell: sidebar and work area on desktop */
.planner-layer-tabs{ grid-template-columns: repeat(3, minmax(0, 1fr)); }
#manageLayerPanel{ flex: 0 0 auto; padding: 0; gap: 0; }
#manageLayerPanel[hidden]{ display: none; }
.manage-group > summary{ box-sizing: border-box; min-height: 36px; padding: 8px 10px; font-size: 14px; font-weight: 600; cursor: pointer;
  border-top: 1px solid color-mix(in srgb, var(--surface-4) 58%, transparent);
  background: color-mix(in srgb, var(--ink) 4%, transparent); }
@media (max-width: 1024px){ .manage-group > summary{ min-height: 44px; box-sizing: border-box; padding-block: 13px; } }
.manage-group > summary:hover{ background: color-mix(in srgb, var(--ink) 7%, transparent); }
.planner-manage-open #crop-cursor-preview{ visibility: hidden; }
/* Primary controls stay outside the desktop sidebar's scrolling tool list. */
#plannerSidebarHeader{
  flex: 0 0 auto; display: grid; grid-template-columns: minmax(0, 1fr);
  align-items: center; gap: 2px; padding: 8px; min-width: 0;
  background: var(--surface-1); color: var(--ink);
}
#plannerSidebarHeader .sidebar-primary-actions{
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px;
}
#plannerSidebarHeader .sidebar-icon-button{
  display: inline-flex; align-items: center; justify-content: center;
  width: 100%; min-width: 0; height: 36px; padding: 0; margin: 0;
  border: 1px solid var(--surface-4); border-radius: 3px; font-size: .85rem;
  background: var(--surface-2); color: var(--ink); box-shadow: none;
}
#plannerSidebarHeader .sidebar-icon-button:not(:disabled):hover{ background: var(--surface-3); }
#plannerSidebarHeader button:focus-visible, #plannerSidebarHeader #gridZoom:focus{ outline: 2px solid var(--brand-300); outline-offset: -2px; }
#plannerSidebarHeader button:disabled{ opacity: .45; cursor: default; }
.sidebar-zoom-controls{
  display: grid; min-width: 0;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  align-items: center; gap: 4px;
}
#plannerSidebarHeader .sidebar-zoom-button{ height: 44px; font-size: 1.2rem; }
#plannerSidebarHeader #gridZoom{
  appearance: none;
  width: 100%;
  min-width: 0;
  height: 44px;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  --zoom-track-height: 6px;
  --zoom-thumb-size: 16px;
}
#gridZoom::-webkit-slider-runnable-track{
  height: var(--zoom-track-height); border-radius: 999px; background: var(--surface-4);
}
#gridZoom::-moz-range-track{
  height: var(--zoom-track-height); border-radius: 999px; background: var(--surface-4);
}
#gridZoom::-webkit-slider-thumb{
  appearance: none;
  box-sizing: border-box;
  width: var(--zoom-thumb-size); height: var(--zoom-thumb-size);
  margin-top: calc((var(--zoom-track-height) - var(--zoom-thumb-size)) / 2);
  border: 1px solid var(--surface-1); border-radius: 50%; background: var(--brand-400);
}
#gridZoom::-moz-range-thumb{
  box-sizing: border-box;
  width: var(--zoom-thumb-size); height: var(--zoom-thumb-size);
  border: 1px solid var(--surface-1); border-radius: 50%; background: var(--brand-400);
}
@media (forced-colors: active){
  #plannerSidebarHeader #gridZoom{ appearance: auto; }
}
#plannerSidebarHeader #plannerBusyBar{ grid-column: 1 / -1; }
@media (min-width: 1025px){
  #appShell #leftPanel{ overflow: hidden; }
  #plannerSidebar{ overflow-y: auto; overflow-x: hidden; }
  #plannerSidebar > .planner-layer-tabs{ position: sticky; top: 0; z-index: 6; background: var(--surface-1); }
}
@media (max-width: 1024px){
  #plannerSidebarHeader .sidebar-icon-button{ height: 44px; }
}
/* Manage action rows. */
#manageLayerPanel .manage-actions{ display: flex; flex-direction: column; gap: 0; }
#manageLayerPanel :is(.manage-action, #exportRetry){
  display: flex; align-items: center; justify-content: flex-start; gap: 8px;
  width: 100%; min-width: 0; min-height: 36px; margin: 0; padding: 7px 10px;
  border: 0; border-top: 1px solid color-mix(in srgb, var(--surface-4) 45%, transparent);
  border-radius: 0; background: transparent; box-shadow: none; color: var(--ink);
  text-align: left; white-space: normal; font-size: 14px; font-weight: 600; text-decoration: none;
}
#manageLayerPanel :is(.manage-action, #exportRetry):not(:disabled):hover{
  background: color-mix(in srgb, var(--ink) 7%, transparent);
}
#manageLayerPanel :is(button, summary, input, select):focus-visible{ outline: 2px solid var(--brand-500); outline-offset: -2px; }
#manageLayerPanel :is(.manage-action, #exportRetry)[hidden]{ display: none; }
.manage-action > i{ flex: 0 0 16px; font-size: 14px; text-align: center; }
#manageClearReset .manage-action > i{ color: color-mix(in srgb, #c64035 60%, var(--ink)); }
.manage-appearance{ display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 4px 10px; border-top: 1px solid var(--surface-4); }
.manage-heading{ margin: 0; font: inherit; font-size: 14px; font-weight: 600; }
.manage-appearance .theme-toggle{ width: auto; flex: 0 0 auto; }
#manageLayerPanel :is(#exportStatus, #manageClearStatus){
  margin: 0; padding: 6px 10px; font-size: .75rem; color: var(--ink-dim); text-align: left;
}
#manageLayerPanel #exportStatus:empty,
#manageLayerPanel #manageClearStatus:empty{ min-height: 0; padding: 0; }
.layout-layer-clear{ align-self: flex-start; min-height: 32px; }
#manageLayerPanel #controlsDrawer{ width: 100%; margin: 0; padding: 0; border: 0; border-radius: 0; box-shadow: none; background: transparent; }
#manageLayerPanel #controlsDrawer .grid-controls{ padding: 0; border: 0; margin: 0; }
#managePlotSettings .controls-sections{ display: flex; flex-direction: column; gap: 0; }
#managePlotSettings .controls-section{ padding: 0; border: 0; background: transparent; gap: 0; }
#manageLayerPanel .plot-size-controls{ display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
#manageLayerPanel .plot-size-field{ display: flex; flex-direction: column; align-items: stretch; gap: 4px; font-size: .8rem; }
#manageLayerPanel .plot-size-input-wrap{ display: flex; align-items: center; gap: 4px; }
#manageLayerPanel .plot-size-input-wrap input{ width: 100%; box-sizing: border-box; }
#managePlotSettings .plot-size-toggle{ align-items: center; }
#managePlotSettings :is(.plot-size-toggle, #applyPlotSizeBtn){
  font: inherit; font-size: 14px; font-weight: 600; color: var(--ink);
}
#managePlotSettings .plot-size-summary{ color: var(--ink-dim); white-space: nowrap; font-size: .95em; font-weight: 400; }
#managePlotSettings .plot-size-chevron{ margin-left: auto; flex: 0 0 auto; font-size: .65rem; }
#managePlotSettings .plot-size-toggle[aria-expanded="true"] .plot-size-chevron{ transform: rotate(90deg); }
#managePlotSettings .plot-size-panel{ padding: 6px 10px; }
#managePlotSettings .plot-size-field{ text-align: left; line-height: 1.4; }
#managePlotSettings :is(.plot-size-input-wrap input, #applyPlotSizeBtn){ border-radius: 3px; }
#manageLayerPanel :is(.plot-size-input-wrap input, #applyPlotSizeBtn),
#backupRestoreDialog #plannerRecoverySelect{
  border-color: color-mix(in srgb, var(--ink-dim) 62%, var(--surface-4));
}
#managePlotSettings #plotSizeNotice{ padding: 0 10px; text-align: left; }
#managePlotSettings #plotSizeNotice:not(:empty){ padding-block: 4px 6px; }
#managePlotSettings #applyPlotSizeBtn{ padding: 7px 10px; min-height: 36px; }
@media (max-width: 279px){ #managePlotSettings .plot-size-controls{ grid-template-columns: minmax(0, 1fr); } }
#manageLayerPanel #applyPlotSizeBtn{ grid-column: 1 / -1; }
#manageLayerPanel #controlsDrawer :is(button, input){ min-width: 0; }
@media (max-width: 1024px){
  #manageLayerPanel :is(.manage-action, #exportRetry, .theme-toggle, .plot-size-input-wrap input, #applyPlotSizeBtn){ min-height: 44px; }
}
html,
body{
  height: 100%;
  min-height: 100%;
  overflow: hidden;
}

#layout{
  max-width: none;
  width: 100%;
  margin: 0;
}

#appShell{
  display: grid;
  grid-template-columns: var(--planner-sidebar-width, 344px) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  grid-template-areas: "sidebar work";
  column-gap: var(--planner-gap);
  row-gap: 0;
  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-area: sidebar;
  display: flex;
  flex-direction: column;
  gap: 0;
  min-width: 0;
  min-height: 0; /* allow children to shrink for scrolling */
  height: 100%;
  align-self: stretch;
  margin: 0;
  overflow-y: auto;
  overflow-x: hidden;
  /* Keep the sidebar wrapper visually neutral; inner crop UI owns the surface. */
  background: transparent;
  border: 0;
  box-shadow: none;
}

/* Desktop-only sidebar scrollbar: subtle but clearly visible */
@media (min-width: 1025px){
  #plannerSidebar{
    scrollbar-width: thin;
    scrollbar-color: color-mix(in srgb, var(--ink-dim) 48%, transparent)
      transparent;
  }

  #plannerSidebar::-webkit-scrollbar{
    width: 9px;
  }

  #plannerSidebar::-webkit-scrollbar-track{
    background: transparent;
    border-radius: 999px;
  }

  #plannerSidebar::-webkit-scrollbar-thumb{
    background: color-mix(in srgb, var(--ink-dim) 48%, transparent);
    border-radius: 999px;
    border: 2px solid color-mix(in srgb, var(--surface-1) 78%, transparent);
  }

  #plannerSidebar:hover::-webkit-scrollbar-thumb,
  #plannerSidebar:focus-within::-webkit-scrollbar-thumb{
    background: color-mix(in srgb, var(--ink) 65%, transparent);
  }
}

#plannerSidebar{
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* Expanded structure editors scroll with Layout instead of compressing the tabs. */
#plannerSidebar > .planner-layer-tabs,
#plannerSidebar > #surfaceLayerPanel{
  flex: 0 0 auto;
}

#plannerSidebar .crop-tray{
  flex: 1 1 360px;
  min-height: 260px;
}

#leftPanel #veg-menu{
  flex: 1 1 auto;
  min-height: 0;
}

/* Controls stay sized to content; no nested scrollbar */
#controlsDrawer{
  flex: 0 0 auto;
  max-height: none;
  overflow: visible;
}

/* Work area (grid) in the center column, optimized for wide landscape canvas */
#workArea{
  grid-area: work;
  min-width: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: clamp(8px, 1.2vw, 14px) var(--planner-gap) clamp(6px, 1vw, 10px);
}

@media (min-width: 1025px){
  #workArea{
    padding-left: 0;
  }

  .grid-scroll-container{
    padding-left: 4px;
  }
}

/* 3) Grid canvas anchoring: top-left by default for predictable planning origin */
#grid-area{
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-start;
  gap: 0;
  flex: 0 0 auto;
  min-width: max-content;
  min-height: max-content;
  width: max-content;
  padding-right: var(--grid-pan-room-x, 0px);
  padding-bottom: var(--grid-pan-room-y, 0px);
}
.grid-wrapper{
  display: grid;
  justify-content: flex-start;
  width: max-content;
  margin: 0;
  min-height: 0;
}

/* 4) Who owns the scroll? The grid, not the page */
html, body{
  overflow-x: hidden;  /* prevent page-wide sideways scroll */
}

body.transfer-dialog-open { overflow: hidden; }
.transfer-dialog { position: fixed; inset: 0; z-index: 10000; display: grid; place-items: center; padding: 16px; }
.transfer-dialog[hidden] { display: none; }
.transfer-dialog__backdrop { position: absolute; inset: 0; background: rgba(8, 15, 12, .72); }
.transfer-dialog__panel { position: relative; width: min(520px, 100%); max-height: calc(100dvh - 32px); overflow: auto; border: 1px solid var(--surface-4); border-radius: 14px; background: var(--surface-1); color: var(--ink); box-shadow: var(--shadow); }
.transfer-dialog__header { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 20px 12px; border-bottom: 1px solid var(--surface-4); }
.transfer-dialog__header h2 { margin: 0; font-size: clamp(1.3rem, 4vw, 1.7rem); }
.transfer-dialog__close { min-width: 44px; min-height: 44px; border: 0; background: transparent; color: inherit; font-size: 2rem; cursor: pointer; }
.transfer-dialog__body { padding: 4px 20px 20px; overflow-wrap: anywhere; }
.transfer-dialog__section { margin-top: 18px; }
.transfer-dialog__section h3 { margin: 0 0 4px; }
.transfer-dialog__section p { margin: 0 0 12px; color: var(--ink-dim); }
.transfer-dialog__qr { display: block; width: min(330px, 100%); height: auto; aspect-ratio: 1; margin: 14px auto 20px; shape-rendering: crispEdges; }
.transfer-dialog__actions { display: flex; flex-wrap: wrap; gap: 10px; }
.transfer-dialog__copy-fallback { display: grid; gap: 7px; margin-top: 16px; font-weight: 600; }
.transfer-dialog__copy-fallback textarea { box-sizing: border-box; width: 100%; max-width: 100%; resize: none; font: .8rem/1.35 monospace; }
.transfer-dialog__status { min-height: 1.4em; margin: 0; padding: 0 20px 18px; font-weight: 600; }
.transfer-dialog__receive { padding-top: 16px; border-top: 1px solid var(--surface-4); }
.transfer-dialog__summary { margin: 16px 0 12px; font-weight: 700; }
.transfer-dialog__warning { margin: 0 0 18px; color: var(--ink-dim); }
.transfer-dialog__destructive { background: var(--brand-400); color: #fff; }
#backupRestoreDialog {
  position: fixed; inset: 0; margin: auto; padding: 0;
  box-sizing: border-box; width: min(410px, calc(100% - 24px)); height: fit-content;
}
#backupRestoreDialog::backdrop { background: rgba(8, 15, 12, .72); }
#backupRestoreDialog .transfer-dialog__header { padding: 6px 12px 6px 16px; }
#backupRestoreDialog h2 { font-size: 1.15rem; }
.backup-restore-body { padding: 0 16px 4px; }
.backup-restore-body section { padding: 12px 0; }
.backup-restore-body .backup-restore-description { margin: 12px 0 0; }
#planProtectionWarning[hidden] + #downloadOriginalPlanBtn { display: none; }
.backup-restore-body h3 { margin: 0 0 6px; font-size: 14px; }
.backup-restore-body p, .backup-restore-status { margin: 6px 0; font-size: 13px; color: var(--ink-dim); }
.backup-restore-status { margin: 0; padding: 10px 16px 0; overflow-wrap: anywhere; }
.backup-restore-status:empty { padding: 0; }
.backup-restore-body :is(button, select) { min-height: 44px; font-size: 14px; }
.backup-restore-body select { display: block; box-sizing: border-box; width: 100%; margin: 0 0 8px; text-overflow: ellipsis; }
.backup-restore-body button:disabled { opacity: .55; }
.backup-restore-body [hidden] { display: none; }
#backupRestoreDialog :is(button, select):focus-visible { outline: 2px solid var(--brand-500); outline-offset: -2px; }
@media (max-width: 560px) {
  .transfer-dialog { padding: 8px; }
  .transfer-dialog__panel { max-height: calc(100dvh - 16px); }
  .transfer-dialog__qr { width: min(290px, 100%); }
  .transfer-dialog__actions > button { flex: 1 1 10rem; }
}
.grid-scroll-container{
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  padding: clamp(6px, 1vw, 12px) clamp(8px, 1.5vw, 14px);
  overflow-x: auto;    /* still scrollable for keyboard/assistive fallback */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: auto;
  overflow-anchor: none;
  touch-action: pan-x pan-y;
  overscroll-behavior: contain;
  cursor: grab;
  scrollbar-width: none;
}

.grid-scroll-container::-webkit-scrollbar{
  width: 0;
  height: 0;
}

.grid-scroll-container.is-panning{
  cursor: grabbing;
}

body.surface-painting-active .grid-scroll-container{
  cursor: crosshair;
}

body.grid-panning-active,
body.grid-panning-active *{
  user-select: none;
}
@supports (height: 1dvh){
  .grid-scroll-container{
    height: 100%;
  }
}
#grid-container{
  overflow: visible;   /* avoid nested scrollbars inside the grid */
}

#veg-menu{
  position: static !important;
  bottom: auto !important;
  z-index: auto !important;
  height: 100%;
  align-self: stretch;
  min-height: 0;
  width: 100%;
  margin-bottom: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow: hidden;
}

@media (min-width: 1025px){
  #placeModeBar{
    display: none !important;
  }
}

@media (min-width: 1025px){
  #leftPanel{
    gap: 0;
  }
  #leftPanel :is(#controlsDrawer, #veg-menu){
    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, #veg-menu){
    margin: 0;
  }
  #leftPanel #veg-menu{
    border-top: 0;
    border-top-left-radius: 0;
    border-top-right-radius: 0;
  }
}

@media (max-width: 767px){
  #cropTrayPanel .crop-search-field{
    display: none;
  }
}

/* Selected apply tools own touch gestures; clearing the tool restores scrolling. */
body.surface-painting-active .grid-scroll-container,
body.crop-placement-active .grid-scroll-container{
  touch-action: none;
}
/* Compact Layout list. Keep crop tray styles scoped separately. */
#surfaceLayerPanel #surfaceToolsPanel {
  gap: 0;
  padding: 8px;
  border-radius: 3px;
  box-shadow: none;
}
#surfaceLayerPanel .surface-tools__title { margin-bottom: 4px; }
#surfaceLayerPanel .surface-tools__help { margin: 6px 0; }
#surfaceLayerPanel .surface-tools__buttons,
#surfaceLayerPanel .surface-tools__group-buttons { display: block; }
#surfaceLayerPanel .layout-tool-group { min-width: 0; }
#surfaceLayerPanel .layout-tool-group summary {
  position: relative;
  padding: 7px 20px 5px 2px;
  color: var(--ink-dim);
  font-size: .75rem;
  font-weight: 700;
  cursor: pointer;
}
#surfaceLayerPanel .layout-group-selection { display: none; position: absolute; right: 6px; color: var(--ink); }
#surfaceLayerPanel .layout-tool-group:has([aria-pressed="true"], .raised-bed-context:not([hidden])) > summary .layout-group-selection { display: inline; }
#surfaceLayerPanel .surface-type-btn {
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 33px;
  padding: 5px 6px;
  border: 0;
  border-bottom: 1px solid color-mix(in srgb, var(--ink) 12%, transparent);
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  box-shadow: none;
  text-align: left;
  transform: none;
}
#surfaceLayerPanel .surface-type-btn:hover:not(:disabled),
#surfaceLayerPanel summary:hover { background: color-mix(in srgb, var(--ink) 6%, transparent); }
#surfaceLayerPanel .surface-type-btn.is-active { background: color-mix(in srgb, var(--ink) 12%, transparent); }
#surfaceLayerPanel .surface-type-btn.is-active::after { content: '✓'; margin-left: auto; font-size: .75rem; }
#surfaceLayerPanel .surface-type-btn:disabled { opacity: .45; cursor: not-allowed; }
#surfaceLayerPanel .surface-type-btn__label {
  order: 1;
  width: auto;
  min-width: 0;
  font-size: .8rem;
  font-weight: 500;
  letter-spacing: normal;
  line-height: 1.25;
  white-space: nowrap;
  overflow-wrap: normal;
  text-align: left;
}
#surfaceLayerPanel .surface-type-btn .surface-type-btn__swatch {
  order: 0;
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  border-radius: 2px;
}
#surfaceLayerPanel .layout-bed-placeholder { border: 1px dashed var(--ink-dim); background: var(--surface-3); }
#surfaceLayerPanel .raised-bed-context { margin: 4px 0; padding: 8px; border-radius: 2px; min-width: 0; }
#surfaceLayerPanel .raised-bed-context select { width: 100%; min-width: 0; max-width: 100%; }
#surfaceLayerPanel summary:focus-visible { outline: 2px solid var(--ink-dim); outline-offset: -2px; }
@media (max-width: 767px), (pointer: coarse) {
  #surfaceLayerPanel .surface-type-btn { min-height: 44px; }
  #surfaceLayerPanel .layout-tool-group summary { min-height: 44px; box-sizing: border-box; padding-top: 13px; }
}

/* Growing-medium preference is secondary to the active bed/structure tool. */
#surfaceLayerPanel .surface-type-btn.is-medium-selected {
  background: color-mix(in srgb, var(--ink) 5%, transparent);
}
#surfaceLayerPanel .surface-type-btn.is-medium-selected::after {
  content: 'Medium';
  margin-left: auto;
  color: var(--ink-dim);
  font-size: .65rem;
}


/* One live instruction region and explicit focus rings within Layout only. */
#surfaceLayerPanel #surfaceModeHelpText { font-size: .78rem; line-height: 1.35; }
#surfaceLayerPanel .surface-type-btn:focus-visible {
  outline: 2px solid var(--brand-400);
  outline-offset: -2px;
}
#surfaceLayerPanel .raised-bed-context { gap: 6px; }
#surfaceLayerPanel #raisedBedContext { margin: 0; padding: 4px 0; border-top: 0; }
#surfaceLayerPanel .raised-bed-context__actions > button { flex: 1 1 auto; min-height: 36px; padding: 6px 8px; font-size: .75rem; }
#surfaceLayerPanel .shed-context > .surface-tools__help { margin: 0; font-size: .72rem; line-height: 1.3; }

@media (max-width: 1024px), (pointer: coarse) {
  #surfaceLayerPanel .raised-bed-context__actions > button { min-height: 44px; }
}

#surfaceLayerPanel .surface-type-btn::after { order: 2; }

/* Covers share the compact Layout rows and original cover swatches. */
#surfaceLayerPanel .layout-cover-tools { min-width: 0; }

@media (min-width:1025px){
  #plannerSidebar #cropLayerPanel .crop-tray{ flex:1 1 auto; min-height:0; }
}

/* Keep the desktop shell fixed while the grid and sidebar content scroll. */
@media (min-width:1025px){
  #appShell{ overflow:clip; }
}

/* Desktop navigation rail: one surface from the application top to bottom. */
@media (min-width: 1025px){
  #appShell{ column-gap: 0; }
  #appShell #leftPanel{
    margin: 0;
    padding: 0;
    border: 0;
    border-right: 1px solid var(--surface-4);
    border-radius: 0;
    box-shadow: none;
    background: var(--surface-1);
    box-sizing: border-box;
  }
  #leftPanel #plannerSidebarHeader{
    margin: 0;
    border: 0;
    border-bottom: 1px solid var(--surface-4);
    border-radius: 0;
    box-shadow: none;
    background: transparent;
  }
  #leftPanel #plannerSidebar{
    margin: 0;
    padding: 0;
    gap: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    background: transparent;
  }
  #plannerSidebar > .planner-layer-tabs{
    margin: 0;
    border: 0;
    border-bottom: 1px solid var(--surface-4);
    border-radius: 0;
    box-shadow: none;
    background: var(--surface-1);
  }
  #plannerSidebar .planner-layer-tab{
    background: transparent;
    border: 0;
  }
  #plannerSidebar .planner-layer-tab:is(:hover, :focus-visible, .is-selected){
    background: color-mix(in srgb, var(--ink) 6%, transparent);
  }
  #plannerSidebar > .planner-layer-panel{
    margin: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    background: transparent;
  }
  #surfaceLayerPanel #surfaceToolsPanel{
    border: 0;
    border-radius: 0;
    box-shadow: none;
    background: transparent;
  }
}

.planner-layer-tab:disabled{ opacity: .55; cursor: default; }

.legacy-migration-dialog {
  width: min(32rem, calc(100% - 2rem));
  max-height: calc(100% - 2rem);
  padding: 1.25rem;
  border: 1px solid currentColor;
  border-radius: 0.5rem;
  background: Canvas;
  color: CanvasText;
}

.legacy-migration-dialog::backdrop {
  background: rgb(0 0 0 / 55%);
}

#legacyMigrationChoices {
  display: grid;
  gap: 0.5rem;
}

#legacyMigrationFreshAction {
  border-block-start: 1px solid currentColor;
  padding-block-start: 1rem;
}

/* Notifications overlay the planner shell without intercepting grid input. */
#appShell{ position: relative; }
#workArea{ isolation: isolate; }
.planner-notification-anchor{
  position: absolute;
  inset-inline: 0;
  bottom: calc(60px + env(safe-area-inset-bottom));
  z-index: 20;
  height: 0;
  pointer-events: none;
}
.planner-notification-stack{
  position: absolute;
  bottom: 0;
  right: max(16px, env(safe-area-inset-right));
  width: min(300px, calc(100% - max(16px, env(safe-area-inset-left)) - max(16px, env(safe-area-inset-right))));
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#plannerNotifications{
  display: flex;
  flex-direction: column-reverse;
  gap: 6px;
}
#plannerNotifications:empty{ display: none; }
#plannerSeasonalNotice:not([hidden]){
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  align-self: flex-end;
  box-sizing: border-box;
  width: 100%;
  gap: 6px;
  padding: 4px 6px 4px 10px;
  border: 1px solid var(--surface-4);
  border-radius: 5px;
  background: var(--surface-1);
  color: var(--ink);
  font-size: .86rem;
  line-height: 1.35;
  pointer-events: auto;
  overflow-wrap: anywhere;
}
#plannerSeasonalNotice summary{
  padding-block: 8px;
  cursor: pointer;
  font-weight: 700;
}
#plannerSeasonalNotice button{
  min-width: 36px;
  min-height: 36px;
  margin: 0;
  padding: 0;
  font-size: 1.2rem;
}
#plannerSeasonalNotice ul{
  padding: 0 4px 0 0;
  margin: 0;
  list-style: none;
  max-height: min(14rem, 32dvh);
  overflow: auto;
  overscroll-behavior: contain;
}
#plannerSeasonalNotice li{ padding-block: 6px; }
#plannerSeasonalNotice li + li{ border-top: 1px solid var(--surface-4); }
#plannerSeasonalNotice p{ margin: 4px 0; }
.planner-notification-stack:has(#plannerNotifications [data-type="error"]:not([hidden])) #plannerSeasonalNotice,
body[data-planner-presentation="touch-portrait"] #plannerSeasonalNotice,
body:has(#mobileLogbookDialog[open]) #plannerSeasonalNotice{
  display: none;
}
body[data-planner-presentation="touch-landscape"] #plannerSeasonalNotice{
  max-width: calc(100dvw - var(--planner-sidebar-width, 280px) - env(safe-area-inset-left) - max(16px, env(safe-area-inset-right)) - 8px);
}
body[data-planner-presentation="touch-landscape"] #plannerSeasonalNotice button{ min-width: 44px; min-height: 44px; }
body[data-planner-presentation="touch-landscape"] #plannerSeasonalNotice ul{ max-height: min(10rem, 25dvh); }
@media (max-width: 379px), (max-height: 259px){
  body[data-planner-presentation="touch-landscape"] #plannerSeasonalNotice{ display: none; }
}
.planner-notification{
  --notice-bg: #202a25;
  --notice-accent: #becfc4;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: start;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid color-mix(in srgb, var(--notice-accent) 58%, var(--notice-bg));
  border-radius: 5px;
  background: var(--notice-bg);
  color: #f8f5ec;
  font-size: .86rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
  pointer-events: auto;
  transition: opacity 150ms ease, transform 150ms ease, display 150ms allow-discrete;
}
.planner-notification[data-type="success"]{ --notice-accent: #99cea2; }
.planner-notification[data-type="pending"]{ --notice-accent: #e6bf78; pointer-events: none; }
.planner-notification[data-type="error"]{ --notice-bg: #402a29; --notice-accent: #f0aaa3; }
:root[data-theme="light"] .planner-notification{ --notice-bg: #303b31; }
:root[data-theme="light"] .planner-notification[data-type="error"]{ --notice-bg: #50332e; }
.planner-notification[hidden]{
  display: none;
  opacity: 0;
  transform: translateY(4px);
  pointer-events: none;
}
@starting-style{
  .planner-notification:not([hidden]){ opacity: 0; transform: translateY(4px); }
}
.planner-notification:nth-child(n+3 of :not([hidden])){ display: none; }
.planner-notification__icon{
  display: grid;
  place-items: center;
  width: 1.2em;
  height: 1.2em;
  margin-top: .06em;
  border: 1px solid currentColor;
  border-radius: 50%;
  color: var(--notice-accent);
  font-weight: 700;
}
.planner-notification summary{ cursor: pointer; text-decoration: underline; }
.planner-notification details p{
  max-height: min(9rem, 20dvh);
  overflow: auto;
  margin: 4px 0 0;
}
.planner-notification .planner-notification__close{
  min-width: 28px;
  min-height: 28px;
  padding: 0;
  margin: -4px -4px -4px 0;
  border: 0;
  background: transparent;
  color: inherit;
  box-shadow: none;
  font: inherit;
  font-size: 1.2rem;
}
.planner-notification :is(button, summary):focus-visible{
  outline: 2px solid var(--notice-accent);
  outline-offset: 2px;
}
@media (max-width: 1024px){
  .planner-notification:nth-child(n+2 of :not([hidden])){ display: none; }
}
@media (prefers-reduced-motion: reduce){
  .planner-notification{ transition: none; }
}
@media print{
  .planner-notification-anchor{ display: none; }
}

/* Keep both scrollports inside the usable viewport. The width rules also
   support narrow desktop windows without changing their presentation mode. */
@media (max-width: 1024px){
  #appShell{ --planner-sidebar-width: clamp(160px, 32vw, 280px); }
}
body[data-planner-presentation^="touch-"] #appShell{
  --planner-sidebar-width: clamp(200px, 32vw, 280px);
}
body:is(.planner-phone-mode, [data-planner-presentation^="touch-"]) #appShell{
  box-sizing: border-box;
  min-height: 0;
  column-gap: 0;
  /* Give the sidebar's inset its own space so its controls keep their width. */
  grid-template-columns: calc(var(--planner-sidebar-width, 344px) + env(safe-area-inset-left)) minmax(0, 1fr);
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
body:is(.planner-phone-mode, [data-planner-presentation^="touch-"]) #appShell #leftPanel{
  overflow: auto;
  overscroll-behavior: contain;
  padding-left: env(safe-area-inset-left);
  background: var(--surface-1);
  border-inline-end: 1px solid var(--surface-4);
  box-sizing: border-box;
}
body:is(.planner-phone-mode, [data-planner-presentation^="touch-"]) #plannerSidebar{
  flex: 0 0 auto;
  padding: 0;
  gap: 0;
  overflow: visible;
}
body:is(.planner-phone-mode, [data-planner-presentation^="touch-"]) #plannerSidebar #cropLayerPanel .crop-tray{
  flex: 0 0 auto;
  min-height: 0;
}
body:is(.planner-phone-mode, [data-planner-presentation^="touch-"]) #cropLayerPanel #veg-scroll{
  max-height: none;
  flex: 0 0 auto;
}
body:is(.planner-phone-mode, [data-planner-presentation^="touch-"]) #plannerSidebarHeader{
  padding: 4px;
}
body:is(.planner-phone-mode, [data-planner-presentation^="touch-"]) #workArea{
  padding: 0 env(safe-area-inset-right) 0 0;
}
body:is(.planner-phone-mode, [data-planner-presentation^="touch-"]) .grid-scroll-container{
  box-sizing: border-box;
  padding: 4px;
}
/* One shared inset keeps landscape controls aligned without nesting padding. */
body[data-planner-presentation="touch-landscape"] #plannerSidebarHeader,
body[data-planner-presentation="touch-landscape"] #plannerSidebar > :is(.planner-layer-tabs, .planner-layer-panel){
  box-sizing: border-box;
  padding-inline: 8px;
}
body[data-planner-presentation="touch-landscape"] #surfaceLayerPanel #surfaceToolsPanel{
  padding-inline: 0;
}
body[data-planner-presentation="touch-landscape"] :is(
  .planner-layer-tab,
  #manageLayerPanel .manage-action, #manageLayerPanel summary,
  #plannerThemeToggle, #cropCategorySelect, #vegSearchInput, #cropLayerPanel .veg-item
){ min-height: 44px; }
body[data-planner-presentation="touch-landscape"] #plannerSidebarHeader .sidebar-icon-button{ height: 44px; }
body[data-planner-presentation="touch-landscape"] #plannerSidebarHeader #gridZoom{
  touch-action: none;
}

#plannerRotationScreen{
  position: fixed;
  inset: 0;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  border: 0;
  padding: max(20px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right))
    max(20px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  background: var(--bg);
  color: var(--ink);
  overflow: auto;
}
#plannerRotationScreen[open]{ display: flex; }
.planner-rotation-card{
  box-sizing: border-box;
  max-width: 28rem;
  margin: auto;
  padding: clamp(16px, 5vw, 28px);
  border: 1px solid var(--surface-4);
  border-top: 4px solid var(--brand-400);
  border-radius: 12px;
  background: var(--surface-1);
  text-align: center;
}
.planner-rotation-card h1{ margin: 0; font-size: clamp(1.35rem, 6vw, 1.75rem); }
.planner-rotation-card p{ margin: 12px 0 0; line-height: 1.5; }
#plannerRotationHelp{ color: var(--ink-dim); font-size: .9rem; }

/* Share the launcher's bottom row so the controls never sit over a planting cell. */
#appShell{
  grid-template-areas: "sidebar work" "sidebar logbook-launcher";
  grid-template-rows: minmax(0, 1fr) auto;
}
.mobile-logbook-launcher{
  display: flex;
  grid-area: logbook-launcher;
  justify-content: flex-end;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  padding-right: calc(8px + env(safe-area-inset-right));
  background: var(--surface-1);
}
body:not([data-planner-presentation^="touch-"]) #mobileLogbookBtn{
  display: none;
}
.planner-context-actions:not([hidden]){
  display: flex;
  gap: 6px;
}
.planner-context-action:not([hidden]){
  display: inline-grid;
  place-items: center;
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  border: 1px solid color-mix(in srgb, var(--action-accent) 48%, #263238);
  border-radius: 8px;
  background: #263238;
  color: var(--action-accent);
  font-size: 17px;
  line-height: 1;
}
.planner-context-action--danger:not([hidden]){ --action-accent: #ffaaa3; }
.planner-context-action--done:not([hidden]){ --action-accent: #a6e4a9; }
.planner-context-action--pan{ --action-accent: #d1d8da; }
.planner-context-action--pan[aria-pressed="true"]{
  --action-accent: #a6e4a9;
  border-color: var(--action-accent);
  background: #284934;
}
.planner-context-action i{ pointer-events: none; }
.planner-context-action:is(:hover, :focus-visible){
  border-color: var(--action-accent);
  background: color-mix(in srgb, var(--action-accent) 16%, #263238);
}
.planner-context-action:active{
  background: color-mix(in srgb, var(--action-accent) 28%, #263238);
}
.planner-context-action:focus-visible{
  outline: 2px solid var(--action-accent);
  outline-offset: -4px;
}
@media (max-height: 744px){
  body[data-planner-presentation="desktop"]:has(.logbook-panel.is-open:not(.is-minimized)) .mobile-logbook-launcher{
    padding-right: 398px;
  }
}
#mobileLogbookBtn{
  display: inline-flex;
  align-items: center;
  gap: .5em;
  min-height: 44px;
  margin: 0;
  padding-inline: 12px;
}
#mobileLogbookDialog{
  position: fixed;
  inset: var(--logbook-viewport-top, 0px) auto auto var(--logbook-viewport-left, 0px);
  box-sizing: border-box;
  width: var(--logbook-viewport-width, 100vw);
  height: var(--logbook-viewport-height, 100dvh);
  max-width: none;
  max-height: none;
  margin: 0;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
    env(safe-area-inset-bottom) env(safe-area-inset-left);
  border: 0;
  overflow: hidden;
  background: #f8edcf;
}
#mobileLogbookDialog .logbook-panel{
  position: static;
  width: 100%;
  height: 100%;
  max-height: none;
  transform: none;
  transition: none;
}
#mobileLogbookDialog .logbook-panel__page{
  height: 100%;
  max-height: none;
  border: 0;
  border-radius: 0;
  scroll-padding-top: 62px;
}
#mobileLogbookDialog .logbook-panel__bar{
  grid-template-columns: minmax(0, 1fr) auto auto;
}
#mobileLogbookDialog .logbook-panel__tabs{ grid-area: 1 / 2; }
#mobileLogbookDialog .logbook-panel__close{
  grid-area: 1 / 3;
  width: auto;
  padding: 0 12px;
}
#mobileLogbookDialog :is(button, input, .logbook-panel__calendar-link){
  min-height: 44px;
}
#mobileLogbookDialog :is(.logbook-panel__bed-rename, .logbook-panel__planting-edit){ min-width: 44px; }
#mobileLogbookDialog .logbook-panel__branding a{
  display: inline-flex;
  align-items: center;
  min-height: 44px;
}
@media (max-width: 480px){
  #mobileLogbookDialog .logbook-panel__branding{ display: none; }
  #mobileLogbookDialog .logbook-panel__bar{ grid-template-columns: minmax(0, 1fr) auto; }
  #mobileLogbookDialog .logbook-panel__tabs{ grid-column: 1; }
  #mobileLogbookDialog .logbook-panel__close{ grid-column: 2; }
}

body[data-planner-presentation="touch-landscape"] :is(button, summary){ touch-action: manipulation; }
body[data-planner-presentation="touch-landscape"] #structureMoveBtn{ touch-action: none; }
body.touch-erase-active .grid-scroll-container,
body.planner-mode-covers .grid-scroll-container,
body.raised-bed-tool-active .grid-scroll-container,
body[data-planner-presentation="touch-landscape"] .plant.is-selected{
  touch-action: none;
}
body[data-planner-presentation="touch-landscape"] :is(.surface-type-btn, #surfaceToolsPanel summary,
  #raisedBedContext button, #shedContext button, .structure-remove-button, #plotSizeToggle){
  min-height: 44px;
}

#touchRaisedBedResizeBtn{ display: none; }
body[data-planner-presentation="touch-landscape"] #touchRaisedBedResizeBtn:not([hidden]){ display: inline-flex; }

/* Narrow tool columns must allow crop names to wrap beside the info control. */
@container (max-width: 220px){
  #cropLayerPanel .veg-item .veg-label{ white-space: normal; overflow-wrap: anywhere; min-width: 0; }
}

#manageLayerPanel #touchExportPngBtn{ display: none; }
body[data-planner-presentation="touch-landscape"] #manageLayerPanel #touchExportPngBtn{ display: flex; }

/* Keep ruler labels legible when individual cells are only a few pixels wide. */
.grid-zoom-overview .grid-ruler-cell:not(.is-major){ color: transparent; }
