/* ================================================================
   Community Pantry Map — Styles
   Mobile-first, then desktop overrides via media query
================================================================ */

/* ---- Reset & tokens ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
.hidden { display: none !important; }

:root {
  --green-dark:  #1a7a40;
  --green-mid:   #2d8a4e;
  --green-light: #52b788;
  --green-pale:  #d8f3dc;
  --text:        #1a1a2e;
  --text-muted:  #6c757d;
  --border:      #dee2e6;
  --surface:     #ffffff;
  --error:       #dc3545;
  --radius:      12px;
  --shadow-sm:   0 2px 8px rgba(0,0,0,0.12);
  --shadow-md:   0 4px 20px rgba(0,0,0,0.18);
  --panel-height: 68vh;   /* bottom sheet height on mobile */
  --topbar-h:    52px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  color: var(--text);
  overflow: hidden;
  background: #e8e4df; /* shows briefly before map loads */
}

/* ================================================================
   MAP
================================================================ */
#map {
  position: fixed;
  inset: 0;
  z-index: 1;
  transition: right 0.3s ease; /* desktop: shrinks when panel opens */
}

/* ================================================================
   TOP BAR
================================================================ */
#topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  z-index: 500;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
}

#topbar-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 16px;
  color: var(--green-dark);
}

#topbar-title span:first-child {
  font-size: 20px;
}

#btn-search-toggle {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
  transition: background 0.2s;
  opacity: 0.7;
}
#btn-search-toggle:hover { background: #f0f0f0; opacity: 1; }

/* ---- Search bar ---- */
#search-bar {
  position: fixed;
  top: var(--topbar-h);
  left: 0; right: 0;
  z-index: 490;
  padding: 8px 12px;
  background: white;
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

#search-input {
  width: 100%;
  padding: 9px 14px;
  font-size: 15px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  outline: none;
  background: #f8f9fa;
}
#search-input:focus { border-color: var(--green-light); background: white; }

#search-results {
  position: absolute;
  top: calc(100% - 8px);
  left: 12px; right: 12px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 0 0 10px 10px;
  box-shadow: 0 6px 16px rgba(0,0,0,0.12);
  max-height: 260px;
  overflow-y: auto;
  z-index: 10;
}

.search-section-header {
  padding: 6px 14px 4px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  background: #f8f9fa;
  border-bottom: 1px solid #f0f0f0;
}

.search-result-item {
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid #f0f0f0;
  font-size: 14px;
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--green-pale); }
.search-result-item strong { display: block; color: var(--text); }
.search-result-item span { color: var(--text-muted); font-size: 12px; }
.search-no-results {
  padding: 14px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

/* ================================================================
   FAB — Add Pantry
================================================================ */
#btn-add {
  position: fixed;
  bottom: 24px;
  right: 20px;
  z-index: 500;
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--green-mid);
  color: white;
  border: none;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,0.3);
  transition: background 0.2s, transform 0.15s;
  display: flex; align-items: center; justify-content: center;
}
#btn-add:hover   { background: var(--green-dark); transform: scale(1.05); }
#btn-add:active  { transform: scale(0.95); }

/* ================================================================
   CROSSHAIR OVERLAY
================================================================ */
#crosshair {
  position: fixed;
  inset: 0;
  z-index: 600;
  pointer-events: none; /* let map clicks through */
  display: flex;
  align-items: center;
  justify-content: center;
}

#crosshair-lines {
  position: absolute;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.ch-h, .ch-v {
  position: absolute;
  background: rgba(26, 122, 64, 0.7);
}
.ch-h {
  width: 40px; height: 2px;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
}
.ch-v {
  width: 2px; height: 40px;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
}
.ch-h::before, .ch-v::before {
  content: '';
  position: absolute;
  inset: -3px;
  background: rgba(255,255,255,0.5);
  z-index: -1;
}

#crosshair-hint {
  position: absolute;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.75);
  color: white;
  border-radius: 100px;
  padding: 10px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
  pointer-events: none;
}

#btn-pick-cancel {
  pointer-events: all;
  background: white;
  color: var(--text);
  border: none;
  border-radius: 100px;
  padding: 6px 18px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}
#btn-pick-cancel:hover { background: #f0f0f0; }

/* Cursor when picking */
.picking-mode { cursor: crosshair !important; }
.picking-mode * { cursor: crosshair !important; }

/* ================================================================
   FORM PANEL — Bottom sheet (mobile)
================================================================ */
#panel {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--panel-height);
  z-index: 700;
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1);
  will-change: transform;
}

#panel.open { transform: translateY(0); }
#panel.hidden { display: none; }

#panel-handle {
  flex-shrink: 0;
  width: 40px; height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 10px auto 4px;
}

#panel-inner {
  flex: 1;
  overflow-y: auto;
  padding: 0 20px 24px;
  -webkit-overflow-scrolling: touch;
}

#panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0 16px;
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}

#panel-header h2 {
  font-size: 17px;
  font-weight: 700;
  color: var(--green-dark);
}

#btn-close-panel {
  background: none;
  border: none;
  font-size: 18px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background 0.2s;
}
#btn-close-panel:hover { background: #f5f5f5; color: var(--text); }

/* ================================================================
   FORM FIELDS
================================================================ */
.field {
  margin-bottom: 16px;
}

.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}

.required {
  color: var(--error);
}

input[type="text"],
input[type="tel"],
input[type="url"],
input[type="email"],
input[type="password"] {
  width: 100%;
  padding: 11px 14px;
  font-size: 15px;
  color: var(--text);
  background: #f8f9fa;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  outline: none;
  transition: border-color 0.2s, background 0.2s;
  -webkit-appearance: none;
}

input:focus {
  border-color: var(--green-light);
  background: white;
}

input::placeholder { color: #aaa; }

/* --- Location row --- */
#location-row {
  background: #f8f9fa;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
}

#location-display {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 8px;
  font-variant-numeric: tabular-nums;
  word-break: break-all;
}

#location-display.has-location {
  color: var(--green-dark);
  font-weight: 600;
}

#location-btns {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* --- Photo zone --- */
#photo-zone {
  background: #f8f9fa;
  border: 2px dashed var(--border);
  border-radius: 8px;
  overflow: hidden;
  transition: border-color 0.2s;
}
#photo-zone:focus-within { border-color: var(--green-light); }

#f-photo {
  position: absolute;
  width: 1px; height: 1px;
  opacity: 0;
  pointer-events: none;
}

#photo-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 24px 16px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-muted);
}
#photo-label span:first-child { font-size: 28px; }
#photo-label:hover { background: #f0f0f0; }

#photo-preview-wrap {
  position: relative;
  background: #000;
}

#photo-preview {
  display: block;
  width: 100%;
  max-height: 200px;
  object-fit: cover;
}

#btn-clear-photo {
  position: absolute;
  top: 8px; right: 8px;
  background: rgba(0,0,0,0.55);
  color: white;
  border: none;
  border-radius: 50%;
  width: 28px; height: 28px;
  font-size: 14px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s;
}
#btn-clear-photo:hover { background: rgba(0,0,0,0.8); }

/* --- Form error --- */
.form-error {
  color: var(--error);
  font-size: 13px;
  background: #fff0f1;
  border: 1px solid #f5c2c7;
  border-radius: 6px;
  padding: 8px 12px;
  margin-bottom: 12px;
}

/* --- Form actions --- */
#form-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

/* ================================================================
   BUTTONS
================================================================ */
.btn-primary {
  background: var(--green-mid);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 12px 20px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
}
.btn-primary:hover   { background: var(--green-dark); }
.btn-primary:active  { opacity: 0.85; }
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-outline {
  background: white;
  color: var(--green-mid);
  border: 1.5px solid var(--green-mid);
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-outline:hover { background: var(--green-pale); }

.btn-sm { padding: 7px 14px; font-size: 13px; }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 10px 20px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-ghost:hover { background: #f5f5f5; }

.btn-full { width: 100%; }

/* ================================================================
   CONSENT MODAL
================================================================ */
#consent-modal {
  position: fixed;
  inset: 0;
  z-index: 800;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
}

@media (min-width: 769px) {
  #consent-modal { align-items: center; }
}

#consent-card {
  background: white;
  border-radius: var(--radius) var(--radius) var(--radius) var(--radius);
  padding: 28px 24px 24px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-md);
}

#consent-icon {
  font-size: 36px;
  text-align: center;
  margin-bottom: 12px;
}

#consent-card h2 {
  font-size: 18px;
  font-weight: 700;
  color: var(--green-dark);
  text-align: center;
  margin-bottom: 16px;
}

#consent-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
}

#consent-list li {
  font-size: 14px;
  color: var(--text);
  line-height: 1.5;
  padding: 10px 12px;
  background: #f8f9fa;
  border-radius: 8px;
}

#consent-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ================================================================
   FIELD HINT
================================================================ */
.field-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
  line-height: 1.4;
}

/* ================================================================
   TOAST
================================================================ */
.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 900;
  background: #1a1a2e;
  color: white;
  padding: 12px 24px;
  border-radius: 100px;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  box-shadow: var(--shadow-md);
  animation: toast-in 0.3s ease;
}
.toast.hidden { display: none; }
.toast.toast-success { background: var(--green-dark); }
.toast.toast-error   { background: var(--error); }

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 12px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* ================================================================
   LEAFLET OVERRIDES
================================================================ */
.leaflet-top .leaflet-control-zoom {
  margin-top: calc(var(--topbar-h) + 8px);
}

/* Custom pantry marker */
.pantry-pin {
  width: 34px; height: 34px;
  border: 3px solid white;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
  transition: transform 0.15s;
  cursor: pointer;
  background: #9e9e9e; /* default grey = pending */
}
.pantry-pin.verified { background: var(--green-mid); }
.pantry-pin:hover { transform: scale(1.15); }

/* Pending (dropped) marker while form is open */
.pantry-pin.pending {
  background: #e67e22;
  animation: pin-drop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes pin-drop {
  from { transform: translateY(-20px) scale(0.7); opacity: 0; }
  to   { transform: translateY(0) scale(1); opacity: 1; }
}

/* Popup */
.pantry-popup .leaflet-popup-content-wrapper {
  border-radius: 12px;
  padding: 0;
  overflow: hidden;
  box-shadow: 0 6px 24px rgba(0,0,0,0.15);
}
.pantry-popup .leaflet-popup-content {
  margin: 0;
  min-width: 220px;
}
.pantry-popup .leaflet-popup-tip-container {
  margin-top: -1px;
}

.popup-photo {
  width: 100%;
  height: 150px;
  object-fit: cover;
  display: block;
}

.popup-body {
  padding: 12px 14px 10px;
}

.popup-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
  line-height: 1.3;
}

.popup-row {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 4px;
  display: flex;
  align-items: flex-start;
  gap: 6px;
}

.popup-row a {
  color: var(--green-mid);
  text-decoration: none;
  word-break: break-all;
}
.popup-row a:hover { text-decoration: underline; }

.popup-badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 600;
}
.popup-badge.verified     { background: var(--green-pale); color: var(--green-dark); }
.popup-badge.pending-badge { background: #f0f0f0; color: #777; }

.popup-date {
  font-size: 11px;
  color: #aaa;
  margin-top: 8px;
}

/* ================================================================
   DESKTOP (≥ 769px) — side panel
================================================================ */
@media (min-width: 769px) {
  #panel {
    top: 0; right: 0; bottom: 0;
    left: auto;
    width: 380px;
    height: 100%;
    border-radius: 0;
    transform: translateX(100%);
  }
  #panel.open { transform: translateX(0); }

  /* Shrink map so it's not hidden behind the panel */
  body.panel-open #map { right: 380px; }

  #panel-handle { display: none; }

  /* Move FAB so it doesn't overlap panel when open */
  body.panel-open #btn-add { right: 400px; }

  .toast { bottom: 30px; }

  #panel-inner { padding: 0 24px 32px; }

  .leaflet-top.leaflet-right { right: 0; }
  body.panel-open .leaflet-top.leaflet-right { right: 380px; }
}

/* ================================================================
   ACCESSIBILITY: reduced motion
================================================================ */
@media (prefers-reduced-motion: reduce) {
  #panel, #btn-add, .pantry-pin { transition: none; }
  .pantry-pin.pending { animation: none; }
  .toast { animation: none; }
}
