/* Layout enhancement for the current deployed Kundkarta. Loaded last. */
.map-stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto minmax(200px, 1fr);
  container-type: inline-size;
}
.map-toolbar {
  position: relative;
  inset: auto;
  grid-column: 1;
  grid-row: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: #f5f7f1;
  border-bottom: 1px solid #dce2d9;
  pointer-events: auto;
}
.map-context,
.map-pane:has(.street-view) .map-context {
  min-width: 0;
  padding: 0;
  background: transparent;
  color: #263c30;
  text-shadow: none;
}
.map-context strong {
  font-size: 21px;
  overflow-wrap: anywhere;
}
.map-kicker {
  color: #61745f;
}
.map-metric {
  min-width: 0;
  margin: 0;
}
.map-metric select {
  min-width: 0;
  max-width: 100%;
}
.map-location-controls {
  position: relative;
  inset: auto;
  grid-column: 1;
  grid-row: 2;
  max-width: none;
  padding: 8px 16px;
  background: #f5f7f1;
  border-bottom: 1px solid #dce2d9;
  align-items: center;
}
.map-stage > .map-canvas {
  position: relative;
  inset: auto;
  grid-column: 1;
  grid-row: 3;
  width: 100%;
  height: 100%;
  min-height: 200px;
}
.map-pane .maplibregl-ctrl-top-right {
  top: 8px;
  right: 8px;
}
.map-pane .maplibregl-ctrl button {
  width: 44px;
  height: 44px;
}
.customer-insights,
.stats-pane {
  min-width: 0;
}
.customer-detail h2,
.customer-detail dd {
  overflow-wrap: anywhere;
}
@container (max-width: 650px) {
  .map-toolbar {
    grid-template-columns: minmax(0, 1fr) auto;
  }
  .map-context,
  .map-metric {
    grid-column: 1 / -1;
  }
  .map-metric select {
    width: 100%;
  }
  .map-metric {
    display: flex;
  }
  .map-metric select {
    flex: 1;
  }
  .map-toolbar .analysis-trigger {
    order: 0;
  }
}
@media (max-width: 1200px) {
  .app-shell {
    padding: 0 max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  }
  .topbar {
    display: grid;
    grid-template-columns: 72px minmax(0, 1fr) auto;
    height: auto;
    min-height: 84px;
    gap: 10px;
    padding: 10px 0;
  }
  .brand {
    width: 72px;
    height: 62px;
  }
  .app-name {
    min-width: 0;
    font-size: 17px;
    white-space: normal;
  }
  .header-right {
    gap: 0;
    margin-left: 0;
    min-width: 0;
  }
  .icon-button {
    width: 44px;
    height: 44px;
    padding: 10px;
    flex-shrink: 0;
  }
  .module-nav {
    grid-column: 1 / -1;
    grid-row: 2;
    order: 0;
    min-width: 0;
    max-width: 100%;
    width: 100%;
    overflow-x: auto;
    margin: 0;
    gap: 3px;
  }
  .module-nav a {
    display: flex;
    align-items: center;
    min-height: 44px;
    flex-shrink: 0;
    padding: 10px 12px;
  }
  .intro-line {
    margin: 24px 0 20px;
    gap: 10px;
    flex-wrap: wrap;
  }
  .intro-line h1 {
    font-size: 25px;
  }
  .filters {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }
  .filters > label,
  .filters > .search {
    min-width: 0;
    width: auto;
    padding: 10px 12px;
  }
  .filters > .search {
    grid-column: 1 / -1;
  }
  .filters input,
  .filters select,
  .modal input,
  .modal select,
  .login input,
  .sales-tools input,
  .sales-tools select,
  .sales-tools textarea {
    font-size: 16px;
    min-width: 0;
    max-width: 100%;
  }
  .filters input,
  .filters select {
    min-height: 34px;
    width: 100%;
  }
  .filters .reset {
    min-height: 64px;
    justify-content: center;
  }
  .reset span {
    display: inline;
  }
  .breadcrumbs {
    min-width: 0;
    flex-wrap: wrap;
    gap: 5px;
  }
  .breadcrumbs button {
    min-height: 44px;
    white-space: normal;
    text-align: left;
  }
  .period-note {
    width: 100%;
    margin-left: 0;
  }
  .mobile-tabs {
    display: flex;
    position: sticky;
    top: 0;
    z-index: 6;
    background: #f5f7f1;
    border: 1px solid #dce2d9;
    margin-bottom: 0;
  }
  .mobile-tabs button {
    min-height: 48px;
    flex: 1;
    font-size: 14px;
    padding: 10px;
  }
  .workspace,
  .workspace.analysis-docked.mobile-map {
    display: block;
    height: auto;
    min-height: 0;
    max-height: none;
    overflow: visible;
  }
  .workspace .map-pane,
  .workspace .map-pane.analysis-open {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto;
    width: 100%;
    height: auto;
    overflow: visible;
  }
  .workspace .map-stage,
  .workspace .map-pane.analysis-open .map-stage {
    min-height: 0;
    height: auto;
    grid-template-rows: auto auto clamp(300px, 58svh, 580px);
  }
  .map-toolbar {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    padding: 12px;
  }
  .map-context {
    grid-column: 1 / -1;
  }
  .map-toolbar .map-metric {
    grid-column: 1;
    min-height: 44px;
    padding: 8px;
  }
  .map-metric select {
    width: 100%;
    font-size: 14px;
  }
  .map-toolbar .analysis-trigger {
    grid-column: 2;
    order: 0;
    min-height: 44px;
    font-size: 13px;
    padding: 10px;
  }
  .stats-toggle {
    display: none;
  }
  .map-location-controls {
    padding: 8px 12px;
    gap: 6px;
  }
  .map-location-controls button,
  .map-neighbors-toggle {
    min-height: 44px;
    font-size: 13px;
    padding: 8px 10px;
    white-space: normal;
  }
  .map-neighbors-toggle input {
    width: 20px;
    height: 20px;
  }
  .map-pane .customer-insights,
  .map-pane.analysis-open .customer-insights {
    height: auto;
    max-height: none;
    overflow: visible;
    width: 100%;
    border-left: 0;
    border-top: 1px solid #dce2d9;
    scroll-margin-top: 56px;
  }
  .customer-insights-head {
    padding: 16px;
  }
  .insight-close {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    margin: -4px;
  }
  .sales-tabs {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }
  .sales-tabs button,
  .sales-tools button,
  .insight-layer-toggle {
    min-height: 44px;
    font-size: 13px;
    white-space: normal;
  }
  .insight-layer-toggle span {
    white-space: normal;
    overflow-wrap: anywhere;
  }
  .insight-layer-list {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }
  .sales-filters,
  .sales-form {
    min-width: 0;
  }
  .sales-tools input,
  .sales-tools select {
    min-height: 44px;
  }
  .sales-form > label {
    min-width: 0;
  }
  .sales-actions {
    flex-wrap: wrap;
  }
  .sales-check {
    min-height: 44px;
  }
  .insight-row {
    min-height: 52px;
    grid-template-columns: 24px minmax(0, 1fr) auto 14px;
  }
  .insight-row > span {
    overflow-wrap: anywhere;
  }
  .workspace.mobile-map > .stats-pane {
    display: none;
  }
  .workspace.mobile-list .map-pane {
    display: none;
    position: relative;
    visibility: visible;
    pointer-events: auto;
    width: 100%;
    height: auto;
  }
  .workspace.mobile-list > .stats-pane,
  .workspace.stats-collapsed.mobile-list > .stats-pane {
    display: block;
    width: 100%;
    height: auto;
    max-height: none;
    overflow: visible;
    padding: 24px 16px;
  }
  .workspace,
  .stats-pane,
  .map-toolbar {
    scroll-margin-top: 56px;
  }
  .rank-list {
    margin: 0 -16px;
  }
  .rank-row,
  .customer-row {
    min-height: 52px;
    padding: 14px 16px;
  }
  .customer-row > span {
    min-width: 0;
    overflow-wrap: anywhere;
  }
  .customer-detail dl {
    min-width: 0;
  }
  .customer-detail section p,
  .customer-detail a {
    overflow-wrap: anywhere;
  }
  .back-button,
  .show-customers,
  .list-controls button,
  .pagination button {
    min-height: 44px;
  }
  .statusbar {
    flex-wrap: wrap;
    gap: 8px;
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }
  .statusbar > span {
    width: 100%;
  }
  .statusbar button {
    min-height: 44px;
    padding: 10px 8px;
    font-size: 12px;
  }
  .modal {
    position: fixed;
    top: calc(var(--oj-visual-top, 0px) + 12px);
    bottom: auto;
    margin: 0 auto;
    width: calc(100% - 24px);
    max-width: 610px;
    max-height: calc(var(--oj-visual-height, 100dvh) - 24px);
    padding: 20px;
    overscroll-behavior: contain;
  }
  .modal-head {
    position: sticky;
    top: -20px;
    background: #fbfcf8;
    padding: 8px 0;
    z-index: 2;
    align-items: flex-start;
  }
  .modal-head button {
    min-width: 44px;
    min-height: 44px;
    flex-shrink: 0;
  }
  .modal button {
    min-height: 44px;
  }
  .place-options {
    max-height: min(340px, calc(var(--oj-visual-height, 100dvh) * 0.5));
    overscroll-behavior: contain;
  }
  .customer-pin {
    min-width: 44px;
    min-height: 44px;
  }
}
@media (max-width: 600px) {
  .mode-badge {
    display: none;
  }
  .app-name {
    font-size: 15px;
  }
  .map-context strong {
    font-size: 21px;
  }
  .legend {
    left: 12px;
    bottom: 38px;
    width: 158px;
    font-size: 10px;
    padding: 10px;
    pointer-events: none;
  }
}
@media (max-width: 360px) {
  .topbar {
    grid-template-columns: 54px minmax(0, 1fr) auto;
    gap: 4px;
  }
  .brand {
    width: 54px;
    height: 54px;
  }
  .icon-button {
    width: 44px;
    padding: 10px;
  }
  .map-toolbar {
    gap: 6px;
    padding: 10px;
  }
  .map-toolbar .analysis-trigger {
    font-size: 12px;
    padding: 8px;
  }
  .insight-layer-list,
  .sales-filters {
    grid-template-columns: minmax(0, 1fr);
  }
}
/* Keep service errors readable without covering map controls or the legend. */
.map-stage > .map-error {
  position: relative;
  inset: auto;
  grid-column: 1;
  grid-row: 4;
  max-width: none;
  margin: 0;
  width: auto;
}
.map-stage:has(> .map-error) > .legend {
  bottom: 110px;
}
@media (max-width: 1200px) {
  .map-stage:has(> .map-error),
  .workspace .map-pane.analysis-open .map-stage:has(> .map-error) {
    grid-template-rows: auto auto clamp(300px, 58svh, 580px) auto;
  }
}
.map-stage {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  min-width: 0;
}
@media (max-width: 1200px) {
  .stats-pane button,
  .place-clear,
  .place-radius select {
    min-height: 44px;
  }
  .stats-pane select,
  .place-radius select {
    font-size: 16px;
    min-height: 44px;
    max-width: 100%;
  }
  .sales-tools .sales-check input {
    width: 20px;
    height: 20px;
    min-height: 20px;
    flex-shrink: 0;
  }
  .insight-map-pin {
    min-width: 44px;
    min-height: 44px;
  }
  .insight-row > span:not(.insight-alert) {
    white-space: normal;
    overflow-wrap: anywhere;
  }
  .product-list li span {
    white-space: normal;
    overflow-wrap: anywhere;
  }
  .place-options [role='option'] {
    min-height: 48px;
  }
  .place-navigation .place-status {
    flex-basis: 100%;
  }
  .place-radius {
    flex-wrap: wrap;
  }
  .modal label,
  .modal input,
  .modal select {
    max-width: 100%;
    min-width: 0;
  }
  .modal input,
  .modal select {
    min-height: 44px;
  }
}
