/* Only loaded by origo-geoserver.html. */

/* The geoposition marker is an unstyled <img> placed directly in an OL overlay, so it
   inherits the generic ".o-ui img { max-width: 100%; height: auto }" reset from style.css.
   That reset resolves against the overlay's containing block on certain zoom/pan reflows,
   blowing the 22x22px marker up to fill the map. Pin it to its real size. */
.o-map img[src*="geolocation_marker"] {
  width: 22px !important;
  height: 22px !important;
  max-width: none !important;
}

/* fieldphoto.js: camera/upload UI injected into the editor form, and the resulting
   image injected into the feature-info popup. Sized responsively so the picture fits
   the viewer's screen instead of overflowing the popup or the edit form. */
.fieldphoto-url-input { display: none; }
.fieldphoto-preview {
  display: block;
  max-width: 100%;
  max-height: 40vh;
  height: auto;
  object-fit: contain;
  border-radius: 6px;
  margin: 6px 0;
}
.fieldphoto-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 6px 0;
}
.fieldphoto-button {
  flex: 1 1 auto;
  padding: 8px 12px;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: white;
  cursor: pointer;
}
.fieldphoto-button:disabled { opacity: 0.6; cursor: default; }
.fieldphoto-file-input { display: none; }
.fieldphoto-message { min-height: 1.2em; margin: 4px 0; font-size: 0.9em; }
.fieldphoto-message.fieldphoto-error { color: #b3261e; }
.fieldphoto-popup-image {
  display: block;
  width: 100%;
  max-height: 45vh;
  object-fit: contain;
  border-radius: 6px;
  margin-top: 8px;
}

@media (max-width: 767px), (max-width: 1000px) and (max-height: 500px) {
  :root, :root > body, #app-wrapper {
    width: 100%;
    height: 100%;
    height: 100dvh;
    overflow: hidden;
  }

  .o-map { overflow: clip; }
  .o-map .o-main { min-height: 0; }
  .o-map #o-tools-left {
    top: max(8px, env(safe-area-inset-top));
    left: max(8px, env(safe-area-inset-left));
    gap: 8px;
    max-height: calc(100% - var(--field-tools-height, 0px) - 72px);
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    padding: 2px;
  }
  .o-map #o-tools-left button,
  .o-map .o-main > button,
  .o-map .o-legend button,
  .o-map .field-draw-toolbar > button,
  .o-map #o-editor-toolbar button {
    min-width: 44px;
    min-height: 44px;
    box-sizing: border-box;
    flex-shrink: 0;
    /* Origo's own button CSS only centers the icon by matching padding to the
       default 40px size; once min-width/height grows it past that, the inline
       SVG icon drifts off-center. Force real centering regardless of size. */
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Both bars occupy the bottom dock; Origo selects the active tool. */
  .o-map .field-draw-panel,
  .o-map #o-tools-bottom {
    position: absolute;
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    bottom: 8px;
    width: auto;
    margin: 0;
    transform: none;
    z-index: 30;
  }
  .o-map .field-draw-toolbar,
  .o-map #o-editor-toolbar:not(.o-hidden) {
    position: relative;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    left: auto;
    bottom: auto;
    width: 100%;
    max-width: 100%;
    height: auto !important;
    margin: 0;
    padding: 8px;
    box-sizing: border-box;
    transform: none;
    border-radius: 12px;
    background: white;
    box-shadow: 0 2px 10px #0003;
  }
  .o-map #o-editor-toolbar > * { margin: 0; }
  .o-map #o-editor-toolbar-drawtools { float: none; }
  .o-map .field-draw-toolbar > button { position: static; }
  .o-map .field-draw-toolbar .o-popover,
  .o-map #o-editor-toolbar .o-popover {
    position: absolute;
    left: 50%;
    max-width: calc(100vw - 32px);
    max-height: 40dvh;
    overflow-y: auto;
  }
  .o-map #o-editor-toolbar .o-popover-container { position: static; }

  /* Leave the left-hand map controls and the entire bottom dock accessible. */
  .o-map .o-legend,
  .o-map .o-main > button.bottom-right {
    bottom: calc(var(--field-tools-height, 0px) + 16px);
    right: max(8px, env(safe-area-inset-right));
  }
  .o-map .o-legend { max-width: calc(100% - 72px); }
  .o-map .o-legend .item > .basis-50 {
    flex-basis: 0;
    min-width: 0;
  }
  .o-map .o-legend > .flex {
    min-width: 0 !important;
    max-width: 100%;
    max-height: min(55dvh, calc(100dvh - var(--field-tools-height, 0px) - 108px)) !important;
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  .o-map .ol-scale-line { bottom: calc(var(--field-tools-height, 0px) + 16px); }
  .o-map .o-draw-stylewindow {
    left: 64px;
    right: 8px;
    top: 64px;
    bottom: calc(var(--field-tools-height, 0px) + 48px);
    width: auto;
    height: auto;
    transform: none;
  }

  /* Origo hardcodes the feature-info popup to 270px, shrinking to 200px on small
     screens via its own breakpoint classes - too narrow once an attribute value
     is long. Let it use most of the screen width instead. */
  .o-map #o-popup,
  .o-map .o-popup {
    width: min(340px, calc(100vw - 32px)) !important;
    max-width: calc(100vw - 32px) !important;
    max-height: min(70vh, calc(100dvh - var(--field-tools-height, 0px) - 96px)) !important;
  }
  .o-map .o-popup .o-card-content {
    max-height: calc(min(70vh, calc(100dvh - var(--field-tools-height, 0px) - 96px)) - 46px) !important;
    overflow-wrap: anywhere;
  }

  .o-map .o-footer {
    flex-shrink: 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .o-map .o-footer-left { width: auto; }
  .o-map .o-footer-right { flex: 1; width: auto; }
  .o-map .o-modal {
    width: min(420px, calc(100vw - 24px));
    max-width: calc(100vw - 24px);
    max-height: calc(100dvh - 24px);
    overflow-y: auto;
  }
  .o-map .o-modal-content { max-height: calc(100dvh - 100px); }
  .o-map input, .o-map select, .o-map textarea,
  .fieldauth-card input { font-size: 16px; }
  .fieldauth-overlay { overflow-y: auto; padding: 12px; box-sizing: border-box; }
  .fieldauth-overlay .fieldauth-card {
    box-sizing: border-box;
    width: min(360px, 100%);
    max-height: 100%;
    overflow-y: auto;
    padding: 18px;
    font-family: Arial, sans-serif;
  }
  .fieldauth-card button, .fieldauth-card input { min-height: 44px; }
  .fieldphoto-button { min-height: 44px; }
  .fieldauth-actions { flex-wrap: wrap; }
  .o-map [data-tooltip] { display: none; }
}

@media (max-width: 1000px) and (max-height: 500px) {
  .o-map #o-tools-left { flex-direction: row; }
  .o-map .o-legend { max-width: calc(100% - 128px); }
}

