/* HabSociety city map. Dark chrome around a light map canvas. */

:root {
  --bg: #12161b;
  --surface: #1a2027;
  --surface-2: #222a33;
  --border: #2e3843;
  --text: #e8ecef;
  --text-dim: #96a2ad;
  --accent: #2dd9c6;
  --accent-deep: #17897c;
  --danger: #e06c6c;
  --map-ground: #dfe6d8;
  --map-road: #b9bfc7;
  --map-park: #a8d5a2;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow: hidden;
}

button { font: inherit; cursor: pointer; }
input, select { font: inherit; }

/* ---------- chrome ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 56px;
  padding: 0 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: baseline; gap: 8px; }
.brand-mark { color: var(--accent); font-size: 18px; }
.brand-name { font-weight: 700; letter-spacing: 0.02em; }
.brand-sub { color: var(--text-dim); font-size: 13px; }

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.save-state { color: #e5b25d; font-size: 13px; }
.user-chip { color: var(--accent); font-size: 14px; }

.btn {
  border: 1px solid var(--accent-deep);
  background: var(--accent-deep);
  color: #fff;
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 14px;
}
.btn:hover { filter: brightness(1.1); }
.btn:active { transform: translateY(1px); }

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

.btn-danger { background: var(--danger); border-color: var(--danger); }

.icon-btn {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  font-size: 16px;
}
.icon-btn:hover { color: var(--text); }
.icon-btn[aria-pressed="true"] { color: var(--accent); border-color: var(--accent-deep); }

/* ---------- layout ---------- */

.layout {
  display: flex;
  height: calc(100% - 56px);
}

.sidebar {
  width: 260px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.search {
  margin: 12px;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  outline: none;
}
.search:focus { border-color: var(--accent-deep); }

.loc-list { flex: 1; overflow-y: auto; padding: 0 8px 12px; }

.district {
  margin: 10px 6px 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.loc-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  padding: 7px 10px;
  border: none;
  background: none;
  color: var(--text);
  border-radius: 8px;
  font-size: 14px;
}
.loc-item:hover { background: var(--surface-2); }
.loc-item.active { background: var(--surface-2); outline: 1px solid var(--accent-deep); }

.loc-dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}

.sidebar-foot {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 12px;
  min-height: 20px;
}

/* ---------- map ---------- */

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

#mapSvg {
  width: 100%;
  height: 100%;
  display: block;
  background: var(--map-ground);
  touch-action: none;
  cursor: grab;
  outline: none;
}
#mapSvg.panning { cursor: grabbing; }
#mapSvg.editing { cursor: crosshair; }

.map-controls {
  position: absolute;
  right: 14px;
  bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.compass {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--accent);
  font-weight: 700;
  pointer-events: none;
}

.edit-toolbar {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 13px;
  color: var(--text-dim);
  max-width: calc(100% - 28px);
}

.tool-switch {
  display: flex;
  gap: 2px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
  flex-shrink: 0;
}

.tool-btn {
  border: none;
  background: none;
  color: var(--text-dim);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 13px;
  white-space: nowrap;
}
.tool-btn:hover { color: var(--text); }
.tool-btn[aria-checked="true"] { background: var(--accent-deep); color: #fff; }

.add-type { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.add-type select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 6px;
}

/* ---------- detail / edit card ---------- */

.detail-card {
  position: absolute;
  left: 14px;
  bottom: 14px;
  width: 300px;
  max-width: calc(100% - 28px);
  max-height: calc(100% - 28px);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}

.detail-card h3 { margin: 0 0 2px; font-size: 17px; }
.detail-card .loc-district { color: var(--text-dim); font-size: 13px; margin: 0 0 8px; }
.detail-card .loc-notes { font-size: 14px; margin: 0; white-space: pre-wrap; }

.detail-card label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 10px;
}

.detail-card input[type="text"],
.detail-card textarea,
.detail-card select {
  width: 100%;
  margin-top: 4px;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  outline: none;
}
.detail-card input:focus, .detail-card textarea:focus { border-color: var(--accent-deep); }
.detail-card textarea { resize: vertical; min-height: 56px; }

.geom-row { display: flex; gap: 8px; }
.geom-row label { flex: 1; }
.geom-row input { width: 100%; }

.swatches { display: flex; gap: 6px; margin-top: 6px; }
.swatch {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 2px solid transparent;
  padding: 0;
}
.swatch.active { border-color: var(--text); }

.card-actions {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 14px;
}

.card-close {
  position: absolute;
  top: 8px;
  right: 8px;
  border: none;
  background: none;
  color: var(--text-dim);
  font-size: 16px;
}
.card-close:hover { color: var(--text); }

/* ---------- modal ---------- */

.modal {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  padding: 22px;
  width: 320px;
  max-width: calc(100vw - 32px);
}
.modal::backdrop { background: rgba(0, 0, 0, 0.55); }
.modal h2 { margin: 0 0 12px; font-size: 18px; }
.modal label { display: block; font-size: 13px; color: var(--text-dim); margin-top: 10px; }
.modal input {
  width: 100%;
  margin-top: 4px;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  outline: none;
}
.modal input:focus { border-color: var(--accent-deep); }
.form-error { color: var(--danger); font-size: 13px; margin: 10px 0 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* ---------- map svg elements ---------- */

.loc-label {
  font-family: system-ui, sans-serif;
  fill: #2c3438;
  pointer-events: none;
  user-select: none;
}
.loc-label.on-road { fill: #5b6470; }
.loc-shape { cursor: pointer; }
.loc-shape.selected { stroke: #17897c !important; stroke-width: 3 !important; }
.draft-rect { fill: rgba(45, 217, 198, 0.3); stroke: #17897c; stroke-dasharray: 4 3; }

/* ---------- mobile ---------- */

.sidebar-toggle { display: none; }

@media (max-width: 760px) {
  .sidebar-toggle { display: grid; }
  .brand-sub { display: none; }
  .sidebar {
    position: absolute;
    z-index: 20;
    top: 56px;
    bottom: 0;
    left: 0;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 8px 0 30px rgba(0, 0, 0, 0.4);
  }
  .sidebar.open { transform: translateX(0); }
  .detail-card { left: 8px; right: 8px; width: auto; bottom: 8px; }
  .edit-toolbar { top: 8px; font-size: 12px; gap: 8px; }
  .edit-hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; }
}
