/* ==========================================================
   TERRAPORTAL – interfejs mobilny (telefony, np. iPhone)
   Układ "aplikacji": mapa na pełnym ekranie, pływający pasek
   projektu u góry, dolny pasek zakładek, a po dotknięciu zakładki
   wysuwa się szuflada z jej zawartością. Ładowany po style.css.
   ========================================================== */
.mobile-fab { display: none; }

@media (max-width: 768px) {
  .mobile-fab {
    position: fixed;
    right: 14px;
    bottom: calc(92px + env(safe-area-inset-bottom, 0px));
    z-index: 1012;
    width: 58px;
    height: 58px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #7c3aed, #6f42c1);
    color: #fff;
    font-size: 26px;
    line-height: 1;
    box-shadow: 0 8px 22px rgba(111, 66, 193, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .mobile-fab:active { transform: scale(0.94); }
  .mobile-fab .mobile-fab-plus {
    position: absolute;
    top: 6px;
    right: 8px;
    font-size: 18px;
    font-weight: 800;
    background: #10b981;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
  }
  .mobile-fab.cancel { background: #dc2626; box-shadow: 0 8px 22px rgba(220, 38, 38, 0.5); font-size: 24px; }
  .mobile-fab.cancel .mobile-fab-plus { display: none; }
  .mobile-fab.fab-hidden { display: none; }
}

@media (max-width: 768px) {
  html, body {
    height: 100%;
    height: 100dvh;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior: none;
  }
  #map { touch-action: none; }

  /* iOS Safari przybliża stronę przy focusie na polach < 16px */
  input, select, textarea,
  .panel input, .panel select,
  .camera-panel input[type="text"], .camera-panel input[type="number"], .camera-panel select,
  .object-inspector input, .object-inspector select {
    font-size: 16px !important;
  }

  /* ---------- KONTENER PANELU = dolna nawigacja + szuflada ---------- */
  .panel {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-height: none;
    padding: 0;
    margin: 0;
    background: transparent;
    border: none;
    box-shadow: none;
    border-radius: 0;
    overflow: visible;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    pointer-events: none;           /* klikalne są tylko dzieci */
    z-index: 1000;
  }
  .panel > * { pointer-events: auto; }
  .panel.mobile-hidden { display: none !important; }

  /* Nagłówek, konsola diagnostyczna – niepotrzebne na telefonie */
  .panel-header,
  .debug-drawer { display: none !important; }

  /* ---------- PASEK PROJEKTU: pływająca pigułka u góry ---------- */
  .project-quickbar {
    position: fixed;
    top: calc(10px + env(safe-area-inset-top, 0px));
    left: 10px;
    right: 10px;
    z-index: 1010;
    margin: 0;
    padding: 6px 8px 6px 12px;
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid rgba(226, 232, 240, 0.9);
    border-radius: 16px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
  }
  .project-quick-label { display: none; }
  .project-quick-name {
    font-size: 14px;
    font-weight: 700;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .project-quick-actions { display: none; }

  /* ---------- DOLNY PASEK ZAKŁADEK ---------- */
  .panel-tabs {
    order: 3;
    margin: 0;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
    gap: 4px;
    border-radius: 0;
    background: #ffffff;
    border-top: 1px solid #e2e8f0;
    box-shadow: 0 -4px 18px rgba(0, 0, 0, 0.12);
  }
  .panel-tab {
    flex-direction: column;
    gap: 2px;
    min-height: 52px;
    padding: 6px 2px;
    font-size: 11px;
    line-height: 1.1;
    border-radius: 12px;
    color: #64748b;
    background: transparent;
    box-shadow: none;
  }
  .panel-tab > span { font-size: 22px; line-height: 1; }
  /* Aktywna zakładka podświetlona tylko, gdy szuflada jest otwarta */
  .panel.sheet-open .panel-tab.active {
    background: #e0f2fe;
    color: #0284c7;
  }
  .panel:not(.sheet-open) .panel-tab.active {
    background: transparent;
    color: #64748b;
    box-shadow: none;
  }

  /* ---------- SZUFLADA Z ZAWARTOŚCIĄ ZAKŁADKI ---------- */
  .panel-tab-content {
    order: 1;
    background: #ffffff;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -10px 34px rgba(0, 0, 0, 0.28);
    padding: 22px 14px 14px;
    max-height: 52vh;
    max-height: 52dvh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    position: relative;
    flex: 0 1 auto;
    animation: sheetUp 0.22s ease-out;
  }
  .panel-tab-content::before {      /* uchwyt szuflady */
    content: '';
    position: absolute;
    top: 8px;
    left: 50%;
    width: 40px;
    height: 4px;
    margin-left: -20px;
    border-radius: 2px;
    background: #cbd5e1;
  }
  .panel:not(.sheet-open) .panel-tab-content { display: none !important; }
  @keyframes sheetUp {
    from { transform: translateY(24px); opacity: 0; }
    to   { transform: translateY(0); opacity: 1; }
  }

  .panel button { min-height: 36px; }
  .panel .btn-tool-action, .panel .btn-project-main, .panel .btn-project-secondary, .panel select,
  .panel input:not([type="checkbox"]):not([type="radio"]):not([type="range"]) {
    min-height: 44px;
  }
  .panel input[type="checkbox"], .panel input[type="radio"] { width: 20px; height: 20px; min-height: 0; flex-shrink: 0; }

  /* ---------- KARTY WARSTW: dwa wiersze zamiast ściśniętego jednego ---------- */
  .layer-card-head { flex-wrap: wrap; gap: 6px 8px; padding: 10px; align-items: center; }
  .layer-card-title {
    flex: 1 1 130px;
    min-width: 0;
    font-size: 14px;
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    word-break: break-word;
  }
  .layer-collapse-btn { padding: 8px 6px; font-size: 14px; }
  .layer-card-head .tag-type { font-size: 11px; padding: 5px 9px; }
  .layer-card-head .tag-obstacle {
    font-size: 14px;
    min-width: 36px;
    min-height: 36px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .layer-card-head .btn-lock-layer {
    min-width: 36px;
    min-height: 36px;
    padding: 0;
    font-size: 17px !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .layer-card-head .btn-draw-action {
    min-width: 36px;
    min-height: 36px;
    padding: 0 8px;
    font-size: 15px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .layer-card-head .btn-clear-layer, .layer-card-head .btn-del-layer {
    min-width: 36px;
    min-height: 36px;
    padding: 0;
    font-size: 17px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .object-picker-menu {
    max-width: calc(100vw - 20px);
    border-radius: 14px;
  }
  .layer-obj-row { padding: 6px 8px; min-height: 44px; }
  .obj-title { font-size: 14px; }
  .obj-left > span, .obj-right > span { padding: 8px 8px !important; font-size: 16px !important; }
  .obj-right { gap: 0; }
  .obj-filter-box input { min-height: 44px; }
  .situational-toolbar button { min-height: 44px; }

  /* ---------- KOMUNIKAT JAKO "TOAST" NAD PASKIEM ---------- */
  .info {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(84px + env(safe-area-inset-bottom, 0px));
    z-index: 1015;
    margin: 0;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 13px;
    max-height: none;
    background: rgba(15, 23, 42, 0.92);
    color: #fff;
    border: none;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    opacity: 0;
    pointer-events: none;
    transform: translateY(8px);
    transition: opacity 0.2s, transform 0.2s;
  }
  .info.toast-show { opacity: 1; transform: translateY(0); }
  .info .success { color: #86efac; }
  .info .error { color: #fca5a5; }

  /* ---------- PRZYCISKI MAPY ---------- */
  /* Zoom przyciskami zbędny - mapa obsługuje gest szczypania */
  .ol-zoom, .ol-scale-line, .ol-attribution { display: none !important; }

  /* ---------- PANELE KAMERY / OBIEKTU: szuflada nad ekranem ---------- */
  .camera-panel, .object-inspector {
    left: 0;
    right: 0;
    top: auto;
    bottom: 0;
    width: 100%;
    max-height: 46vh;
    max-height: 46dvh;
    padding: 0 14px calc(14px + env(safe-area-inset-bottom, 0px));
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -10px 34px rgba(0, 0, 0, 0.3);
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    font-size: 13px;
  }
  .camera-panel-header, .inspector-header { padding-top: 18px; min-height: 40px; }
  .camera-panel-header h4 { font-size: 15px; }
  .close-cam-btn { font-size: 22px; min-width: 40px; min-height: 40px; display: inline-flex; align-items: center; justify-content: center; }
  .camera-panel label { font-size: 12px; }
  .val-badge { font-size: 12px; padding: 2px 8px; }
  .camera-panel input[type="range"] { height: 34px; margin: 4px 0; touch-action: pan-y; }
  .camera-panel input[type="range"]::-webkit-slider-thumb { width: 26px; height: 26px; }
  .cam-action-btn, .btn-sub { min-height: 44px; }
  .cam-action-btn { font-size: 14px !important; border-radius: 10px !important; }
  .btn-sub { font-size: 12px !important; }
  .cam-prefix-chips { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 2px; }
  .cam-prefix-chip { padding: 6px 12px; font-size: 13px; display: inline-flex; align-items: center; min-height: 38px; flex: 0 0 auto; }

  /* ---------- TRYB RYSOWANIA ---------- */
  .drawing-hud {
    top: auto;
    bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    width: calc(100% - 20px);
  }
  .hud-btn, .hud-select, .hud-name-input { min-height: 40px; font-size: 14px; }

  /* ---------- PODGLĄD ZDJĘCIA PRZY KAMERZE ---------- */
  .map-hover-tooltip.has-photo { max-width: 90vw; }
  .cam-photo-view { width: min(280px, 80vw); height: min(210px, 60vw); }
  .cam-live-float { max-width: 70vw; }
  .cam-live-view { width: min(240px, 62vw) !important; height: min(180px, 46vw) !important; }
  .cam-live-view img { max-width: 100% !important; max-height: 100% !important; }
}
