/* ─────────────────────────────────────────────────────────────
   PR Property Scout — clean, professional, touch-friendly
   ───────────────────────────────────────────────────────────── */
:root {
  --bg:        #f4f6f8;
  --surface:   #ffffff;
  --ink:       #16242e;
  --ink-soft:  #5b6b76;
  --line:      #e2e8ed;
  --brand:     #0e7490;   /* teal — ties to Fix Up brand */
  --brand-dk:  #0b5566;
  --danger:    #dc2626;
  --shadow:    0 6px 24px rgba(16, 36, 46, 0.12);

  /* Deal-status palette */
  --s-interested:     #2563eb;  /* blue   */
  --s-contacted:      #0e7490;  /* teal   */
  --s-offer:          #d97706;  /* amber  */
  --s-contract:       #16a34a;  /* green  */
  --s-passed:         #6b7280;  /* gray   */

  --radius: 12px;
  --header-h: 56px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

/* ───────────── Top bar ───────────── */
.topbar {
  height: calc(var(--header-h) + env(safe-area-inset-top, 0px));
  display: flex;
  align-items: center;
  gap: 12px;
  /* Respect the notch / safe areas when installed full-screen on iOS */
  padding-top: env(safe-area-inset-top, 0px);
  padding-left: max(12px, env(safe-area-inset-left, 0px));
  padding-right: max(12px, env(safe-area-inset-right, 0px));
  background: var(--brand);
  color: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,.12);
  position: relative;
  z-index: 1200;
}
.brand { display: flex; align-items: baseline; gap: 8px; min-width: 0; flex: 1 1 auto; overflow: hidden; }
.brand-mark { font-size: 20px; }
.brand-text { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub  { font-size: 12px; opacity: .8; white-space: nowrap; }
@media (max-width: 520px) { .brand-sub { display: none; } }

.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }

/* Compact, tidy top bar on phones so the title never collides with the
   Import / Export buttons. */
@media (max-width: 600px) {
  .topbar {
    gap: 8px;
    padding-left: max(8px, env(safe-area-inset-left, 0px));
    padding-right: max(8px, env(safe-area-inset-right, 0px));
  }
  .topbar-actions { gap: 6px; }
  .topbar-actions .btn {
    padding: 8px 14px;
    font-size: 13px;
    min-height: 36px;
    border-radius: 999px;
  }
  .brand-text { font-size: 15px; }
  .brand-mark { font-size: 18px; }
  .count-badge { display: none; }   /* count still shows in the sidebar */
}
.count-badge {
  background: rgba(255,255,255,.2);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 13px;
  font-weight: 600;
  min-width: 28px;
  text-align: center;
}

/* ───────────── Layout ───────────── */
.layout {
  display: flex;
  height: calc(100% - var(--header-h) - env(safe-area-inset-top, 0px));
  position: relative;
}
.sidebar {
  width: 320px;
  flex: 0 0 320px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: margin-left .25s ease, transform .25s ease;
}
.sidebar.collapsed { margin-left: -320px; }

/* On phones/tablets the sidebar floats OVER the map instead of squeezing it.
   It is HIDDEN by default (pure CSS — no JS required) so the map always gets
   the full screen, and slides in only when the ☰ button adds .open. */
@media (max-width: 768px) {
  .sidebar {
    position: absolute;
    top: 0; bottom: 0; left: 0;
    z-index: 1100;
    width: 86%;
    max-width: 340px;
    flex-basis: auto;
    margin-left: 0;
    box-shadow: var(--shadow);
    transform: translateX(-105%);
  }
  .sidebar.open { transform: translateX(0); }
}

.sidebar-head { padding: 12px; border-bottom: 1px solid var(--line); }
.search {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 15px;
  outline: none;
}
.search:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(14,116,144,.15); }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  color: var(--ink-soft);
}
.legend-item { display: flex; align-items: center; gap: 5px; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

.property-list { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; }
.property-list li {
  padding: 11px 12px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  gap: 10px;
  align-items: center;
}
.property-list li:hover, .property-list li.active { background: #eef4f6; }
.pl-thumb {
  width: 44px; height: 44px; border-radius: 8px; object-fit: cover;
  background: var(--line); flex: 0 0 44px;
}
.pl-thumb.placeholder { display: flex; align-items: center; justify-content: center; color: var(--ink-soft); font-size: 18px; }
.pl-body { min-width: 0; flex: 1; }
.pl-addr { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pl-meta { font-size: 12px; color: var(--ink-soft); margin-top: 2px; display: flex; align-items: center; gap: 6px; }
.status-chip {
  font-size: 11px; font-weight: 600; color: #fff;
  padding: 2px 8px; border-radius: 999px; white-space: nowrap;
}

.empty-state { padding: 24px; color: var(--ink-soft); font-size: 14px; text-align: center; }

/* ───────────── Map ───────────── */
.map-wrap { position: relative; flex: 1; }
#map { position: absolute; inset: 0; background: #e8edf0; }
.map-fallback {
  position: absolute; inset: 0; z-index: 1;
  display: flex; align-items: center; justify-content: center;
  text-align: center; padding: 24px;
  color: var(--ink-soft); font-size: 15px; line-height: 1.5;
}
.map-hint {
  position: absolute;
  top: 12px; left: 50%; transform: translateX(-50%);
  background: rgba(22,36,46,.85); color: #fff;
  padding: 7px 14px; border-radius: 999px;
  font-size: 13px; z-index: 500; pointer-events: none;
  box-shadow: var(--shadow);
}

/* Custom pin markers */
.pin {
  width: 26px; height: 26px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  border: 2px solid #fff;
  box-shadow: 0 2px 5px rgba(0,0,0,.35);
}
.pin::after {
  content: ""; position: absolute;
  top: 7px; left: 7px; width: 8px; height: 8px;
  background: #fff; border-radius: 50%;
}

/* Municipio name labels — text only, with a white halo for legibility */
.leaflet-tooltip.muni-label {
  background: transparent; border: 0; box-shadow: none;
  padding: 0; margin: 0;
  color: #4c1d95; font-weight: 700; font-size: 11px;
  text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 2px #fff;
  white-space: nowrap;
}
.leaflet-tooltip.muni-label::before { display: none; border: 0; }

/* ───────────── Buttons ───────────── */
.btn {
  border: none; cursor: pointer;
  padding: 11px 16px; border-radius: 10px;
  font-size: 15px; font-weight: 600;
  min-height: 44px;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dk); }
.btn-ghost { background: transparent; color: inherit; border: 1px solid currentColor; opacity: .9; }
.btn-ghost:hover { opacity: 1; }
.topbar .btn-ghost { border-color: rgba(255,255,255,.5); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.icon-btn {
  background: transparent; border: none; cursor: pointer;
  color: inherit; font-size: 22px; line-height: 1;
  width: 40px; height: 40px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: rgba(0,0,0,.06); }
.topbar .icon-btn:hover { background: rgba(255,255,255,.15); }
.hamburger, .hamburger::before, .hamburger::after {
  display: block; width: 20px; height: 2px; background: currentColor; border-radius: 2px; position: relative;
}
.hamburger::before, .hamburger::after { content: ""; position: absolute; left: 0; }
.hamburger::before { top: -6px; } .hamburger::after { top: 6px; }

/* ───────────── Modal ───────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(16,36,46,.5);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0;
}
@media (min-width: 640px) { .modal-overlay { align-items: center; padding: 20px; } }

.modal {
  background: var(--surface);
  width: 100%; max-width: 480px;
  border-radius: 16px 16px 0 0;
  max-height: 92vh; overflow-y: auto;
  box-shadow: var(--shadow);
  animation: slideUp .22s ease;
}
@media (min-width: 640px) { .modal { border-radius: 16px; } }
@keyframes slideUp { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }

.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 16px 8px;
}
.modal-head h2 { margin: 0; font-size: 18px; }

.form { padding: 4px 16px 16px; }
.field { display: block; margin-bottom: 14px; }
.field-label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-soft); margin-bottom: 6px; }
.field-label small { font-weight: 400; }
.field input[type=text], .field select, .field textarea {
  width: 100%; padding: 12px; font-size: 16px;
  border: 1px solid var(--line); border-radius: 10px;
  outline: none; font-family: inherit; background: #fff;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--brand); box-shadow: 0 0 0 3px rgba(14,116,144,.15);
}
.field textarea { resize: vertical; }

.image-preview { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.image-preview .thumb {
  position: relative; width: 76px; height: 76px;
  border-radius: 10px; overflow: hidden; background: var(--line);
}
.image-preview .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.image-preview .thumb .rm {
  position: absolute; top: 2px; right: 2px;
  width: 22px; height: 22px; border-radius: 50%;
  background: rgba(0,0,0,.6); color: #fff; border: none;
  cursor: pointer; font-size: 14px; line-height: 1;
}
.upload-btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 10px 14px; border: 1.5px dashed var(--brand); color: var(--brand);
  border-radius: 10px; cursor: pointer; font-weight: 600; font-size: 14px;
}
.upload-btn.disabled { opacity: .4; pointer-events: none; }

.modal-actions { display: flex; align-items: center; gap: 8px; padding-top: 6px; }
.modal-actions .spacer { flex: 1; }

/* ───────────── Popup summary card ───────────── */
.leaflet-popup-content { margin: 0; }
.leaflet-popup-content-wrapper { border-radius: 12px; padding: 0; overflow: hidden; }
.card { width: 240px; }
.card-head { padding: 12px 14px 8px; }
.card-addr { font-weight: 700; font-size: 15px; }
.card-status { display: inline-block; margin-top: 6px; }
.card-notes { padding: 0 14px 10px; font-size: 13px; color: var(--ink-soft); white-space: pre-wrap; }
.card-thumbs { display: flex; gap: 6px; padding: 0 14px 12px; }
.card-thumbs img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; cursor: zoom-in; }
.card-actions { display: flex; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--line); }
.card-actions .btn { flex: 1; padding: 9px; font-size: 14px; min-height: 40px; }

/* ───────────── Lightbox ───────────── */
.lightbox {
  position: fixed; inset: 0; z-index: 3000;
  background: rgba(0,0,0,.9);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }
.lightbox-close { position: absolute; top: 12px; right: 12px; color: #fff; font-size: 32px; }

/* ───────────── PWA: install steps modal ───────────── */
.install-steps ol { margin: 0; padding-left: 20px; }
.install-steps li { font-size: 14px; line-height: 1.55; margin-bottom: 8px; color: var(--ink); }
.install-steps strong { font-weight: 700; }
.install-note {
  font-size: 13px; line-height: 1.5; color: var(--ink-soft);
  background: #eef4f6; border-radius: 10px; padding: 10px 12px; margin: 4px 0 0;
}

/* ───────────── PWA: offline hint + iOS install banner ───────────── */
.offline-hint {
  position: absolute;
  bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  left: 50%; transform: translateX(-50%);
  background: rgba(220, 38, 38, .94); color: #fff;
  padding: 7px 14px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
  max-width: 92%; overflow: hidden; text-overflow: ellipsis;
  z-index: 650; box-shadow: var(--shadow); pointer-events: none;
}

.ios-hint {
  position: fixed; z-index: 2500;
  left: 12px; right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  background: var(--ink); color: #fff;
  padding: 13px 42px 13px 15px; border-radius: 12px;
  font-size: 13px; line-height: 1.45;
  box-shadow: var(--shadow);
  animation: slideUp .25s ease;
}
.ios-hint strong { color: #fff; font-weight: 700; }
.ios-hint-close {
  position: absolute; top: 6px; right: 8px;
  background: transparent; border: 0; color: #fff;
  font-size: 24px; line-height: 1; cursor: pointer;
  width: 34px; height: 34px;
}
@media (min-width: 640px) {
  .ios-hint { left: auto; right: 16px; max-width: 360px; }
}

/* Keep the bottom action bar of the modal clear of the home indicator */
@media (max-width: 639px) {
  .modal { padding-bottom: env(safe-area-inset-bottom, 0px); }
}

[hidden] { display: none !important; }
