* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body {
  display: grid;
  height: 100dvh;
  min-height: 100vh;
  /* desktop / wide: боковая колонка фиксированной доли + карта */
  grid-template-columns: clamp(280px, 32vw, 420px) 1fr;
  grid-template-rows: 1fr;
}

/* Bottom sheet виден только на узких экранах */
#sheet { display: none; }

@media (max-width: 820px) {
  body { grid-template-columns: 1fr; grid-template-rows: 1fr; }
  .sidebar { display: none; }
  #map { height: 100dvh; }

  #sheet {
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    background: white;
    box-shadow: 0 -8px 24px rgba(0,0,0,0.12);
    z-index: 5;
    overflow: hidden;
    transition: height 0.25s ease;
  }
  #sheet.sheet--peek { height: 68px; }
  #sheet.sheet--open { height: 75dvh; }
  #sheet.sheet--peek .sheet-body { display: none; }
  #sheet.sheet--open .sheet-toggle { transform: rotate(180deg); }

  .sheet-search {
    padding: 10px 12px;
    border-bottom: 1px solid #eef2f7;
  }
  .sheet-search form {
    display: flex;
    gap: 8px;
    margin: 0;
  }
  .sheet-search input,
  .sheet-search button {
    -webkit-appearance: none;
    appearance: none;
    box-sizing: border-box;
    height: 44px;
    line-height: 1;
    padding: 0 14px;
    margin: 0;
    font-family: inherit;
    font-size: 16px;
    border-radius: 8px;
    border: 1px solid transparent;
    display: block;
  }
  .sheet-search input {
    flex: 1 1 auto;
    min-width: 0;
    border-color: #cbd5e1;
    background: #fff;
    color: #111;
  }
  .sheet-search button[type="submit"] {
    flex: 0 0 auto;
    background: #2563eb;
    color: #fff;
    font-weight: 500;
    cursor: pointer;
  }
  .sheet-search button[type="submit"]:hover { background: #1d4ed8; }
  .sheet-search .sheet-toggle {
    flex: 0 0 auto;
    width: 44px;
    padding: 0;
    background: #f3f4f6;
    color: #475569;
    font-size: 14px;
    cursor: pointer;
    border-color: #cbd5e1;
    transition: transform 0.25s ease;
  }
  .sheet-search .sheet-toggle:hover { background: #e5e7eb; }
  .sheet-search input:focus,
  .sheet-search input:focus-visible { outline: none; border-color: #cbd5e1; }

  .sheet-body {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0 14px;
  }
  .sheet-body:empty { padding: 0; }
  .sheet-body .card { margin-top: 8px; padding: 10px; border: 0; box-shadow: none; }
  .sheet-body .card h2 { font-size: 15px; }
  .sheet-body .card h3 { margin: 10px 0 4px; }

  /* Маплибре зум-контролы выше шторки */
  .maplibregl-ctrl-bottom-right { bottom: 76px !important; }
}

.sidebar {
  padding: clamp(12px, 2vw, 22px);
  overflow-y: auto;
  background: #fafafa;
  border-right: 1px solid #e3e3e3;
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 820px) {
  .sidebar {
    border-right: 0;
    border-top: 1px solid #e3e3e3;
    order: 2;
  }
  #map { order: 1; }
}

.sidebar h1 {
  margin: 0 0 4px;
  font-size: clamp(18px, 2.4vw, 22px);
}

.hint { color: #666; font-size: 13px; margin: 0 0 16px; }

form label {
  display: block;
  margin-bottom: 12px;
  font-size: 13px;
  color: #444;
}

form input, form select {
  width: 100%;
  padding: 10px 12px;
  font-size: 16px; /* 16px чтобы iOS не зумил при фокусе */
  border: 1px solid #ccc;
  border-radius: 6px;
  margin-top: 4px;
}

button {
  background: #2563eb;
  color: white;
  border: 0;
  padding: 10px 18px;
  border-radius: 6px;
  font-size: 15px;
  cursor: pointer;
  min-height: 40px; /* удобный таргет на тач */
}
button:hover { background: #1d4ed8; }

.htmx-indicator { display: none; margin-left: 8px; color: #666; }
.htmx-request .htmx-indicator { display: inline; }

#map {
  height: 100%;
  min-height: 0;
}

.card {
  margin-top: 18px;
  padding: clamp(10px, 1.4vw, 16px);
  background: white;
  border: 1px solid #e3e3e3;
  border-radius: 8px;
}
.card h2 { margin: 0 0 10px; font-size: clamp(15px, 1.6vw, 17px); word-break: break-all; }
.card.error { border-color: #fca5a5; background: #fef2f2; color: #991b1b; }
.card h3 {
  margin: 16px 0 6px;
  font-size: 12px;
  text-transform: uppercase;
  color: #666;
  letter-spacing: 0.5px;
}

.muted { color: #888; font-size: 12px; margin-top: 6px; }
.muted em { font-style: normal; color: #bbb; }

dl { margin: 0; font-size: 13px; }
dt {
  color: #6b7280;
  font-size: 12px;
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: baseline;
}
dt .key {
  color: #aaa;
  font-size: 11px;
  font-family: ui-monospace, monospace;
}
dd { margin: 2px 0 0; color: #111; word-break: break-word; }
dl > dd + dt { border-top: 1px dashed #eee; padding-top: 8px; }

.parcel-popup { font-size: 13px; line-height: 1.5; }
.parcel-popup .lbl { color: #666; }
.parcel-popup b { display: inline-block; width: 22px; }
.custom-marker {
  width: 22px;
  height: 22px;
  background: #dc2626;
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 2px 6px rgba(0,0,0,0.35);
  cursor: pointer;
}

ol.coords {
  margin: 4px 0 0;
  padding: 6px 6px 6px 28px;
  font-family: ui-monospace, monospace;
  font-size: 12px;
  color: #1e3a8a;
  max-height: 240px;
  overflow-y: auto;
  background: #f8fafc;
  border-radius: 4px;
}
ol.coords li { padding: 2px 0; }
.coords-wrap { overflow-x: auto; margin-top: 6px; -webkit-overflow-scrolling: touch; }
table.coords-table { width: 100%; min-width: 0; font-size: 12px; border-collapse: collapse; }
table.coords-table th { text-align: left; background: #f1f5f9; color: #475569; padding: 6px 8px; font-weight: 600; border-bottom: 1px solid #e2e8f0; font-size: 11px; white-space: nowrap; }
table.coords-table td { padding: 5px 8px; border-bottom: 1px solid #f1f5f9; vertical-align: top; }
table.coords-table td:first-child { color: #94a3b8; text-align: right; }
table.coords-table .c-num { font-family: ui-monospace, monospace; font-size: 11.5px; white-space: nowrap; }
table.coords-table tr:hover td { background: #fafbfc; }

.actions {
  margin-top: 12px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.actions a {
  padding: 8px 12px;
  background: #f3f4f6;
  border-radius: 6px;
  text-decoration: none;
  color: #1f2937;
  font-size: 13px;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
}
.actions a:hover { background: #e5e7eb; }

details { margin-top: 10px; font-size: 12px; }
details pre {
  max-height: 300px;
  overflow: auto;
  background: #f8f8f8;
  padding: 8px;
  border-radius: 4px;
  font-size: 11px;
}
