:root {
  --primary: #0d47a1;
  --primary-light: #1976d2;
  --surface: #ffffff;
  --danger: #c62828;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, "Segoe UI", Roboto, "Heebo", Arial, sans-serif;
  direction: rtl;
  overscroll-behavior: none;
  touch-action: manipulation;
}

#map { position: fixed; inset: 0; z-index: 0; background: #dde5ee; }

/* ---------- סרגל עליון ---------- */
#topbar {
  position: fixed;
  top: env(safe-area-inset-top, 0px);
  right: 0; left: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  pointer-events: none;
}
#topbar .chip {
  pointer-events: auto;
  background: var(--surface);
  border: none;
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 9px 14px;
  font-size: 14px;
  font-weight: 600;
  color: #222;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  white-space: nowrap;
}
#topbar .chip svg { width: 18px; height: 18px; flex: none; }
#title-chip { background: var(--primary); color: #fff; }

/* ---------- כפתורים צפים ---------- */
#fabs {
  position: fixed;
  bottom: calc(20px + var(--safe-bottom));
  left: 16px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.fab {
  width: 54px; height: 54px;
  border-radius: 50%;
  border: none;
  background: var(--surface);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #333;
}
.fab.primary { background: var(--primary); color: #fff; }
.fab svg { width: 24px; height: 24px; }
.fab.active { background: var(--primary-light); color: #fff; }

/* ---------- פאנלים (bottom sheet) ---------- */
.panel {
  position: fixed;
  bottom: 0; right: 0; left: 0;
  z-index: 1200;
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.3);
  max-height: 72vh;
  display: none;
  flex-direction: column;
  padding-bottom: var(--safe-bottom);
}
.panel.open { display: flex; }
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px 10px;
  border-bottom: 1px solid #eee;
}
.panel-header h2 { font-size: 17px; }
.panel-close {
  border: none; background: #f0f0f0; border-radius: 50%;
  width: 32px; height: 32px; font-size: 16px; cursor: pointer;
}
.panel-body { overflow-y: auto; padding: 12px 18px 18px; }

/* רשימת קבצים */
.file-item { border: 1px solid #e4e4e4; border-radius: var(--radius); padding: 12px; margin-bottom: 12px; }
.file-item .row { display: flex; align-items: center; gap: 10px; }
.file-item .name { font-weight: 700; font-size: 15px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-item .badge {
  font-size: 11px; padding: 3px 8px; border-radius: 10px;
  background: #e3f2fd; color: var(--primary); flex: none;
}
.file-item .badge.warn { background: #fff3e0; color: #e65100; }
.file-item .controls { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.file-item .controls button {
  border: 1px solid #d0d0d0; background: #fafafa; border-radius: 9px;
  padding: 7px 11px; font-size: 13px; cursor: pointer;
}
.file-item .controls button.danger { color: var(--danger); border-color: #f2c1c1; }
.file-item .opacity-row { display: flex; align-items: center; gap: 10px; margin-top: 10px; font-size: 13px; color: #555; }
.file-item input[type="range"] { flex: 1; direction: ltr; }
.dxf-sublayers { margin-top: 8px; }
.dxf-sublayers summary { font-size: 13px; color: #666; cursor: pointer; }
.dxf-sublayers label { display: flex; align-items: center; gap: 6px; font-size: 13px; padding: 4px 2px; }

/* בחירת מפת רקע */
.base-option {
  display: flex; align-items: center; gap: 10px;
  padding: 12px; border: 1px solid #e4e4e4; border-radius: var(--radius);
  margin-bottom: 8px; cursor: pointer; font-size: 15px;
}
.base-option.selected { border-color: var(--primary); background: #e8f1fd; font-weight: 700; }
.base-option .note { font-size: 12px; color: #888; font-weight: 400; }

/* הגדרות */
.settings-field { margin-bottom: 14px; }
.settings-field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; color: #444; }
.settings-field input, .settings-field textarea {
  width: 100%; border: 1px solid #ccc; border-radius: 9px;
  padding: 9px 11px; font-size: 14px; direction: ltr; text-align: left;
  font-family: ui-monospace, monospace;
}
.settings-field textarea { min-height: 84px; resize: vertical; }
.settings-help { font-size: 12.5px; color: #777; line-height: 1.5; margin-bottom: 14px; }
.btn-primary {
  background: var(--primary); color: #fff; border: none;
  border-radius: 10px; padding: 12px 18px; font-size: 15px; font-weight: 700;
  cursor: pointer; width: 100%;
}

/* ---------- באנר כיול ---------- */
#calibrate-banner {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 58px);
  right: 12px; left: 12px;
  z-index: 1100;
  background: #263238;
  color: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 16px;
  display: none;
  font-size: 14px;
  line-height: 1.5;
}
#calibrate-banner.open { display: block; }
#calibrate-banner .actions { margin-top: 8px; display: flex; gap: 8px; }
#calibrate-banner button {
  border: none; border-radius: 8px; padding: 7px 12px; font-size: 13px; cursor: pointer;
}

/* ---------- טוסט ---------- */
#toast {
  position: fixed;
  bottom: calc(96px + var(--safe-bottom));
  right: 50%;
  transform: translateX(50%);
  z-index: 2000;
  background: rgba(30, 30, 30, 0.92);
  color: #fff;
  padding: 11px 18px;
  border-radius: 24px;
  font-size: 14px;
  max-width: 86vw;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}
#toast.show { opacity: 1; }

/* ---------- טקסטים של DXF ---------- */
.dxf-text { pointer-events: none; }
.dxf-text span {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  text-shadow: 0 0 3px rgba(255, 255, 255, 0.9), 0 0 3px rgba(255, 255, 255, 0.9);
  direction: rtl;
}
.dark-base .dxf-text span { text-shadow: 0 0 3px rgba(0, 0, 0, 0.9), 0 0 3px rgba(0, 0, 0, 0.9); }
#map:not(.show-labels) .dxf-text { display: none; }

/* מיקום נוכחי */
.loc-dot {
  width: 16px; height: 16px; border-radius: 50%;
  background: #1a73e8; border: 3px solid #fff;
  box-shadow: 0 0 6px rgba(26, 115, 232, 0.9);
}

/* עיגון נקודת כיול */
.cal-pin {
  width: 22px; height: 22px; border-radius: 50%;
  background: #ff6d00; border: 3px solid #fff;
  box-shadow: var(--shadow);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 12px; font-weight: 800;
}

/* מסך פתיחה ריק */
#empty-hint {
  position: fixed;
  bottom: calc(100px + var(--safe-bottom));
  right: 50%;
  transform: translateX(50%);
  z-index: 900;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 20px;
  font-size: 14px;
  color: #444;
  text-align: center;
  max-width: 82vw;
  line-height: 1.6;
}
#empty-hint.hidden { display: none; }

#loading-overlay {
  position: fixed; inset: 0; z-index: 3000;
  background: rgba(255, 255, 255, 0.75);
  display: none;
  align-items: center; justify-content: center;
  flex-direction: column; gap: 14px;
  font-size: 15px; font-weight: 600; color: #333;
}
#loading-overlay.show { display: flex; }
.spinner {
  width: 44px; height: 44px;
  border: 5px solid #d3e3f8;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
