:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1f232c;
  --border: #2a2f3a;
  --text: #e6e8ec;
  --text-dim: #9aa0ab;
  --accent: #f2a13d;
  --base: #22c55e;
  --raid: #ef4444;
  --car: #3b82f6;
  --other: #a1a1aa;
  --shadow: 0 8px 24px rgba(0,0,0,.45);
}

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

#app { display: flex; height: 100vh; }

/* ---------- Sidebar ---------- */
#sidebar {
  width: 320px;
  min-width: 320px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 1200;
}
#sidebar.collapsed { margin-left: -320px; }

.side-head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.side-head h1 {
  font-size: 16px; margin: 0 0 2px; letter-spacing: .3px;
}
.side-head .sub { font-size: 11px; color: var(--text-dim); }
.side-head .user-row { display:flex; align-items:center; justify-content:space-between; margin-top:8px; }
.side-head .user-row .who { font-size: 12px; color: var(--accent); }

.search-box { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.search-box input {
  width: 100%; padding: 9px 11px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--panel-2);
  color: var(--text); font-size: 13px; outline: none;
}
.search-box input:focus { border-color: var(--accent); }

.search-results { max-height: 200px; overflow:auto; }
.search-results .item { padding: 7px 12px; font-size: 12px; cursor: pointer; border-bottom: 1px solid var(--border); display:flex; justify-content:space-between; gap:8px; }
.search-results .item:hover { background: var(--panel-2); }
.search-results .item .tag { color: var(--text-dim); font-size: 10px; }

.section-title { padding: 12px 14px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--text-dim); }

.filters { padding: 4px 8px 8px; }
.filter {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px; cursor: pointer; user-select: none;
}
.filter:hover { background: var(--panel-2); }
.filter .dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.filter .name { flex: 1; font-size: 13px; }
.filter .count { font-size: 11px; color: var(--text-dim); background: var(--panel-2); padding: 1px 8px; border-radius: 10px; }
.filter input { accent-color: var(--accent); width: 15px; height: 15px; }

.marker-list { flex: 1; overflow: auto; padding: 4px 8px 12px; }
.list-group { display:flex; align-items:center; gap:7px; font-size:11px; text-transform:uppercase; letter-spacing:.5px; color:var(--text-dim); padding:10px 8px 4px; }
.list-group .dot { width:9px; height:9px; border-radius:50%; }
.list-group .n { color:var(--text-dim); }
.marker-item {
  padding: 9px 10px; border-radius: 8px; cursor: pointer; margin-bottom: 3px;
  border: 1px solid transparent; display: flex; gap: 9px; align-items: flex-start;
}
.marker-item:hover { background: var(--panel-2); border-color: var(--border); }
.marker-item .ic { font-size: 15px; line-height: 1.2; }
.marker-item .body { flex: 1; min-width: 0; }
.marker-item .t { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.marker-item .c { font-size: 11px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.marker-item .acts { display: none; gap: 4px; align-items: flex-start; }
.marker-item:hover .acts { display: flex; }
.marker-item .mini { padding: 3px 7px; font-size: 12px; line-height: 1; }

.poi-box { padding: 4px 12px 8px; }
.poi-box .filters { max-height: 260px; overflow: auto; padding: 4px 0 0; }
.poi-note { font-size: 10px; color: var(--text-dim); padding: 6px 2px 0; }

/* Иконка объекта на карте */
.poi-pin {
  width: 22px; height: 22px; border-radius: 50%;
  background: rgba(15,17,21,.92); border: 2px solid var(--other);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; line-height: 1; cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,.6);
}
.poi-pin:hover { transform: scale(1.25); z-index: 500; }
/* та же иконка в списке фильтров */
.poi-ic {
  width: 20px; height: 20px; border-radius: 50%; flex: none;
  background: var(--panel-2); border: 2px solid var(--other);
  display: flex; align-items: center; justify-content: center; font-size: 11px;
}

.poi-group { border-bottom: 1px solid var(--border); }
.poi-group:last-child { border-bottom: none; }
.poi-group-head { display: flex; align-items: center; gap: 8px; padding: 7px 4px; cursor: default; }
.poi-group-head .dot { width: 11px; height: 11px; border-radius: 50%; flex: none; }
.poi-group-head .name { flex: 1; font-size: 12px; font-weight: 600; cursor: pointer; user-select: none; }
.poi-group-head .count { font-size: 10px; color: var(--text-dim); }
.poi-group-head .chev { font-size: 10px; color: var(--text-dim); cursor: pointer; transition: transform .15s; padding: 0 2px; }
.poi-group.open .chev { transform: rotate(90deg); }
.poi-group-head input { accent-color: var(--accent); width: 14px; height: 14px; }

.poi-subs { display: none; padding: 0 0 6px 10px; }
.poi-group.open .poi-subs { display: block; }
.filter.sub { padding: 5px 8px; gap: 8px; }
.filter.sub .name { font-size: 12px; font-weight: 400; }
.filter.sub .dot { width: 9px; height: 9px; }
.filter.sub input { width: 13px; height: 13px; }

.routes-list { padding: 2px 8px 8px; max-height: 180px; overflow: auto; }
.route-item { display: flex; gap: 8px; align-items: center; padding: 8px 10px; border-radius: 8px; cursor: pointer; border: 1px solid transparent; }
.route-item:hover { background: var(--panel-2); border-color: var(--border); }
.route-item .body { flex: 1; min-width: 0; }
.route-item .t { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.route-item .c { font-size: 11px; color: var(--text-dim); }
.route-item .mini { padding: 3px 7px; font-size: 12px; line-height: 1; }

.side-foot { border-top: 1px solid var(--border); padding: 10px 12px; display: flex; gap: 8px; flex-wrap: wrap; }
.side-foot button { flex: 1; }

/* ---------- Buttons ---------- */
button {
  font-family: inherit; cursor: pointer; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text); padding: 8px 12px;
  border-radius: 8px; font-size: 12px; transition: .12s;
}
button:hover { border-color: var(--accent); color: #fff; }
button.primary { background: var(--accent); border-color: var(--accent); color: #17130b; font-weight: 600; }
button.primary:hover { filter: brightness(1.08); color: #17130b; }
button.danger { color: #ff8a8a; }
button.danger:hover { border-color: var(--raid); color: #fff; background: var(--raid); }

/* ---------- Map ---------- */
#map-wrap { position: relative; flex: 1; }
#map { position: absolute; inset: 0; background: #0b3a52; }
.leaflet-container { background: #0b3a52; font-family: inherit; }

/* Toolbar over map */
.toolbar {
  position: absolute; top: 12px; left: 12px; z-index: 1000;
  display: flex; gap: 8px; flex-wrap: wrap;
}
.toolbar .grp { display: flex; gap: 6px; background: rgba(23,26,33,.9); backdrop-filter: blur(6px); padding: 6px; border-radius: 10px; border: 1px solid var(--border); box-shadow: var(--shadow); }
.toolbar button { padding: 7px 11px; }
.toolbar button.active { background: var(--accent); border-color: var(--accent); color: #17130b; font-weight: 600; }

.map-hint {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  z-index: 1000; background: rgba(242,161,61,.95); color:#17130b;
  padding: 7px 14px; border-radius: 20px; font-size: 12px; font-weight: 600;
  box-shadow: var(--shadow); display: none;
}
.map-hint.show { display: block; }

.coord-box {
  position: absolute; bottom: 12px; left: 12px; z-index: 1000;
  background: rgba(23,26,33,.92); border: 1px solid var(--border);
  padding: 7px 12px; border-radius: 8px; font-size: 12px; font-family: "Consolas", monospace;
  color: var(--text); box-shadow: var(--shadow);
}
.coord-box b { color: var(--accent); }

.route-box {
  position: absolute; bottom: 12px; right: 12px; z-index: 1000;
  background: rgba(23,26,33,.94); border: 1px solid var(--border);
  padding: 10px 14px; border-radius: 10px; font-size: 12px; box-shadow: var(--shadow);
  display: none; min-width: 180px;
}
.route-box.show { display: block; }
.route-box .dist { font-size: 18px; font-weight: 700; color: var(--accent); }
.route-box .sub { color: var(--text-dim); font-size: 11px; margin-top: 2px; }
.route-box .eta { color: var(--text); font-size: 11px; margin-top: 4px; }
.route-box .route-avoid { display: flex; align-items: center; gap: 6px; font-size: 12px; margin-top: 8px; cursor: pointer; user-select: none; }
.route-box .route-avoid input { accent-color: #38bdf8; width: 15px; height: 15px; }
.route-box .beta { font-size: 9px; background: var(--panel-2); color: var(--text-dim); padding: 1px 5px; border-radius: 6px; text-transform: uppercase; }
.route-box .route-btns { display: flex; gap: 6px; margin-top: 8px; }
.route-box .route-btns button { flex: 1; }

/* Панель сопровождения */
.nav-panel {
  position: absolute; top: 70px; right: 12px; z-index: 1100; display: none;
  background: rgba(23,26,33,.96); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; box-shadow: var(--shadow); width: 210px;
}
.nav-panel.show { display: block; }
.nav-head { display: flex; justify-content: space-between; align-items: center; font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .5px; }
.nav-head button { padding: 2px 7px; font-size: 11px; }
.nav-main { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
.nav-arrow-wrap { width: 46px; height: 46px; border-radius: 50%; border: 2px solid var(--accent); display: flex; align-items: center; justify-content: center; flex: none; }
.nav-arrow { font-size: 20px; color: var(--accent); line-height: 1; transition: transform .2s; }
.nav-deg { font-size: 26px; font-weight: 700; color: var(--accent); line-height: 1; }
.nav-card { font-size: 12px; color: var(--text-dim); }
.nav-dist { font-size: 17px; font-weight: 600; margin-top: 8px; }
.nav-rest { font-size: 11px; color: var(--text-dim); margin-top: 2px; }
.nav-btns { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.nav-btns button { width: 100%; }
.nav-target {
  width: 22px; height: 22px; border-radius: 50%; border: 3px solid #fff;
  background: rgba(255,255,255,.25); box-shadow: 0 0 0 2px rgba(0,0,0,.5);
  animation: pulse 1.6s infinite;
}

/* Маршрутные точки */
.wp {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent); border: 2px solid #17130b;
  display: flex; align-items: center; justify-content: center;
  color: #17130b; font-weight: 700; font-size: 12px;
  box-shadow: 0 2px 5px rgba(0,0,0,.5); cursor: grab;
}

/* ---------- Location labels ---------- */
.loc-label {
  background: transparent; border: none; box-shadow: none;
  color: #fff; font-weight: 600; text-shadow: 0 0 3px #000, 0 0 3px #000, 0 1px 2px #000;
  white-space: nowrap; pointer-events: none;
}
.loc-label.type-capital { font-size: 15px; text-transform: uppercase; letter-spacing: .5px; color:#ffe9c7; }
.loc-label.type-city { font-size: 13px; color:#fff; }
.loc-label.type-village { font-size: 11px; color:#e6e8ec; }
.loc-label.type-camp,.loc-label.type-local,.loc-label.type-hill,.loc-label.type-ruin,.loc-label.type-marine {
  font-size: 10px; color:#c7ccd6; font-weight: 500;
}
.leaflet-tooltip.loc-label:before { display: none; }

/* Grid labels */
.grid-label {
  color: #ffd7a0; font-size: 10px; font-family: "Consolas", monospace;
  font-weight: 700; text-shadow: 0 0 3px #000, 0 0 2px #000;
  text-align: center; pointer-events: none; opacity: .7;
}

/* User marker pins */
.pin {
  width: 26px; height: 26px; border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg); border: 2px solid rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 6px rgba(0,0,0,.5);
}
.pin span { transform: rotate(45deg); font-size: 13px; }
.pin.base { background: var(--base); }
.pin.raid { background: var(--raid); }
.pin.car { background: var(--car); }
.pin.other { background: var(--other); }
.pin.me { background: #fff; border-color: var(--accent); border-width:3px; border-radius:50%; transform:none; animation: pulse 1.6s infinite; }
.pin.me span { transform:none; }
@keyframes pulse { 0%{box-shadow:0 0 0 0 rgba(242,161,61,.6);} 70%{box-shadow:0 0 0 12px rgba(242,161,61,0);} 100%{box-shadow:0 0 0 0 rgba(242,161,61,0);} }

/* Popups */
.leaflet-popup-content-wrapper { background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 10px; }
.leaflet-popup-tip { background: var(--panel); border: 1px solid var(--border); }
.leaflet-popup-content { margin: 12px 14px; font-size: 13px; min-width: 180px; }
.popup h3 { margin: 0 0 4px; font-size: 14px; display:flex; align-items:center; gap:6px; }
.popup .cat { font-size: 11px; color: var(--text-dim); margin-bottom: 6px; }
.popup .notes { font-size: 12px; color: var(--text); margin: 6px 0; white-space: pre-wrap; }
.popup .co { font-family: monospace; font-size: 11px; color: var(--accent); margin-bottom: 8px; }
.popup .row { display: flex; gap: 5px; flex-wrap: wrap; }
.popup .row button { flex: 1 1 auto; padding: 6px 8px; font-size: 11px; white-space: nowrap; }

/* ---------- Modal ---------- */
.modal-bg {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 3000;
  display: none; align-items: center; justify-content: center;
}
.modal-bg.show { display: flex; }
.modal {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  width: 360px; max-width: 92vw; box-shadow: var(--shadow); overflow: hidden;
}
.modal h2 { margin: 0; padding: 16px 18px; font-size: 15px; border-bottom: 1px solid var(--border); }
.modal .content { padding: 16px 18px; }
.modal label { display: block; font-size: 11px; color: var(--text-dim); margin: 10px 0 5px; text-transform: uppercase; letter-spacing: .5px; }
.modal input, .modal textarea, .modal select {
  width: 100%; padding: 9px 11px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text); font-size: 13px; font-family: inherit; outline: none;
}
.modal input:focus, .modal textarea:focus, .modal select:focus { border-color: var(--accent); }
.modal textarea { resize: vertical; min-height: 60px; }
.cat-picker { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cat-opt {
  display: flex; align-items: center; gap: 8px; padding: 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--panel-2); cursor: pointer; font-size: 12px;
}
.cat-opt.sel { border-color: var(--accent); background: rgba(242,161,61,.12); }
.cat-opt .dot { width: 12px; height: 12px; border-radius: 50%; }
.modal .actions { display: flex; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--border); }
.modal .actions button { flex: 1; }

/* Login screen */
#login {
  position: fixed; inset: 0; z-index: 5000; background: var(--bg);
  display: flex; align-items: center; justify-content: center;
}
#login .card { width: 340px; max-width: 92vw; background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 26px; box-shadow: var(--shadow); }
#login h1 { margin: 0 0 4px; font-size: 20px; }
#login .sub { color: var(--text-dim); font-size: 12px; margin-bottom: 18px; }
#login label { display:block; font-size:11px; color:var(--text-dim); margin: 12px 0 5px; text-transform: uppercase; letter-spacing:.5px; }
#login input { width:100%; padding: 10px 12px; border-radius:8px; border:1px solid var(--border); background: var(--panel-2); color: var(--text); font-size: 14px; outline:none; }
#login input:focus { border-color: var(--accent); }
#login button { width:100%; margin-top: 18px; padding: 11px; }
#login .err { color: #ff8a8a; font-size: 12px; margin-top: 10px; min-height: 16px; }
#login .note { color: var(--text-dim); font-size: 11px; margin-top: 14px; line-height: 1.5; }
#login .note code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; }
.login-switch { font-size: 12px; color: var(--text-dim); margin-top: 12px; text-align: center; }
.login-switch a { color: var(--accent); text-decoration: none; margin-left: 5px; }
.login-switch a:hover { text-decoration: underline; }

/* режим работы + ошибки синхронизации */
.mode-badge { font-size: 10px; padding: 2px 7px; border-radius: 10px; }
.mode-badge.on { color: var(--base); background: rgba(34,197,94,.12); }
.mode-badge.off { color: var(--text-dim); background: var(--panel-2); }
.sync-note { display: none; font-size: 11px; color: #ff8a8a; margin-top: 8px; }
.sync-note.show { display: block; }

.leaflet-control-zoom a { background: var(--panel) !important; color: var(--text) !important; border-color: var(--border) !important; }

@media (max-width: 640px) {
  #sidebar { position: absolute; height: 100%; box-shadow: var(--shadow); }
}
