/* Land Measurement — map-first mobile UI (vilamarketinfo tokens) */

:root {
  --color-primary: #0d7a4f;
  --color-primary-dark: #065f3c;
  --color-primary-deep: #04452b;
  --color-primary-soft: #e8f5ef;
  --color-accent: #1a9b68;
  --color-bg: #f7faf8;
  --color-surface: #ffffff;
  --color-text: #15231c;
  --color-text-secondary: #4a5c53;
  --color-muted: #6b7c73;
  --color-border: #dce6e0;
  --color-danger: #b42318;
  --color-front: #c9881a;
  --shadow-sm: 0 1px 2px rgba(21, 35, 28, 0.04);
  --shadow-md: 0 8px 24px rgba(21, 35, 28, 0.06);
  --radius-sm: 10px;
  --radius-md: 16px;
  --font: "Vazirmatn", "Segoe UI", Tahoma, sans-serif;
  --focus: 0 0 0 3px rgba(13, 122, 79, 0.28);
  --brand-h: 40px;
  --toolbar-h: auto;
  --map-min: 580px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font);
  overflow: hidden;
}

.hidden { display: none !important; }

.gate {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(13, 122, 79, 0.12), transparent 50%),
    var(--color-bg);
}

.gate-card {
  max-width: 22rem;
  text-align: center;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 1.75rem 1.25rem;
  box-shadow: var(--shadow-md);
}

.gate-card h1 {
  margin: 0.35rem 0 0.75rem;
  font-size: 1.25rem;
  color: var(--color-primary-deep);
}

.gate-hint {
  margin: 0.85rem 0 0;
  font-size: 0.85rem;
  color: var(--color-muted);
  line-height: 1.6;
}

.brand-mark { font-size: 2rem; }

.app {
  height: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--color-bg);
  position: relative;
}

.brand-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  min-height: var(--brand-h);
  padding: 0.3rem 0.65rem;
  background: linear-gradient(135deg, var(--color-primary-deep), var(--color-primary));
  color: #fff;
}

.brand-bar strong {
  font-size: 0.88rem;
  font-weight: 700;
}

.btn-fs {
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border-radius: 8px;
  padding: 0.25rem 0.55rem;
  font-size: 0.75rem;
  font-family: inherit;
  cursor: pointer;
}

.map-toolbar {
  flex: 0 0 auto;
  padding: 0.35rem 0.5rem 0.3rem;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  z-index: 500;
}

.search-row {
  display: flex;
  gap: 0.3rem;
}

.search-row input {
  flex: 1;
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  color: var(--color-text);
  border-radius: 8px;
  padding: 0.4rem 0.55rem;
  font-size: 0.88rem;
  font-family: inherit;
  min-width: 0;
}

.search-row input:focus {
  outline: none;
  box-shadow: var(--focus);
  border-color: var(--color-accent);
}

.mode-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.28rem;
  margin-top: 0.3rem;
}

.search-results {
  margin-top: 0.3rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  max-height: 7rem;
  overflow: auto;
  box-shadow: var(--shadow-sm);
}

.search-results button {
  display: block;
  width: 100%;
  text-align: right;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text);
  padding: 0.45rem 0.55rem;
  font-size: 0.82rem;
  font-family: inherit;
  cursor: pointer;
}

.search-results button:last-child { border-bottom: 0; }

/* —— Map-first —— */
.map-wrap {
  position: relative;
  flex: 1 1 auto;
  height: 68vh;
  min-height: var(--map-min);
  max-height: none;
}

@media (max-height: 720px) {
  :root { --map-min: 520px; }
  .map-wrap {
    height: 62vh;
    min-height: min(var(--map-min), 58vh);
  }
}

@media (min-height: 900px) {
  .map-wrap {
    height: 70vh;
    min-height: 650px;
  }
}

#map { width: 100%; height: 100%; }

.crosshair {
  pointer-events: none;
  position: absolute;
  left: 50%;
  top: 50%;
  width: 28px;
  height: 28px;
  margin: -14px 0 0 -14px;
  z-index: 450;
  border: 2px solid var(--color-primary);
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.9);
}

.crosshair::before,
.crosshair::after {
  content: "";
  position: absolute;
  background: var(--color-primary);
}
.crosshair::before {
  left: 50%;
  top: -8px;
  bottom: -8px;
  width: 2px;
  margin-left: -1px;
}
.crosshair::after {
  top: 50%;
  left: -8px;
  right: -8px;
  height: 2px;
  margin-top: -1px;
}

.imagery-notice {
  position: absolute;
  left: 0.55rem;
  right: 0.55rem;
  bottom: 0.55rem;
  z-index: 460;
  background: rgba(21, 35, 28, 0.88);
  color: #f7faf8;
  font-size: 0.75rem;
  line-height: 1.45;
  padding: 0.4rem 0.6rem;
  border-radius: 10px;
  text-align: center;
  pointer-events: none;
}

.fs-hud {
  position: absolute;
  inset: 0;
  z-index: 470;
  pointer-events: none;
}

.fs-hud .fs-area,
.fs-hud .fs-actions {
  pointer-events: auto;
}

.fs-area {
  position: absolute;
  top: 0.55rem;
  left: 0.55rem;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 0.35rem 0.55rem;
  box-shadow: var(--shadow-sm);
}

.fs-area span {
  display: block;
  font-size: 0.68rem;
  color: var(--color-muted);
}

.fs-area strong {
  font-size: 0.9rem;
  color: var(--color-primary-deep);
}

.fs-actions {
  position: absolute;
  bottom: 0.7rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 0.35rem;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  padding: 0.35rem;
  box-shadow: var(--shadow-md);
}

/* —— Bottom sheet —— */
.sheet {
  flex: 0 0 auto;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -6px 20px rgba(21, 35, 28, 0.06);
  padding: 0 0.65rem calc(0.55rem + env(safe-area-inset-bottom, 0));
  max-height: 38vh;
  overflow: hidden;
  z-index: 520;
}

.sheet.collapsed {
  max-height: none;
}

.sheet.collapsed .sheet-body {
  display: none;
}

.sheet.collapsed .metric-verts {
  display: none;
}

.sheet-handle {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  width: 100%;
  border: 0;
  background: transparent;
  padding: 0.35rem 0 0.2rem;
  cursor: pointer;
  font-family: inherit;
  color: var(--color-muted);
  font-size: 0.72rem;
}

.sheet-grip {
  width: 36px;
  height: 4px;
  border-radius: 999px;
  background: #c5d0c9;
}

.sheet-summary {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.35rem;
}

.sheet:not(.collapsed) .sheet-summary {
  grid-template-columns: 1fr 1fr 1fr 1fr;
}

.sheet-summary div {
  background: var(--color-primary-soft);
  border-radius: 8px;
  padding: 0.35rem 0.45rem;
}

.sheet-summary span {
  display: block;
  font-size: 0.68rem;
  color: var(--color-muted);
}

.sheet-summary strong {
  font-size: 0.88rem;
  color: var(--color-primary-deep);
}

.sheet-body {
  margin-top: 0.4rem;
  max-height: 28vh;
  overflow: auto;
  padding-bottom: 0.2rem;
}

.warn {
  margin: 0.35rem 0 0;
  color: var(--color-danger);
  font-size: 0.8rem;
}

.edge-list {
  list-style: none;
  margin: 0.4rem 0 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.edge-list li {
  font-size: 0.78rem;
  padding: 0.28rem 0.5rem;
  border-radius: 999px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  cursor: pointer;
  color: var(--color-text-secondary);
}

.edge-list li.front {
  background: #fff8e8;
  border-color: var(--color-front);
  color: #7a5208;
  font-weight: 600;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.45rem;
}

.btn {
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  border-radius: 8px;
  padding: 0.4rem 0.6rem;
  font-size: 0.82rem;
  font-family: inherit;
  cursor: pointer;
}

.btn.compact {
  padding: 0.32rem 0.5rem;
  font-size: 0.78rem;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn.primary,
.btn.success {
  background: var(--color-primary);
  border-color: var(--color-primary-dark);
  color: #fff;
  font-weight: 600;
}

.btn.success { background: var(--color-accent); border-color: var(--color-primary); }

.btn.danger {
  color: var(--color-danger);
  border-color: #f2c4c0;
  background: #fff5f4;
}

.btn.ghost {
  background: var(--color-bg);
}

.btn.chip {
  border-radius: 999px;
  padding: 0.22rem 0.55rem;
  font-size: 0.72rem;
  background: var(--color-bg);
}

.btn.chip.active {
  background: var(--color-primary-soft);
  border-color: var(--color-accent);
  color: var(--color-primary-dark);
  font-weight: 600;
}

.btn.chip:disabled {
  opacity: 0.35;
}

.disclaimer {
  margin: 0.45rem 0 0;
  font-size: 0.68rem;
  color: var(--color-muted);
  line-height: 1.5;
}

.result {
  position: absolute;
  inset: 0;
  z-index: 800;
  background: var(--color-bg);
  padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom, 0));
  overflow: auto;
}

.result h2 {
  margin: 0 0 0.75rem;
  color: var(--color-primary-deep);
  font-size: 1.15rem;
}

.result pre {
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 0.85rem;
  font-family: inherit;
  font-size: 0.88rem;
  line-height: 1.7;
  box-shadow: var(--shadow-sm);
}

.edge-label {
  background: rgba(255, 255, 255, 0.92);
  color: var(--color-primary-deep);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 1px 5px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
}

.edge-label.front {
  background: #fff3d4;
  border-color: var(--color-front);
  color: #7a5208;
}

/* Fullscreen map */
.app.fullscreen .brand-bar,
.app.fullscreen .map-toolbar {
  display: none;
}

.app.fullscreen .sheet {
  display: none;
}

.app.fullscreen .map-wrap {
  flex: 1;
  height: 100%;
  min-height: 100%;
}

.app.fullscreen #fsHud {
  display: block;
}

.gmap-edge-label {
  position: absolute;
  transform: translate(-50%, -50%);
  background: rgba(255, 255, 255, 0.94);
  color: #04452b;
  border: 1px solid #dce6e0;
  border-radius: 6px;
  padding: 1px 5px;
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font);
  white-space: nowrap;
  box-shadow: 0 1px 2px rgba(21, 35, 28, 0.08);
  pointer-events: none;
}

.gmap-edge-label.front {
  background: #fff3d4;
  border-color: #c9881a;
  color: #7a5208;
}
