* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0;
  font-family: Tahoma, Vazir, system-ui, sans-serif;
  background: #121212; color: #eaeaea;
  font-size: 14px;
  height: 100%;
  overscroll-behavior: none;
}
body {
  display: flex; flex-direction: column;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}

/* TOP BAR */
#topbar {
  display: flex; justify-content: space-between; align-items: center;
  background: linear-gradient(90deg, #f57c00, #ff9800);
  color: white; padding: 6px 12px;
  padding-top: calc(6px + env(safe-area-inset-top));
  font-weight: bold; font-size: 14px;
  position: sticky; top: 0; z-index: 1000;
}
.brand { font-size: 14px; }
.status { display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #4caf50; }
.dot.offline { background: #f44336; }
#pendingBadge { background: rgba(0,0,0,0.3); border-radius: 10px; padding: 1px 7px; font-size: 11px; }
#syncBtn { background: rgba(255,255,255,0.2); border: none; color: white; width: 28px; height: 28px; border-radius: 50%; font-size: 14px; cursor: pointer; }

/* GPS BAR */
#gpsBar {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 12px;
  background: #1e1e1e;
  border-bottom: 1px solid #333;
  font-size: 12px;
}
#gpsCoords { flex: 1; }
#gpsAcc { color: #999; font-size: 10px; }
#gpsBtn {
  background: #2196f3; color: white; border: none;
  padding: 5px 10px; border-radius: 16px;
  font-size: 13px; cursor: pointer; min-width: 40px;
}
#gpsBtn.searching { background: #666; animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.5; } }

/* TABS */
#tabs { display: flex; background: #1a1a1a; border-bottom: 1px solid #333; }
.tab {
  flex: 1; padding: 8px 4px;
  background: transparent; border: none; color: #999;
  font-size: 12px; font-family: inherit;
  border-bottom: 2px solid transparent; cursor: pointer;
}
.tab.active { color: #ff9800; border-bottom-color: #ff9800; font-weight: bold; }

/* MAP */
#map { height: 260px; background: #222; border-bottom: 1px solid #333; z-index: 1; flex-shrink: 0; }
.leaflet-container { background: #222; }

/* FORM */
#formArea {
  flex: 1; padding: 8px 10px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Compact labels and inputs */
label {
  display: block; font-size: 11px; color: #999;
  margin: 6px 0 2px;
}
input[type="text"], input[type="tel"], input[type="number"],
select, textarea {
  width: 100%; padding: 7px 10px;
  font-size: 14px; font-family: inherit;
  background: #1e1e1e; color: #eaeaea;
  border: 1px solid #333; border-radius: 6px;
  -webkit-appearance: none;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: #ff9800;
}
textarea { resize: vertical; min-height: 44px; }

.row {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
}

/* Compact save button — NOT full width */
.save-btn {
  width: 100%; padding: 11px;
  margin-top: 12px;
  background: linear-gradient(90deg, #4caf50, #43a047);
  color: white; border: none; border-radius: 8px;
  font-size: 15px; font-weight: bold; font-family: inherit;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(76,175,80,0.3);
}
.save-btn:active { transform: scale(0.98); }
.save-btn:disabled { background: #666; box-shadow: none; }

/* TOAST */
#toast {
  position: fixed; bottom: 20px; left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #333; color: white;
  padding: 10px 20px; border-radius: 20px;
  font-size: 13px;
  opacity: 0; transition: all 0.3s;
  pointer-events: none; z-index: 9999;
  max-width: 90%; text-align: center;
}
#toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
#toast.success { background: #4caf50; }
#toast.error { background: #f44336; }
#toast.info { background: #2196f3; }

/* Marker pin for main point */
.marker-pin {
  width: 20px; height: 20px;
  border-radius: 50% 50% 50% 0;
  background: #f44336;
  position: absolute; transform: rotate(-45deg);
  left: 50%; top: 50%;
  margin: -20px 0 0 -10px;
  border: 2px solid white;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}

/* Unit markers (emoji + count) */
.unit-marker {
  background: rgba(255,255,255,0.95);
  border: 2px solid #ff9800;
  border-radius: 10px;
  padding: 2px 6px;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  min-width: 36px; min-height: 36px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
  font-family: Tahoma, sans-serif;
}
.unit-marker .emoji { font-size: 18px; line-height: 1; }
.unit-marker .count {
  font-size: 11px; font-weight: bold;
  color: #f57c00; line-height: 1; margin-top: 1px;
}
.unit-marker.preview {
  background: rgba(33,150,243,0.95);
  border-color: #2196f3;
  animation: markerPulse 1.5s infinite;
}
.unit-marker.preview .count { color: #fff; }
@keyframes markerPulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.08); }
}

.leaflet-div-icon { background: transparent; border: none; }

/* Smaller screens: even tighter */
@media (max-height: 700px) {
  #map { height: 200px; }
  input, select, textarea { padding: 6px 8px; font-size: 13px; }
  label { margin: 4px 0 2px; }
  .save-btn { padding: 10px; margin-top: 10px; }
}

/* ============ Compact grid form ============ */
.fgrid {
  display: grid;
  grid-template-columns: auto 1fr auto 1fr;
  gap: 4px 8px;
  align-items: center;
}
.fgrid label {
  margin: 0;
  font-size: 12px;
  color: #999;
  white-space: nowrap;
  text-align: left;
  padding-left: 4px;
}
.fgrid input,
.fgrid select,
.fgrid textarea {
  margin: 0;
  padding: 5px 8px;
  font-size: 13px;
  border-radius: 6px;
  width: 100%;
  min-width: 0;
}
.fgrid .col-2 {
  grid-column: 2 / -1;
}
.fgrid textarea {
  min-height: 32px;
  max-height: 80px;
  resize: vertical;
  padding-top: 6px;
}
.fgrid > span:empty {
  display: none;
}

/* Override earlier #formArea padding for tighter fit */
#formArea { padding: 6px 8px; }

/* bigger map when using compact form */
#map { height: 280px; }

/* save btn tighter */
.save-btn {
  padding: 9px;
  margin-top: 8px;
  font-size: 14px;
}

/* very small screens */
@media (max-height: 700px) {
  #map { height: 220px; }
  .fgrid label { font-size: 11px; }
  .fgrid input, .fgrid select, .fgrid textarea { padding: 4px 6px; font-size: 12px; }
  .save-btn { padding: 8px; font-size: 13px; }
}

/* ============ Fill vertical space with map ============ */
html, body { height: 100%; }
body { height: 100vh; overflow: hidden; }

#map {
  flex: 1 1 auto;
  min-height: 180px;
  height: auto !important;
}

#formArea {
  flex: 0 0 auto;
  max-height: 55vh;
  overflow-y: auto;
  padding: 6px 8px 10px;
}

/* Sticky save at bottom of form area */
.save-btn {
  position: sticky;
  bottom: 0;
  z-index: 5;
}

/* Map takes all remaining space, form is compact below */
#map {
  flex: 1 1 auto !important;
  min-height: 200px;
  height: auto !important;
}
#formArea {
  flex: 0 0 auto !important;
  max-height: 40vh !important;
  overflow-y: auto;
  background: #121212;
  border-top: 2px solid #ff9800;
}
.save-btn {
  position: sticky;
  bottom: 0;
  margin-bottom: 0;
}
