:root {
  --bg: #f4f6fb;
  --text: #1e2433;
  --muted: #6f7788;
  --card: #ffffff;
  --border: #e5e9f2;
  --brand: #1760ff;
  --brand-dark: #0e48c4;
  --premium: #ffb547;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  min-height: 100vh;
}

body.view-map {
  overflow: hidden;
  height: 100dvh;
  height: 100vh;
}

body.view-map #app {
  height: 100dvh;
  height: 100vh;
  max-height: 100dvh;
  max-height: 100vh;
  overflow: hidden;
}

.cabinet-btn-short {
  display: none;
}

.topbar {
  height: 68px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 0 18px;
  gap: 12px;
}

.brand {
  font-weight: 700;
  font-size: 20px;
}

.filters {
  display: flex;
  gap: 8px;
  flex: 1;
  max-width: 760px;
}

.filters input,
.filters select,
.filters button,
.auth button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: var(--text);
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  padding: 0 12px;
  font-size: 14px;
}

.filters input,
.filters select {
  flex: 1;
}

.filters .price-input {
  flex: 1;
  min-width: 140px;
}

.filters .bedrooms-select {
  flex: 0 0 112px;
}

.auth {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

.top-action {
  color: var(--text);
  border-color: transparent;
  background: transparent;
}

.top-action:hover {
  border-color: var(--border);
  background: #fff;
}

.filters button,
.auth button,
.btn {
  cursor: pointer;
}

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

.primary:hover {
  background: var(--brand-dark);
}

.contact-call-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  height: 40px;
  padding: 0 14px;
}

.map-layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 380px 1fr;
}

.map-layout.collapsed {
  grid-template-columns: 1fr;
}

.left-panel {
  border-right: 1px solid var(--border);
  background: #fff;
  overflow: auto;
  padding: 16px;
}

.map-layout.collapsed .left-panel {
  display: none;
}

.left-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.close-left-panel {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}

.map {
  width: 100%;
  height: 100%;
}

.map-wrap {
  position: relative;
  width: 100%;
  height: 100%;
}

.map-draw-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 8;
}

.map-draw-canvas.active {
  pointer-events: auto;
  cursor: crosshair;
}

.open-left-panel-btn {
  position: absolute;
  left: max(10px, env(safe-area-inset-left, 0px));
  top: max(56px, env(safe-area-inset-top, 0px));
  transform: none;
  z-index: 10;
  width: 32px;
  height: 46px;
  border-radius: 10px;
  border: 1px solid var(--brand);
  background: var(--brand);
  color: #fff;
  box-shadow: 0 4px 14px rgba(23, 96, 255, 0.35);
  cursor: pointer;
  display: none;
}

.map-layout.collapsed .open-left-panel-btn {
  display: block;
}

.map-draw-tools {
  position: absolute;
  right: max(14px, env(safe-area-inset-right, 0px));
  top: max(16px, env(safe-area-inset-top, 0px));
  transform: none;
  z-index: 5000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.map-draw-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  font-size: 18px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
}

.map-draw-btn.active {
  border-color: var(--brand);
  color: var(--brand);
}

.card {
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  margin-bottom: 12px;
  background: #fff;
}

.card.premium {
  border-color: var(--premium);
  box-shadow: 0 8px 18px rgba(255, 181, 71, 0.26);
}

.card img {
  width: 100%;
  height: 170px;
  object-fit: cover;
}

.card-body {
  padding: 12px;
}

.price {
  font-size: 20px;
  font-weight: 700;
}

.muted {
  color: var(--muted);
}

.page {
  max-width: 1080px;
  margin: 20px auto;
  padding: 0 14px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 16px;
}

.gallery {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.gallery img {
  width: 100%;
  border-radius: 12px;
  height: 220px;
  object-fit: cover;
  cursor: zoom-in;
}

.gallery-lightbox {
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 24, 0.88);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.gallery-lightbox.open {
  display: flex;
}

.gallery-lightbox-image {
  max-width: min(90vw, 1200px);
  max-height: 80vh;
  border-radius: 14px;
  box-shadow: 0 10px 35px rgba(0, 0, 0, 0.4);
}

.gallery-lightbox-close {
  position: absolute;
  top: 18px;
  right: 18px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.45);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
}

.gallery-lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.45);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 30px;
  line-height: 1;
  cursor: pointer;
}

#galleryPrevBtn {
  left: 18px;
}

#galleryNextBtn {
  right: 18px;
}

.gallery-lightbox-counter {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  color: #fff;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
}

.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.panel-head h2,
.panel-head h3 {
  margin: 0;
}

.cabinet-head-main {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.close-panel-action {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}

.auth-wrap,
.cabinet {
  max-width: 760px;
  margin: 22px auto;
  padding: 0 14px;
}

.cabinet .card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
}

.cabinet .card img {
  width: 88px;
  height: 66px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
}

.cabinet .card .card-body {
  padding: 0;
  min-width: 0;
}

.cabinet .card .card-body p {
  margin: 6px 0 0;
}

.login-page {
  min-height: 100dvh;
  min-height: 100vh;
  background: #f3f3f3;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  padding-bottom: max(20px, env(safe-area-inset-bottom, 0px));
  box-sizing: border-box;
}

.login-wrapper {
  width: 100%;
  max-width: 420px;
}

.login-box {
  background: #fff;
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 5px 20px rgba(0, 0, 0, 0.08);
}

.login-box h3,
.auth-modal-content h3 {
  margin-top: 0;
}

.login-box input,
.auth-modal-content input {
  margin-top: 10px;
}

.login-box .btn,
.auth-modal-content .btn {
  margin-top: 12px;
}

.full {
  width: 100%;
}

.auth-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
}

.auth-modal.active {
  display: flex;
  justify-content: center;
  align-items: flex-end;
}

.auth-modal-content {
  background: #fff;
  width: 100%;
  max-width: 420px;
  padding: 20px;
  border-radius: 20px 20px 0 0;
  max-height: 90vh;
  overflow-y: auto;
}

.phone-group {
  display: flex;
  margin-top: 10px;
}

.phone-group span {
  display: flex;
  align-items: center;
  padding: 0 14px;
  background: #eee;
  border: 1px solid var(--border);
  border-right: none;
  border-radius: 10px 0 0 10px;
  font-size: 14px;
}

.phone-group input {
  margin-top: 0;
  border-radius: 0 10px 10px 0;
}

.note {
  font-size: 12px;
  color: #666;
  margin: 8px 0 0;
}

.checkbox-line {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: 12px;
  font-size: 14px;
  line-height: 1.35;
  cursor: pointer;
}

.checkbox-line input {
  width: 18px;
  height: 18px;
  margin: 2px 0 0;
  flex-shrink: 0;
}

.checkbox-line a {
  color: #007aff;
  text-decoration: none;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.field-block {
  display: flex;
  flex-direction: column;
}

.field-label {
  font-size: 13px;
  color: var(--muted);
  margin: 0 0 6px;
}

.field-block .phone-group {
  margin-top: 0;
}

.photo-drop-zone {
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 12px;
  background: #f8faff;
  color: var(--muted);
  text-align: center;
  margin-bottom: 8px;
}

.photo-drop-zone.active {
  border-color: var(--brand);
  background: #eef3ff;
  color: #264fba;
}

.photo-list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 56px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 10px;
  margin-bottom: 8px;
  background: #fff;
}

.photo-list-row img {
  width: 72px;
  height: 48px;
  object-fit: cover;
  border-radius: 8px;
}

.field-span-2 {
  grid-column: span 2;
}

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

.address-row input {
  margin-top: 0;
}

.address-preview-map {
  margin-top: 10px;
  height: 0;
  border-radius: 12px;
  overflow: hidden;
  transition: height 0.2s ease;
}

.address-preview-map.visible {
  height: 180px;
  border: 1px solid var(--border);
}

input,
textarea,
select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
}

textarea {
  min-height: 120px;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(14, 21, 35, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.modal.open {
  display: flex;
}

.modal-card {
  width: min(620px, 90vw);
  background: #fff;
  border-radius: 16px;
  padding: 16px;
}

@media (max-width: 900px) {
  .map-layout {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(160px, 40vh) minmax(220px, 1fr);
  }

  .map-layout.collapsed {
    grid-template-rows: 1fr;
  }

  .grid-2 {
    grid-template-columns: 1fr;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .field-span-2 {
    grid-column: span 1;
  }

  .topbar {
    height: auto;
    min-height: 56px;
    flex-wrap: wrap;
    padding: 10px 12px;
    padding-left: max(12px, env(safe-area-inset-left, 0px));
    padding-right: max(12px, env(safe-area-inset-right, 0px));
    padding-top: max(10px, env(safe-area-inset-top, 0px));
    gap: 0;
  }

  .brand {
    order: 1;
    font-size: 18px;
  }

  .auth {
    order: 2;
    margin-left: auto;
  }

  .filters {
    order: 3;
    flex: 1 1 100%;
    width: 100%;
    max-width: none;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 8px;
  }

  .filters .price-input,
  .filters .bedrooms-select {
    min-width: 0;
    width: 100%;
  }

  .filters .bedrooms-select {
    grid-column: 1 / -1;
  }

  .filters #moreFilters {
    grid-column: 1;
  }

  .filters #resetFilters {
    grid-column: 2;
  }

  .card img {
    height: 140px;
  }

  .page {
    margin: 12px auto;
    padding: 0 12px;
    padding-bottom: max(16px, env(safe-area-inset-bottom, 0px));
  }

  .cabinet,
  .auth-wrap {
    margin: 12px auto;
    padding: 0 12px;
    padding-bottom: max(16px, env(safe-area-inset-bottom, 0px));
  }

  .address-row {
    flex-direction: column;
  }
}

@media (max-width: 480px) {
  .cabinet-btn-long {
    display: none;
  }

  .cabinet-btn-short {
    display: inline;
  }

  .gallery {
    grid-template-columns: 1fr;
  }

  .gallery img {
    height: 200px;
  }

  .filters input,
  .filters select,
  .filters button,
  .auth button,
  .topbar .btn,
  .login-box input,
  .auth-modal-content input,
  input,
  textarea,
  select {
    font-size: 16px;
  }

  .map-draw-btn {
    width: 44px;
    height: 44px;
  }

  .open-left-panel-btn {
    min-width: 44px;
    min-height: 44px;
  }

  .modal-card {
    width: 100%;
    max-width: none;
    margin: 0 12px;
    max-height: 88dvh;
    max-height: 88vh;
    overflow-y: auto;
  }

  .gallery-lightbox-nav {
    width: 40px;
    height: 40px;
  }

  #galleryPrevBtn {
    left: 8px;
  }

  #galleryNextBtn {
    right: 8px;
  }
}

.topbar-slim {
  flex-wrap: wrap;
  gap: 8px;
}

.topbar-slim .auth {
  margin-left: auto;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.admin-page h1 {
  margin: 0 0 8px;
  font-size: 1.5rem;
}

.admin-page h2 {
  margin: 24px 0 10px;
  font-size: 1.1rem;
}

.admin-tabs {
  display: flex;
  gap: 8px;
  margin: 14px 0 6px;
}

.admin-tab-btn {
  background: #fff;
  border-color: var(--border);
}

.admin-tab-btn.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.admin-tab-panel {
  display: none;
}

.admin-tab-panel.active {
  display: block;
}

.admin-modal-card {
  width: min(720px, 94vw);
  max-height: 86vh;
  overflow-y: auto;
}

.admin-mini-list {
  display: grid;
  gap: 6px;
}

.admin-mini-list-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  background: #fff;
  font-size: 13px;
}

.admin-stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 8px;
}

.admin-stat {
  text-align: center;
  padding: 16px;
}

.admin-stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--brand);
}

.admin-table-wrap {
  overflow-x: auto;
  margin-bottom: 8px;
  -webkit-overflow-scrolling: touch;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.admin-table th,
.admin-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.admin-table th {
  background: #f4f6fb;
  font-weight: 600;
  font-size: 13px;
}

.admin-table tr:last-child td {
  border-bottom: none;
}

.admin-table code {
  font-size: 12px;
  word-break: break-all;
}

.danger-btn {
  background: #b91c1c;
  border-color: #b91c1c;
  color: #fff;
}

.danger-btn:hover {
  background: #991b1b;
  border-color: #991b1b;
}

@media (min-width: 768px) {
  .auth-modal.active {
    align-items: center;
  }

  .auth-modal-content {
    border-radius: 16px;
  }
}
