:root {
  --bg: #ffffff;
  --bg-soft: #f5f6f8;
  --fg: #1f2933;
  --fg-muted: #66717f;
  --border: #e1e4e8;
  --accent: #1F6FEB; /* брэндийн Electric Blue-ийн бараан хувилбар (../assets/css/brand.css) */
  --accent-soft: #e7f0ff;
  --map-bg: #f4f1ea;
  --shadow: 0 4px 18px rgba(15, 23, 42, .14);
  --sidebar-w: 340px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--fg);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
body { display: flex; flex-direction: column; overflow: hidden; }
a { color: var(--accent); }
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--fg-muted); margin: 18px 0 8px; }
p { line-height: 1.5; font-size: 14px; }

/* Дээд мөр */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 14px; border-bottom: 1px solid var(--border); background: var(--bg); z-index: 1000;
}
.brand { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.brand strong { font-size: 16px; }
.brand span { font-size: 12px; color: var(--fg-muted); }
.status { margin-left: auto; font-size: 12px; color: var(--fg-muted); text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status.error { color: #b91c1c; }

.btn {
  font: inherit; font-size: 13px; padding: 6px 12px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--border); background: var(--bg); color: var(--fg); white-space: nowrap;
}
.btn:hover { background: var(--bg-soft); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: .5; cursor: progress; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font: inherit; font-size: 12px; text-transform: none; letter-spacing: 0; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg);
  cursor: pointer; font-size: 16px; display: inline-grid; place-items: center; color: var(--fg);
}
.icon-btn:hover { background: var(--bg-soft); }
.icon-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
#toggle-sidebar { display: none; }
.home-link { text-decoration: none; }

/* Үндсэн хэсэг */
.layout { flex: 1; display: flex; min-height: 0; }
.sidebar { width: var(--sidebar-w); border-right: 1px solid var(--border); display: flex; flex-direction: column; background: var(--bg); z-index: 900; }
.tabs { display: flex; border-bottom: 1px solid var(--border); }
.tabs button {
  flex: 1; font: inherit; font-size: 11.5px; padding: 10px 1px; border: 0; background: none; cursor: pointer;
  color: var(--fg-muted); border-bottom: 2px solid transparent;
}
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.panel { display: none; padding: 4px 16px 24px; overflow-y: auto; flex: 1; }
.panel.active { display: block; }
.hint { font-size: 13px; color: var(--fg-muted); }
ul.hint { padding-left: 18px; line-height: 1.6; }
.row-head { display: flex; justify-content: space-between; align-items: baseline; }

.radio-list label, .check-list label {
  display: flex; align-items: center; gap: 8px; padding: 5px 4px; font-size: 14px; cursor: pointer; border-radius: 4px;
}
.radio-list label:hover, .check-list label:hover { background: var(--bg-soft); }
.check-list .count { margin-left: auto; font-size: 12px; color: var(--fg-muted); font-variant-numeric: tabular-nums; }
.swatch { width: 14px; height: 14px; border-radius: 3px; flex: none; border: 1px solid rgba(0,0,0,.15); }
.dot { width: 18px; height: 18px; border-radius: 50%; flex: none; display: grid; place-items: center; font-size: 10px; color: #fff; }
.slider { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--fg-muted); margin-top: 8px; }

.legend { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; font-size: 12.5px; }
.legend div { display: flex; align-items: center; gap: 6px; }
.legend .line { width: 22px; height: 0; border-top-width: 4px; border-top-style: solid; flex: none; }

/* Хайлт */
#search-input, #search-filter, .form input, .form select, .form textarea {
  width: 100%; font: inherit; font-size: 14px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px;
  margin-top: 10px; background: var(--bg); color: var(--fg);
}
.results { margin-top: 10px; }
.result {
  display: flex; gap: 10px; align-items: flex-start; padding: 8px 6px; border-radius: 6px; cursor: pointer; border-bottom: 1px solid var(--bg-soft);
}
.result:hover { background: var(--bg-soft); }
.result .title { font-size: 14px; font-weight: 500; }
.result .sub { font-size: 12px; color: var(--fg-muted); }
.result .actions { margin-left: auto; }
.empty { font-size: 13px; color: var(--fg-muted); padding: 12px 4px; }

/* Статистик */
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.kpi { background: var(--bg-soft); border-radius: 8px; padding: 10px; }
.kpi b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.kpi span { font-size: 12px; color: var(--fg-muted); }
.bars { display: flex; flex-direction: column; gap: 6px; }
.bar { display: grid; grid-template-columns: 120px 1fr 54px; align-items: center; gap: 8px; font-size: 12.5px; }
.bar .track { height: 10px; background: var(--bg-soft); border-radius: 5px; overflow: hidden; }
.bar .fill { height: 100%; border-radius: 5px; }
.bar .val { text-align: right; font-variant-numeric: tabular-nums; color: var(--fg-muted); }

.kpi.wide { grid-column: 1 / -1; }
.kpi.wide b { font-size: 15px; }
.mini { width: 100%; font-size: 12px; margin-top: 6px; border-collapse: collapse; }
.mini td { padding: 2px 0; border-top: 1px solid var(--border); }
.mini td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
#import-stats h3 { grid-column: 1 / -1; }

/* Өгөгдөл оруулах */
#import-crs, #import-proj { width: 100%; font: inherit; font-size: 13px; padding: 7px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--fg); }
#import-proj { margin-top: 6px; }
.drop {
  display: flex; flex-direction: column; align-items: center; gap: 4px; margin-top: 12px; padding: 20px 12px; cursor: pointer;
  border: 2px dashed var(--border); border-radius: 10px; text-align: center; font-size: 14px;
}
.drop span { font-size: 12px; color: var(--fg-muted); }
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.import-card { border: 1px solid var(--border); border-radius: 8px; padding: 10px; margin-top: 10px; }
.import-head { display: flex; align-items: center; gap: 8px; }
.import-head input[type=color] { width: 28px; height: 24px; padding: 0; border: 1px solid var(--border); border-radius: 4px; background: none; }
.import-title { display: flex; flex-direction: column; min-width: 0; }
.import-title b { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.import-title .sub { font-size: 12px; color: var(--fg-muted); }
.field-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--fg-muted); margin-top: 8px; }
.field-row select { max-width: 60%; font: inherit; font-size: 13px; padding: 4px; border: 1px solid var(--border); border-radius: 4px; }
.import-card details { margin-top: 8px; font-size: 13px; }
.import-card .fields { max-height: 180px; overflow-y: auto; }
.import-card .fields label { font-size: 13px; padding: 2px 4px; }
.import-legend { margin-top: 8px; }
.tag { font-size: 10.5px; background: #fef3c7; color: #92400e; padding: 1px 5px; border-radius: 3px; }

/* Газрын зураг */
.map-wrap { flex: 1; position: relative; min-width: 0; }
#map { position: absolute; inset: 0; background: var(--map-bg); }
#map.tiles { background: #dfe3e8; }
#map.adding, #map.measuring { cursor: crosshair; }
.map-tools { position: absolute; top: 90px; right: 10px; z-index: 800; display: flex; flex-direction: column; gap: 6px; }
.map-tools .icon-btn { box-shadow: var(--shadow); }
.coords {
  position: absolute; left: 10px; bottom: 10px; z-index: 800; font-size: 11.5px; background: rgba(255,255,255,.85);
  padding: 3px 8px; border-radius: 4px; font-variant-numeric: tabular-nums; color: var(--fg-muted);
}

/* Мэдээллийн самбар */
.info {
  position: absolute; top: 10px; left: 10px; z-index: 850; width: 330px; max-height: calc(100% - 50px); overflow-y: auto;
  background: var(--bg); border-radius: 10px; box-shadow: var(--shadow); padding: 16px;
}
.info .close { position: absolute; top: 10px; right: 10px; width: 28px; height: 28px; font-size: 13px; }
.info h2 { margin: 0 34px 2px 0; font-size: 18px; }
.info .type { font-size: 13px; color: var(--fg-muted); margin-bottom: 12px; display: flex; align-items: center; gap: 6px; }
.info table { width: 100%; border-collapse: collapse; font-size: 13px; }
.info td { padding: 5px 0; border-bottom: 1px solid var(--bg-soft); vertical-align: top; }
.info td:first-child { color: var(--fg-muted); width: 42%; padding-right: 8px; }
.info details { margin-top: 12px; font-size: 12px; }
.info details pre { white-space: pre-wrap; word-break: break-all; background: var(--bg-soft); padding: 8px; border-radius: 6px; }

/* POI тэмдэг */
.poi { background: none; border: 0; }
.poi-dot {
  width: 22px; height: 22px; border-radius: 50%; background: var(--c); color: #fff; display: grid; place-items: center;
  font-size: 11px; border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,.35); line-height: 1;
}
.poi-label {
  position: absolute; left: 25px; top: 3px; white-space: nowrap; font-size: 11.5px; font-weight: 600; color: #222;
  text-shadow: 0 0 2px #fff, 0 0 2px #fff, 0 0 3px #fff; display: none; pointer-events: none;
}
#map.show-labels .poi-label { display: block; }
.my-place .poi-dot { border-radius: 4px; transform: rotate(45deg); }
.my-place .poi-dot > * { transform: rotate(-45deg); }

.place-label { background: none; border: 0; }
.place-label span {
  display: block; transform: translate(-50%, -50%); white-space: nowrap; font-weight: 700; color: #4b4237; letter-spacing: .06em;
  text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 4px #fff; font-size: 13px; text-transform: uppercase; pointer-events: none;
}
.place-label.town span { font-size: 22px; letter-spacing: .12em; }

.measure-tip { font-weight: 600; }
.leaflet-popup-content { margin: 12px 14px; }
.form { display: flex; flex-direction: column; min-width: 220px; }
.form input, .form select, .form textarea { margin-top: 6px; font-size: 13px; padding: 6px 8px; }
.form .btn-row { margin: 8px 0 0; }

/* Гар утас */
@media (max-width: 760px) {
  #toggle-sidebar { display: inline-grid; }
  .brand span { display: none; }
  .status { display: none; }
  .sidebar {
    position: absolute; left: 0; right: 0; bottom: 0; top: auto; height: 55%; width: auto;
    border-right: 0; border-top: 1px solid var(--border); box-shadow: var(--shadow); transform: translateY(100%); transition: transform .2s;
  }
  .sidebar.open { transform: none; }
  .layout { position: relative; }
  .info { left: 10px; right: 10px; width: auto; max-height: 50%; }
  .tabs button { font-size: 11.5px; }
}

@media print {
  .topbar, .sidebar, .map-tools, .info, .leaflet-control-zoom { display: none !important; }
  .layout { height: 100vh; }
}
