:root {
  --company: #1d5fd1;
  --individual: #e0620d;
  --bg: #ffffff;
  --panel: #f7f8fa;
  --line: #e2e5ea;
  --text: #1c2330;
  --muted: #6a7384;
  --hover: #eef2f8;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; color: var(--text); background: var(--bg); }
body { display: flex; }
.muted { color: var(--muted); font-size: 12px; }

/* ---------- panel ---------- */
#panel { width: 340px; flex: none; height: 100%; display: flex; flex-direction: column; background: var(--panel); border-right: 1px solid var(--line); z-index: 1000; }
#panel header { display: flex; justify-content: space-between; align-items: flex-start; padding: 14px 16px 8px; }
#panel h1 { font-size: 18px; margin: 0 0 2px; }
.icon-btn { display: none; border: 1px solid var(--line); background: #fff; border-radius: 6px; font-size: 18px; width: 36px; height: 36px; cursor: pointer; }
.controls { padding: 0 16px 8px; display: grid; gap: 8px; }
.controls input[type=search], .controls select { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; font: inherit; background: #fff; }
.kinds { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border: 1px solid var(--line); border-radius: 999px; background: #fff; cursor: pointer; user-select: none; }
.chip input { margin: 0; }
.chip b { font-weight: 600; color: var(--muted); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot.company { background: var(--company); }
.dot.individual { background: var(--individual); }
.legend svg { vertical-align: -1px; }
#count { padding: 4px 16px 6px; border-bottom: 1px solid var(--line); }

#list, #unmapped { list-style: none; margin: 0; padding: 0; }
#list { flex: 1; overflow-y: auto; }
#list li, #unmapped li { padding: 8px 16px; border-bottom: 1px solid var(--line); cursor: pointer; display: flex; gap: 8px; align-items: flex-start; }
#list li:hover { background: var(--hover); }
#list li .dot { margin-top: 5px; flex: none; }
.li-name { font-weight: 600; }
#unmappedBox { border-top: 1px solid var(--line); padding: 8px 16px; max-height: 35%; overflow-y: auto; }
#unmappedBox summary { cursor: pointer; font-weight: 600; }
#unmapped li { padding: 6px 0; cursor: default; flex-direction: column; gap: 0; }
#unmapped a { color: var(--company); }
footer { padding: 8px 16px; border-top: 1px solid var(--line); font-size: 12px; }
footer a { color: var(--muted); }

/* ---------- map ---------- */
#map { flex: 1; height: 100%; }
.pin { background: none; border: none; }
.pin svg { display: block; filter: drop-shadow(0 1px 1.5px rgba(0,0,0,.35)); }

.pop h3 { margin: 0 0 2px; font-size: 15px; }
.pop .kind { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; font-weight: 700; }
.pop .kind.company { color: var(--company); }
.pop .kind.individual { color: var(--individual); }
.pop .addr { margin: 6px 0; }
.pop .note { font-size: 11px; color: var(--muted); }
.pop .tags { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0; }
.pop .tags span { font-size: 11px; padding: 1px 6px; border-radius: 4px; background: #eef1f5; }
.pop .contacts { margin: 8px 0; padding: 0; list-style: none; max-height: 170px; overflow-y: auto; }
.pop .contacts li { padding: 5px 0; border-top: 1px solid var(--line); }
.pop .contacts a { color: var(--company); text-decoration: none; }
.pop .crm { display: inline-block; margin-top: 4px; padding: 5px 10px; border-radius: 5px; background: var(--company); color: #fff !important; text-decoration: none; font-weight: 600; }
.leaflet-popup-content { margin: 12px 14px; min-width: 230px; }

/* ---------- login ---------- */
body.login { align-items: center; justify-content: center; background: var(--panel); }
.login-card { background: #fff; padding: 28px; border: 1px solid var(--line); border-radius: 10px; width: min(340px, 92vw); display: grid; gap: 10px; }
.login-card h1 { margin: 0; font-size: 20px; }
.login-card p { margin: 0 0 6px; color: var(--muted); }
.login-card input, .login-card button { padding: 10px; font: inherit; border-radius: 6px; border: 1px solid var(--line); }
.login-card button { background: var(--company); color: #fff; border: none; font-weight: 600; cursor: pointer; }
.err { color: #b42318; font-size: 13px; }

/* ---------- mobile: panel becomes a bottom sheet ---------- */
@media (max-width: 760px) {
  body { flex-direction: column-reverse; }
  #panel { width: 100%; height: auto; max-height: 55%; border-right: none; border-top: 1px solid var(--line); }
  #panel.collapsed #list, #panel.collapsed #unmappedBox, #panel.collapsed #count, #panel.collapsed footer, #panel.collapsed .legend { display: none; }
  .icon-btn { display: block; }
  #map { flex: 1; min-height: 45%; }
}
