:root {
  --bg: #ffffff;
  --sheet-bg: rgba(255, 255, 255, 0.86);
  --text: #1c1c1e;
  --muted: #8a8a8e;
  --accent: #2563eb;
  --border: rgba(60, 60, 67, 0.12);
  --warn-bg: #fff4e5;
  --warn-text: #8a4b00;
  --field-bg: rgba(118, 118, 128, 0.12);
  --row-bg: rgba(118, 118, 128, 0.06);
  --sheet-radius: 14px;
}

* { box-sizing: border-box; }
::selection { background: rgba(37, 99, 235, 0.2); }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  font-family: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

#map {
  position: fixed;
  inset: 0;
}

/* ---------- Bottom sheet ---------- */

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  height: var(--sheet-h, 92vh);
  max-height: var(--sheet-h, 92vh);
  margin: 0 auto;
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  background: var(--sheet-bg);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  backdrop-filter: blur(24px) saturate(180%);
  border-radius: var(--sheet-radius) var(--sheet-radius) 0 0;
  box-shadow: 0 -6px 30px rgba(0, 0, 0, 0.18);
  transform: translateY(0);
  will-change: transform;
  touch-action: none;
}

.sheet.dragging {
  transition: none;
}

.sheet:not(.dragging) {
  transition: transform 320ms cubic-bezier(0.32, 0.72, 0, 1);
}

@media (min-width: 640px) {
  .sheet {
    left: 16px;
    right: auto;
    bottom: 16px;
    height: 88vh;
    max-height: 760px;
    border-radius: var(--sheet-radius);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.22);
  }
}

.sheet-handle {
  flex: none;
  display: flex;
  justify-content: center;
  padding: 8px 0 2px;
  cursor: grab;
}

.sheet-handle .grip {
  width: 36px;
  height: 5px;
  border-radius: 3px;
  background: rgba(60, 60, 67, 0.28);
}

.sheet-header {
  flex: none;
  padding: 2px 16px 10px;
  cursor: grab;
}

.sheet-title {
  margin: 2px 2px 10px;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.search {
  display: flex;
  align-items: center;
  gap: 8px;
}

.search-field {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  background: var(--field-bg);
  border-radius: 10px;
  transition: background 150ms ease;
}

.search-field:focus-within {
  background: rgba(118, 118, 128, 0.18);
}

.search-icon {
  flex: none;
  color: var(--muted);
}

.search-field input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  font-size: 16px;
  color: var(--text);
  font-family: inherit;
}

.search-field input::placeholder {
  color: var(--muted);
}

.search-clear {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(118, 118, 128, 0.4);
  color: #fff;
  cursor: pointer;
}

.search-cancel {
  flex: none;
  max-width: 0;
  overflow: hidden;
  white-space: nowrap;
  border: none;
  background: transparent;
  color: var(--accent);
  font-size: 16px;
  font-weight: 500;
  padding: 0;
  cursor: pointer;
  opacity: 0;
  transition: max-width 200ms ease, opacity 150ms ease, padding 200ms ease;
}

.search-cancel:not([hidden]) {
  max-width: 90px;
  opacity: 1;
  padding-left: 2px;
}

.sheet-content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px 16px calc(24px + env(safe-area-inset-bottom));
}

.hint {
  margin: 8px 2px 12px;
  font-size: 14px;
  line-height: 1.4;
  color: var(--muted);
}

.notice {
  margin: 0 0 12px;
  padding: 10px 12px;
  font-size: 14px;
  line-height: 1.4;
  background: var(--warn-bg);
  color: var(--warn-text);
  border-radius: 10px;
}

/* ---------- Address card ---------- */

.address-card[hidden] {
  display: none;
}

.address-card {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 4px 0 12px;
  padding: 12px;
  background: var(--row-bg);
  border-radius: 12px;
}

.address-pin {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
}

.address-text {
  flex: 1;
  min-width: 0;
}

.address-title {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
  word-break: break-word;
}

.address-subtitle {
  margin-top: 2px;
  font-size: 13px;
  color: var(--muted);
}

.address-clear {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(118, 118, 128, 0.18);
  color: var(--muted);
  cursor: pointer;
}

.address-clear:hover {
  background: rgba(118, 118, 128, 0.3);
}

/* ---------- Collapsible sections (ГИС ЖКХ / ОДПУ / квартиры / коммерция) ---------- */

.collapsible {
  margin: 0 0 10px;
  background: var(--row-bg);
  border: none;
  border-radius: 12px;
  overflow: hidden;
}

.collapsible summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  cursor: pointer;
  list-style: none;
}

.collapsible summary::-webkit-details-marker {
  display: none;
}

.collapsible-icon {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  font-size: 15px;
  background: #5856d6;
}

.icon-gis { background: #5856d6; }
.icon-odpu { background: #ff9500; }
.icon-apt { background: #34c759; }
.icon-commercial { background: #007aff; }

.collapsible-heading {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.collapsible-title {
  font-size: 15px;
  font-weight: 600;
}

.collapsible-sub {
  margin-top: 1px;
  font-size: 12.5px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chevron {
  flex: none;
  width: 10px;
  height: 10px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
  margin-right: 4px;
  transition: transform 150ms ease;
}

.collapsible[open] .chevron {
  transform: rotate(-135deg);
}

.collapsible-body {
  padding: 2px 12px 12px;
}

/* ---------- Key/value rows (ГИС ЖКХ, ОДПУ шапка) ---------- */

.kv-list {
  display: flex;
  flex-direction: column;
}

.kv-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
}

.kv-row:last-child {
  border-bottom: none;
}

.kv-label {
  color: var(--muted);
  flex: none;
}

.kv-value {
  font-weight: 600;
  text-align: right;
  word-break: break-word;
}

.kv-value-with-action {
  display: flex;
  align-items: center;
  gap: 6px;
}

.copy-btn {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: rgba(118, 118, 128, 0.18);
  color: var(--muted);
  cursor: pointer;
}

.copy-btn:hover {
  background: rgba(118, 118, 128, 0.3);
}

.copy-btn.copied {
  color: #34c759;
}

/* ---------- ОДПУ: показания по периодам ---------- */

.reading-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.reading-row {
  padding: 10px;
  background: #fff;
  border-radius: 10px;
}

.reading-date {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
}

.reading-period {
  font-weight: 400;
  color: var(--muted);
}

.reading-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px 12px;
}

.stat {
  display: flex;
  flex-direction: column;
}

.stat-label {
  font-size: 11px;
  color: var(--muted);
}

.stat-value {
  font-size: 13.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.stat-value.strong {
  color: var(--accent);
}

/* ---------- Показание (значение) ---------- */

.stat-value-empty {
  color: var(--muted);
  font-weight: 500;
}

/* ---------- Квартиры / коммерческие объекты ---------- */

.apt-list {
  display: flex;
  flex-direction: column;
  margin-top: 10px;
}

.apt-row {
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
}

.apt-row:last-child {
  border-bottom: none;
}

.apt-row-top {
  display: flex;
  align-items: center;
  gap: 10px;
}

.apt-badge {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}

.apt-badge.commercial-badge {
  background: #007aff;
  font-size: 14px;
}

.apt-title {
  flex: 1;
  min-width: 0;
  font-size: 13.5px;
  font-weight: 600;
}

.apt-reading {
  flex: none;
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.apt-row-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 4px;
  padding-left: 40px;
}

.apt-sub {
  min-width: 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

/* ---------- Фото ---------- */

.photo-cell {
  flex: none;
  display: flex;
  align-items: center;
  gap: 4px;
}

.photo-thumbs {
  display: inline-flex;
  gap: 4px;
}

.photo-thumb-wrap {
  position: relative;
  display: inline-block;
}

.photo-thumb {
  width: 28px;
  height: 28px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
  display: block;
}

.photo-delete-btn {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 16px;
  height: 16px;
  line-height: 14px;
  padding: 0;
  font-size: 10px;
  color: #fff;
  background: var(--accent);
  border: 1px solid #fff;
  border-radius: 50%;
  cursor: pointer;
}

.photo-uploading {
  font-size: 11px;
  color: var(--muted);
  margin-left: 4px;
  white-space: nowrap;
}

/* =====================================================================
   Крупнее шрифт + карточки с подписанными полями (переопределяет стили выше)
   ===================================================================== */

html { font-size: 17px; }

@media (min-width: 640px) {
  .sheet { max-width: 560px; max-height: 92vh; height: 92vh; }
}

.sheet-title { font-size: 26px; margin-bottom: 12px; }
.search-field { padding: 11px 12px; border-radius: 12px; }
.search-field input, .search-cancel { font-size: 18px; }
.hint, .notice { font-size: 16px; }

.address-card { padding: 14px; gap: 12px; }
.address-pin { width: 36px; height: 36px; }
.address-title { font-size: 18px; }
.address-subtitle { font-size: 15.5px; margin-top: 4px; }
.address-clear { width: 30px; height: 30px; }

.collapsible { border-radius: 14px; margin-bottom: 12px; }
.collapsible summary { padding: 14px; gap: 12px; }
.collapsible-icon { width: 38px; height: 38px; font-size: 19px; border-radius: 10px; }
.collapsible-title { font-size: 18px; }
.collapsible-sub { font-size: 15px; margin-top: 2px; white-space: normal; }
.collapsible-body { padding: 2px 14px 14px; }

.kv-row { font-size: 16px; padding: 10px 0; }
.kv-row-stack { flex-direction: column; align-items: flex-start; gap: 3px; }
.kv-row-stack .kv-value { text-align: left; font-weight: 500; }
.copy-btn { width: 28px; height: 28px; }

/* ---------- Белые карточки (как показания ОДПУ) во всех разделах ---------- */

.reading-list { gap: 10px; margin-top: 12px; }
.reading-row { padding: 14px; border-radius: 12px; }
.reading-date { font-size: 17px; margin-bottom: 10px; }
.reading-period { font-size: 15px; }
.reading-stats { gap: 10px 16px; }
.stat { min-width: 0; }
.stat-wide { grid-column: 1 / -1; }
.stat-label { font-size: 14px; margin-bottom: 1px; }
.stat-value { font-size: 18px; word-break: break-word; }
.reading-note { margin-top: 10px; font-size: 14px; color: var(--muted); }

/* Один счётчик ОДПУ / коммерческого объекта */
.meter-block { padding: 6px 0 16px; }
.meter-block + .meter-block { border-top: 1px solid var(--border); padding-top: 16px; }
.meter-title { font-size: 18px; font-weight: 700; line-height: 1.3; }
.meter-subtitle { font-size: 15px; color: var(--muted); margin-top: 2px; margin-bottom: 4px; }
.apt-list { margin-top: 0; }

.card-photos {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.card-photos-flat { border-top: none; padding-top: 0; }
.card-photos-label { font-size: 14px; color: var(--muted); }

.photo-thumb { width: 44px; height: 44px; border-radius: 8px; }
.photo-delete-btn { width: 20px; height: 20px; font-size: 12px; line-height: 18px; }
.photo-uploading { font-size: 14px; }

/* ---------- Коммерческие объекты: одна белая карточка на объект ---------- */

.obj-list { display: flex; flex-direction: column; gap: 14px; margin-top: 8px; }

.obj-card {
  background: #fff;
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.obj-title {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.3;
  margin-bottom: 12px;
  word-break: break-word;
}

.obj-main .stat-value { font-size: 19px; }
.obj-main .stat-value.strong { font-size: 21px; }

.obj-secondary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 16px;
  margin: 12px 0 0;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.obj-secondary dt { font-size: 12.5px; color: var(--muted); }
.obj-secondary dd { margin: 0; font-size: 14px; color: #48484a; word-break: break-word; }
.obj-secondary div:last-child { grid-column: 1 / -1; }


/* =====================================================================
   Обход: карточки квартир, кнопка «Внести», экран внесения показания
   ===================================================================== */

.apt-cards { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }

.apt-card {
  background: #fff;
  border-radius: 14px;
  padding: 14px;
}
.apt-card-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.apt-card-num { font-size: 18px; font-weight: 700; }
.apt-card-ls { font-size: 15px; color: var(--muted); }
.apt-card-meta { margin-top: 4px; font-size: 14px; color: var(--muted); line-height: 1.35; }
.apt-card-main { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 10px; }
.apt-card-main .stat { min-width: 0; }
.apt-card .photo-cell { margin-top: 10px; }
.apt-card .photo-cell:has(.photo-thumbs:empty) { display: none; }

/* Нижняя строка: миниатюры фото + «Внести» */
.card-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
}
.card-actions .photo-cell { min-width: 0; flex-wrap: wrap; }

.enter-btn {
  flex: none;
  min-width: 112px;
  min-height: 44px;
  padding: 10px 20px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.enter-btn:active { transform: scale(0.97); opacity: 0.9; }

.apt-more { margin-top: 10px; border-top: 1px solid var(--border); padding-top: 8px; }
.apt-more summary {
  font-size: 14.5px;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  list-style: none;
}
.apt-more summary::-webkit-details-marker { display: none; }
.apt-more[open] summary { margin-bottom: 8px; }
.apt-more .obj-secondary { margin-top: 0; padding-top: 0; border-top: none; }

/* ---------- Экран внесения показания ---------- */

body.entry-open { overscroll-behavior: none; }

.entry {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  background: #f2f2f7;
}
.entry[hidden] { display: none; }

.entry-head {
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 14px 12px;
  background: #fff;
  border-bottom: 1px solid var(--border);
}
.entry-back {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: none;
  border-radius: 12px;
  background: var(--row-bg);
  color: var(--text);
  cursor: pointer;
}
.entry-head-text { min-width: 0; }
.entry-title { font-size: 18px; font-weight: 700; line-height: 1.25; word-break: break-word; }
.entry-sub { font-size: 14px; color: var(--muted); margin-top: 1px; }

.entry-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.entry-prev {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: #fff;
  border-radius: 14px;
}
.entry-prev-label { font-size: 14.5px; color: var(--muted); }
.entry-prev-value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; color: #48484a; }

.entry-label { display: block; margin-bottom: 8px; font-size: 14.5px; font-weight: 600; color: #48484a; }

.entry-input {
  display: block;
  width: 100%;
  padding: 16px;
  border: 2px solid transparent;
  border-radius: 14px;
  background: #1c1c1e;
  color: #fff;
  font: inherit;
  font-size: 32px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 1px;
  text-align: center;
  outline: none;
}
.entry-input:focus { border-color: var(--accent); }
.entry-input::placeholder { color: #8a8a8e; font-size: 20px; font-weight: 500; letter-spacing: 0; }

.entry-photo-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 130px;
  border: 2px dashed #c7c7cc;
  border-radius: 14px;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
.entry-photo-btn[hidden] { display: none; }

.entry-photo-preview {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  background: #000;
}
.entry-photo-preview[hidden] { display: none; }
.entry-photo-preview img { display: block; width: 100%; max-height: 300px; object-fit: contain; }
.entry-photo-retake {
  position: absolute;
  right: 10px;
  bottom: 10px;
  min-height: 40px;
  padding: 8px 16px;
  border: none;
  border-radius: 10px;
  background: rgba(28, 28, 30, 0.85);
  color: #fff;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.entry-hint { margin-top: 8px; font-size: 14px; color: var(--muted); }
.entry-hint:empty { display: none; }

.entry-error {
  padding: 12px 14px;
  border-radius: 12px;
  background: #ffe8e6;
  color: #b3261e;
  font-size: 15px;
  line-height: 1.35;
}
.entry-error[hidden] { display: none; }

.entry-foot {
  flex: none;
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  background: #fff;
  border-top: 1px solid var(--border);
}
.entry-save {
  display: block;
  width: 100%;
  min-height: 52px;
  border: none;
  border-radius: 14px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
}
.entry-save:disabled { opacity: 0.6; cursor: default; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 200;
  transform: translateX(-50%);
  padding: 12px 20px;
  border-radius: 12px;
  background: rgba(28, 28, 30, 0.92);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
}
.toast[hidden] { display: none; }

.auth-screen{position:fixed;inset:0;background:#eef3f8;z-index:99999;display:grid;place-items:center;padding:20px}.auth-screen[hidden]{display:none}.login-card{width:min(100%,370px);padding:28px;background:white;border-radius:18px;box-shadow:0 12px 40px #0002;display:grid;gap:14px;font-family:Arial,sans-serif}.login-card h2{margin:0}.login-card p{margin:0;color:#687484}.login-card input{font:inherit;padding:13px;border:1px solid #cdd5e0;border-radius:9px}.login-card button{padding:13px;border:0;border-radius:9px;background:#1877e8;color:white;font:inherit;cursor:pointer}.login-card #login-error{color:#b42318}.logout-button{position:fixed;right:12px;top:12px;z-index:5000;border:0;border-radius:9px;background:white;padding:9px;box-shadow:0 2px 9px #0003}
