:root {
  --navy: #0f2438;
  --navy-light: #1c3a57;
  --accent: #2e7d32;
  --accent-dark: #1b5e20;
  --brand-orange: #e8630a;
  --brand-orange-dark: #b94f08;
  --government: #8e27ad;
  --houthi: #0e6859;
  /* New (tracked) areas; mirrors NEW_GOV_STYLE / NEW_HOUTHI_STYLE in
     app.js. */
  --new-government: #c812ff;
  --new-government-border: #7a009c;
  --new-houthi: #01ffd5;
  --new-houthi-border: #00957c;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --border: #dfe4e8;
  --text: #1b2733;
  --text-muted: #5c6b78;
  --danger: #c0392b;
  --radius: 10px;
  --shadow: 0 2px 10px rgba(15, 36, 56, 0.08);
}

* { box-sizing: border-box; }

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

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

button { font-family: inherit; cursor: pointer; }

/* ---------- Password gate ---------- */

.gate {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, var(--navy) 0%, #0a1826 100%);
  padding: 16px;
  z-index: 50;
}

.gate[hidden] {
  display: none;
}

.gate-card {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
  padding: 40px 32px;
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.gate-logo {
  height: 56px;
  margin-bottom: 16px;
}

.gate-card h1 {
  font-size: 1.3rem;
  margin: 0 0 4px;
}

.gate-card h2 {
  font-size: 1rem;
  margin: 4px 0 10px;
}

.gate-subtitle {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin: 0 0 24px;
}

.gate-card input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  margin-bottom: 14px;
}

.gate-error {
  color: var(--danger);
  font-size: 0.85rem;
  margin: 12px 0 0;
}

/* "Is that you?" — the name is taken and this browser is new to it. */
.gate-device-warning {
  margin-top: 14px;
  padding: 14px;
  border-radius: 10px;
  background: #fff7ed;
  border: 1px solid #f5c08a;
  border-inline-start: 4px solid var(--brand-orange);
  text-align: start;
}
.gate-device-warning[hidden] { display: none; }
.gate-device-title {
  margin: 0 0 4px;
  font-weight: 700;
  color: var(--brand-orange-dark);
  font-size: 0.92rem;
}
.gate-device-text {
  margin: 0 0 12px;
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--text);
}
.gate-device-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.gate-device-actions .btn { width: 100%; }

/* Admin panel: each account's known devices. */
.user-devices {
  margin-top: 10px;
  border-top: 1px dashed var(--border);
  padding-top: 8px;
}
.user-devices-toggle { font-size: 0.75rem; }
.user-devices-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.user-devices-list[hidden] { display: none; }
.user-device {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  background: var(--bg);
  border-radius: 8px;
}
.user-device-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  fill: none;
  stroke: var(--text-muted);
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.user-device-info { flex: 1; min-width: 0; }
.user-device-label { font-size: 0.8rem; font-weight: 600; color: var(--text); }
.user-device-dates { font-size: 0.7rem; color: var(--text-muted); }
.user-devices-empty { font-size: 0.74rem; color: var(--text-muted); margin-top: 6px; }

.gate-links {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin: 14px 0 0;
}
.gate-links .link-btn { margin-inline-start: 0; }

.locale-switch { display: flex; gap: 4px; justify-content: center; margin-bottom: 12px; }
.locale-btn {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
}
.locale-btn.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.topbar .locale-switch { margin-bottom: 0; }
.topbar .locale-btn { background: transparent; border-color: rgba(255,255,255,0.25); color: #fff; }
.topbar .locale-btn.active { background: rgba(255,255,255,0.18); border-color: rgba(255,255,255,0.4); }

#gate-admin-fields[hidden], #gate-team-fields[hidden] { display: none; }

/* ---------- App shell ---------- */

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.app[hidden] {
  display: none;
}

.topbar {
  background: var(--navy);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  flex-wrap: wrap;
  gap: 10px;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  height: 36px;
}

.brand-text h1 {
  font-size: 1.05rem;
  margin: 0;
  font-weight: 700;
}

.brand-subtitle {
  font-size: 0.72rem;
  color: #b7c6d3;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.updated-info {
  font-size: 0.75rem;
  color: #b7c6d3;
  margin-inline-end: 6px;
}

.toolbar {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 10px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.edit-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
  max-width: 520px;
}

.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 0.85rem;
  font-weight: 600;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }

.btn-success { background: #1565c0; color: #fff; }
.btn-success:hover { background: #0d47a1; }

/* Same orange the measurement shapes are drawn in on the map — the button
   itself signals what color to look for once you start measuring. */
.btn-measure { background: var(--brand-orange); color: #fff; }
.btn-measure:hover { background: var(--brand-orange-dark); }
.btn-measure.active { background: var(--brand-orange-dark); box-shadow: inset 0 0 0 2px rgba(255,255,255,0.6); }

.btn-outline {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}
.btn-outline:hover { border-color: var(--navy); }

.btn-ghost {
  background: transparent;
  color: inherit;
  border-color: rgba(255,255,255,0.25);
}
.topbar .btn-ghost:hover { background: rgba(255,255,255,0.1); }

.btn-accent { background: var(--brand-orange); color: #fff; }
.btn-accent:hover { background: var(--brand-orange-dark); }

.btn-sm { padding: 6px 12px; font-size: 0.72rem; flex-shrink: 0; }

.btn-block { width: 100%; }

.gate-card .btn { font-size: 1rem; padding: 12px; }

/* ---------- Workspace ---------- */

.workspace {
  flex: 1;
  display: flex;
  min-height: 0;
  position: relative;
}

.sidebar {
  width: 300px;
  flex-shrink: 0;
  background: var(--panel);
  border-inline-end: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}

.sidebar-tab {
  flex: 1;
  border: none;
  background: transparent;
  padding: 12px 8px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
}

.sidebar-tab.active {
  color: var(--navy);
  border-bottom-color: var(--accent);
}

.pill {
  display: inline-block;
  background: var(--border);
  color: var(--text);
  border-radius: 10px;
  font-size: 0.68rem;
  padding: 1px 7px;
  margin-inline-start: 4px;
}

.sidebar-panel {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.sidebar-panel.active { display: flex; flex-direction: column; gap: 12px; }

.legend-item { display: block; }

.legend-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  cursor: pointer;
}

.swatch {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  display: inline-block;
  flex-shrink: 0;
  border: 1px solid rgba(0,0,0,0.15);
}

.swatch-government { background: var(--government); }
.swatch-houthi { background: var(--houthi); }
/* Same fill as the map, with the bold border. */
.swatch-new-government {
  background: var(--new-government);
  border: 2px solid var(--new-government-border);
}
.swatch-new-houthi {
  background: var(--new-houthi);
  border: 2px solid var(--new-houthi-border);
}
.swatch-frontlines {
  background: var(--danger);
  border-radius: 50%;
}
.swatch-governorates {
  background: transparent;
  border: 2px solid #1257c7;
}

.point-groups-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 8px;
  padding-inline-start: 4px;
  border-inline-start: 2px solid var(--border);
}

.point-group-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-block: 4px;
  padding-inline-start: 8px;
}

.point-group-row .legend-toggle {
  flex: 1;
  min-width: 0;
  font-size: 0.8rem;
}
.point-group-row .legend-toggle span:not(.swatch) {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.point-group-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

/* "Frontlines" title above the per-governorate toggles, with the admin
   download and "+" buttons. */
.frontlines-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  font-size: 0.85rem;
}
.frontlines-header[hidden] { display: none; }
.frontlines-header-title { flex: 1; font-weight: 600; }
.frontlines-header + .point-groups-list { margin-top: 4px; }
.frontline-header-btn {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  color: var(--navy);
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
}
.frontline-header-btn:hover { border-color: var(--navy); background: #eef3f7; }
.frontline-header-btn[hidden] { display: none; }

.sidebar-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

.opacity-label {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.sidebar-help {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.zone-context {
  background: #eef3f7;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.78rem;
}

.link-btn {
  background: none;
  border: none;
  color: #1565c0;
  font-size: 0.75rem;
  padding: 0;
  margin-inline-start: 6px;
  text-decoration: underline;
}

.notes-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.note-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.82rem;
  background: #fbfcfd;
}

.note-card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.author-badge {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--navy);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 700;
  flex-shrink: 0;
}

.note-author-name {
  font-weight: 700;
  font-size: 0.78rem;
  color: var(--text);
}

.note-time {
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-inline-start: auto;
  white-space: nowrap;
}

.note-card-zone {
  display: inline-block;
  font-size: 0.68rem;
  color: var(--navy);
  background: #eef3f7;
  border-radius: 6px;
  padding: 1px 6px;
  margin-bottom: 4px;
}

.note-card-text { white-space: pre-wrap; word-break: break-word; }

.note-delete {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.7rem;
  text-decoration: underline;
  padding: 0;
  margin-top: 6px;
}
.note-delete:hover { color: var(--danger); }

.notes-empty {
  color: var(--text-muted);
  font-size: 0.8rem;
  text-align: center;
  padding: 20px 0;
}

.history-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fbfcfd;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-card-top {
  display: flex;
  align-items: center;
  gap: 10px;
}

.history-card-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.history-card-actions .btn-outline-danger {
  background: transparent;
  border-color: var(--border);
  color: var(--danger);
}
.history-card-actions .btn-outline-danger:hover { border-color: var(--danger); background: rgba(192,57,43,0.08); }

.history-card-info {
  flex: 1;
  min-width: 0;
}

.history-card-change {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 2px;
}
.history-card-action {
  font-size: 0.74rem;
  color: var(--text);
  margin-top: 3px;
}

.map-wrap {
  flex: 1;
  position: relative;
}

#map {
  position: absolute;
  inset: 0;
}

/* Floating banner shown while a Records "Show" diff overlay is active. */
.diff-banner {
  position: absolute;
  /* Below the place-search bar, which sits along the top of the map. */
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 900;
  background: var(--navy);
  color: #fff;
  padding: 9px 14px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.82rem;
  max-width: calc(100% - 32px);
}
.diff-banner[hidden] { display: none; }
.diff-banner-close {
  border: none;
  background: rgba(255,255,255,0.15);
  color: #fff;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  flex-shrink: 0;
  font-size: 1rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.diff-banner-close:hover { background: rgba(255,255,255,0.3); }

/* Floating panel shown while the Measure tool is active. */
.measure-panel {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 900;
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px;
  width: 220px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.measure-panel[hidden] { display: none; }
.measure-panel-modes {
  display: flex;
  gap: 6px;
}
.measure-panel-modes .btn { flex: 1; }
.measure-panel-modes .btn.active {
  background: var(--brand-orange);
  color: #fff;
  border-color: transparent;
}
.measure-result {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--navy);
  min-height: 1.2em;
}
.measure-panel-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.measure-panel-actions .diff-banner-close {
  background: var(--border);
  color: var(--text-muted);
}
.measure-panel-actions .diff-banner-close:hover { background: #cfd6db; }

/* Leaflet's own popup chrome is quite generic and its default content
   margin eats a big, asymmetric chunk out of whatever maxWidth is set —
   this is what made popups feel cramped. Override with the app's own
   spacing/radius so popups read as part of the same design system as
   everything else, not a separate default-styled widget. */
.leaflet-popup-content-wrapper {
  border-radius: var(--radius);
}
.note-popup .leaflet-popup-content-wrapper {
  box-shadow: 0 10px 30px rgba(15, 36, 56, 0.22);
}
.note-popup .leaflet-popup-content {
  margin: 16px;
  text-align: start;
}

/* Popup styling for zone info */
.zone-popup h3 {
  margin: 0 0 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  font-size: 1rem;
  font-weight: 700;
  color: var(--navy);
}
.zone-popup .zone-popup-force {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.zone-popup button {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 0.78rem;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.zone-popup button.btn-accent {
  background: var(--brand-orange);
  color: #fff;
  border-color: transparent;
  width: 100%;
  padding: 9px 10px;
  font-weight: 600;
  font-size: 0.85rem;
}
.zone-popup button.btn-accent:hover { background: var(--brand-orange-dark); }

.quick-note-textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  font-family: inherit;
  font-size: 0.85rem;
  line-height: 1.4;
  resize: vertical;
  margin-bottom: 10px;
  box-sizing: border-box;
  transition: border-color 0.15s ease;
}
.quick-note-textarea:focus {
  outline: none;
  border-color: var(--brand-orange);
}

.zone-popup-links {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}
.zone-popup-links button {
  border: none;
  background: none;
  padding: 0;
  color: #1565c0;
  text-decoration: underline;
  font-size: 0.75rem;
}

/* ---------- New-area details ---------- */

/* Who/when card at the top of the map-click popup on a new area, with a
   side-colored accent edge. */
.change-label {
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(15, 36, 56, 0.12);
  border-inline-start: 4px solid var(--new-houthi);
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(15, 36, 56, 0.18);
  padding: 5px 9px 6px;
  white-space: nowrap;
  text-align: start;
  line-height: 1.3;
  font-family: inherit;
}
.change-label-government { border-inline-start-color: var(--new-government); }
.change-label-title {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}
.change-label-houthi .change-label-title { color: var(--new-houthi-border); }
.change-label-government .change-label-title { color: var(--new-government-border); }
.change-label-when {
  font-size: 0.68rem;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.change-label-who {
  font-size: 0.66rem;
  color: var(--text-muted);
}

/* Top of the map-click popup when the click lands in a new area. */
.change-details {
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.change-details .change-label {
  box-shadow: none;
  white-space: normal;
}
.change-details-edited {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 6px;
}
.change-details-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}
.zone-popup .change-details-actions button.btn-danger-text {
  color: var(--danger);
  border-color: rgba(192, 57, 43, 0.35);
}

/* Admin popup on a frontline point: details, then an edit form. */
.frontline-names {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 10px;
  margin: 0 0 8px;
  font-size: 0.8rem;
}
.frontline-names dt { color: var(--text-muted); }
.frontline-names dd { margin: 0; }
.frontline-form label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.75rem;
  color: var(--text-muted);
}
.frontline-form input {
  display: block;
  width: 100%;
  box-sizing: border-box;
  margin-top: 3px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 9px;
  font: inherit;
  font-size: 0.85rem;
  color: var(--text);
}
.frontline-form input:focus { outline: none; border-color: var(--brand-orange); }
.frontline-form .change-details-actions button.btn-accent { width: auto; flex: 1; }
.frontline-moving { cursor: move; }
.frontline-moving .point-marker-dot { box-shadow: 0 0 0 4px rgba(192, 57, 43, 0.35); }

/* Add-a-frontline-point dialog (#frontline-add-modal). */
.frontline-add-field { margin-bottom: 12px; }
.frontline-add-card .coord-field input,
.frontline-add-card select {
  width: 100%;
  box-sizing: border-box;
  margin: 0;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 400;
  color: var(--text);
  background: var(--panel);
}
.frontline-add-card .coord-field input[dir="rtl"] { text-align: right; }
.frontline-add-card select:focus { outline: none; border-color: var(--navy-light); }
.frontline-add-location-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.frontline-add-modes {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin-bottom: 10px;
  font-size: 0.82rem;
}
.frontline-add-modes label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.frontline-add-pick { display: flex; align-items: center; gap: 10px; }
.frontline-add-pick[hidden], #frontline-add-type-fields[hidden] { display: none; }
.frontline-add-picked {
  flex: 1;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.frontline-add-error {
  margin: 0 0 12px !important;
  color: var(--danger) !important;
  font-size: 0.8rem !important;
}
.frontline-picking, .frontline-picking .leaflet-interactive { cursor: crosshair !important; }

/* Map rotation: compass (needle always points north; click = north-up,
   drag = rotate) between rotate-left/right buttons, under the zoom. */
.compass-control {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  background: #fff;
  overflow: hidden;
}
.compass-control .compass-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 30px;
  padding: 0;
  border: none;
  border-bottom: 1px solid #ccc;
  background: #fff;
  color: var(--navy);
  cursor: pointer;
}
.compass-control .compass-btn:last-child { border-bottom: none; }
.compass-control .compass-btn:hover:not(:disabled) { background: #f4f6f8; }
.compass-control .compass-btn:focus-visible { outline: 2px solid var(--brand-orange); outline-offset: -2px; }
.compass-control .compass-reset { height: 44px; cursor: grab; touch-action: none; }
.compass-control .compass-reset:active { cursor: grabbing; }
.compass-rose { display: block; transform-origin: 50% 50%; }
.compass-ring { fill: #fff; stroke: #c9d2db; stroke-width: 1.5; }
.compass-north { fill: #c0392b; }
.compass-south { fill: #9aa7b4; }
.compass-hub { fill: #fff; stroke: #5d6d7e; stroke-width: 1; }
.compass-n {
  font: 800 9px/1 system-ui, sans-serif;
  fill: #c0392b;
  pointer-events: none;
}
.compass-control.is-rotated .compass-ring { stroke: var(--brand-orange); stroke-width: 2; }
.compass-control.is-locked .compass-btn { cursor: not-allowed; opacity: 0.45; }
.compass-control.is-locked .compass-btn:hover { background: #fff; }

/* Floating bar while a saved new area is being reshaped. */
.shape-edit-bar {
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 900;
  background: var(--navy);
  color: #fff;
  padding: 9px 12px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.82rem;
  max-width: calc(100% - 32px);
}
.shape-edit-bar[hidden] { display: none; }
.shape-edit-bar .btn-outline {
  background: transparent;
  color: #fff;
  border-color: rgba(255, 255, 255, 0.5);
}
.shape-edit-bar .btn-outline:hover { background: rgba(255, 255, 255, 0.12); }
@media (max-width: 640px) {
  .shape-edit-bar { flex-wrap: wrap; justify-content: center; text-align: center; }
}

/* ---------- Who's online (toolbar avatars) ---------- */

.presence-bar {
  display: flex;
  align-items: center;
  padding-inline-start: 6px;
}
.presence-bar[hidden] { display: none; }
.presence-avatar-btn {
  border: none;
  background: none;
  padding: 0;
  border-radius: 50%;
  margin-inline-start: -6px; /* slight overlap, like a stack */
  transition: transform 0.12s ease;
}
.presence-avatar-btn:first-child { margin-inline-start: 0; }
.presence-avatar-btn:hover,
.presence-avatar-btn:focus-visible { transform: translateY(-2px); z-index: 1; }
.presence-avatar {
  position: relative;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--avatar-color);
  color: #fff;
  font-weight: 700;
  font-size: 0.9rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--panel);
  box-shadow: 0 1px 3px rgba(15, 36, 56, 0.25);
  flex-shrink: 0;
}
.presence-avatar-lg { width: 44px; height: 44px; font-size: 1.1rem; }
.presence-me { box-shadow: 0 0 0 2px var(--navy), 0 1px 3px rgba(15, 36, 56, 0.25); }
.presence-idle { filter: grayscale(0.7); opacity: 0.55; }
.presence-dot {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 2px solid var(--panel);
  background: #2e9d4f; /* active */
}
.presence-editing .presence-dot { background: var(--brand-orange); }
.presence-idle .presence-dot { background: #9aa5af; }
.presence-more {
  width: 34px;
  height: 34px;
  background: var(--bg);
  border: 2px solid var(--panel);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 700;
  box-shadow: 0 1px 3px rgba(15, 36, 56, 0.2);
}

.presence-popover {
  position: fixed;
  z-index: 1200;
  width: 270px;
  max-width: calc(100vw - 16px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(15, 36, 56, 0.22);
  padding: 14px;
}
.presence-popover[hidden] { display: none; }
.presence-card-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 10px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.presence-card-who { min-width: 0; }
.presence-card-name {
  font-weight: 700;
  color: var(--navy);
  font-size: 0.95rem;
  overflow-wrap: anywhere;
}
.presence-you-tag {
  font-size: 0.66rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  margin-inline-start: 6px;
  vertical-align: middle;
}
.presence-card-role { font-size: 0.74rem; color: var(--text-muted); margin-top: 2px; }
.presence-detail { font-size: 0.8rem; color: var(--text); margin-top: 6px; }
.presence-status { display: flex; align-items: center; gap: 7px; font-weight: 600; }
.presence-status::before {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #2e9d4f;
  flex-shrink: 0;
}
.presence-status-editing::before { background: var(--brand-orange); }
.presence-status-idle::before { background: #9aa5af; }
.presence-muted { color: var(--text-muted); font-size: 0.74rem; }
.presence-locate { width: 100%; margin-top: 12px; }
.presence-card-title {
  font-weight: 700;
  color: var(--navy);
  font-size: 0.85rem;
  margin-bottom: 8px;
}
.presence-list-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: none;
  background: none;
  padding: 6px;
  border-radius: 8px;
  text-align: start;
  font: inherit;
}
.presence-list-row:hover { background: var(--bg); }
.presence-list-text { display: flex; flex-direction: column; min-width: 0; }
.presence-list-name { font-size: 0.82rem; font-weight: 600; color: var(--text); }
.presence-list-status { font-size: 0.72rem; color: var(--text-muted); }

/* ---------- Basemap switch (bottom-left of the map) ---------- */

.basemap-switch {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--panel);
  border-radius: 10px !important;
}
.basemap-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  border: 2px solid transparent;
  border-radius: 8px;
  background: none;
  padding: 3px 3px 4px;
  font: inherit;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}
.basemap-btn:hover { background: var(--bg); }
.basemap-btn.active { border-color: var(--brand-orange); color: var(--navy); }
.basemap-thumb {
  width: 52px;
  height: 36px;
  border-radius: 5px;
  border: 1px solid rgba(15, 36, 56, 0.15);
}
/* Little stylized previews, so the choice reads at a glance. */
.basemap-btn-osm .basemap-thumb {
  background:
    linear-gradient(115deg, transparent 46%, #f7d26b 46% 54%, transparent 54%),
    linear-gradient(20deg, transparent 60%, #ffffff 60% 66%, transparent 66%),
    linear-gradient(160deg, #cfe6c3 0 35%, #f2efe9 35% 70%, #aad3df 70%);
}
.basemap-btn-hybrid .basemap-thumb {
  background:
    linear-gradient(115deg, transparent 47%, rgba(255, 220, 120, 0.9) 47% 52%, transparent 52%),
    radial-gradient(circle at 30% 35%, #6f7b4a 0 22%, transparent 23%),
    linear-gradient(160deg, #4d5a33 0 40%, #8a7a58 40% 72%, #2f4a5c 72%);
}

/* ---------- Live cursors ---------- */

/* Zero-sized marker at the exact point; the arrow's tip sits on it and
   the name tag trails just below-right, in that editor's color. Always
   left-to-right, like a real pointer, even in the Arabic layout. */
.remote-cursor-marker { width: 0; height: 0; }
.remote-cursor {
  position: absolute;
  left: -2px;
  top: -2px;
  color: var(--cursor-color);
  direction: ltr;
  pointer-events: none;
  transition: opacity 0.4s ease;
}
.remote-cursor svg {
  width: 20px;
  height: 22px;
  display: block;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.35));
}
.remote-cursor-name {
  position: absolute;
  left: 14px;
  top: 18px;
  background: var(--cursor-color);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1;
  padding: 4px 7px;
  border-radius: 4px 9px 9px 9px;
  white-space: nowrap;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}
/* Smooth the ~15/s position updates — but not while Leaflet animates a
   zoom, when the transition would make cursors swim. */
.leaflet-cursors-pane .remote-cursor-marker { transition: transform 0.08s linear; }
.leaflet-zoom-anim .leaflet-cursors-pane .remote-cursor-marker { transition: none; }
.remote-cursor-idle .remote-cursor { opacity: 0.35; }

.swatch-cursor {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  fill: var(--navy);
}

/* ---------- Place search ---------- */

/* Floats over the top of the map, just right of Leaflet's zoom buttons
   (which stay on the left in both LTR and RTL). */
.place-search {
  position: absolute;
  top: 10px;
  left: 56px;
  z-index: 950;
  width: min(360px, calc(100% - 70px));
}
.place-search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(15, 36, 56, 0.16);
  padding: 0 8px 0 12px;
  height: 42px;
}
.place-search-bar:focus-within { border-color: var(--navy-light); }
.place-search-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  fill: none;
  stroke: var(--text-muted);
  stroke-width: 2;
  stroke-linecap: round;
}
.place-search-bar input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  font: inherit;
  font-size: 0.88rem;
  color: var(--text);
}
.place-search-bar input::-webkit-search-cancel-button { display: none; }
.place-search-clear {
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 1.25rem;
  line-height: 1;
  width: 28px;
  height: 28px;
  border-radius: 50%;
}
.place-search-clear:hover { background: var(--bg); }
.place-search-clear[hidden] { display: none; }
.place-search-divider {
  width: 1px;
  height: 22px;
  background: var(--border);
  flex-shrink: 0;
}
.place-search-coord-btn {
  border: none;
  background: none;
  width: 32px;
  height: 32px;
  border-radius: 7px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.place-search-coord-btn svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: var(--text-muted);
  stroke-width: 2;
  stroke-linecap: round;
}
.place-search-coord-btn svg .fill { fill: var(--text-muted); stroke: none; }
.place-search-coord-btn:hover,
.place-search-coord-btn.active { background: var(--bg); }
.place-search-coord-btn.active svg { stroke: var(--brand-orange); }
.place-search-coord-btn.active svg .fill { fill: var(--brand-orange); }

.coord-panel {
  margin-top: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 6px 20px rgba(15, 36, 56, 0.18);
  padding: 12px;
}
.coord-panel[hidden] { display: none; }
.coord-panel-title {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 10px;
}
.coord-fields { display: flex; gap: 8px; }
.coord-field {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
}
.coord-field input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 8px 10px;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 400;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  text-align: left;
}
.coord-field input:focus { outline: none; border-color: var(--navy-light); }
.coord-field input[aria-invalid="true"] { border-color: var(--danger); }
.coord-hint {
  margin: 8px 0 0;
  font-size: 0.7rem;
  color: var(--text-muted);
}
.coord-error {
  margin-top: 8px;
  font-size: 0.74rem;
  color: var(--danger);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
}
.coord-error[hidden] { display: none; }
.coord-error .link-btn { font-size: 0.74rem; }
.coord-submit { width: 100%; margin-top: 10px; }

.place-search-results {
  margin-top: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 6px 20px rgba(15, 36, 56, 0.18);
  max-height: min(360px, 50vh);
  overflow-y: auto;
  padding: 4px;
}
.place-search-results[hidden] { display: none; }
.place-search-result {
  display: block;
  width: 100%;
  border: none;
  background: none;
  text-align: start;
  padding: 9px 10px;
  border-radius: 7px;
  font: inherit;
  color: var(--text);
}
.place-search-result:hover,
.place-search-result.active { background: var(--bg); }
.place-search-result-name {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  font-weight: 600;
}
.place-search-result-type {
  font-size: 0.66rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  text-transform: capitalize;
}
.place-search-result-address {
  font-size: 0.74rem;
  color: var(--text-muted);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.place-search-status {
  padding: 10px 12px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Search-result marker: a navy pin with an orange core, and a soft pulse
   on the exact point it marks. */
.search-pin-marker { width: 0; height: 0; }
.search-pin {
  position: absolute;
  left: -17px;
  top: -46px;
  width: 34px;
  height: 46px;
  filter: drop-shadow(0 3px 4px rgba(15, 36, 56, 0.35));
}
.search-pin svg { width: 100%; height: 100%; display: block; }
.search-pin-pulse {
  position: absolute;
  left: -9px;
  top: -9px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(232, 99, 10, 0.35);
  animation: search-pin-pulse 2s ease-out infinite;
}
@keyframes search-pin-pulse {
  0% { transform: scale(0.4); opacity: 0.9; }
  100% { transform: scale(2.6); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .search-pin-pulse { animation: none; }
}

.search-popup h3 {
  margin: 0 0 4px;
  font-size: 0.95rem;
  color: var(--navy);
}
.search-popup-address {
  font-size: 0.76rem;
  color: var(--text-muted);
  line-height: 1.4;
  margin-bottom: 8px;
}
.search-popup-coords {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.76rem;
  font-variant-numeric: tabular-nums;
  background: var(--bg);
  border-radius: 6px;
  padding: 6px 8px;
  margin-bottom: 8px;
  direction: ltr;
}
.search-popup-coords span { flex: 1; }
.search-popup-private {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.zone-popup .search-popup-remove {
  width: 100%;
  color: var(--danger);
  border-color: rgba(192, 57, 43, 0.35);
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--navy);
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 0.85rem;
  box-shadow: var(--shadow);
  /* Above the mobile bottom-sheet sidebar (z-index 1200) so a toast fired
     while it's expanded (e.g. after saving a note) is still visible. */
  z-index: 1300;
}
.toast.error { background: var(--danger); }

/* ---------- Confirm modal (replaces browser confirm()) ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 36, 56, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  /* Same reasoning as .toast above — must clear the mobile bottom sheet. */
  z-index: 1300;
  padding: 16px;
  transform: translateZ(0);
}

.modal-overlay[hidden] { display: none; }

/* Native <dialog> version (main dashboard's confirm/prompt): the browser
   centers it and draws it in the top layer, above the map; the card
   styling stays the same as .modal-overlay's. */
.modal-dialog {
  border: none;
  padding: 0;
  background: transparent;
  width: min(380px, calc(100% - 32px));
  max-width: none;
  overflow: visible;
}
.modal-dialog::backdrop { background: rgba(15, 36, 56, 0.55); }
.modal-dialog .modal-card { width: 100%; }

.modal-card {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
  padding: 24px;
  width: 100%;
  max-width: 380px;
}

.modal-card h2 {
  margin: 0 0 8px;
  font-size: 1.05rem;
}

/* Confirm dialog in warning mode (showConfirm({ warning: true })). */
.modal-warning .modal-card { border-top: 4px solid var(--danger); }
.modal-warning h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--danger);
}
.modal-warning h2::before {
  content: "!";
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.modal-card p {
  margin: 0 0 20px;
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.modal-actions .btn { padding: 8px 16px; }

.modal-card input[type="text"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  margin-bottom: 18px;
  font-family: inherit;
}

.modal-card-wide { max-width: 620px; }

/* ---------- Admin page ---------- */

.admin-shell {
  max-width: 720px;
  margin: 24px auto;
  padding: 0 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.admin-shell[hidden] { display: none; }
.admin-shell .modal-card-wide {
  max-width: none;
  width: 100%;
  box-shadow: var(--shadow);
}
.admin-shell h2 { font-size: 1.1rem; }
.admin-shell .field-row { align-items: flex-end; flex-wrap: wrap; }
.admin-shell .field-row > input,
.admin-shell .field-row > select { flex: 1 1 160px; }

/* "Add an admin account" + "Change the shared password": two equal cards
   side by side, stacked on narrow screens. */
.admin-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
}
@media (max-width: 760px) {
  .admin-grid { grid-template-columns: 1fr; }
}
.admin-form-card { display: flex; flex-direction: column; }
.admin-form-card .modal-hint { margin-bottom: 16px; line-height: 1.5; }
.admin-form {
  display: flex;
  flex-direction: column;
  flex: 1;
}
/* Fields keep their natural height (the generic .field-label grows to
   fill a row) and drop the generic text-input bottom margin, so spacing
   is even and any spare height goes above the button. */
.admin-form .field-label { flex: none; margin-bottom: 12px; }
.admin-form .field-label input { margin-bottom: 0; }
.admin-form .field-label input:focus {
  outline: none;
  border-color: var(--navy-light);
  box-shadow: 0 0 0 3px rgba(28, 58, 87, 0.12);
}
.admin-form .field-label input[aria-invalid="true"] { border-color: var(--danger); }
.admin-form-error {
  margin: 0 0 12px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(192, 57, 43, 0.08);
  color: var(--danger);
  font-size: 0.8rem;
}
.admin-form-error[hidden] { display: none; }
/* Pinned to the bottom so both cards' buttons line up even when their
   explanations wrap to different lengths. */
.admin-form-submit { margin-top: auto; width: 100%; }

.field-row {
  display: flex;
  gap: 12px;
  margin-bottom: 4px;
}

.field-label {
  display: block;
  flex: 1;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.field-label input,
.field-label select {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: inherit;
  font-weight: 400;
  color: var(--text);
  background: #fff;
}

.modal-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin: 0 0 12px;
}

/* ---------- "Download image" menu ---------- */

.image-download-menu { padding: 6px; width: 300px; }
.image-download-menu button {
  display: block;
  width: 100%;
  text-align: start;
  background: none;
  border: none;
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
}
.image-download-menu button:hover,
.image-download-menu button:focus-visible { background: var(--bg); outline: none; }
.image-download-menu strong { display: block; font-size: 0.85rem; color: var(--navy); }
.image-download-menu span { display: block; font-size: 0.74rem; color: var(--text-muted); margin-top: 2px; }

/* "New areas from a period" dialog (#period-download-modal), shared by the shapefile and PSD downloads. */
.period-download-intro { font-size: 0.82rem; color: var(--text-muted); margin: 0 0 14px; line-height: 1.5; }
.period-download-summary { font-size: 0.8rem; color: var(--navy); margin: 0 0 10px; }
.period-download-summary:empty { display: none; }

/* ---------- Note options and badge ---------- */

.note-option {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--text);
  margin: 0 0 8px;
  cursor: pointer;
}
.note-option input { margin: 0; flex-shrink: 0; }

.note-private-badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg);
  border-radius: 4px;
  padding: 1px 6px;
  margin: 4px 0 2px;
}

/* ---------- Point markers ---------- */

.point-marker {
  display: flex;
  align-items: center;
  gap: 5px;
  pointer-events: none;
  /* Always lay out dot-then-label, regardless of the page's text
     direction. Leaflet's iconAnchor (see pointMarkerIcon in app.js) is
     computed assuming the dot sits at the icon's left edge; under RTL,
     flexbox would otherwise visually reverse the row and move the dot to
     the right edge of this auto-sized (label-length-dependent) box,
     while the anchor offset stayed fixed — the marker's actual geographic
     point then drifted by a different, wrong amount for every label,
     which is what looked like "unstable" placement in Arabic. */
  direction: ltr;
}

.point-marker-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--navy);
  border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.5);
  flex-shrink: 0;
  pointer-events: auto;
}

.point-marker-label {
  /* White text with a black outline and no box, so it reads over any
     zone color or basemap without hiding what's underneath. */
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  text-shadow:
    -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000,
    -1px 0 0 #000, 1px 0 0 #000, 0 -1px 0 #000, 0 1px 0 #000;
  white-space: nowrap;
  pointer-events: auto;
}

/* Below POINT_LABEL_MIN_ZOOM (app.js) only the dots are shown. */
.point-labels-hidden .point-marker-label { display: none; }

/* ---------- Reference boundary labels (governorates) ---------- */
/* Permanent Leaflet tooltips, bound to an invisible marker rather than the
   polygon itself (see bindBoundaryLabel in app.js) — stripped of the
   library's default tooltip chrome (background/border/arrow) in favor of a
   plain text-shadow halo, so the label reads over any fill color beneath it
   without competing visually with the note/point markers. */
.leaflet-tooltip.boundary-label {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0;
  pointer-events: none;
  white-space: nowrap;
}

.leaflet-tooltip.boundary-label-governorate {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: #1c2733;
  text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 5px #fff, 0 1px 2px rgba(0,0,0,0.25);
}

/* White halo around the boundary line itself (see GOVERNORATE_BOUNDARY_STYLE
   in app.js) — stacking several zero-offset drop-shadows reads as a solid
   halo, the same trick the label above uses with text-shadow, so a thin
   line still stands out crossing OSM's own roads/admin-boundary lines
   instead of blending into them. */
.boundary-line-governorate {
  filter: drop-shadow(0 0 1.5px #fff) drop-shadow(0 0 1.5px #fff) drop-shadow(0 0 1.5px #fff);
}

/* ---------- Draw-tool attention pulse ---------- */
/* When "Start Editing"/"Suggest an edit" is clicked, Leaflet-Geoman injects
   its own draw-tool button (top-left of the map, .leaflet-pm-toolbar) fresh
   into the DOM each time — a small, easy-to-miss icon for anyone who
   hasn't used the tool before. Pulsing it a few times draws the eye there
   without needing to touch Geoman's own markup. Stops automatically once
   the tool is actually activated (Geoman adds .active to the button's
   container at that point) or after a few pulses, whichever comes first —
   a one-time cue, not a nag. */
@keyframes pm-draw-tool-pulse {
  0% { box-shadow: 0 0 0 0 rgba(46, 125, 50, 0.65); transform: scale(1); }
  50% { box-shadow: 0 0 0 9px rgba(46, 125, 50, 0); transform: scale(1.12); }
  100% { box-shadow: 0 0 0 0 rgba(46, 125, 50, 0); transform: scale(1); }
}
.leaflet-pm-toolbar a.leaflet-buttons-control-button:has(.leaflet-pm-icon-polygon) {
  border-radius: 4px;
  animation: pm-draw-tool-pulse 1.1s ease-in-out 3;
}
.leaflet-pm-toolbar .button-container.active a.leaflet-buttons-control-button:has(.leaflet-pm-icon-polygon) {
  animation: none;
}

/* Icon for the "curved area" draw tool (see addCurvedAreaControl in
   app.js): a closed curvy outline with a few dots on it, in the same dark
   line style as Geoman's own polygon icon. */
.leaflet-pm-toolbar .leaflet-pm-icon-curve {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23333' stroke-width='2' stroke-linejoin='round'%3E%3Cpath d='M5 13C3 8 8 3 13 5s8 4 6 9-6 6-9 5-4-3-5-6z'/%3E%3Ccircle cx='5' cy='13' r='1.6' fill='%23333'/%3E%3Ccircle cx='13' cy='5' r='1.6' fill='%23333'/%3E%3Ccircle cx='19' cy='14' r='1.6' fill='%23333'/%3E%3C/svg%3E");
}

/* ---------- Responsive ---------- */

/* Tablets (portrait iPad and similar, ~600-1024px): keep the desktop
   side-by-side layout — there's room for it — just trim the sidebar a
   little and tighten spacing so more of the map stays visible. */
@media (max-width: 1024px) {
  .sidebar { width: 280px; }
  .topbar { padding: 8px 14px; }
  .toolbar { padding: 8px 14px; }
  .leaflet-touch .leaflet-bar a { width: 32px; height: 32px; line-height: 32px; }
}

/* Phones (~680px and below): the sidebar sits above the map (same
   document order as tablet/desktop, just stacked instead of side by
   side) and collapses to just its tab strip by default, so the map gets
   most of the screen instead of losing 42% of it to a panel nobody
   opened yet. Deliberately kept in normal document flow rather than
   position:fixed/absolute — those anchor against the *layout* viewport,
   which on phones (Safari's collapsing address bar especially) can be
   taller than what's actually on screen, silently pushing a
   bottom/top-anchored panel below the fold. Plain flexbox has no such
   failure mode: the browser can't get "how much space is left" wrong.
   Every touch target also grows a bit. */
@media (max-width: 680px) {
  .workspace { flex-direction: column; }
  .sidebar {
    width: 100%;
    flex-shrink: 0;
    border-inline-end: none;
    border-bottom: 1px solid var(--border);
  }
  .sidebar:not(.collapsed) {
    max-height: 55vh;
    max-height: 55dvh;
  }
  .sidebar::before {
    content: "";
    display: block;
    flex-shrink: 0;
    width: 36px;
    height: 4px;
    margin: 8px auto 0;
    background: var(--border);
    border-radius: 2px;
  }
  .sidebar.collapsed .sidebar-panel { display: none !important; }

  .brand-subtitle { display: none; }
  .edit-hint { display: none; }

  .topbar-brand { gap: 8px; }
  .brand-logo { height: 28px; }
  .brand-text h1 { font-size: 0.92rem; }

  .toolbar { gap: 8px; }
  .toolbar-group { gap: 8px; }

  .btn { padding: 10px 14px; font-size: 0.85rem; }
  .btn-sm { padding: 8px 12px; }

  .sidebar-tab { padding: 12px 6px; font-size: 0.78rem; }

  .field-row { flex-direction: column; gap: 0; }

  .modal-card { padding: 20px; max-height: 88vh; overflow-y: auto; }

  .legend-toggle { font-size: 0.82rem; }

  .place-search { left: 52px; width: calc(100% - 62px); }
  .measure-panel { top: 62px; }

  /* Leaflet's default zoom buttons (~26px) are cramped for touch. */
  .leaflet-touch .leaflet-bar a { width: 34px; height: 34px; line-height: 34px; }
}

@media (max-width: 400px) {
  .updated-info { display: none; }
  .brand-text h1 { font-size: 0.85rem; }
}
