* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg: #0f0f1a;
  --bg-card: #1a1a2e;
  --bg-nav: #16162a;
  --bg-surface: #222240;
  --text-primary: #e8e8f0;
  --text-secondary: #8888a8;
  --accent: #00d4aa;
  --accent-dim: rgba(0, 212, 170, 0.15);
  --danger: #d94a4a;
  --nav-height: 56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --radius: 12px;
}

html, body {
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#app {
  height: calc(100% - var(--nav-height) - var(--safe-bottom));
  overflow: hidden;
  position: relative;
}

.tab-content {
  height: 100%;
  width: 100%;
  position: relative;
}

/* ── Map ── */
#map { width: 100%; height: 100%; }

/* ── Top bar (search + category) ── */
.map-top-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  padding: 10px 10px 0;
  pointer-events: none;
}

.search-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  pointer-events: auto;
}

#search-input {
  flex: 1;
  height: 40px;
  padding: 0 14px;
  border: none;
  border-radius: 20px;
  background: rgba(22, 22, 42, 0.92);
  backdrop-filter: blur(12px);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
}
#search-input::placeholder { color: var(--text-secondary); }

#listing-count {
  display: flex;
  align-items: center;
  padding: 0 14px;
  height: 40px;
  border-radius: 20px;
  background: rgba(22, 22, 42, 0.92);
  backdrop-filter: blur(12px);
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  pointer-events: auto;
}

#category-bar {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  padding-bottom: 6px;
  pointer-events: auto;
}
#category-bar::-webkit-scrollbar { display: none; }

.cat-chip {
  flex-shrink: 0;
  height: 32px;
  padding: 0 14px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 16px;
  background: rgba(22, 22, 42, 0.88);
  backdrop-filter: blur(12px);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
.cat-chip.active {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
  font-weight: 600;
}

/* ── Map pick hint ── */
#map-pick-hint {
  display: none;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 20;
  background: rgba(0,0,0,0.8);
  color: #fff;
  padding: 12px 24px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  pointer-events: none;
  animation: pulse 1.5s infinite;
}
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.6} }

/* ── FAB (create button) ── */
#fab-create {
  position: absolute;
  bottom: 16px;
  right: 16px;
  z-index: 10;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent);
  color: #000;
  border: none;
  font-size: 26px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,212,170,0.4);
  transition: transform 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}
#fab-create:active { transform: scale(0.92); }

/* ── Bottom sheet (create form) ── */
#sheet-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 100;
}
#sheet-overlay.open { display: block; }

#create-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 101;
  max-height: 85vh;
  background: var(--bg-card);
  border-radius: 16px 16px 0 0;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform 0.3s ease;
}
#create-sheet.open { transform: translateY(0); }

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  position: sticky;
  top: 0;
  background: var(--bg-card);
  z-index: 1;
}
.sheet-header h3 { font-size: 16px; font-weight: 600; }
#create-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 22px;
  cursor: pointer;
  padding: 4px;
}

.sheet-body { padding: 16px; }

.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}
.form-control:focus { border-color: var(--accent); }
textarea.form-control { resize: vertical; min-height: 80px; }
select.form-control { appearance: none; }

.form-row { display: flex; gap: 10px; }
.form-row .form-group { flex: 1; }

.location-picker {
  display: flex;
  align-items: center;
  gap: 10px;
}
#pick-location-btn {
  flex-shrink: 0;
  padding: 10px 16px;
  border-radius: 8px;
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid rgba(0,212,170,0.3);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
#location-display {
  font-size: 13px;
  color: var(--text-secondary);
}

.file-input-wrap {
  position: relative;
}
.file-input-wrap input[type="file"] {
  width: 100%;
  padding: 10px;
  border: 1px dashed rgba(255,255,255,0.15);
  border-radius: 8px;
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-size: 13px;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: opacity 0.2s;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: var(--accent);
  color: #000;
  width: 100%;
}
.btn-primary:active { opacity: 0.85; }

/* ── Detail modal ── */
#detail-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,0.6);
  align-items: flex-end;
  justify-content: center;
}
#detail-modal.open { display: flex; }

.detail-sheet {
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  background: var(--bg-card);
  border-radius: 16px 16px 0 0;
  overflow-y: auto;
  padding: 0 0 calc(20px + var(--safe-bottom));
}

.detail-sheet-header {
  display: flex;
  justify-content: flex-end;
  padding: 12px 16px 0;
  position: sticky;
  top: 0;
  background: var(--bg-card);
  z-index: 1;
}
#detail-close {
  background: rgba(255,255,255,0.1);
  border: none;
  color: var(--text-primary);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

#detail-content { padding: 0 16px; }

.detail-images {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin-bottom: 16px;
  scrollbar-width: none;
}
.detail-images::-webkit-scrollbar { display: none; }
.detail-images img {
  height: 200px;
  border-radius: 10px;
  object-fit: cover;
  flex-shrink: 0;
}

.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.detail-cat {
  font-size: 13px;
  color: var(--text-secondary);
}
.detail-type {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 4px;
  text-transform: uppercase;
}
.type-offering { background: rgba(0,212,170,0.15); color: var(--accent); }
.type-looking\ for { background: rgba(90,122,217,0.15); color: #5a7ad9; }

.detail-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 6px;
  line-height: 1.3;
}
.detail-price {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 8px;
}
.detail-location {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}
.detail-desc {
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-secondary);
  margin-bottom: 12px;
  white-space: pre-wrap;
}
.detail-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}
.tag {
  padding: 4px 10px;
  border-radius: 12px;
  background: var(--bg-surface);
  font-size: 12px;
  color: var(--text-secondary);
}
.detail-meta {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 16px;
}
.btn-contact { margin-top: 8px; }

/* ── Popups ── */
.listing-popup {
  display: flex;
  gap: 10px;
  cursor: pointer;
  min-width: 200px;
}
.popup-thumb {
  width: 60px;
  height: 60px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
}
.popup-body { flex: 1; min-width: 0; }
.popup-cat { font-size: 11px; color: #888; margin-bottom: 2px; }
.popup-title { font-size: 13px; font-weight: 600; color: #222; line-height: 1.3; margin-bottom: 3px; }
.popup-price { font-size: 14px; font-weight: 700; color: #00a080; }
.popup-meta { font-size: 11px; color: #999; margin-top: 2px; }
.free-tag { color: #888; font-weight: 400; font-size: 13px; }

.maplibregl-popup-content {
  padding: 10px !important;
  border-radius: 10px !important;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15) !important;
}

/* ── Toast ── */
.toast {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  z-index: 300;
  background: var(--bg-card);
  color: var(--text-primary);
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  border: 1px solid rgba(0,212,170,0.3);
  opacity: 0;
  transition: all 0.3s;
  pointer-events: none;
  white-space: nowrap;
  max-width: 90vw;
  overflow: hidden;
  text-overflow: ellipsis;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Bottom Navigation Bar ── */
#navbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--bg-nav);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  justify-content: space-around;
  align-items: center;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  z-index: 50;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 12px;
  text-decoration: none;
  color: var(--text-secondary);
  transition: color 0.2s;
  -webkit-user-select: none;
  user-select: none;
}

.nav-item svg { width: 22px; height: 22px; }
.nav-item span { font-size: 10px; font-weight: 500; letter-spacing: 0.3px; }
.nav-item.active { color: var(--accent); }
.nav-item:active { transform: scale(0.92); }

/* ── Placeholder views ── */
.placeholder-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 16px;
  padding: 32px;
  text-align: center;
  color: var(--text-secondary);
}
.placeholder-view h2 { font-size: 20px; font-weight: 600; color: var(--text-primary); }
.placeholder-view p { font-size: 14px; max-width: 260px; line-height: 1.5; }

/* ── Account tab ── */
.account-view {
  height: 100%;
  overflow-y: auto;
  padding: 20px 16px calc(20px + var(--safe-bottom));
}
.auth-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px 20px;
  max-width: 400px;
  margin: 0 auto;
}
.auth-card h2 { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.auth-card .subtitle { font-size: 13px; color: var(--text-secondary); margin-bottom: 20px; }
.auth-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 20px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.1);
}
.auth-tab {
  flex: 1;
  padding: 10px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  background: var(--bg-surface);
  color: var(--text-secondary);
  cursor: pointer;
  border: none;
  transition: all 0.2s;
}
.auth-tab.active { background: var(--accent); color: #000; }

.auth-form { display: none; }
.auth-form.active { display: block; }

/* ── MapLibre overrides ── */
.maplibregl-ctrl-bottom-left,
.maplibregl-ctrl-bottom-right { bottom: 8px !important; }
.maplibregl-ctrl-attrib {
  font-size: 10px !important;
  background: rgba(0, 0, 0, 0.5) !important;
  color: #888 !important;
}
.maplibregl-ctrl-attrib a { color: #aaa !important; }
