/* Safari's visual viewport excludes its keyboard. Updated through this external rule. */
:root {
  --keyboard-height: 100dvh;
  --keyboard-top: 0px;
}

/* Shared navigation; the desktop arrangement remains a conventional sidebar. */
.site-menu {
  display: flex;
  align-items: center;
  gap: 10px;
}

.account-attribution {
  display: block;
  padding: 6px 0;
  font-size: 16px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

/* Claim touch gestures on the HTML map surface before Safari starts scrolling. */
#mapWorkspace .frame {
  touch-action: none;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.mobile-only,
.menu-toggle,
.compact-menu-tools,
.layers-icon,
.layers-chevron {
  display: none;
}

#addCanopy {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 9px;
}

.add-tree-icon {
  display: block;
}

.add-tree-label {
  display: none;
}

#saveLoginDialog .button {
  display: inline-block;
  padding: 10px 12px;
  border-radius: 8px;
  text-decoration: none;
}

@media (min-width: 901px) {
  .map-tools {
    position: relative;
  }

  #layersToggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
  }

  .layers-chevron {
    display: block;
    transition: transform 150ms ease;
  }

  #layersToggle[aria-expanded="true"] {
    position: relative;
    z-index: 21;
    background: white;
    border-color: var(--line);
    border-bottom-color: white;
    border-radius: 8px 8px 0 0;
  }

  #layersToggle[aria-expanded="true"] .layers-chevron {
    transform: rotate(180deg);
  }

  .map-tools > .layers-panel {
    top: calc(100% - 1px);
    right: 0;
    width: 310px;
    max-height: calc(100dvh - 174px);
    border-radius: 9px 0 9px 9px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .layers-chevron {
    transition: none;
  }
}

html[data-layout="desktop"] body {
  min-width: 940px;
}

html[data-layout="desktop"] .layout {
  height: calc(100dvh - 82px);
  grid-template-columns: minmax(0, 1fr) 330px;
}

html[data-layout="mobile"] body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  overflow-y: auto;
  padding-top: env(safe-area-inset-top);
}

html[data-layout="mobile"] button,
html[data-layout="mobile"] select,
html[data-layout="mobile"] input,
html[data-layout="mobile"] textarea,
html[data-layout="mobile"] summary {
  font-size: 16px;
}

html[data-layout="mobile"] button,
html[data-layout="mobile"] select,
html[data-layout="mobile"] input:not([type="checkbox"]),
html[data-layout="mobile"] summary {
  min-height: 44px;
}

html[data-layout="mobile"] .mobile-only {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

html[data-layout="mobile"] .app-header {
  flex: 0 0 auto;
  height: 64px;
  min-height: 64px;
  padding: 8px max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
  gap: 8px;
  flex-wrap: nowrap;
  position: sticky;
  top: 0;
  z-index: 26;
}

html[data-layout="mobile"] .map-brand {
  gap: 8px;
}

html[data-layout="mobile"] .map-brand .site-seal {
  width: 40px;
  height: 40px;
}

html[data-layout="mobile"] .map-brand h1 {
  font-size: 19px;
  letter-spacing: -.025em;
  white-space: nowrap;
}

html[data-layout="mobile"] .map-brand .eyebrow {
  font-size: 9px;
  letter-spacing: .04em;
  white-space: nowrap;
}

html[data-layout="mobile"] #mapSubtitle,
html[data-layout="mobile"] #downloadMenu,
html[data-layout="mobile"] .mode-switch,
html[data-layout="mobile"] .mode-help,
html[data-layout="mobile"] .map-pane > .map-legend,
html[data-layout="mobile"] body:not([data-sheet]) .panel-content,
html[data-layout="mobile"] body:not([data-sheet]) .panel-footer {
  display: none;
}

html[data-layout="mobile"] .header-actions {
  gap: 4px;
  flex-wrap: nowrap;
  flex-shrink: 0;
  margin: 0;
}

html[data-layout="mobile"] .layout {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  height: auto;
  min-height: 0;
  padding: 0 max(0px, env(safe-area-inset-right)) 0 max(0px, env(safe-area-inset-left));
  gap: 0;
}

html[data-layout="mobile"] .map-pane {
  flex: 0 0 auto;
  min-height: 180px;
  height: calc(100dvh - 120px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
}

html[data-layout="mobile"] body[data-sheet="open"] .map-pane {
  height: 44dvh;
  min-height: 220px;
}

html[data-layout="mobile"] .map-workspace {
  min-height: 0;
  border-radius: 0;
}

html[data-layout="mobile"] .frame {
  border: 0;
  border-radius: 0;
}

html[data-layout="mobile"] .map-top {
  position: absolute;
  inset: 10px 10px auto;
  margin: 0;
  z-index: 4;
  flex-wrap: nowrap;
  pointer-events: none;
}

html[data-layout="mobile"] .map-top button {
  pointer-events: auto;
  box-shadow: 0 2px 8px #142b2625;
  background: white;
}

html[data-layout="mobile"] #addCanopy {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 9px;
}

html[data-layout="mobile"] .add-tree-label {
  display: none;
}

html[data-layout="mobile"] .add-tree-icon {
  display: block;
}

html[data-layout="mobile"] .scale {
  display: none;
}

html[data-layout="mobile"] .north {
  top: auto;
  bottom: 24px;
}

html[data-layout="mobile"] .layers-panel {
  inset: 60px 10px auto;
  width: auto;
  max-height: min(65dvh, calc(100dvh - 180px));
  overscroll-behavior: contain;
}

html[data-layout="mobile"] .drawer-heading {
  position: sticky;
  top: -16px;
  background: white;
  z-index: 1;
}

html[data-layout="mobile"] #closeLayers {
  min-width: 44px;
}

html[data-layout="mobile"] .map-legend {
  border-top: 1px solid var(--line);
  margin-top: 16px;
  font-size: 12px;
}

html[data-layout="mobile"] .legend {
  gap: 10px;
}

html[data-layout="mobile"] .inspector {
  flex: 0 0 auto;
  height: auto;
  max-height: none;
  border-radius: 16px 16px 0 0;
  margin-top: -8px;
  z-index: 6;
  box-shadow: 0 -3px 12px #15382920;
  padding-bottom: env(safe-area-inset-bottom);
  overflow: visible;
}

html[data-layout="mobile"] body[data-sheet="open"] .inspector,
html[data-layout="mobile"] body[data-sheet="open"][data-session="true"] .inspector {
  height: auto;
}

html[data-layout="mobile"] .panel-heading {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  min-height: 62px;
}

html[data-layout="mobile"] .panel-heading .eyebrow {
  display: none;
}

html[data-layout="mobile"] .panel-heading h2 {
  font-size: 17px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

html[data-layout="mobile"] #clearSelection {
  min-width: 44px;
  font-size: 25px;
}

html[data-layout="mobile"] #sheetToggle {
  flex: 0 0 auto;
  width: 44px;
  padding: 10px;
  border: 0;
}

html[data-layout="mobile"] #sheetToggle[aria-expanded="false"] img {
  transform: rotate(180deg);
}

html[data-layout="mobile"] .panel-heading #editTree {
  flex: 0 0 auto;
  width: auto;
  padding: 8px 10px;
  font-size: 14px;
  color: var(--ink);
  background: white;
  border-color: var(--line);
}

html[data-layout="mobile"] .panel-content {
  padding: 12px 16px;
  overflow: visible;
  flex: 0 0 auto;
  scroll-padding: 16px;
}

html[data-layout="mobile"] .panel-footer {
  position: static;
  padding: 8px 16px;
  flex-shrink: 0;
}

html[data-layout="mobile"] body[data-session="true"] .panel-content {
  padding-bottom: calc(112px + env(safe-area-inset-bottom));
}

html[data-layout="mobile"] body[data-session="true"] .panel-footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
}

html[data-layout="mobile"] .outline-actions {
  grid-template-columns: minmax(0, 1fr) 44px;
}

html[data-layout="mobile"] .street-view-link {
  width: 44px;
  height: 44px;
}

html[data-layout="mobile"] .help-row > .help-button {
  min-width: 44px;
  flex-basis: 44px;
}

html[data-layout="mobile"] .check-field {
  min-height: 44px;
}

html[data-layout="mobile"] .check-field input {
  width: 22px;
  height: 22px;
}

html[data-layout="mobile"] .dialog-actions {
  flex-wrap: wrap;
}

html[data-layout="mobile"] dialog {
  width: calc(100% - 24px);
  max-height: calc(100dvh - 24px);
  padding: 20px;
  overflow: auto;
}

html[data-layout="mobile"] body[data-map-task="true"] .map-workspace {
  inset: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  min-height: 0;
}

html[data-layout="mobile"] .drawbar {
  max-height: 42dvh;
  overflow: auto;
  padding: 10px;
}

html[data-layout="mobile"] .drawbar .actions button {
  font-size: 13px;
}

html[data-layout="mobile"] .toast {
  bottom: 54px;
  left: 12px;
  max-width: calc(100vw - 24px);
}

html[data-layout="mobile"] body[data-keyboard="true"] {
  position: fixed;
  top: var(--keyboard-top);
  width: 100%;
  height: var(--keyboard-height);
  padding-top: 0;
  overflow: hidden;
}

html[data-layout="mobile"] body[data-keyboard="true"] .app-header,
html[data-layout="mobile"] body[data-keyboard="true"] .map-pane {
  display: none;
}

html[data-layout="mobile"] body[data-keyboard="true"] .inspector {
  width: 100%;
  height: 100% !important;
  max-height: none;
  margin: 0;
  overflow: hidden;
  flex: 1;
}

html[data-layout="mobile"] body[data-keyboard="true"] .layout,
html[data-layout="mobile"] body[data-keyboard="true"] .panel-content {
  flex: 1;
  min-height: 0;
}

html[data-layout="mobile"] body[data-keyboard="true"] .panel-content {
  overflow: auto;
  padding-bottom: 16px;
}

html[data-layout="mobile"] body[data-keyboard="true"] .panel-footer {
  position: static;
}

@media (max-width: 900px) {
  html,
  body,
  .panel-content,
  .site-menu,
  .layers-panel {
    touch-action: pan-x pan-y;
  }

  html[data-layout] .header-actions {
    position: fixed;
    top: calc(10px + env(safe-area-inset-top));
    right: max(12px, env(safe-area-inset-right));
    z-index: 26;
  }

  .menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 10px;
    border: 0;
    background: white;
  }

  /* Keep Menu accessible even when a phone is showing the wide desktop layout. */
  .site-menu {
    position: fixed;
    top: calc(64px + env(safe-area-inset-top));
    left: max(12px, env(safe-area-inset-left));
    right: max(12px, env(safe-area-inset-right));
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    padding: 12px;
    max-height: calc(100dvh - 88px - env(safe-area-inset-top));
    overflow: auto;
    background: white;
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: 0 12px 30px #15382930;
  }

  .header-actions > .account-button,
  .map-tools > #layersToggle {
    display: none;
  }

  .compact-menu-tools {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--line);
  }

  .compact-menu-tools button {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 44px;
    border: 0;
    padding: 10px;
    text-align: left;
    font-size: 16px;
  }

  .compact-menu-tools img {
    display: block;
    flex: 0 0 auto;
  }

  .compact-menu-tools .layers-chevron {
    display: none;
  }

  .compact-menu-tools #accountButtonName {
    max-width: none;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .site-menu .quiet {
    min-height: 44px;
    font-size: 16px;
    text-align: left;
    padding: 10px;
  }

  .site-menu .popover {
    position: static;
    width: auto;
    padding: 8px;
    border: 0;
    box-shadow: none;
  }

  html[data-layout] .layers-panel {
    position: fixed;
    inset: calc(74px + env(safe-area-inset-top)) 10px auto;
    width: auto;
    max-height: calc(100dvh - 90px - env(safe-area-inset-top));
    z-index: 27;
  }
}

@media (max-height: 500px) and (orientation: landscape) {
  html[data-layout="mobile"] .app-header {
    height: 60px;
    min-height: 60px;
    padding-top: 4px;
    padding-bottom: 4px;
  }

  html[data-layout="mobile"] .layout {
    flex-direction: row;
    align-items: flex-start;
  }

  html[data-layout="mobile"] .map-pane,
  html[data-layout="mobile"] body[data-sheet="open"] .map-pane {
    flex: 1;
    height: calc(100dvh - 60px);
    position: sticky;
    top: 60px;
  }

  html[data-layout="mobile"] .inspector {
    width: 40%;
    height: auto !important;
    max-height: none;
    margin-top: 0;
    border-radius: 0;
  }

  html[data-layout="mobile"] body[data-sheet="closed"] .inspector {
    width: 170px;
  }

  html[data-layout="mobile"] .panel-heading {
    flex-wrap: wrap;
  }

  html[data-layout="mobile"] body[data-session="true"] .panel-footer {
    left: 60%;
  }
}

/* Mobile panels cover the map; they never take height away from its frame. */
html[data-layout="mobile"] body { height: 100svh; min-height: 0; overflow: hidden; }
html[data-layout="mobile"] .layout { position: relative; flex: 1; min-height: 0; height: calc(100svh - 64px); }
html[data-layout="mobile"] .map-pane,
html[data-layout="mobile"] body[data-sheet="open"] .map-pane { height: calc(100svh - 64px - env(safe-area-inset-top)); min-height: 0; width: 100%; }
html[data-layout="mobile"] .inspector,
html[data-layout="mobile"] body[data-sheet="open"] .inspector { position: absolute; bottom: 0; left: 0; right: 0; width: auto; height: auto; max-height: 58%; margin: 0; overflow: hidden; display: flex; flex-direction: column; }
html[data-layout="mobile"] .panel-content { min-height: 0; overflow: auto; overscroll-behavior: contain; }
html[data-layout="mobile"] .panel-heading, html[data-layout="mobile"] .panel-footer { flex-shrink: 0; }
html[data-layout="mobile"] body[data-map-task="true"] .inspector { visibility: hidden; pointer-events: none; }
html[data-layout="mobile"] body[data-keyboard="true"] .map-pane { display: flex; }
html[data-layout="mobile"] body[data-keyboard="true"] .inspector { position: fixed; top: var(--keyboard-top); bottom: auto; height: var(--keyboard-height) !important; max-height: var(--keyboard-height); }
html[data-layout="mobile"] body[data-keyboard="true"] .layout { flex: none; height: calc(100svh - 64px); }
html[data-layout="mobile"] body[data-keyboard="true"] { height: 100svh; top: 0; }
html[data-layout="mobile"] body[data-keyboard="true"] .app-header { display: flex; }

html[data-layout="mobile"] body[data-map-task="true"] .map-workspace { position: relative; inset: auto; height: 100%; width: 100%; }
html[data-layout="mobile"] .map-workspace .drawbar { position: absolute; left: 0; right: 0; bottom: 0; z-index: 12; background: white; max-height: 38%; }
html[data-layout="mobile"] .map-workspace:has(.drawbar:not([hidden])) .frame { flex: 1; height: 100%; min-height: 0; }
html[data-layout="mobile"] .task-imagery-slot:not([hidden]) { position: absolute; top: 0; left: 0; z-index: 11; max-width: calc(100% - 60px); }

/* Let Chrome shrink the flex child into the sheet so its contents can scroll. */
html[data-layout="mobile"] .panel-content,
html[data-layout="mobile"] body[data-session="true"] .panel-content {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  touch-action: pan-y;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 16px;
}
html[data-layout="mobile"] body[data-session="true"] .panel-footer {
  position: static;
  flex: 0 0 auto;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
}
