:root {
  --bg: #0d1014;
  --bg-2: #12161c;
  --panel: #171c23;
  --panel-2: #1e252e;
  --border: #2a323d;
  --text: #e7eaef;
  --muted: #8a94a3;
  --accent: #f0a020;
  --accent-2: #ffbf4d;
  --t: #e0ae4b;
  --ct: #5ea2e0;
  --smoke: #b9c2ce;
  --flash: #f3e35c;
  --molotov: #ff6b3d;
  --he: #7fd36b;
  --danger: #e5484d;
  --radius: 10px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 var(--font);
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
button { font: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }

/* ---------- Кнопки и поля ---------- */
.btn {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
  white-space: nowrap;
}
.btn:hover { border-color: #3d4755; background: #252d38; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #141414; font-weight: 600; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.wide { width: 100%; }

input, select, textarea {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 11px;
  font: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; font-family: Consolas, "Cascadia Mono", monospace; font-size: 14px; line-height: 1.5; }
label { display: block; font-size: 13px; color: var(--muted); }
label > input, label > select, label > textarea { margin-top: 4px; }

/* ---------- Логин ---------- */
.login-page {
  display: grid;
  place-items: center;
  background:
    radial-gradient(1000px 500px at 20% 0%, rgba(240,160,32,.12), transparent 60%),
    radial-gradient(800px 500px at 100% 100%, rgba(94,162,224,.10), transparent 60%),
    var(--bg);
  padding: 16px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px 28px;
  display: grid;
  gap: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,.45);
}
.login-card p { margin: -6px 0 6px; }
.error { color: var(--danger); min-height: 1.2em; font-size: 14px; }

/* ---------- Шапка ---------- */
.logo { display: inline-flex; align-items: center; gap: 6px; font-weight: 800; letter-spacing: .08em; color: var(--text); font-size: 17px; }
.logo-mark { background: var(--accent); color: #111; padding: 1px 7px; border-radius: 5px; }
.logo.big { font-size: 26px; justify-content: center; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 24px;
  padding: 0 24px;
  height: 60px;
  background: rgba(13,16,20,.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.map-tabs { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; height: 100%; }
.map-tabs::-webkit-scrollbar { display: none; }
.map-tabs a {
  display: flex; align-items: center;
  padding: 0 16px;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: .03em;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
  transition: color .15s;
}
.map-tabs a:hover { color: var(--text); }
.map-tabs a.active { color: var(--text); border-bottom-color: var(--accent); }
.user-box { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.role-badge { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; padding: 2px 8px; border-radius: 20px; border: 1px solid var(--border); color: var(--muted); }
.role-badge.admin { color: var(--accent); border-color: rgba(240,160,32,.5); }

/* ---------- Шапка карты ---------- */
.map-hero {
  padding: 28px 24px 0;
  background: linear-gradient(180deg, var(--hero, #222a33) -200%, var(--bg) 100%);
  border-bottom: 1px solid var(--border);
}
.map-hero h1 { margin: 0 0 14px; font-size: 34px; letter-spacing: .04em; text-transform: uppercase; }
.sub-tabs { display: flex; gap: 4px; }
.sub-tabs a {
  padding: 10px 18px;
  color: var(--muted);
  font-weight: 600;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  border: 1px solid transparent;
  border-bottom: none;
}
.sub-tabs a:hover { color: var(--text); }
.sub-tabs a.active { background: var(--panel); color: var(--text); border-color: var(--border); }
.sub-tabs .count { font-size: 12px; color: var(--muted); margin-left: 6px; }

/* ---------- Раскладка ---------- */
.layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 24px;
  padding: 24px;
  max-width: 1400px;
}
.sidebar { min-width: 0; }
.sidebar-head { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.sidebar-head .btn { justify-content: center; }
.filters { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-size: 12px; font-weight: 600;
  padding: 4px 10px; border-radius: 20px;
  border: 1px solid var(--border); color: var(--muted);
  cursor: pointer; user-select: none; background: transparent;
}
.chip:hover { color: var(--text); }
.chip.active { color: #111; background: var(--accent); border-color: var(--accent); }

.list { display: grid; gap: 4px; }
.list-group { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 12px 4px 4px; display: flex; align-items: center; gap: 8px; }
.list-group:first-child { margin-top: 0; }
.list-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text);
  border: 1px solid transparent;
  cursor: pointer;
}
.list-item:hover { background: var(--panel); }
.list-item.active { background: var(--panel); border-color: var(--border); box-shadow: inset 3px 0 0 var(--accent); }
.list-item .title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .order { display: none; gap: 2px; }
body.is-admin .list-item:hover .order { display: flex; }
.order button { background: none; border: none; color: var(--muted); cursor: pointer; padding: 0 3px; font-size: 12px; }
.order button:hover { color: var(--text); }
.empty { color: var(--muted); padding: 14px 4px; font-size: 14px; }

/* ---------- Бейджи ---------- */
.side { font-size: 11px; font-weight: 800; padding: 1px 7px; border-radius: 4px; letter-spacing: .04em; }
.side.T { color: var(--t); background: rgba(224,174,75,.12); }
.side.CT { color: var(--ct); background: rgba(94,162,224,.12); }
.cat { font-size: 11px; color: var(--muted); border: 1px solid var(--border); border-radius: 4px; padding: 0 6px; }
.gtype { display: inline-flex; width: 22px; height: 22px; border-radius: 50%; align-items: center; justify-content: center; font-size: 11px; font-weight: 800; color: #111; flex: none; }
.gtype.smoke { background: var(--smoke); }
.gtype.flash { background: var(--flash); }
.gtype.molotov { background: var(--molotov); }
.gtype.he { background: var(--he); }

/* ---------- Контент ---------- */
.content {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 32px;
  min-height: 400px;
  min-width: 0;
}
.content-head { display: flex; gap: 16px; align-items: flex-start; justify-content: space-between; border-bottom: 1px solid var(--border); padding-bottom: 16px; margin-bottom: 20px; }
.content-head h2 { margin: 0 0 6px; font-size: 26px; line-height: 1.25; }
.content-head .meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.content-head .actions { display: flex; gap: 6px; }
.placeholder { color: var(--muted); text-align: center; padding: 80px 20px; }
.placeholder .big { font-size: 46px; opacity: .35; }

.md h1, .md h2, .md h3 { line-height: 1.3; margin: 1.4em 0 .5em; }
.md h1 { font-size: 24px; } .md h2 { font-size: 20px; } .md h3 { font-size: 17px; }
.md > :first-child { margin-top: 0; }
.md p { margin: .6em 0; }
.md ul, .md ol { padding-left: 1.4em; margin: .6em 0; }
.md li { margin: .25em 0; }
.md blockquote {
  margin: 1em 0; padding: 10px 16px;
  border-left: 3px solid var(--accent);
  background: rgba(240,160,32,.07);
  border-radius: 0 8px 8px 0;
}
.md code { background: var(--bg-2); padding: 1px 6px; border-radius: 4px; font-size: 13px; }
.md hr { border: none; border-top: 1px solid var(--border); margin: 1.5em 0; }
.md strong { color: #fff; }

/* Упоминание раскида в тексте */
.lu-ref {
  display: inline-flex; align-items: baseline; gap: 5px;
  color: var(--accent-2);
  border-bottom: 1px dashed rgba(255,191,77,.6);
  cursor: pointer;
  font-weight: 600;
}
.lu-ref::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; align-self: center; }
.lu-ref.smoke { color: var(--smoke); border-color: rgba(185,194,206,.6); }
.lu-ref.flash { color: var(--flash); border-color: rgba(243,227,92,.6); }
.lu-ref.molotov { color: var(--molotov); border-color: rgba(255,107,61,.6); }
.lu-ref.he { color: var(--he); border-color: rgba(127,211,107,.6); }
.lu-ref.broken { color: var(--muted); border-color: var(--muted); text-decoration: line-through; cursor: default; }

/* Всплывающее окно */
.lu-popup {
  position: fixed; z-index: 60;
  width: 440px; max-width: calc(100vw - 24px);
  background: var(--panel-2);
  border: 1px solid #3a4452;
  border-radius: 12px;
  box-shadow: 0 18px 50px rgba(0,0,0,.6);
  overflow: hidden;
  pointer-events: none;
  animation: pop .12s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.lu-popup img { display: block; width: 100%; aspect-ratio: 16/9; object-fit: cover; background: #0a0c0f; }
.lu-popup .body { padding: 10px 14px 12px; }
.lu-popup .head { display: flex; gap: 8px; align-items: center; font-weight: 700; }
.lu-popup .desc { font-size: 13px; color: #c4cad3; margin-top: 4px; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.lu-popup .more { font-size: 12px; color: var(--muted); margin-top: 6px; }
.lu-popup .noimg { padding: 30px; text-align: center; color: var(--muted); background: #0a0c0f; font-size: 13px; }

/* Галерея раскида */
.gallery { display: grid; gap: 14px; margin-top: 20px; }
.gallery img { width: 100%; border-radius: 10px; border: 1px solid var(--border); cursor: zoom-in; display: block; }

.lightbox { position: fixed; inset: 0; z-index: 80; background: rgba(0,0,0,.88); display: grid; place-items: center; cursor: zoom-out; padding: 20px; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }

/* ---------- Модалка ---------- */
.modal-bg { position: fixed; inset: 0; z-index: 70; background: rgba(0,0,0,.65); display: flex; justify-content: center; align-items: flex-start; padding: 40px 16px; overflow-y: auto; }
.modal {
  width: 100%; max-width: 1100px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px 24px;
  display: grid; gap: 14px;
}
.modal h3 { margin: 0; font-size: 20px; }
.row { display: grid; gap: 12px; grid-template-columns: 2fr 1fr 1fr; }
.row.two { grid-template-columns: 2fr 1fr 1fr; }
.editor { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.editor .pane-title { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.editor textarea { min-height: 420px; }
.editor .preview { background: var(--bg-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px 16px; min-height: 420px; max-height: 60vh; overflow: auto; }
.toolbar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.toolbar select { width: auto; max-width: 280px; padding: 5px 8px; font-size: 13px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }
.modal-actions .spacer { flex: 1; }
.hint { font-size: 12px; color: var(--muted); }
.hint code { background: var(--bg-2); padding: 0 4px; border-radius: 4px; }

.img-list { display: flex; flex-wrap: wrap; gap: 10px; }
.img-thumb { position: relative; width: 160px; aspect-ratio: 16/9; border-radius: 8px; overflow: hidden; border: 1px solid var(--border); background: #0a0c0f; }
.img-thumb img { width: 100%; height: 100%; object-fit: cover; }
.img-thumb .x { position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; border-radius: 50%; border: none; background: rgba(0,0,0,.7); color: #fff; cursor: pointer; }
.img-thumb .mv { position: absolute; bottom: 4px; left: 4px; display: flex; gap: 3px; }
.img-thumb .mv button { border: none; background: rgba(0,0,0,.7); color: #fff; border-radius: 4px; cursor: pointer; font-size: 11px; padding: 1px 6px; }
.dropzone {
  width: 160px; aspect-ratio: 16/9;
  border: 2px dashed var(--border); border-radius: 8px;
  display: grid; place-items: center; text-align: center;
  color: var(--muted); font-size: 12px; cursor: pointer; padding: 6px;
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent); color: var(--text); }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--border); padding: 10px 18px; border-radius: 8px; z-index: 90; box-shadow: 0 10px 30px rgba(0,0,0,.4); }
.toast.err { border-color: var(--danger); color: #ffb3b5; }

.admin-only { display: none !important; }
body.is-admin .admin-only { display: inline-flex !important; }

/* ---------- Адаптив ---------- */
@media (max-width: 900px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 16px 0; gap: 8px 16px; }
  .map-tabs { order: 3; flex-basis: 100%; height: 44px; }
  .user-box { margin-left: auto; }
  .user-name { display: none; }
  .map-hero { padding: 20px 16px 0; }
  .map-hero h1 { font-size: 26px; }
  .layout { grid-template-columns: 1fr; padding: 16px; gap: 16px; }
  .content { padding: 20px 18px; }
  .content-head { flex-direction: column; gap: 10px; }
  .editor { grid-template-columns: 1fr; }
  .editor textarea, .editor .preview { min-height: 260px; }
  .row, .row.two { grid-template-columns: 1fr; }
}
