/* === Base ============================================================ */
html, body { height: 100%; margin: 0; }
body {
  /* Avoid double-scroll on iOS when bottom-nav is fixed */
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

/* iOS safe-area for bottom nav and inputs */
:root { --safe-bottom: env(safe-area-inset-bottom, 0px); }

/* === Touch targets =================================================== */
.btn { min-height: 38px; }                 /* Bootstrap default = 31px */
@media (max-width: 767.98px) {
  .btn { min-height: 44px; }                /* Apple/Google guideline */
  .form-control, .form-select { min-height: 44px; font-size: 16px; }
  .form-control-sm, .form-select-sm { min-height: 38px; font-size: 14px; }
  /* iOS won't auto-zoom on focus if font-size >= 16px */
  input[type=text], input[type=number], input[type=email], input[type=password],
  input[type=search], select, textarea { font-size: 16px; }
}

/* === Map page ======================================================== */
#map, #pickerMap { width: 100%; height: 100%; }

/* Layout: full-height map + side sidebar on desktop, bottom sheet on mobile */
.map-shell {
  position: relative;
  height: calc(100vh - 56px);
  height: calc(100dvh - 56px);                /* dynamic vh on mobile */
}
@media (min-width: 768px) {
  .map-shell { display: grid; grid-template-columns: 1fr 380px; }
  .map-sidebar {
    border-left: 1px solid #dee2e6;
    background: #f8f9fa;
    overflow-y: auto;
    padding: 1rem;
  }
}
@media (max-width: 767.98px) {
  /* Mobile: map fills shell, sidebar becomes a bottom sheet */
  .map-shell { display: block; }
  .map-sidebar {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    background: #fff;
    border-top: 1px solid #dee2e6;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 12px rgba(0,0,0,0.08);
    max-height: 70vh;
    overflow-y: auto;
    transition: transform 0.25s ease;
    z-index: 500;
    padding: 0.5rem 1rem 1rem;
    padding-bottom: calc(1rem + var(--safe-bottom));
    transform: translateY(calc(100% - 48px));   /* collapsed = handle visible */
  }
  .map-sidebar.expanded { transform: translateY(0); }
  .sheet-handle {
    display: flex; flex-direction: column; align-items: center;
    cursor: pointer; padding: 8px 0;
  }
  .sheet-handle::before {
    content: ""; width: 40px; height: 4px; border-radius: 2px;
    background: #ccc; margin-bottom: 6px;
  }
  .sheet-title { font-weight: 500; font-size: 0.95rem; }
}
@media (min-width: 768px) {
  .sheet-handle { display: none; }
}

/* Map FAB buttons (GPS, sites picker) */
.map-fab {
  position: absolute; right: 12px; z-index: 400;
  width: 48px; height: 48px; border-radius: 50%;
  background: #fff; border: 1px solid #ccc;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
  font-size: 20px; color: #212529;
}
.map-fab:active { background: #e9ecef; }
.map-fab.primary { background: #0d6efd; color: #fff; border-color: #0d6efd; }
.fab-gps { top: 12px; }
.fab-sites { top: 70px; }

/* === Result cards on map sidebar ===================================== */
.antenna-card { border-left: 4px solid #ccc; }
.antenna-card.los-ok  { border-left-color: #198754; }
.antenna-card.los-bad { border-left-color: #dc3545; }

/* === Bottom navigation (mobile only) ================================ */
.bottom-nav {
  display: none;
}
@media (max-width: 767.98px) {
  .bottom-nav {
    display: flex;
    position: fixed; left: 0; right: 0; bottom: 0;
    background: #212529; color: #fff;
    border-top: 1px solid #495057;
    z-index: 600;
    padding-bottom: var(--safe-bottom);
  }
  .bottom-nav a {
    flex: 1; text-align: center; padding: 8px 4px;
    color: #adb5bd; text-decoration: none;
    display: flex; flex-direction: column; align-items: center;
    font-size: 11px; min-height: 56px;
    justify-content: center;
  }
  .bottom-nav a i { font-size: 20px; margin-bottom: 2px; }
  .bottom-nav a.active { color: #fff; }
  .bottom-nav a.active i { color: #0d6efd; }

  /* When bottom-nav is visible, push everything else up */
  body.has-bottom-nav { padding-bottom: 56px; padding-bottom: calc(56px + var(--safe-bottom)); }
  /* Map shell already accounts for navbar (-56px) so no extra */
  .map-shell { height: calc(100vh - 56px); height: calc(100dvh - 56px); }

  /* Hide the top navbar links on mobile (we use bottom nav instead) */
  .navbar-collapse { display: none !important; }
  .navbar-toggler { display: none !important; }
}

/* === Card list as alternative to tables on mobile ==================== */
.card-list { display: none; }
@media (max-width: 767.98px) {
  .responsive-table { display: none; }
  .card-list { display: block; }
  .card-list .item-card {
    background: #fff; border: 1px solid #dee2e6; border-radius: 8px;
    padding: 12px; margin-bottom: 8px;
    cursor: pointer;
  }
  .card-list .item-card:active { background: #f8f9fa; }
  .item-card .item-title { font-weight: 500; margin-bottom: 4px; }
  .item-card .item-meta { font-size: 13px; color: #6c757d; }
  .item-card .item-row { display: flex; justify-content: space-between; align-items: center; }
}

/* === Modals: fullscreen on mobile ==================================== */
@media (max-width: 767.98px) {
  .modal-dialog:not(.modal-fullscreen-lg) {
    margin: 0; max-width: 100%;
    height: 100vh; height: 100dvh;
  }
  .modal-content { border-radius: 0; height: 100%; }
}

/* === Login page ====================================================== */
.login-shell {
  min-height: 100vh; min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #1a3a6e 0%, #0d2447 100%);
  padding: 1rem;
}
.login-card {
  background: #fff; border-radius: 12px; padding: 2rem;
  width: 100%; max-width: 400px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}
.login-card h1 { font-size: 1.5rem; margin: 0 0 1.5rem; text-align: center; }
.login-card .brand-icon {
  text-align: center; font-size: 2.5rem; color: #0d6efd; margin-bottom: 0.5rem;
}

/* === Mobile-only "Analizza qui" floating action ================= */
/* Shows up over the map after a target is selected so the user can
 * run the verification without opening the bottom sheet. Desktop
 * hides it — the analyze button lives in the always-visible sidebar. */
.map-quick-check {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(48px + env(safe-area-inset-bottom, 0px) + 12px);
  z-index: 600;
  background: #198754;
  color: #fff;
  border: none;
  border-radius: 26px;
  padding: 12px 22px;
  font-size: 1rem;
  font-weight: 500;
  box-shadow: 0 4px 14px rgba(0,0,0,0.25);
  display: flex;
  align-items: center;
  gap: 6px;
}
.map-quick-check:active {
  background: #157347;
  transform: translateX(-50%) scale(0.97);
}
.map-quick-check.busy {
  background: #6c757d;
  pointer-events: none;
}
@media (min-width: 768px) {
  .map-quick-check { display: none !important; }
}

/* === Marker legend in sidebar ================================ */
.marker-legend {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 6px 8px;
  background: #f8f9fa;
  border: 1px solid #e9ecef;
  border-radius: 6px;
  flex-wrap: wrap;
}
.marker-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}
.legend-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1.5px solid #0a1628;
  flex-shrink: 0;
}
.legend-dot.legend-cluster {
  background: #1e3a8a;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1.5px #1e3a8a;
  color: #fff;
  font-size: 10px;
  line-height: 10px;
  text-align: center;
  font-weight: bold;
  padding: 1px;
  width: 14px;
  height: 14px;
}

/* === Profile chart canvas ============================================ */
.profile-chart-wrap {
  width: 100%;
  height: 400px;
  position: relative;
  padding: 0 8px;        /* inner breathing room so first/last X labels fit */
  box-sizing: border-box;
}
@media (max-width: 767.98px) {
  .profile-chart-wrap { height: 280px; padding: 0 4px; }
}
.profile-chart-wrap canvas {
  width: 100% !important;
  height: 100% !important;
  max-width: 100%;
  display: block;
}

/* === Photo uploader ================================================== */
.photo-main-preview { width: 120px; height: 120px; border: 1px solid #dee2e6; border-radius: 8px; overflow: hidden; display: flex; align-items: center; justify-content: center; background: #f8f9fa; }
.photo-main-preview img { width: 100%; height: 100%; object-fit: cover; }
.photo-empty { color: #adb5bd; font-size: 2rem; }
.photo-thumb { width: 100%; height: 100%; object-fit: cover; }

.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); gap: 6px; }
.gallery-item { position: relative; aspect-ratio: 1; border-radius: 6px; overflow: hidden; border: 1px solid #dee2e6; cursor: pointer; }
.gallery-item img { width: 100%; height: 100%; object-fit: cover; }
.gallery-del { position: absolute; top: 2px; right: 2px; padding: 0 6px; line-height: 1; border-radius: 50%; font-size: 12px; }
.gallery-add { aspect-ratio: 1; border: 2px dashed #adb5bd; border-radius: 6px; display: flex; align-items: center; justify-content: center; color: #6c757d; cursor: pointer; font-size: 1.5rem; background: #f8f9fa; }
.gallery-add:hover { background: #e9ecef; }

.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,0.85); display: flex; align-items: center; justify-content: center; z-index: 2000; padding: 1rem; }
.lightbox-inner { position: relative; max-width: 100%; max-height: 100%; }
.lightbox-inner img { max-width: 95vw; max-height: 90vh; object-fit: contain; }
.lightbox-close { position: absolute; top: -8px; right: -8px; width: 40px; height: 40px; border-radius: 50%; background: #fff; border: none; font-size: 24px; line-height: 1; cursor: pointer; box-shadow: 0 2px 6px rgba(0,0,0,0.3); }

/* === Save-as-site radio panels ================================= */
.save-mode-panel { display: none; }
.save-mode-panel.active { display: block; }
