/* ==========================================================================
   TOOL STAGE STYLES — POLIGON DYDAKTYCZNY
   ========================================================================== */

/* Wspólny kontener SVG i warstwa interakcji */

/* Narzędzie 1: Azymut w terenie (Panorama + Busola) */
.field-stage-stack {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.panorama-frame {
  height: clamp(104px, 18dvh, 172px);
  border-radius: var(--radius-md);
  border: 1px solid var(--map-frame-border);
  overflow: hidden;
  position: relative;
  background: linear-gradient(180deg, #86b3d2 0%, #c1d8e6 42%, #e4ece7 58%, #809a68 58.5%, #5b7546 100%);
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.panorama-frame.res-panorama-frame {
  height: clamp(136px, 25dvh, 218px);
}

.panorama-frame svg,
.panorama-frame svg *,
.compass-canvas-stage svg,
.compass-canvas-stage svg *,
.map-frame svg,
.map-frame svg * {
  user-select: none;
  -webkit-user-select: none;
}

[data-theme="dark"] .panorama-frame {
  background: linear-gradient(180deg, #040814 0%, #0b1628 58%, #09130b 58%, #050b06 100%);
}

.panorama-frame:active {
  cursor: grabbing;
}

.compass-canvas-stage {
  position: relative;
  width: 100%;
  padding: 0.2rem 0;
  background: var(--bg-stage);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
}

.compass-main-grid {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(min(250px, 100%), 1.15fr) minmax(min(210px, 100%), 0.85fr);
  gap: 1rem;
  align-items: center;
}

@media (max-width: 860px) {
  .compass-main-grid {
    grid-template-columns: 1fr;
  }
}

.compass-main-grid.zoom-collapsed {
  grid-template-columns: 1fr;
  justify-items: center;
}

.compass-svg-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
}

.compass-svg {
  width: 100%;
  max-width: min(480px, max(250px, calc((100dvh - 300px) * 1.19)));
  height: auto;
  touch-action: none;
}

.compass-main-grid.zoom-collapsed .compass-svg {
  max-width: min(600px, max(250px, calc((100dvh - 300px) * 1.19)));
}

.zoom-loupes-stack {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.zoom-card {
  background: var(--bg-surface-alt);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.zoom-card-header {
  padding: 0.42rem 0.7rem;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
}

.zoom-card.minimized .zoom-card-header {
  border-bottom: none;
}

.zoom-mini-btn {
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  width: 28px;
  height: 28px;
  display: inline-grid;
  place-items: center;
  font-size: 0.85rem;
  font-weight: 800;
  cursor: pointer;
  line-height: 1;
}

.zoom-mini-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.zoom-card-body {
  padding: 0.45rem;
  background: var(--bg-surface-alt);
}

.zoom-svg {
  width: 100%;
  height: auto;
  display: block;
}

@media (max-width: 780px) {
  .compass-main-grid {
    grid-template-columns: 1fr;
  }
}

.compass-drag-ring {
  cursor: grab;
}

.compass-drag-ring:active {
  cursor: grabbing;
}

.zoom-drag-ring {
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.zoom-drag-ring:active {
  cursor: grabbing;
}

.map-frame {
  background: var(--map-paper);
  border: 1px solid var(--map-frame-border);
  border-radius: var(--radius-md);
  box-shadow: var(--map-sheet-shadow);
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
}

.map-pinned-controls {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 8;
  display: inline-flex;
  align-items: center;
  gap: 0.26rem;
  padding: 0.22rem;
  background: var(--hud-bg);
  backdrop-filter: blur(6px);
  border: 1px solid var(--hud-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
}

.map-pinned-controls .cad-dock-btn {
  width: auto;
  min-width: 34px;
  height: 32px;
  padding: 0 0.46rem;
  gap: 0.22rem;
}

.map-pinned-controls .cad-dock-label {
  display: inline;
  font-size: 0.72rem;
  font-weight: 700;
}

.map-pinned-controls.is-orient-loupe-btn {
  top: auto;
  bottom: 10px;
  right: 10px;
}

.map-zoom-overlay {
  position: absolute;
  z-index: 6;
  width: clamp(204px, 36%, 262px);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--hud-border);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  backdrop-filter: blur(6px);
  overflow: hidden;
}

.map-zoom-overlay.is-top { top: 10px; }
.map-zoom-overlay.is-bottom { bottom: 10px; }
.map-zoom-overlay.is-left { left: 62px; }
.map-zoom-overlay.is-right { right: 10px; }

.map-zoom-overlay .zoom-card-header {
  padding: 0.28rem 0.48rem;
  font-size: 0.69rem;
  gap: 0.24rem;
  flex-wrap: nowrap;
  min-width: 0;
  background: var(--surface-muted);
  border-bottom: none;
}

.map-zoom-overlay .zoom-card-header > .settings-row-icon-label {
  flex: 1 1 0;
  min-width: 0;
  overflow: hidden;
}

.map-zoom-overlay .zoom-card-header > .settings-row-icon-label > span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.map-zoom-overlay .micro-nudge-group {
  flex-shrink: 0;
  gap: 0.2rem;
}

.map-zoom-overlay .micro-nudge-btn {
  min-width: 28px;
  min-height: 26px;
  height: 26px;
  padding: 0 0.28rem;
  font-size: 0.7rem;
  border: none;
  background: var(--bg-surface);
  box-shadow: var(--shadow-sm);
}

.map-zoom-overlay .zoom-mini-btn {
  min-width: 26px !important;
  min-height: 26px !important;
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  border: none;
  background: var(--surface-key-fn);
}

.map-zoom-overlay .zoom-card-body {
  padding: 0.28rem;
  background: var(--bg-surface);
}

.map-svg {
  display: block;
  width: 100%;
  max-width: 100%;
  flex: 1 1 auto;
  height: auto;
  margin: 0 auto;
  touch-action: none;
}

.map-cad-dock,
.stage-canvas-dock {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 7;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.28rem;
  padding: 0.34rem 0.28rem;
  background: var(--hud-bg);
  backdrop-filter: blur(6px);
  border: 1px solid var(--hud-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
}

.stage-canvas-dock {
  left: 4px;
  top: 10px;
  transform: none;
}

html.projector-mode .map-cad-dock,
html.projector-mode .stage-canvas-dock {
  background: var(--bg-surface);
  backdrop-filter: none;
  box-shadow: none;
}

.cad-dock-sep {
  width: 22px;
  height: 1px;
  background: var(--border-subtle);
  margin: 0.08rem 0;
}

.cad-dock-btn {
  position: relative;
  width: 34px;
  height: 34px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-primary);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  transition: background var(--transition-fast), border-color var(--transition-fast), transform var(--transition-fast);
}

.cad-dock-btn:hover {
  background: var(--surface-muted);
  border-color: transparent;
}

.cad-dock-btn.active {
  background: var(--accent-amber-soft);
  border-color: rgba(180, 83, 9, 0.42);
  color: var(--accent-amber);
  box-shadow: none;
}

.cad-dock-label {
  display: none;
}

.cad-dock-label.cad-dock-label-always {
  display: inline;
  font-size: 0.73rem;
  font-weight: 700;
  margin-left: 0.28rem;
  white-space: nowrap;
}

.cad-dock-btn.is-pill-btn {
  width: auto;
  padding: 0 0.52rem;
}

.orient-stage-frame {
  background: var(--bg-stage);
}

.cad-dock-badge {
  position: absolute;
  right: 1px;
  bottom: 1px;
  padding: 0 3px;
  border-radius: 4px;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  font-size: 0.56rem;
  font-weight: 800;
  font-family: var(--font-mono);
  line-height: 1.2;
  color: var(--text-primary);
  pointer-events: none;
}

.map-feedback-backdrop {
  position: absolute;
  inset: 0;
  z-index: 12;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(15, 23, 42, 0.28);
  backdrop-filter: blur(2px);
}

.map-feedback-modal {
  width: min(420px, 94%);
  max-height: calc(100dvh - 1.5rem);
  background: var(--bg-surface);
  border: 2px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.28);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.map-feedback-modal.is-success { border-color: var(--accent-green); }
.map-feedback-modal.is-danger { border-color: var(--accent-red); }
.map-feedback-modal.is-warn { border-color: var(--accent-amber); }
.map-feedback-modal.is-info { border-color: var(--accent-blue); }

.map-feedback-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.55rem 0.85rem;
  font-size: 0.86rem;
  font-weight: 800;
  color: var(--text-primary);
  background: var(--bg-surface-alt);
  border-bottom: 1px solid var(--border-subtle);
}

.map-feedback-modal.is-success .map-feedback-header { background: var(--accent-green-soft); color: var(--accent-green); }
.map-feedback-modal.is-danger .map-feedback-header { background: var(--accent-red-soft); color: var(--accent-red); }
.map-feedback-modal.is-warn .map-feedback-header { background: var(--accent-amber-soft); color: var(--accent-amber); }
.map-feedback-modal.is-info .map-feedback-header { background: var(--accent-blue-soft); color: var(--accent-blue); }

.map-feedback-body {
  padding: 0.85rem 0.95rem;
  font-size: 0.9rem;
  line-height: 1.48;
  color: var(--text-primary);
}

.map-feedback-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.65rem 0.85rem;
  background: var(--bg-surface-alt);
  border-top: 1px solid var(--border-subtle);
}

.map-legend-strip {
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
  padding: 0.5rem 0.72rem;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  font-size: 0.76rem;
  line-height: 1.42;
  color: var(--text-secondary);
}

.legend-item {
  display: block;
}

/* Narzędzie 4: Parokroki i koraliki marszowe */

/* Tabela przeliczeń parokroków */

.chip-btn {
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface-alt);
  color: var(--text-secondary);
  border-radius: var(--radius-pill);
  padding: 0.28rem 0.68rem;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.chip-btn:hover {
  border-color: var(--accent-primary);
  color: var(--text-primary);
}

.chip-btn.active {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: #ffffff;
}

/* Wspólna ramka mapowa dla wszystkich narzędzi kartograficznych */
.map-frame {
  background: var(--map-paper);
  border: 1px solid var(--map-frame-border);
  border-radius: var(--radius-md);
  box-shadow: var(--map-sheet-shadow);
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  width: 100%;
}

#mgrs-topo-svg {
  width: 100%;
  max-width: 100%;
  flex: 1 1 auto;
}

/* Na telefonach i małych tabletach dock przyborów zmienia się w czytelny, podpisany pasek pod mapą */
@media (max-width: 760px) {
  .stage-card,
  .stage-body {
    display: flex;
    flex-direction: column;
    flex: 1 1 0;
    min-height: 0;
  }

  .stage-body > div:not(.terrain-feedback-sheet):not(.dist-calc-bar):not(.res-guided-cta-bar):not(.map-feedback-backdrop):not(.terrain-ex-wrap) {
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    width: 100%;
  }

  .field-stage-stack {
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
  }

  .compass-canvas-stage {
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    overflow: hidden;
  }

  .compass-main-grid {
    flex: 1 1 0;
    min-height: 0;
    width: 100%;
    height: 100%;
    align-items: center;
  }

  .compass-svg-wrap {
    width: 100%;
    height: 100%;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .compass-main-grid.zoom-collapsed .compass-svg,
  .compass-svg {
    max-height: 100%;
    max-width: 100%;
    width: auto;
    height: auto;
  }

  .map-frame {
    flex: 1 1 0;
    min-height: 0 !important;
    height: 100%;
    justify-content: center;
    overflow: hidden;
  }

  .map-frame > svg {
    flex: 1 1 0;
    min-height: 0;
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
  }

  #geo-desk-wrap {
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
  }

  .map-cad-dock {
    position: static;
    transform: none;
    left: auto;
    top: auto;
    width: 100%;
    flex-shrink: 0;
    flex-direction: row;
    justify-content: flex-start;
    overflow-x: auto;
    scrollbar-width: none;
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
    border-top: 1.5px solid var(--border-strong);
    padding: 0.34rem 1.4rem 0.34rem 0.45rem;
    gap: 0.3rem;
    box-shadow: inset -22px 0 16px -14px rgba(15, 23, 42, 0.35);
    -webkit-mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 22px), rgba(0, 0, 0, 0.38) 100%);
    mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 22px), rgba(0, 0, 0, 0.38) 100%);
  }

  .map-cad-dock::-webkit-scrollbar {
    display: none;
  }

  .cad-dock-btn {
    width: auto;
    min-width: 40px;
    height: 36px;
    padding: 0 0.48rem;
    gap: 0.24rem;
    flex-shrink: 0;
  }

  .cad-dock-label {
    display: inline;
    font-size: 0.72rem;
    font-weight: 700;
    white-space: nowrap;
    letter-spacing: -0.01em;
  }

  .cad-dock-sep {
    width: 1px;
    height: 22px;
    margin: 0 0.06rem;
    flex-shrink: 0;
  }

  /* Pływająca lupa skali w przeciwległym narożniku mapy — nigdy nie ucina przycisku zamykania */
  .map-zoom-overlay {
    position: absolute;
    width: clamp(192px, 60%, 248px) !important;
    max-width: calc(100% - 12px);
    z-index: 8;
    border-radius: var(--radius-sm);
    border: 1.5px solid var(--border-strong);
    box-shadow: var(--shadow-md);
  }

  .map-zoom-overlay.is-top {
    top: 44px;
    bottom: auto;
  }

  .map-zoom-overlay.is-top.is-left {
    top: 6px;
  }

  .map-zoom-overlay.is-bottom {
    bottom: 48px;
    top: auto;
  }

  .map-zoom-overlay.is-left {
    left: 6px;
    right: auto;
  }

  .map-zoom-overlay.is-right {
    right: 6px;
    left: auto;
  }

  .map-zoom-overlay .zoom-card-header {
    padding: 0.22rem 0.38rem;
    font-size: 0.67rem;
  }
}

/* Responsywna otoczka na tabele i kontrolki */

/* Style wspólne dla nowych narzędzi (Tysięczna, Poziomice 3D, TCCC, Balistyka, Tarcza, Zacięcia) */
.tool-subpanel {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.85rem 0.95rem;
}

.action-seq-btn {
  border: 1.5px solid var(--border-strong);
  background: var(--bg-surface);
  color: var(--text-primary);
  border-radius: var(--radius-md);
  padding: 0.65rem 0.75rem;
  min-height: 48px;
  text-align: left;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.18rem;
  transition: transform var(--transition-fast), border-color var(--transition-fast), background var(--transition-fast);
}

.action-seq-btn:hover {
  border-color: var(--accent-primary);
  background: var(--bg-hover);
}

.action-seq-btn.is-done {
  border-color: var(--accent-green);
  background: var(--accent-green-soft);
}

.action-seq-btn.is-error {
  border-color: var(--accent-red);
  background: var(--accent-red-soft);
}

.canvas-responsive-box {
  width: 100%;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  overflow: hidden;
  position: relative;
}

.canvas-responsive-box canvas,
.canvas-responsive-box svg {
  display: block;
  width: 100%;
  max-width: min(100%, max(260px, calc((100dvh - 290px) * 1.38)));
  height: auto;
  margin: 0 auto;
  touch-action: manipulation;
}

@media (max-width: 768px) {
  .field-stage-stack {
    gap: 0.32rem;
    flex: 1 1 0;
    min-height: 0;
  }

  .panorama-frame {
    height: clamp(104px, 19dvh, 165px);
    flex-shrink: 0;
  }

  .compass-canvas-stage {
    padding: 0;
    flex: 1 1 0;
    min-height: 0;
  }

  .compass-main-grid.zoom-collapsed .compass-svg,
  .compass-svg {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
  }

  .stage-canvas-dock {
    position: absolute;
    top: 8px;
    right: 8px;
    left: auto;
    transform: none;
    flex-direction: row;
    border: 1px solid rgba(15, 23, 42, 0.14);
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(4px);
    padding: 0.2rem;
    margin: 0;
    width: auto;
    z-index: 6;
    box-shadow: var(--shadow-sm);
  }
}

@media (pointer: coarse) {
  .cad-dock-btn {
    min-width: 38px;
    min-height: 38px;
  }
}

/* Kalkulator odcinków i przeliczeń skali w NAV-03 (miękkie powierzchnie bez zagnieżdżonych szarych ramek) */
.dist-calc-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem 0.6rem;
  padding: 0.48rem 0.68rem;
  margin-bottom: 0.42rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  font-size: 0.8rem;
}

.dist-calc-head {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  width: 100%;
}

.dist-calc-close {
  margin-left: auto;
  width: 26px !important;
  height: 26px !important;
  min-width: 26px !important;
  min-height: 26px !important;
  font-size: 0.88rem;
  flex-shrink: 0;
  border: none !important;
  background: var(--surface-key-fn) !important;
}

.dist-calc-tabs {
  display: inline-flex;
  background: var(--surface-muted);
  border: none;
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
}

.dist-calc-tab {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.2rem 0.48rem;
  border-radius: calc(var(--radius-sm) - 2px);
  cursor: pointer;
  line-height: 1.2;
}

.dist-calc-tab.active {
  background: var(--accent-primary);
  color: #ffffff;
}

.dist-calc-segs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.28rem;
  flex: 1 1 auto;
}

.dist-calc-seg-wrap {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
}

.dist-calc-seg-lbl {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.dist-calc-seg-input {
  width: 62px !important;
  height: 28px !important;
  padding: 0.15rem 0.35rem !important;
  font-size: 0.8rem !important;
  font-family: var(--font-mono);
  text-align: center;
  border: none !important;
  background: var(--surface-muted) !important;
}

.dist-calc-plus {
  font-weight: 800;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.dist-calc-expr-wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem;
  flex: 1 1 auto;
}

.dist-calc-expr-input {
  width: 190px !important;
  max-width: 100%;
  height: 28px !important;
  padding: 0.15rem 0.45rem !important;
  font-size: 0.82rem !important;
  font-family: var(--font-mono);
  border: none !important;
  background: var(--surface-muted) !important;
}

.dist-calc-ops {
  display: inline-flex;
  align-items: center;
  gap: 0.22rem;
}

.dist-calc-op-btn {
  border: none;
  background: var(--surface-key-fn);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  min-width: 26px;
  height: 26px;
  padding: 0 0.38rem;
  font-family: var(--font-mono);
  font-size: 0.76rem;
  font-weight: 800;
  cursor: pointer;
}

.dist-calc-op-btn:hover {
  background: var(--bg-hover);
}

.dist-calc-res {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-left: auto;
  font-family: var(--font-mono);
}

.dist-calc-badge {
  background: var(--surface-muted);
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.2rem 0.52rem;
  font-size: 0.78rem;
  color: var(--text-primary);
}

.dist-calc-badge.is-ready {
  background: var(--accent-amber-soft);
  color: var(--accent-amber);
}

@media (max-width: 640px) {
  .dist-calc-res {
    margin-left: 0;
    width: 100%;
    justify-content: space-between;
  }
}

/* Dopasowanie wysokości scen narzędzi na mniejszych ekranach (bez przewijania) */
@media (max-height: 860px) and (min-width: 761px) {
  .field-stage-stack {
    gap: 0.45rem;
  }

  .map-legend-strip {
    margin-top: 0.25rem !important;
    padding: 0.3rem 0.55rem;
    font-size: 0.72rem;
  }

  .map-cad-dock {
    max-height: calc(100% - 10px);
    overflow-y: auto;
    gap: 0.2rem;
    padding: 0.24rem 0.24rem;
  }

  .map-frame > svg,
#orient-desk-svg {
    max-width: min(100%, max(320px, calc((100dvh - 235px) * 1.42)));
    margin: 0 auto;
  }

  
}

/* ==========================================================================
   RESPONSYWNOŚĆ NARZĘDZI TOPOGRAFICZNYCH (PION DOMYŚLNY + POZIOM OPCJONALNY)
   ========================================================================== */

.landscape-stage-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.45rem 0.75rem;
  margin-bottom: 0.45rem;
  background: var(--accent-primary-soft);
  border: 1px solid rgba(47, 93, 58, 0.32);
  border-radius: var(--radius-md);
  font-size: 0.79rem;
  color: var(--text-primary);
}

html.mobile-landscape-stage .topbar,
html.mobile-landscape-stage .guest-qr-promo-bar,
html.mobile-landscape-stage .tool-header-card {
  display: none !important;
}

html.mobile-landscape-stage .main-content {
  padding: 0.35rem 0.45rem 0.6rem !important;
  max-width: 100% !important;
}

/* Gdy telefon jest obrócony poziomo (landscape), dopasowujemy przyrząd w głównej kolumnie bez zasłaniania i przewijania */
@media (max-height: 560px) and (orientation: landscape) {
  .field-stage-stack {
    gap: 0.3rem;
  }

  .panorama-frame {
    height: clamp(76px, 24dvh, 114px);
  }

  .panorama-frame.res-panorama-frame {
    height: clamp(102px, 31dvh, 148px);
  }

  .compass-canvas-stage {
    padding: 0;
  }

  .compass-main-grid,
  .compass-main-grid.zoom-collapsed {
    gap: 0.45rem;
  }

  .compass-svg,
  .compass-main-grid.zoom-collapsed .compass-svg {
    max-height: calc(100dvh - 172px);
    width: auto;
    max-width: 100%;
  }

  .stage-canvas-dock {
    position: absolute;
    top: 6px;
    right: 6px;
    left: auto;
    transform: none;
    flex-direction: row;
    padding: 0.16rem;
    background: rgba(255, 255, 255, 0.9);
    z-index: 6;
  }

  .stage-body > div:not(.terrain-feedback-sheet):not(.dist-calc-bar):not(.res-guided-cta-bar):not(.map-feedback-backdrop):not(.terrain-ex-wrap) {
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    width: 100%;
  }

  .map-frame {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: center;
    flex: 1 1 0;
    min-height: 0 !important;
    height: 100%;
    overflow: hidden;
  }

  .map-frame > svg,
  #orient-desk-svg,
  #mgrs-topo-svg,
  #map-az-svg,
  #map-dist-svg,
  #res-map-svg {
    flex: 1 1 0;
    min-height: 0 !important;
    max-height: 100% !important;
    width: 100% !important;
    max-width: 100% !important;
    height: 100% !important;
    margin: 0 auto;
  }

  .map-cad-dock {
    position: absolute;
    left: 6px;
    top: 50%;
    transform: translateY(-50%);
    width: auto;
    flex-direction: column;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-strong);
    padding: 0.2rem;
    gap: 0.22rem;
    box-shadow: var(--shadow-sm);
    max-height: calc(100% - 12px);
    overflow-y: auto;
    -webkit-mask-image: none;
    mask-image: none;
  }

  .map-pinned-controls {
    top: 6px;
    right: 6px;
    padding: 0.16rem;
    gap: 0.18rem;
  }

  .map-pinned-controls .cad-dock-btn {
    min-width: 30px;
    height: 30px;
    padding: 0 0.36rem;
  }

  .map-pinned-controls .cad-dock-label {
    display: none;
  }

  .cad-dock-btn {
    min-width: 34px;
    min-height: 34px;
    width: 34px;
    height: 34px;
    padding: 0;
    font-size: 0.9rem;
  }

  .cad-dock-label:not(.cad-dock-label-always) {
    display: none;
  }

  .cad-dock-sep {
    width: 20px;
    height: 1px;
    margin: 0.08rem auto;
  }

  .map-legend-strip {
    padding: 0.3rem 0.5rem;
    font-size: 0.7rem;
    line-height: 1.3;
  }

  #cnt-3d-canvas,
  #cnt-ex-fpv-canvas,
  #cnt-ex-3d-canvas {
    max-height: calc(100dvh - 140px);
    width: auto;
    max-width: 100%;
    margin: 0 auto;
    display: block;
  }

  .terrain-options-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.4rem;
    margin-top: 0.4rem;
  }

  .terrain-option-card {
    padding: 0.3rem;
  }
}

/* ==========================================================================
   OCHRONA GESTÓW DOTYKOWYCH (TELEFONY + TABLETY) I SIATKI POZIOMIC / TABLETU
   ========================================================================== */

#map-az-svg,
#map-dist-svg,
#mgrs-topo-svg,
#orient-desk-svg,
#cnt-3d-canvas,
#cnt-ex-3d-canvas {
  touch-action: none;
}

.terrain-fpv-box {
  max-width: 580px;
  margin: 0 auto;
}

.terrain-split-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr));
  gap: 0.75rem;
  align-items: start;
}

.terrain-ex-wrap {
  display: flex;
  flex-direction: column;
  width: 100%;
}

.terrain-meta-caption {
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--hud-text);
  text-align: center;
  padding: 0.2rem 0.68rem;
  background: var(--hud-bg);
  border: 1px solid var(--hud-border);
  border-radius: var(--radius-pill);
  align-self: center;
  margin: 0.35rem auto 0.18rem;
}

.terrain-options-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.65rem;
  margin-top: 0.45rem;
}

.terrain-options-grid.is-profile-list {
  grid-template-columns: 1fr;
  gap: 0.48rem;
}

.terrain-option-card {
  padding: 0.45rem;
  flex-direction: column;
  align-items: stretch;
  width: 100%;
}

.terrain-option-label {
  margin-bottom: 0.25rem;
  font-weight: 800;
}

@media (max-width: 639px) and (orientation: portrait) {
  .terrain-options-grid.is-map-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.45rem;
    margin-top: 0.32rem;
  }

  .terrain-options-grid.is-map-grid > .terrain-option-card:nth-child(3):last-child {
    grid-column: 1 / -1;
    width: min(56%, 225px);
    justify-self: center;
  }

  .terrain-options-grid.is-profile-list {
    grid-template-columns: 1fr !important;
    gap: 0.42rem;
    margin-top: 0.36rem;
  }

  .terrain-option-card {
    padding: 0.34rem;
  }

  .terrain-option-label {
    font-size: 0.78rem;
    margin-bottom: 0.18rem;
  }
}

/* Tablet poziomy i średnie ekrany dotykowe (769–1180px × <=860px) — mapy mieszczą się bez scrollowania */
@media (min-width: 769px) and (max-width: 1180px) and (max-height: 860px) {
  .map-frame > svg,
  #orient-desk-svg,
  #mgrs-topo-svg,
  #map-az-svg,
  #map-dist-svg {
    max-height: calc(100dvh - 205px);
    width: auto;
    max-width: 100%;
    height: auto;
    margin: 0 auto;
  }

  .compass-svg,
  .compass-main-grid.zoom-collapsed .compass-svg {
    max-height: calc(100dvh - 310px);
    width: auto;
  }
}

/* Czytelniejsze pola notatnika wcinania wstecz na telefonach i tabletach */
@media (max-width: 768px) {
  .res-note-input {
    min-height: 36px;
    padding: 0.22rem 0.38rem;
  }

  .res-calc-btn {
    min-height: 36px;
    padding: 0.24rem 0.5rem;
  }
}

/* Wcinanie wstecz — spójny, przejrzysty pasek kroku i notatnika pomiarów */
.res-stage-switcher {
  display: inline-flex;
  align-items: center;
  background: var(--bg-surface-alt);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.14rem;
  gap: 0.14rem;
}

.res-stage-btn {
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.3rem 0.65rem;
  border-radius: calc(var(--radius-sm) - 2px);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
}

.res-stage-btn:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.res-stage-btn.active {
  background: var(--bg-surface);
  color: var(--text-primary);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
}

.res-guide-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem 0.65rem;
  padding: 0.38rem 0.58rem;
  margin-bottom: 0.45rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

.res-notes-group {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  align-items: center;
  gap: 0.36rem 0.55rem;
  flex: 1 1 auto;
  width: 100%;
}

.res-note-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: nowrap;
  gap: 0.32rem;
  padding: 0.24rem 0.48rem;
  background: var(--surface-muted);
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-primary);
}

.res-note-name {
  min-width: 58px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.res-note-fields {
  display: inline-flex;
  align-items: center;
  gap: 0.26rem;
  margin-left: auto;
  flex-shrink: 0;
}

.res-note-input {
  width: 68px;
  padding: 0.16rem 0.28rem;
  font-size: 0.8rem;
  font-weight: 800;
  font-family: var(--font-mono);
  text-align: center;
  color: var(--text-primary);
  border: 1px solid transparent;
  background: var(--bg-surface);
  box-shadow: var(--shadow-sm);
}

.res-note-input:placeholder-shown {
  font-weight: 600;
  color: var(--text-muted);
  border-color: transparent;
  background: var(--bg-surface);
  box-shadow: none;
}

.res-note-input:placeholder-shown::placeholder {
  color: var(--text-muted);
  opacity: 0.68;
}

.res-note-input.is-back,
.res-note-input.is-back:placeholder-shown {
  border-color: transparent;
  background: var(--bg-surface);
}

.res-note-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  color: #ffffff;
  font-size: 0.7rem;
  font-weight: 800;
  flex-shrink: 0;
}

.res-note-arrow {
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--text-muted);
}

.res-calc-btn {
  padding: 0.15rem 0.42rem;
  font-size: 0.74rem;
  font-weight: 800;
  font-family: var(--font-mono);
  border-radius: calc(var(--radius-sm) - 2px);
  border: none;
  background: var(--surface-key-fn);
  color: var(--text-secondary);
  cursor: pointer;
  line-height: 1.3;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.res-calc-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.res-back-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.16rem 0.46rem;
  border-radius: calc(var(--radius-sm) - 2px);
  background: var(--bg-surface);
  border: none;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 800;
  min-width: 52px;
  justify-content: center;
}

.res-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.24rem 0.55rem;
  border-radius: var(--radius-pill);
  font-size: 0.75rem;
  font-weight: 700;
  background: var(--bg-surface-alt);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  white-space: nowrap;
}

.res-status-pill.is-ready {
  background: var(--accent-primary-soft);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

/* ==========================================================================
   POZIOMICE 2D -> 3D: CZYSTE KARTY 1-KLIK + NIEBLOKUJĄCY PASEK WYNIKU
   ========================================================================== */
.terrain-option-card.is-correct {
  border: 2.5px solid #16a34a !important;
  background: rgba(22, 163, 74, 0.1) !important;
}

.terrain-option-card.is-wrong {
  border: 2.5px solid #dc2626 !important;
  background: rgba(220, 38, 38, 0.1) !important;
}

.terrain-feedback-sheet {
  position: sticky;
  bottom: 0;
  z-index: 30;
  margin-top: 0.5rem;
  padding: 0.52rem 0.72rem max(12px, env(safe-area-inset-bottom, 0px));
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 2px solid var(--border-strong);
  box-shadow: 0 -6px 20px rgba(15, 23, 42, 0.16);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.48rem;
}

.terrain-feedback-sheet.is-success {
  border-color: #16a34a;
  background: #f0fdf4;
}

.terrain-feedback-sheet.is-danger {
  border-color: #dc2626;
  background: #fef2f2;
}

.terrain-sheet-body {
  flex: 1 1 200px;
  font-size: 0.8rem;
  line-height: 1.38;
  color: var(--text-primary);
}

.terrain-sheet-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.42rem;
  flex-shrink: 0;
}

/* Wcinanie wstecz — notatnik pomiarów wewnątrz paska roboczego (w poziomie w prawej kolumnie) */
.res-guide-strip.is-in-toolbar {
  width: 100%;
  margin: 0 0 0.2rem;
  padding: 0;
  border: none;
  background: transparent;
}

@media (max-height: 560px) and (orientation: landscape) and (min-width: 560px), (min-width: 769px) and (max-width: 1200px) {
  .stage-sticky-dock .res-guide-strip.is-in-toolbar .res-notes-group {
    grid-template-columns: 1fr;
    gap: 0.24rem;
  }

  .stage-sticky-dock .res-note-chip {
    padding: 0.2rem 0.34rem;
    font-size: 0.73rem;
  }

  .stage-sticky-dock .res-note-input {
    width: 52px;
    min-height: 30px;
    font-size: 0.76rem !important;
  }

  .stage-sticky-dock .res-stage-switcher {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .stage-sticky-dock .res-stage-btn {
    padding: 0.26rem 0.35rem;
    font-size: 0.74rem;
    justify-content: center;
    display: inline-flex;
    align-items: center;
    gap: 0.24rem;
  }
}

/* Wcinanie wstecz — kompaktowy pojedynczy wiersz 2 kapsułek */
.res-capsule-head {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
  min-width: 0;
}

.res-capsule.is-empty {
  background: var(--surface-muted);
}

.res-capsule.is-filled {
  background: var(--surface-muted);
  box-shadow: inset 0 0 0 1px var(--border-subtle);
}

/* Edge-to-edge mapy, panorama i busola w telefonie (pion i poziom) */
@media (max-width: 768px) {
  .map-frame,
  .panorama-frame {
    border-left: none;
    border-right: none;
    border-radius: 0;
  }

  .res-guide-strip {
    border-left: none;
    border-right: none;
    border-radius: 0;
    margin-bottom: 0.25rem;
    padding: 0.28rem 0.42rem;
  }

  .res-notes-group {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.3rem;
  }

  .res-note-chip {
    padding: 0.18rem 0.32rem;
    font-size: 0.72rem;
  }

  .res-note-input {
    width: 50px;
    font-size: 0.76rem !important;
    min-height: 30px;
    padding: 0.12rem 0.2rem;
  }
}

@media (max-height: 560px) and (orientation: landscape) {
  .field-stage-stack {
    flex: 1 1 0;
    min-height: 0;
    height: 100%;
    gap: 0.25rem;
  }

  .panorama-frame {
    height: clamp(78px, 24dvh, 118px);
    flex-shrink: 0;
  }

  .compass-canvas-stage {
    width: 100%;
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    background: var(--bg-surface);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
    overflow: hidden;
  }

  .compass-main-grid,
  .compass-main-grid.zoom-collapsed {
    width: 100%;
    height: 100%;
    min-height: 0;
    justify-content: center;
  }

  .compass-svg-wrap {
    width: 100%;
    height: 100%;
    min-height: 0;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .compass-svg,
  .compass-main-grid.zoom-collapsed .compass-svg {
    max-height: 100%;
    max-width: 100%;
    width: auto;
    height: 100%;
  }
}
