:root {
  --bg: #0c1218;
  --bg-2: #121b23;
  --bg-3: #18242e;
  --line: #24333f;
  --text: #e6eef4;
  --muted: #8fa3b3;
  --accent: #2f9cf4;
  --accent-2: #1b7fd0;
  --danger: #e0533d;
  --ok: #3ecf8e;
  --warn: #f2b544;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

.brand {
  font-weight: 700;
  letter-spacing: .3px;
  white-space: nowrap;
}

.status {
  font-size: 12px;
  color: var(--muted);
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--bg-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.status.saved { color: var(--ok); }
.status.error { color: var(--danger); }
.status.busy { color: var(--warn); }

.top-actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

/* ---------- buttons ---------- */

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg-3);
  color: var(--text);
  padding: 7px 12px;
  border-radius: 8px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: #1f2f3b; }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #04121d;
  font-weight: 600;
}
.btn.primary:hover { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }

/* ---------- toolbar ---------- */

.toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
  flex: 0 0 auto;
}

.tool {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg-3);
  color: var(--text);
  padding: 7px 12px;
  border-radius: 8px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.tool:hover { background: #1f2f3b; }
.tool.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #04121d;
  font-weight: 600;
}

.shared {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  padding: 0 6px;
  cursor: pointer;
  user-select: none;
}
.shared input { accent-color: var(--accent); }

.shared select {
  background: var(--bg-3);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 6px;
  padding: 4px 6px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.sep {
  width: 1px;
  height: 22px;
  background: var(--line);
  margin: 0 4px;
}

.seg {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.seg-btn {
  appearance: none;
  border: none;
  background: var(--bg-3);
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  padding: 7px 11px;
  cursor: pointer;
}
.seg-btn:hover { background: #1f2f3b; }
.seg-btn.active {
  background: var(--accent);
  color: #04121d;
  font-weight: 600;
}

/* ---------- layout ---------- */

.layout {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
}

.map-wrap {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  background: #08131b;
  overflow: hidden;
}

#mapCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}
#mapCanvas.drawing { cursor: crosshair; }
#mapCanvas.panning { cursor: grabbing; }

.hint {
  position: absolute;
  left: 12px;
  bottom: 12px;
  padding: 6px 11px;
  border-radius: 8px;
  background: rgba(8, 18, 26, .78);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  pointer-events: none;
  max-width: calc(100% - 24px);
}

/* ---------- panel ---------- */

.panel {
  flex: 0 0 290px;
  background: var(--bg-2);
  border-left: 1px solid var(--line);
  overflow-y: auto;
  padding: 12px;
}

.panel-block + .panel-block { margin-top: 18px; }

.panel h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--muted);
  margin: 0 0 8px;
}

.add-country {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}

.add-country input[type="text"] {
  flex: 1 1 auto;
  min-width: 0;
  background: var(--bg-3);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 7px 9px;
  font: inherit;
  font-size: 13px;
}
.add-country input[type="text"]:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.add-country input[type="color"] {
  width: 36px;
  height: 34px;
  padding: 2px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}

.country-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.country-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: var(--bg-3);
  cursor: pointer;
}
.country-row:hover { border-color: var(--line); }
.country-row.selected {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(47, 156, 244, .35);
}

.country-row .swatch {
  width: 20px;
  height: 20px;
  padding: 0;
  border: none;
  border-radius: 5px;
  background: none;
  cursor: pointer;
  flex: 0 0 auto;
}
.country-row .swatch::-webkit-color-swatch-wrapper { padding: 0; }
.country-row .swatch::-webkit-color-swatch { border: 1px solid rgba(255,255,255,.25); border-radius: 5px; }

.country-row .name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.icon-btn {
  appearance: none;
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 4px 5px;
  border-radius: 6px;
}
.icon-btn:hover { background: #24333f; color: var(--text); }
.icon-btn.danger:hover { background: rgba(224, 83, 61, .2); color: var(--danger); }

.empty {
  color: var(--muted);
  font-size: 12px;
  margin: 6px 2px 0;
}

.region-info { font-size: 13px; color: var(--muted); }
.region-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--muted);
  margin-bottom: 6px;
}
.owner-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  padding: 4px 0;
}
.dot {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  border: 1px solid rgba(255,255,255,.3);
  flex: 0 0 auto;
}

.layer-toggles {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  padding: 4px 2px;
  cursor: pointer;
  user-select: none;
}

.toggle input {
  accent-color: var(--accent);
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
}

.loc-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--muted);
  margin: 10px 0 5px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  color: var(--text);
}

.chip.unlock {
  border-color: rgba(62, 207, 142, .45);
  color: #b9f0d4;
}

.chip button {
  appearance: none;
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  padding: 0;
}
.chip button:hover { color: var(--danger); }

/* ---------- modal ---------- */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(4, 9, 13, .72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}

.modal-card {
  width: 100%;
  max-width: 340px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
}
.modal-card h2 { margin: 0 0 4px; font-size: 16px; }
.muted { color: var(--muted); font-size: 13px; margin: 0 0 12px; }

.modal-card input {
  width: 100%;
  background: var(--bg-3);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 10px;
  font: inherit;
}
.modal-card input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.modal-error {
  color: var(--danger);
  font-size: 12px;
  min-height: 18px;
  margin-top: 6px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #1d2b36;
  border: 1px solid var(--line);
  color: var(--text);
  padding: 9px 15px;
  border-radius: 10px;
  font-size: 13px;
  z-index: 60;
  max-width: min(90vw, 460px);
  text-align: center;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}

.hidden { display: none !important; }

/* ---------- small screens ---------- */

@media (max-width: 820px) {
  body { overflow: auto; }
  .layout { flex-direction: column; }
  .map-wrap { flex: 0 0 58vh; min-height: 320px; }
  .panel {
    flex: 1 1 auto;
    border-left: none;
    border-top: 1px solid var(--line);
    max-height: none;
  }
  .brand { font-size: 14px; }
  .status { font-size: 11px; }
}
