:root {
  --bg: #ffffff;
  --panel: #ffffff;
  --panel-2: #f5f6f8;
  --text: #1b1f24;
  --muted: #5f6b7a;
  --border: #dfe3e8;
  --accent: #d40000;
  --accent-soft: #fde8e8;
  --select: #f2b705;
  --shadow: 0 6px 24px rgba(16, 24, 40, .14);
  --radius: 10px;
  --font: "Noto Sans Georgian", system-ui, -apple-system, "Segoe UI", "Sylfaen", Roboto, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151a; --panel: #1a1e25; --panel-2: #232831; --text: #e8ebef; --muted: #9aa5b2;
    --border: #2f3640; --accent: #ff4d4d; --accent-soft: #3a1d1f; --shadow: 0 6px 24px rgba(0,0,0,.5);
  }
}
:root[data-theme="dark"] {
  --bg: #12151a; --panel: #1a1e25; --panel-2: #232831; --text: #e8ebef; --muted: #9aa5b2;
  --border: #2f3640; --accent: #ff4d4d; --accent-soft: #3a1d1f; --shadow: 0 6px 24px rgba(0,0,0,.5);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.4 var(--font); display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; gap: 12px; padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--border); z-index: 5; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; white-space: nowrap; }
.logo { width: 18px; height: 18px; border: 2.5px solid var(--accent); border-radius: 3px; background: linear-gradient(var(--accent),var(--accent)) center/100% 1.5px no-repeat, linear-gradient(var(--accent),var(--accent)) center/1.5px 100% no-repeat; }
.search { position: relative; flex: 1 1 260px; max-width: 460px; }
.search input { width: 100%; padding: 8px 12px 8px 34px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='10' cy='10' r='6' fill='none' stroke='%23889' stroke-width='2'/%3E%3Cpath d='m15 15 5 5' stroke='%23889' stroke-width='2'/%3E%3C/svg%3E") 10px center/16px no-repeat; color: var(--text); font: 14px var(--mono); outline: none; }
.search input:focus { border-color: var(--accent); background-color: var(--panel); }
#search-results { position: absolute; top: calc(100% + 4px); left: 0; right: 0; margin: 0; padding: 4px; list-style: none; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); max-height: 340px; overflow: auto; z-index: 20; }
#search-results li { padding: 6px 10px; border-radius: 6px; cursor: pointer; display: flex; justify-content: space-between; gap: 12px; }
#search-results li .c { font-family: var(--mono); }
#search-results li .c mark { background: var(--accent-soft); color: inherit; }
#search-results li .o { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 55%; font-size: 12px; }
#search-results li[aria-selected="true"], #search-results li:hover { background: var(--panel-2); }
#search-results li.none { color: var(--muted); cursor: default; }

.updated { font-size: 12.5px; color: var(--muted); white-space: nowrap; display: flex; align-items: center; gap: 6px; }
.updated::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #2fbf71; flex: none; }
.toolbar { display: flex; gap: 4px; margin-left: auto; }
.tool { display: flex; align-items: center; gap: 6px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel); }
.tool svg { width: 18px; height: 18px; }
a.tool { text-decoration: none; color: inherit; }
a.tool[hidden] { display: none; }
.tool:hover { background: var(--panel-2); }
.tool.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- map area ---------- */
.layout { position: relative; flex: 1; min-height: 0; }
#map { position: absolute; inset: 0; }
.basemaps { position: absolute; left: 12px; top: 12px; display: flex; flex-wrap: wrap; gap: 4px 10px; padding: 4px 10px 4px 4px; background: var(--panel); border-radius: 10px; box-shadow: var(--shadow); align-items: center; max-width: calc(100% - 90px); z-index: 2; }
.basemaps .seg { display: flex; gap: 2px; padding: 2px; background: var(--panel-2); border-radius: 8px; }
.basemaps .seg button { border: 0; background: none; padding: 5px 12px; border-radius: 6px; }
.basemaps .seg button.active { background: var(--text); color: var(--panel); }
.basemaps .chk { display: flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; font-size: 13px; }
.basemaps .chk[hidden] { display: none; }
.sw { width: 14px; height: 10px; border-radius: 2px; border: 2px solid; }
.sw-red { border-color: #ff0000; }
.sw-purple { border-color: #7b2cbf; border-style: dashed; }
.sw-dot { width: 10px; height: 10px; border-radius: 50%; border: 2px solid #1b1f24; background: #fff; }
.tool.lang { font-weight: 700; min-width: 40px; justify-content: center; }
.coords { position: absolute; left: 12px; bottom: 30px; padding: 3px 8px; background: color-mix(in srgb, var(--panel) 88%, transparent); border-radius: 6px; font: 12px var(--mono); color: var(--muted); pointer-events: none; }
.coords:empty { display: none; }
.hint { position: absolute; left: 50%; bottom: 64px; transform: translateX(-50%); background: var(--text); color: var(--panel); padding: 7px 14px; border-radius: 20px; font-size: 13px; box-shadow: var(--shadow); pointer-events: none; z-index: 4; max-width: min(640px, calc(100% - 140px)); text-align: center; }
.layout.sb-open .hint { left: calc((100% - 392px) / 2); max-width: min(560px, calc(100% - 520px)); }
.loading { position: absolute; inset: 0; display: grid; place-items: center; background: color-mix(in srgb, var(--bg) 70%, transparent); font-weight: 600; z-index: 10; }
.loading.done { display: none; }
.measure { position: absolute; left: 12px; top: 64px; max-width: calc(100% - 24px); background: var(--panel); padding: 8px 14px; border-radius: 8px; box-shadow: var(--shadow); font: 13px var(--mono); z-index: 4; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: var(--panel); padding: 8px 16px; border-radius: 8px; z-index: 50; }
.boxdraw { position: absolute; top: 0; left: 0; border: 2px dashed var(--accent); background: rgba(212, 0, 0, .08); pointer-events: none; z-index: 3; }

/* ---------- sidebar ---------- */
.sidebar { position: absolute; top: 12px; right: 12px; bottom: 12px; width: 380px; max-width: calc(100% - 24px); background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); display: flex; flex-direction: column; z-index: 6; overflow: hidden; }
.sidebar[hidden] { display: none; }
.sb-head { display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); padding: 4px 6px 0 8px; }
.tabs { display: flex; }
.tabs button { border: 0; background: none; padding: 10px 12px; border-bottom: 2px solid transparent; color: var(--muted); font-weight: 600; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
.badge { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--panel-2); font-size: 12px; text-align: center; }
.icon-btn { border: 0; background: none; padding: 6px 8px; border-radius: 6px; color: var(--muted); }
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.tab-body { padding: 16px; overflow: auto; flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 14px; }
.tab-body[hidden] { display: none; }
.empty { color: var(--muted); padding: 24px 4px; text-align: center; }
.field label { display: block; font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); margin-bottom: 3px; }
.field.big .mono { font-size: 20px; font-weight: 650; }
.value-row { display: flex; align-items: center; gap: 4px; }
.mono { font-family: var(--mono); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }
.num.big { font-size: 20px; font-weight: 650; }
.owners { white-space: pre-line; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.actions, .export { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.export > span { font-size: 11px; font-weight: 600; text-transform: uppercase; color: var(--muted); margin-right: 4px; }
.btn { padding: 6px 10px; border: 1px solid var(--border); background: var(--panel-2); border-radius: 6px; font-size: 13px; }
.btn:hover { border-color: var(--accent); }
.info-btn { display: inline-flex; align-items: center; gap: 8px; align-self: flex-start; padding: 8px 14px; font-weight: 600; }
.info-btn[aria-expanded="true"] { background: var(--accent-soft); border-color: var(--accent); }
.details { display: flex; flex-direction: column; gap: 14px; padding: 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel-2); }
.details[hidden] { display: none; }
.sel-summary { display: flex; justify-content: space-between; align-items: baseline; padding: 10px 12px; background: var(--panel-2); border-radius: 8px; }
.mode { display: flex; gap: 6px; align-items: center; color: var(--muted); font-size: 13px; }
.table-wrap { flex: 1; min-height: 120px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { position: sticky; top: 0; background: var(--panel-2); text-align: left; font-size: 11px; text-transform: uppercase; color: var(--muted); padding: 6px 8px; }
td { padding: 5px 8px; border-top: 1px solid var(--border); vertical-align: top; }
td:first-child { font-family: var(--mono); white-space: nowrap; }
td.o { max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.r { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--panel-2); }
kbd { font: 11px var(--mono); border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; }

.measure .m-k { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-left: 6px; }
.measure .m-k:first-child { margin-left: 0; }
.measure .m-crs { font-size: 11px; color: var(--muted); margin-left: 6px; }
.btn-primary { display: inline-flex; align-items: center; gap: 8px; background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; padding: 8px 12px; }
.btn-primary:hover { filter: brightness(1.08); }
.btn small { font-weight: 400; opacity: .8; }
.export-col { flex-direction: column; align-items: stretch; }

/* ---------- NAPR-style floating vertical toolbar ---------- */
.vtools { position: absolute; right: 12px; top: 12px; display: flex; flex-direction: column; gap: 10px; z-index: 5; transition: right .2s ease; }
.layout.sb-open .vtools { right: 404px; }
.vgroup { display: flex; flex-direction: column; background: #fff; border-radius: 22px; box-shadow: 0 2px 10px rgba(16,24,40,.18), 0 0 0 1px rgba(16,24,40,.06); overflow: visible; }
.vgroup-rel { position: relative; }
.vbtn { width: 42px; height: 42px; display: grid; place-items: center; border: 0; background: none; color: #2b3440; border-radius: 22px; padding: 0; }
.vbtn + .vbtn { border-top: 1px solid #e7eaee; border-radius: 0; }
.vgroup .vbtn:first-child:not(:only-child) { border-radius: 22px 22px 0 0; }
.vgroup .vbtn:last-child:not(:only-child) { border-radius: 0 0 22px 22px; }
.vbtn svg { width: 22px; height: 22px; }
.vbtn:hover { background: #f1f3f6; }
.vbtn.active { color: #fff; background: var(--accent); }
.vbtn[hidden] { display: none; }
.needle { transform-origin: 12px 12px; transition: transform .15s; }
.flyout { position: absolute; right: 52px; top: 0; background: #fff; color: #2b3440; border-radius: 12px; box-shadow: 0 6px 24px rgba(16,24,40,.2); padding: 6px; display: flex; flex-direction: column; gap: 2px; min-width: 170px; }
.flyout[hidden] { display: none; }
.flyout button { display: flex; align-items: center; gap: 10px; border: 0; background: none; padding: 8px 10px; border-radius: 8px; text-align: left; color: inherit; }
.flyout button svg { width: 20px; height: 20px; flex: none; }
.flyout button small { margin-left: auto; color: #6b7684; }
.flyout button:hover, .flyout button.active { background: #f1f3f6; }

/* ---------- medium screens: icon-only top tools so the bar stays on one line ---------- */
@media (max-width: 1280px) {
  .tool:not(.lang) span { display: none; }
  .search { flex-basis: 220px; }
}

/* ---------- mobile ---------- */
@media (max-width: 760px) {
  .topbar { padding: 8px 16px; gap: 8px; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
  .updated { order: 4; font-size: 11.5px; }
  .tool span { display: none; }
  .tool.lang span { display: inline; }
  .sidebar { top: auto; left: 0; right: 0; bottom: 0; width: 100%; max-width: none; height: 55%; border-radius: 14px 14px 0 0; }
  .coords { display: none; }
  .basemaps { font-size: 12px; max-width: calc(100% - 80px); }
  .layout.sb-open .vtools { right: 12px; }
  .hint, .layout.sb-open .hint { left: 50%; bottom: auto; top: 8px; max-width: calc(100% - 80px); font-size: 12px; }
  .vbtn { width: 38px; height: 38px; }
  .vtools { gap: 8px; }
}
