:root {
  --pink: #e5c2c5;
  --pink-light: #f4e8e9;
  --navy: #0a0f2c;
  --navy-soft: #1a2040;
  --white: #ffffff;
  --gray-100: #faf8f8;
  --gray-200: #e8e2e2;
  --gray-400: #8a8585;
  --radius: clamp(10px, 2vw, 14px);
  --radius-sm: clamp(6px, 1.5vw, 10px);
  --font-text: "Montserrat", system-ui, sans-serif;
  --font-brand: "Playfair Display", Georgia, "Times New Roman", serif;
  --font-num: "Roboto Mono", ui-monospace, monospace;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --pad-x: clamp(14px, 4.5vw, 40px);
  --app-max: 1120px;
  --card-cols: 1;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-family: var(--font-text);
  background: var(--pink);
  color: var(--navy);
  min-height: 100dvh;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* Layout tiers (set by JS + media queries) */
body[data-layout="xs"] { --card-cols: 1; --pad-x: 12px; }
body[data-layout="sm"] { --card-cols: 1; }
body[data-layout="md"] { --card-cols: 2; }
body[data-layout="lg"] { --card-cols: 2; }
body[data-layout="xl"] { --card-cols: 3; }

@media (min-width: 520px)  { :root, body[data-layout="sm"] { --card-cols: 2; } }
@media (min-width: 900px)  { :root, body[data-layout="md"] { --card-cols: 2; } }
@media (min-width: 1200px) { :root, body[data-layout="lg"],
                              body[data-layout="xl"] { --card-cols: 3; } }

/* Watermark */
.watermark {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  user-select: none;
  background-image: url("assets/logo-brand.png");
  background-repeat: repeat;
  background-size: clamp(120px, 24vw, 180px) auto;
  opacity: 0.06;
  mix-blend-mode: normal;
}

.watermark::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, transparent 15%, var(--pink) 90%);
  opacity: 0.45;
}

/* Shell */
.app-shell {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  padding: 0 var(--pad-x);
}

.app {
  width: 100%;
  max-width: var(--app-max);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(8px + var(--safe-bottom));
}

@media (min-width: 768px) {
  body[data-layout="lg"] .app-shell,
  body[data-layout="xl"] .app-shell {
    padding-top: 12px;
  }

  body[data-layout="lg"] .app,
  body[data-layout="xl"] .app {
    min-height: auto;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 0 40px rgba(10, 15, 44, 0.06);
    margin-bottom: 24px;
  }
}

/* Header */
.brand-header {
  text-align: center;
  padding: calc(16px + var(--safe-top)) 0 14px;
}

.brand-logo {
  width: clamp(148px, 40vw, 188px);
  height: auto;
  display: block;
  margin: 0 auto 14px;
}

.brand-tagline {
  font-family: var(--font-text);
  font-size: clamp(8px, 2.4vw, 11px);
  font-weight: 300;
  letter-spacing: clamp(0.18em, 0.6vw, 0.28em);
  text-transform: lowercase;
  color: var(--navy);
  line-height: 1.65;
  padding: 0 8px;
  max-width: 360px;
  margin: 0 auto;
  word-wrap: break-word;
}

.num {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
}

/* Stats */
.stats-row {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 0 12px;
  padding: clamp(12px, 3vw, 16px) clamp(16px, 4vw, 24px);
  background: rgba(255, 255, 255, 0.88);
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.65);
  max-width: 360px;
  margin-left: auto;
  margin-right: auto;
  width: 100%;
}

.stat {
  flex: 1;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-num {
  font-size: clamp(20px, 5vw, 26px);
  font-weight: 500;
  line-height: 1;
}

.stat-label {
  font-size: clamp(8px, 2vw, 9px);
  letter-spacing: 0.14em;
  text-transform: lowercase;
  color: var(--gray-400);
}

.stat-divider {
  width: 1px;
  height: clamp(28px, 7vw, 36px);
  background: var(--gray-200);
  flex-shrink: 0;
}

/* Controls block */
.controls-block {
  width: 100%;
  max-width: 720px;
  margin: 0 auto 4px;
}

.search-wrap {
  position: relative;
  margin-bottom: 10px;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--gray-400);
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: clamp(10px, 2.5vw, 13px) 14px clamp(10px, 2.5vw, 13px) 38px;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  font-family: var(--font-text);
  font-size: clamp(12px, 3.2vw, 14px);
  color: var(--navy);
  outline: none;
}

.search-input:focus { border-color: var(--navy-soft); }
.search-input::placeholder { color: var(--gray-400); }

/* Tabs */
.tabs {
  display: flex;
  gap: clamp(4px, 1.5vw, 8px);
  margin-bottom: 10px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 2px;
}

.tabs::-webkit-scrollbar { display: none; }

@media (min-width: 520px) {
  .tabs { justify-content: center; flex-wrap: wrap; overflow: visible; }
}

.tab {
  flex: 1 1 auto;
  min-width: 0;
  padding: clamp(7px, 2vw, 10px) clamp(10px, 3vw, 18px);
  border: 1px solid var(--gray-200);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.88);
  font-family: var(--font-text);
  font-size: clamp(10px, 2.8vw, 12px);
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--navy-soft);
  cursor: pointer;
  white-space: nowrap;
  text-align: center;
}

@media (min-width: 520px) {
  .tab { flex: 0 1 auto; }
}

.tab.active {
  background: var(--navy);
  border-color: var(--navy);
  color: var(--white);
}

/* Toolbar */
.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  min-height: 28px;
}

.toolbar-count {
  font-size: clamp(9px, 2.5vw, 11px);
  color: var(--gray-400);
  letter-spacing: 0.05em;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toolbar-sort {
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid var(--gray-200);
  font-family: var(--font-text);
  font-size: clamp(9px, 2.5vw, 11px);
  font-weight: 500;
  color: var(--navy-soft);
  cursor: pointer;
  padding: 5px 12px;
  border-radius: 999px;
}

.toolbar-sort.active {
  background: var(--navy);
  border-color: var(--navy);
  color: var(--white);
}

/* Cards grid */
.cards {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(var(--card-cols), minmax(0, 1fr));
  gap: clamp(8px, 2vw, 12px);
  width: 100%;
  align-content: start;
}

/* Card */
.card {
  background: rgba(255, 255, 255, 0.9);
  border-radius: var(--radius);
  padding: clamp(10px, 2.8vw, 14px);
  border: 1px solid rgba(255, 255, 255, 0.75);
  display: flex;
  flex-direction: column;
  gap: clamp(6px, 1.5vw, 8px);
  min-width: 0;
  user-select: none;
  -webkit-user-select: none;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 6px;
  min-width: 0;
}

.card-cad {
  font-size: clamp(8px, 2.2vw, 10px);
  color: var(--gray-400);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  flex: 1;
}

.card-district {
  font-size: clamp(7px, 2vw, 8px);
  letter-spacing: 0.1em;
  text-transform: lowercase;
  color: var(--gray-400);
  flex-shrink: 0;
}

.card-addr {
  font-size: clamp(13px, 3.5vw, 15px);
  font-weight: 500;
  line-height: 1.35;
  word-break: break-word;
}

.card-chips {
  display: flex;
  flex-wrap: wrap;
  gap: clamp(4px, 1.2vw, 6px);
}

.chip {
  display: inline-flex;
  align-items: baseline;
  gap: 3px;
  padding: 3px clamp(6px, 2vw, 10px);
  background: var(--pink-light);
  border-radius: 999px;
  border: 1px solid rgba(229, 194, 197, 0.45);
}

.chip-l {
  font-size: clamp(7px, 2vw, 8px);
  letter-spacing: 0.08em;
  text-transform: lowercase;
  color: var(--gray-400);
}

.chip-v {
  font-size: clamp(11px, 3vw, 13px);
  font-weight: 500;
}

.card-desc-preview {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  width: 100%;
  text-align: left;
  padding: clamp(6px, 2vw, 9px) clamp(8px, 2.5vw, 10px);
  border: none;
  border-radius: var(--radius-sm);
  background: rgba(244, 232, 233, 0.65);
  cursor: pointer;
  font-family: inherit;
  min-width: 0;
}

.card-desc-preview:active { background: rgba(244, 232, 233, 0.95); }

.desc-icon {
  flex-shrink: 0;
  width: 13px;
  height: 13px;
  margin-top: 2px;
  background: var(--navy);
  opacity: 0.45;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Cpath d='M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z'/%3E%3Cpath d='M14 2v6h6M8 13h8M8 17h5'/%3E%3C/svg%3E") center/contain no-repeat;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Cpath d='M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z'/%3E%3Cpath d='M14 2v6h6M8 13h8M8 17h5'/%3E%3C/svg%3E") center/contain no-repeat;
}

.desc-text {
  flex: 1;
  min-width: 0;
  font-size: clamp(10px, 2.8vw, 12px);
  line-height: 1.4;
  color: var(--navy-soft);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.desc-more {
  flex-shrink: 0;
  font-size: 8px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--navy);
  opacity: 0.55;
  padding-top: 2px;
}

/* Buttons */
.card-actions {
  display: flex;
  gap: clamp(6px, 1.5vw, 8px);
  margin-top: 2px;
}

@media (max-width: 359px) {
  .card-actions { flex-direction: column; }
}

.btn {
  padding: clamp(9px, 2.5vw, 11px) clamp(10px, 3vw, 14px);
  border-radius: var(--radius-sm);
  font-family: var(--font-text);
  font-size: clamp(10px, 2.6vw, 11px);
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  border: none;
  background: var(--navy);
  color: var(--white);
  transition: opacity 0.12s;
  white-space: nowrap;
}

.btn:hover { opacity: 0.88; }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--gray-200);
  color: var(--navy-soft);
}

.btn-ghost:hover {
  background: var(--gray-100);
  opacity: 1;
}

.card-actions .btn { flex: 1; min-width: 0; margin: 0; }
.card-actions .btn-ghost { flex: 0 1 42%; }

@media (max-width: 359px) {
  .card-actions .btn,
  .card-actions .btn-ghost { flex: 1 1 auto; width: 100%; }
}

/* Empty & footer */
.empty {
  text-align: center;
  padding: clamp(32px, 8vw, 48px) 16px;
  grid-column: 1 / -1;
}

.empty p { font-size: clamp(14px, 4vw, 17px); font-weight: 500; margin-bottom: 4px; }
.empty span { font-size: clamp(11px, 3vw, 13px); color: var(--gray-400); }

.hidden { display: none !important; }

.app-footer {
  text-align: center;
  padding: 12px 0 4px;
  font-size: clamp(8px, 2.2vw, 9px);
  color: var(--gray-400);
  letter-spacing: 0.1em;
}

/* Bottom sheet */
body.sheet-open { overflow: hidden; }

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(10, 15, 44, 0.4);
  opacity: 0;
  transition: opacity 0.28s ease;
}

.sheet-backdrop.open { opacity: 1; }

.sheet {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 201;
  width: min(100%, 520px);
  max-height: min(88dvh, 88vh);
  background: var(--white);
  border-radius: 18px 18px 0 0;
  display: flex;
  flex-direction: column;
  transform: translate(-50%, 100%);
  transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1);
  box-shadow: 0 -8px 40px rgba(10, 15, 44, 0.15);
}

.sheet.open { transform: translate(-50%, 0); }

.sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--gray-200);
  border-radius: 999px;
  margin: 10px auto 0;
  flex-shrink: 0;
}

.sheet-body {
  flex: 1;
  overflow-y: auto;
  padding: clamp(12px, 4vw, 20px);
  -webkit-overflow-scrolling: touch;
}

.sheet-cad { font-size: 10px; color: var(--gray-400); margin-bottom: 6px; }
.sheet-title { font-size: clamp(17px, 4.5vw, 22px); font-weight: 500; line-height: 1.25; margin-bottom: 4px; }
.sheet-district { font-size: 10px; letter-spacing: 0.1em; text-transform: lowercase; color: var(--gray-400); margin-bottom: 14px; }
.sheet-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.sheet-desc-block { background: var(--pink-light); border-radius: var(--radius); padding: clamp(12px, 3vw, 16px); margin-bottom: 14px; }
.sheet-desc-label { font-size: 8px; letter-spacing: 0.14em; text-transform: lowercase; color: var(--gray-400); margin-bottom: 8px; }
.sheet-desc { font-size: clamp(12px, 3.2vw, 14px); line-height: 1.55; color: var(--navy-soft); white-space: pre-wrap; word-break: break-word; }
.sheet-full-addr { font-size: 10px; color: var(--gray-400); line-height: 1.5; padding-top: 8px; border-top: 1px solid var(--gray-200); word-break: break-all; }

.sheet-footer {
  padding: 12px clamp(12px, 4vw, 20px) calc(12px + var(--safe-bottom));
  border-top: 1px solid var(--gray-200);
  flex-shrink: 0;
}

.sheet-footer .btn { width: 100%; }

/* Toast */
@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.toast {
  position: fixed;
  bottom: calc(16px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--navy);
  color: var(--white);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: clamp(10px, 2.8vw, 12px);
  z-index: 300;
  pointer-events: none;
  animation: toast-in 0.25s ease;
  max-width: calc(100vw - 24px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Content protection */
.card-addr, .desc-text, .sheet-desc, .sheet-full-addr {
  -webkit-touch-callout: none;
}

@media (prefers-reduced-motion: reduce) {
  .sheet, .sheet-backdrop, .toast { transition: none; animation: none; }
}

/* Экран «только Telegram» */
.gate {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  text-align: center;
  background: var(--bg, #f7f5f4);
}

.gate-logo {
  width: min(180px, 60vw);
  margin-bottom: 28px;
}

.gate-title {
  font-family: "Playfair Display", serif;
  font-size: clamp(20px, 5vw, 26px);
  font-weight: 500;
  color: var(--navy, #0a0f2c);
  margin-bottom: 12px;
}

.gate-text {
  font-size: clamp(13px, 3.5vw, 15px);
  line-height: 1.55;
  color: var(--gray-400, #8a8585);
  max-width: 320px;
}

.gate-text strong {
  color: var(--navy, #0a0f2c);
  font-weight: 500;
}
