:root {
	--gap: 10px;
	--panel: rgba(255, 255, 255, .95);
	--line: #d7deea;
	--text: #0f172a;
	--muted: #64748b;
	--accent: #2563eb;
	--accent-soft: #eff6ff;
	--danger: #dc2626;
	--ok: #15803d;
	--shadow: 0 12px 36px rgba(15, 23, 42, .18);
	--toolbar-h: 64px;
	--sidebar-w: 382px;
	--radius: 18px
}

* {
	box-sizing: border-box
}

html,
body {
	width: 100%;
	height: 100%;
	margin: 0;
	font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
	color: var(--text);
	overflow: hidden;
	background: #dbe5f1
}

.app {
	position: relative;
	width: 100%;
	height: 100%
}

#map {
	position: absolute;
	inset: 0;
	z-index: 1
}

.leaflet-control-zoom {
	display: none !important
}

.leaflet-container {
	background: #dce6f3
}

.leaflet-container.is-picking-label,
.leaflet-container.is-picking-label * {
	cursor: crosshair !important
}

.leaflet-container.inspect-mode,
.leaflet-container.inspect-mode * {
	cursor: default !important
}

.topbar {
	position: absolute;
	top: var(--gap);
	left: var(--gap);
	right: var(--gap);
	min-height: var(--toolbar-h);
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 10px 14px;
	background: var(--panel);
	border: 1px solid rgba(255, 255, 255, .72);
	border-radius: var(--radius);
	box-shadow: var(--shadow);
	backdrop-filter: blur(12px);
	z-index: 1000
}

.brand {
	display: flex;
	align-items: center;
	gap: 12px;
	min-width: 0
}

.brand-badge {
	width: 42px;
	height: 42px;
	border-radius: 12px;
	background: linear-gradient(135deg, #2563eb, #1e40af);
	color: #fff;
	display: grid;
	place-items: center
}

.brand-title {
	font-size: 13px;;
	font-weight: 800
}

.brand-subtitle {
	font-size: 11px;
	color: var(--muted)
}

.topbar-actions {
	display: flex;
	align-items: center;
	gap: 8px;
	flex-wrap: wrap;
	justify-content: flex-end
}

.tool-btn,
.btn,
.icon-btn,
.mini-btn,
.list-item {
	border: 1px solid var(--line);
	background: #fff;
	color: var(--text);
	border-radius: 12px;
	transition: .18s ease;
	box-shadow: 0 1px 0 rgba(255, 255, 255, .8) inset
}

.tool-btn {
	width: 46px;
	height: 46px;
	display: grid;
	place-items: center;
	font-size: 17px;
	cursor: pointer
}

.tool-btn.active {
	background: var(--accent-soft);
	color: var(--accent);
	border-color: #bfdbfe
}

.btn {
	height: 36px;
	padding: 0 10px;
	display: inline-flex;
	align-items: center;
	gap: 8px;
	font-size: 12px;
	font-weight: 700;
	cursor: pointer
}

.btn.primary {
	background: var(--accent);
	color: #fff;
	border-color: var(--accent)
}

.btn.success {
	background: var(--ok);
	color: #fff;
	border-color: var(--ok)
}

.btn.danger {
	color: var(--danger);
	border-color: #fecaca;
	background: #fff
}

.icon-btn {
	width: 42px;
	height: 42px;
	display: grid;
	place-items: center;
	cursor: pointer
}

.sidebar {
	position: absolute;
	top: calc(var(--gap) + var(--toolbar-h) + var(--gap));
	right: var(--gap);
	width: min(var(--sidebar-w), calc(100vw - 32px));
	max-height: calc(100vh - 112px);
	background: var(--panel);
	border: 1px solid rgba(255, 255, 255, .75);
	border-radius: 22px;
	box-shadow: var(--shadow);
	backdrop-filter: blur(12px);
	z-index: 1000;
	display: flex;
	flex-direction: column;
	overflow: hidden
}

.sidebar.is-hidden {
	display: none
}

.sidebar-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 16px 18px 12px;
	border-bottom: 1px solid #e8edf4
}

.sidebar-title {
	font-size: 15px;
	font-weight: 800
}

.sidebar-body {
	padding: 14px;
	overflow: auto;
	display: flex;
	flex-direction: column;
	gap: 14px
}

.panel {
	display: none;
	flex-direction: column;
	gap: 12px;
	border: 1px solid #e6ebf2;
	background: #fbfdff;
	border-radius: 18px;
	padding: 14px
}

.panel.active {
	display: flex
}

.panel h3 {
	margin: 0;
	font-size: 13px;
	font-weight: 700
}

.field {
	display: flex;
	flex-direction: column;
	gap: 6px
}

.field label {
	font-size: 11px;
	font-weight: 700;
	color: #334155
}

.input,
.textarea,
.select {
	width: 100%;
	border: 1px solid #d9e1ec;
	background: #fff;
	border-radius: 12px;
	padding: 11px 12px;
	font: inherit;
	color: inherit;
	outline: none;
	font-size: 13px;
}

.textarea {
	min-height: 88px;
	resize: vertical
}

.row {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 10px
}

.compact-row {
	display: flex;
	gap: 8px;
	flex-wrap: wrap
}

.range-wrap {
	display: flex;
	align-items: center;
	gap: 10px
}

.range-wrap input[type=range] {
	flex: 1
}

.value-box,
.empty-state {
	min-height: 36px;
	padding: 8px 12px;
	border: 1px solid #dbe4ef;
	border-radius: 12px;
	background: #fff;
	font-size: 11px;
	color: #334155
}

.search-input-wrap {
	position: relative
}

.search-input-wrap i {
	position: absolute;
	left: 12px;
	top: 50%;
	transform: translateY(-50%);
	color: #64748b;
	font-size: 13px;
}

.search-input-wrap .input {
	padding-left: 36px
}

.result-list,
.object-list {
	display: flex;
	flex-direction: column;
	gap: 10px;
	max-height: 320px;
	overflow: auto
}

.list-item {
	padding: 12px;
	display: flex;
	flex-direction: column;
	gap: 8px;
	cursor: pointer;
	text-align: left
}

.list-item.active {
	background: #eff6ff;
	border-color: #bfdbfe
}

.list-title {
	font-size: 12px;
	font-weight: 800
}

.list-meta {
	font-size: 11px;
	color: var(--muted)
}

.mini-btn {
	height: 32px;
	padding: 0 10px;
	font-size: 11px;
	font-weight: 700;
	display: inline-flex;
	align-items: center;
	gap: 6px;
	cursor: pointer
}

.help-fab {
	position: absolute;
	left: 24px;
	bottom: 24px;
	width: 54px;
	height: 54px;
	border-radius: 999px;
	background: #fff;
	border: 1px solid rgba(255, 255, 255, .85);
	box-shadow: var(--shadow);
	display: grid;
	place-items: center;
	z-index: 1000;
	font-size: 20px;
	cursor: pointer
}

.tooltip {
	position: absolute;
	max-width: 280px;
	padding: 10px 12px;
	border-radius: 12px;
	background: rgba(15, 23, 42, .92);
	color: #fff;
	font-size: 11px;
	line-height: 1.45;
	box-shadow: 0 10px 20px rgba(15, 23, 42, .18);
	pointer-events: none;
	opacity: 0;
	transition: opacity .15s ease;
	z-index: 1200
}

.map-label {
	display: inline-flex;
	overflow: hidden;
	align-items: center;
	justify-content: center;
	border: 1px solid rgba(15, 23, 42, .12);
	box-shadow: 0 4px 12px rgba(15, 23, 42, .12);
	font-weight: 700;
	white-space: nowrap;
	transform: translate(-50%, -50%);
	line-height: 1;
	text-align: center;
}

.map-label.transparent {
	background: transparent;
	border-color: transparent;
	box-shadow: none
}

.leaflet-div-icon {
	background: transparent;
	border: none
}

.inline-check {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	font-size: 11px;
	font-weight: 700;
	color: #334155;
	background: #fff;
	border: 1px solid #dbe4ef;
	border-radius: 12px;
	padding: 10px 12px;
	user-select: none
}

.inline-check input {
	margin: 0
}

.hint-box {
	font-size: 10px;
	color: var(--muted);
	line-height: 1.45;
	background: #f8fafc;
	border: 1px dashed #cbd5e1;
	border-radius: 12px;
	padding: 10px 12px
}

.list-link a {
	font-size: 10px;
	color: black;
}

/* ── Responsive ─────────────────────────────────────────────────────────────
   768 px  tablet / large phone  — sidebar becomes a bottom sheet,
                                   topbar stays horizontal but compact.
   480 px  phone                 — tighter padding, smaller controls,
                                   constrained textarea / list heights.
   ───────────────────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
	:root {
		--gap: 10px;
		--toolbar-h: 56px
	}

	.help-fab {
		display: none
	}

	.row {
		grid-template-columns: 1fr
	}

	/* Topbar: stays horizontal, shrinks padding, no column flip */
	.topbar {
		flex-direction: row;
		align-items: center;
		padding: 8px 12px;
		gap: 8px;
		border-radius: 14px
	}

	.brand-badge {
		width: 36px;
		height: 36px;
		border-radius: 10px;
		font-size: 15px
	}

	.brand-title {
		font-size: 13px;
	}

	.brand-subtitle {
		display: none
	}

	/* Actions strip: single scrollable row, no wrapping */
	.topbar-actions {
		/*overflow-x: auto; */
		/* flex-wrap: nowrap;*/
		scrollbar-width: none;
		-webkit-overflow-scrolling: touch
	}

	.topbar-actions::-webkit-scrollbar {
		display: none
	}

	/* Prevent buttons from shrinking inside the scroll strip */
	.tool-btn,
	.btn {
		flex-shrink: 0
	}

	/* Sidebar → bottom sheet */
	.sidebar {
		left: var(--gap);
		right: var(--gap);
		bottom: var(--gap);
		/* top: auto;*/
		width: auto;
		height: fit-content;
		max-height: 58vh;
		border-radius: 18px
	}

	/* Drag-handle indicator at top of bottom sheet */
	.sidebar::before {
		content: '';
		display: block;
		width: 36px;
		height: 4px;
		background: rgba(15, 23, 42, .15);
		border-radius: 2px;
		margin: 10px auto 0;
		flex-shrink: 0
	}
}

@media (max-width: 480px) {
	/* Truncate long brand title before it squeezes the action strip */
	.brand-title {
		font-size: 10px;
		/* white-space: nowrap;*/
		overflow: hidden;
		text-overflow: ellipsis;
		max-width: 120px
	}

	.tool-btn {
		width: 40px;
		height: 40px;
		font-size: 12px;
		border-radius: 10px
	}

	.btn {
		height: 40px;
		padding: 0 10px;
		font-size: 12px;
		border-radius: 10px
	}

	.sidebar {
		height: fit-content;
		max-height: 64vh
	}

	.sidebar-body {
		padding: 10px;
		gap: 10px
	}

	.panel {
		padding: 10px;
		gap: 8px;
		border-radius: 14px
	}

	/* Compact textarea so it doesn't eat the whole sheet */
	.textarea {
		min-height: 64px
	}

	/* Shorter scrollable lists so footer buttons stay reachable */
	.result-list,
	.object-list {
		max-height: 180px
	}
}

/* ── Edit-only controls ────────────────────────────────────────────────────
   Hidden by default (view mode). body[data-app-mode="edit"] reveals them.
   Two selectors are required: .tool-btn uses display:grid (icon centering
   via place-items) while .btn uses display:inline-flex. A single
   inline-flex rule would break the grid-based icon alignment on tool buttons.
   ───────────────────────────────────────────────────────────────────────── */
.edit-only {
	display: none !important;
}

body[data-app-mode="edit"] .tool-btn.edit-only {
	display: grid !important;
}

body[data-app-mode="edit"] .btn.edit-only {
	display: inline-flex !important;
}

/* ── Kadastr ──────────────────────────────────────────────────────────────── */

:root {
  --kadastr-color:        #c0392b;
  --kadastr-color-hover:  #e74c3c;
  --kadastr-color-border: #a93226;
  --kadastr-panel-w:      320px;
  --kadastr-panel-z:      1100;
}

#toggleKadastrBtn.active {
  background:   var(--kadastr-color);
  color:        #fff;
  border-color: var(--kadastr-color-border);
}

.kadastr-info-panel {
  display:      none;
  position:     fixed;
  top:       94px;
  left: 18px;
  /*right:        var(--gap); */
  /*width:        min(var(--kadastr-panel-w), 120vw); */
  max-width: 30%;
  max-height:   60vh;
  overflow-y:   auto;
  background:   var(--panel);
  border:       1px solid var(--line);
  border-radius: var(--radius);
  box-shadow:   var(--shadow);
  z-index:      var(--kadastr-panel-z);
  font-size:    12px;
}
.kadastr-info-panel.visible { display: flex; flex-direction: column; }

.kadastr-info-header {
  display:         flex;
  align-items:     center;
  justify-content: space-between;
  padding:         10px 14px 8px;
  border-bottom:   1px solid var(--line);
  background:      var(--panel);
  border-radius:   var(--radius) var(--radius) 0 0;
  position:        sticky;
  top:             0;
  z-index:         1;
}
.kadastr-info-title {
  font-weight: 700;
  font-size:   14px;
  color:       var(--text);
}
.kadastr-info-close {
  background:    none;
  border:        none;
  cursor:        pointer;
  color:         var(--muted);
  font-size:     14px;
  padding:       2px 4px;
  border-radius: 4px;
  line-height:   1;
}
.kadastr-info-close:hover {
  color:      var(--kadastr-color);
  background: #fdecea;
}

.kadastr-info-body { padding: 10px 14px; }

.kadastr-info-row {
  display:         flex;
  justify-content: space-between;
  gap:             8px;
  padding:         4px 0;
  border-bottom:   1px solid var(--line);
  font-size:       12px;
}
.kadastr-info-row:last-child { border-bottom: none; }

.kadastr-info-key {
  color:      var(--muted);
  flex-shrink: 0;
  max-width:  45%;
  word-break: break-word;
}
.kadastr-info-val {
  color:      var(--text);
  text-align: right;
  word-break: break-all;
}
.kadastr-cadnum {
  font-weight:  700;
  color:        var(--kadastr-color);
  font-family:  monospace;
  font-size:    12px;
}
.kadastr-info-empty {
  color:        var(--muted);
  font-style:   italic;
  margin-bottom: 8px;
}
.kadastr-raw-dump {
  font-size:    10px;
  background:   #f8fafc;
  padding:      8px;
  border-radius: 6px;
  overflow-x:   auto;
  white-space:  pre-wrap;
  word-break:   break-all;
  color:        var(--muted);
}


/* ===== Mobile Optimization Enhancements ===== */

html,
body {
    min-height: 100vh;
    min-height: 100dvh;
}

.app {
    min-height: 100vh;
    min-height: 100dvh;
}

html,
body,
.app {
    overflow-x: hidden;
}


@media (max-width: 768px) {
    :root {
        --shadow: 0 4px 12px rgba(15,23,42,.12);
    }

    .topbar {
        overflow: hidden;
    }

    .topbar-actions {
        overflow-x: auto;
        flex-wrap: nowrap;
        max-width: 55%;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
    }

    .topbar-actions::-webkit-scrollbar {
        display: none;
    }

    .sidebar {
        max-height: 58dvh;
    }

    .topbar,
    .sidebar {
        backdrop-filter: blur(6px);
    }

    .kadastr-info-panel {
        left: 10px;
        right: 10px;
        width: auto;
        max-width: none;
        top: 80px;
        max-height: 50dvh;
    }

    .tool-btn,
    .icon-btn {
        min-width: 48px;
        min-height: 48px;
    }

    .btn {
        min-height: 48px;
    }
}

@media (max-width: 480px) {
    .sidebar {
        max-height: 70dvh;
    }

    .topbar,
    .sidebar {
        backdrop-filter: none;
        background: rgba(255,255,255,.98);
    }

    .tool-btn,
    .icon-btn,
    .btn {
        min-width: 44px;
        min-height: 44px;
    }
}

.topbar {
    padding-top: max(10px, env(safe-area-inset-top));
}

.sidebar {
    padding-bottom: env(safe-area-inset-bottom);
}

.help-fab {
    bottom: calc(24px + env(safe-area-inset-bottom));
}
.info-box {

	font-size: 12px;
}
.info-box strong {
	color: darkgray;
	font-weight: normal;
}
.search-row {
    display: flex;
    gap: 8px;
    align-items: stretch;
}

.search-row .search-input-wrap {
    flex: 1;
}

.search-row .btn {
    flex-shrink: 0;
    height: auto;
}
@media (max-width: 480px) {
    .search-row {
        flex-direction: column;
    }
}