/* ==========================================================
   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 (z logo aplikacji) ---------- */
  .project-quickbar {
    position: fixed;
    top: calc(10px + env(safe-area-inset-top, 0px));
    left: 10px;
    right: 10px;
    z-index: 1010;
    margin: 0;
    padding: 6px 10px;
    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);
    display: flex;
    align-items: center;
    gap: 8px;
  }
  .mobile-project-brand {
    display: inline-flex !important;
    align-items: center;
    gap: 4px;
    padding: 3px 6px;
    border-radius: 8px;
    cursor: pointer;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    transition: background 0.15s, transform 0.1s;
  }
  .mobile-project-brand:active {
    background: rgba(2, 132, 199, 0.12);
    transform: scale(0.96);
  }
  .mobile-brand-title {
    font-family: 'Orbitron', 'Segoe UI', sans-serif;
    font-weight: 800;
    font-size: 13px;
    color: #0f172a;
    letter-spacing: 1px;
    text-transform: uppercase;
    line-height: 1;
    display: inline-flex;
    align-items: center;
  }
  .mobile-brand-title .brand-icon {
    font-size: 0.95em;
    margin: 0 1px;
  }
  .mobile-view-badge {
    font-size: 8px;
    padding: 1px 4px;
    margin-left: 2px;
  }
  .mobile-quickbar-divider {
    display: block !important;
    width: 1px;
    height: 18px;
    background: #cbd5e1;
    flex-shrink: 0;
    margin: 0 1px;
  }
  .project-quick-info {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    flex: 1;
    min-width: 0;
  }
  .project-quick-label { display: none; }
  .project-quick-name {
    font-size: 13px;
    font-weight: 700;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .project-quick-actions { display: none; }
  .project-actions-dropdown {
    top: calc(100% + 8px);
    border-radius: 12px;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.25);
    max-height: calc(100vh - 120px);
    overflow-y: auto;
  }

  /* ---------- 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;
  }
  /* ---------- OBIEKTY NA WARSTWACH: CZYSTY, PRZEJRZYSTY WIDOK MOBILNY ---------- */
  .desktop-actions {
    display: none !important;
  }
  .mobile-actions-trigger {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    min-width: 30px;
    min-height: 30px;
    padding: 0;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #ffffff;
    color: #64748b;
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 0.5px;
    cursor: pointer;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
  }
  .mobile-actions-trigger:active {
    background: #e0f2fe;
    border-color: #38bdf8;
    color: #0284c7;
  }
  .mobile-layer-hint {
    display: block !important;
    font-size: 11px;
    color: #64748b;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 6px 10px;
    margin: 6px 0 8px 0;
    line-height: 1.35;
  }
  .layer-obj-row {
    padding: 8px 10px;
    min-height: 44px;
    margin: 4px 0;
    border-radius: 10px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
    touch-action: pan-y;
    user-select: none;
    -webkit-user-select: none;
    transition: background-color 0.15s, border-color 0.15s;
  }
  .layer-obj-row:active {
    background: #f8fafc;
  }
  .layer-obj-row.actions-open {
    background: #f0fdf4 !important;
    border-color: #86efac !important;
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.12);
  }
  .layer-obj-row.is-selected {
    background: #e0f2fe !important;
    border-color: #38bdf8 !important;
    box-shadow: 0 0 0 1.5px rgba(2, 132, 199, 0.45);
  }
  .obj-main-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    gap: 8px;
  }
  .obj-left {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    min-width: 0;
    overflow: hidden;
  }
  .obj-left > .bulb-toggle {
    min-width: 28px;
    min-height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    cursor: pointer;
    flex-shrink: 0;
  }
  .obj-type-icon {
    font-size: 15px;
    flex-shrink: 0;
    line-height: 1;
  }
  .obj-title {
    flex: 1;
    min-width: 0;
    font-size: 14px !important;
    font-weight: 600;
    color: #0f172a;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
  }
  .obj-height-badge {
    font-size: 11px !important;
    padding: 2px 6px !important;
    border-radius: 6px;
    background: #e0f2fe;
    color: #0369a1;
    border: 1px solid #bae6fd;
    font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
  }
  .obj-status-indicator {
    display: inline-flex !important;
    font-size: 12px;
    line-height: 1;
    flex-shrink: 0;
  }
  .obj-photo-badge {
    font-size: 13px !important;
    flex-shrink: 0;
    cursor: pointer;
  }

  /* Pasek akcji wysuwany po przytrzymaniu palca na obiekcie lub kliknięciu ••• */
  .obj-actions-drawer {
    display: flex !important;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    padding: 8px 6px 2px;
    border-top: 1px solid rgba(226, 232, 240, 0.8);
    animation: drawerSlideDown 0.18s cubic-bezier(0.16, 1, 0.3, 1);
  }
  @keyframes drawerSlideDown {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: translateY(0); }
  }
  .btn-action-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-height: 38px;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 600;
    border-radius: 8px;
    border: 1px solid #cbd5e1;
    background: #ffffff;
    color: #334155;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: transform 0.1s, background 0.15s;
    flex: 1 1 auto;
  }
  .btn-action-pill:active {
    transform: scale(0.96);
  }
  .btn-action-pill.edit {
    background: #e0f2fe;
    border-color: #bae6fd;
    color: #0284c7;
  }
  .btn-action-pill.lock.is-locked {
    background: #fef3c7;
    border-color: #fde68a;
    color: #b45309;
  }
  .btn-action-pill.obstacle.is-obstacle {
    background: #fee2e2;
    border-color: #fecaca;
    color: #b91c1c;
  }
  .btn-action-pill.del {
    background: #fff1f2;
    border-color: #fecdd3;
    color: #e11d48;
  }
  .btn-action-pill.close {
    flex: 0 0 38px;
    padding: 0;
    font-size: 14px;
    background: #f1f5f9;
    color: #64748b;
  }
  .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, SKALA, ATRYBUCJA, GPS) ---------- */
  .ol-zoom {
    display: flex !important;
    flex-direction: column !important;
    top: auto !important;
    left: auto !important;
    right: 12px !important;
    bottom: calc(160px + env(safe-area-inset-bottom, 0px)) !important;
    z-index: 1010 !important;
    background: rgba(15, 23, 42, 0.85) !important;
    backdrop-filter: blur(8px) !important;
    -webkit-backdrop-filter: blur(8px) !important;
    border-radius: 8px !important;
    padding: 3px !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(255, 255, 255, 0.1) !important;
  }
  .ol-zoom button {
    width: 36px !important;
    height: 36px !important;
    line-height: 36px !important;
    font-size: 18px !important;
    background: #1e293b !important;
    color: #f8fafc !important;
  }

  /* Przycisk GPS umieszczony nad kontrolkami zoomu */
  .ol-gps-control {
    display: flex !important;
    top: auto !important;
    left: auto !important;
    right: 12px !important;
    bottom: calc(248px + env(safe-area-inset-bottom, 0px)) !important;
    z-index: 1011 !important;
    background: rgba(15, 23, 42, 0.85) !important;
    backdrop-filter: blur(8px) !important;
    -webkit-backdrop-filter: blur(8px) !important;
    border-radius: 8px !important;
    padding: 3px !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(255, 255, 255, 0.1) !important;
  }
  .ol-gps-control button {
    width: 36px !important;
    height: 36px !important;
    line-height: 36px !important;
    border-radius: 6px !important;
    background: #1e293b !important;
    color: #f8fafc !important;
  }
  .ol-gps-control button svg {
    width: 20px !important;
    height: 20px !important;
  }

  /* Pasek skali widoczny na dole po lewej stronie */
  .ol-scale-line,
  .ol-scale-bar {
    display: flex !important;
    bottom: calc(72px + env(safe-area-inset-bottom, 0px)) !important;
    left: 8px !important;
    right: auto !important;
    transform: none !important;
    z-index: 1005 !important;
    padding: 3px 6px !important;
    font-size: 10px !important;
  }

  /* Atrybucja podkładu mapowego (np. OpenStreetMap) */
  .ol-attribution {
    display: block !important;
    bottom: calc(72px + env(safe-area-inset-bottom, 0px)) !important;
    right: 8px !important;
    left: auto !important;
    z-index: 1004 !important;
    max-width: calc(100% - 150px) !important;
    font-size: 10px !important;
    padding: 2px 6px !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;
    left: 50%;
    max-width: calc(100vw - 16px);
    bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    width: calc(100% - 16px);
    padding: 8px 10px;
    border-radius: 16px;
  }
  .hud-btn, .hud-select, .hud-name-input { min-height: 36px; font-size: 13px; }
  .hud-height-group { min-height: 36px; }

  /* ---------- 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; }

  /* ---------- OBSŁUGA KAMERY WBUDOWANEJ NA TABLETACH I TELEFONACH ---------- */
  .cam-photo-actions {
    flex-direction: row;
    gap: 8px;
  }
  .cam-photo-action-btn {
    min-height: 44px !important;
    font-size: 13px !important;
    border-radius: 8px !important;
  }
  .cam-capture-modal {
    width: 96vw;
    max-height: 94vh;
    border-radius: 14px;
  }
  .cam-capture-view {
    aspect-ratio: auto;
    height: min(52vh, 360px);
  }
  .cam-capture-tool-btn {
    min-height: 40px;
    font-size: 12px;
    padding: 8px 12px;
  }
  .cam-btn-snap, .cam-btn-confirm, .cam-btn-secondary {
    min-height: 46px !important;
    font-size: 14px !important;
  }
  .cam-exif-prompt-modal {
    width: 95vw;
    max-height: 92vh;
    border-radius: 14px;
  }
  .cam-exif-prompt-footer button {
    min-height: 44px !important;
    font-size: 13px !important;
  }
}

