/* ── Reset & base ─────────────────────────────────────────────────────────── */

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

:root {
  --bg:         #0f1117;
  --bg-card:    #1a1d27;
  --bg-input:   #22263a;
  --border:     #2e3350;
  --accent:     #4fc3f7;
  --accent-2:   #0288d1;
  --success:    #2ecc71;
  --danger:     #e74c3c;
  --text:       #e0e4f0;
  --text-muted: #8890aa;
  --radius:     8px;
  --sidebar-w:  270px;
  --font:       'Inter', 'Segoe UI', system-ui, sans-serif;
}

html, body { height: 100%; font-family: var(--font); background: var(--bg); color: var(--text); overflow: hidden; }

/* ── Stage container ──────────────────────────────────────────────────────── */

.stage { position: fixed; inset: 0; display: flex; }
.hidden { display: none !important; }

/* ── STAGE: Address ───────────────────────────────────────────────────────── */

#stage-address {
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.address-card {
  width: 520px;
  max-width: 95vw;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 36px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--accent);
}

.logo h1 { font-size: 1.6rem; font-weight: 700; }
.logo svg { flex-shrink: 0; }

.subtitle { color: var(--text-muted); font-size: 0.92rem; }

.input-row { display: flex; gap: 8px; }

.input-row input, #address-input {
  flex: 1;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color .2s;
}
.input-row input:focus, #address-input:focus { border-color: var(--accent); }
.input-row input::placeholder, #address-input::placeholder { color: var(--text-muted); }

.options summary { cursor: pointer; font-size: 0.82rem; color: var(--text-muted); user-select: none; }
.options summary:hover { color: var(--text); }

.options-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px;
}
.options-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 0.78rem; color: var(--text-muted); }
.options-grid input, .options-grid select {
  padding: 6px 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text); font-size: 0.85rem; outline: none;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 9px 16px;
  border: none; border-radius: var(--radius);
  font-size: 0.88rem; font-weight: 600; cursor: pointer;
  transition: filter .15s, transform .1s;
  white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn:hover  { filter: brightness(1.15); }
.btn.full   { width: 100%; }

.btn-primary   { background: var(--accent-2); color: #fff; }
.btn-success   { background: var(--success);  color: #fff; }
.btn-secondary { background: var(--bg-input); color: var(--text); border: 1px solid var(--border); }

/* ── Loading / error ──────────────────────────────────────────────────────── */

.loading {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; background: var(--bg-input);
  border-radius: var(--radius); font-size: 0.85rem; color: var(--text-muted);
}

.spinner {
  width: 16px; height: 16px; flex-shrink: 0;
  border: 2px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-box {
  padding: 10px 12px;
  background: rgba(231,76,60,.15);
  border: 1px solid var(--danger);
  border-radius: var(--radius); font-size: 0.85rem; color: #ff8a80;
  word-break: break-word;
}

/* ── Shared sidebar ───────────────────────────────────────────────────────── */

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  z-index: 10;
}

.sidebar-header strong { font-size: 0.9rem; line-height: 1.4; }
.hint { font-size: 0.78rem; color: var(--text-muted); margin-top: 4px; }

.coord-display {
  display: flex; flex-direction: column; gap: 4px;
  padding: 8px 10px;
  background: var(--bg-input); border-radius: var(--radius);
  font-size: 0.82rem; color: var(--text-muted);
}
.coord-display b { color: var(--accent); font-weight: 600; }

.key-hint {
  font-size: 0.72rem; color: var(--text-muted);
  padding: 6px 8px;
  border: 1px solid var(--border); border-radius: var(--radius);
  text-align: center;
}

.sidebar-actions { display: flex; flex-direction: column; gap: 6px; }

/* ── Map panes ────────────────────────────────────────────────────────────── */

.map-pane { position: relative; flex: 1; background: #111; overflow: hidden; }
.map-pane .panel-label {
  position: absolute; top: 10px; left: 50%;
  transform: translateX(-50%);
  z-index: 800;
  background: rgba(0,0,0,.55); color: #ccc;
  font-size: 0.78rem; padding: 3px 10px; border-radius: 12px;
  pointer-events: none;
}

/* ── STAGE: Picker ────────────────────────────────────────────────────────── */

#stage-picker { flex-direction: row; }
#picker-map   { flex: 1; }

/* ── STAGE: Editor ────────────────────────────────────────────────────────── */

#stage-editor { flex-direction: row; }

#editor-maps {
  flex: 1;
  display: flex;
  flex-direction: row;
  overflow: hidden;
}

/* Leaflet map and canvas each take exactly half of editor-maps */
#map-ortho, #map-schema-wrap { flex: 1; }
#map-schema-wrap { border-left: 1px solid var(--border); }

#map-schema {
  width: 100%; height: 100%;
  display: block;
}

/* ── Editor sidebar internals ─────────────────────────────────────────────── */

.stats-row {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;
}
.stat {
  display: flex; flex-direction: column; align-items: center;
  padding: 8px 4px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius);
}
.stat span { font-size: 1.3rem; font-weight: 700; color: var(--accent); line-height: 1; }
.stat small { font-size: 0.68rem; color: var(--text-muted); margin-top: 2px; }

.ortho-date {
  padding: 7px 9px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.76rem;
  color: var(--text-muted);
}

.toolbar-label {
  font-size: 0.72rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-muted);
}

.toolbar {
  display: grid; grid-template-columns: 1fr 1fr; gap: 5px;
}

.mode-btn {
  padding: 7px 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted); font-size: 0.8rem; font-weight: 500;
  cursor: pointer; text-align: left;
  transition: background .15s, color .15s, border-color .15s;
}
.mode-btn:hover { background: var(--bg); color: var(--text); border-color: var(--accent); }
.mode-btn.active { background: rgba(79,195,247,.12); color: var(--accent); border-color: var(--accent); }

.layer-toggles {
  display: grid; grid-template-columns: 1fr 1fr; gap: 5px;
}
.layer-toggles label {
  display: flex; align-items: center; gap: 5px;
  font-size: 0.78rem; color: var(--text-muted); cursor: pointer; user-select: none;
}
.layer-toggles input[type="checkbox"] { accent-color: var(--accent); }

.status-bar {
  padding: 7px 9px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.72rem; color: var(--text-muted);
  line-height: 1.5;
}

/* ── Leaflet overrides ────────────────────────────────────────────────────── */

.leaflet-container { background: #111; }
.leaflet-control-attribution { background: rgba(0,0,0,.5) !important; color: #aaa !important; font-size: 10px !important; }
.leaflet-control-attribution a { color: var(--accent) !important; }
.height-label { background: none; border: none; }

/* ── Responsive ───────────────────────────────────────────────────────────── */

@media (max-width: 900px) {
  :root { --sidebar-w: 220px; }
}
@media (max-width: 640px) {
  #stage-picker, #stage-editor { flex-direction: column; }
  .sidebar { width: 100%; height: auto; max-height: 40vh; border-right: none; border-bottom: 1px solid var(--border); }
  #editor-maps { flex-direction: column; }
}
