* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #f5f5f5;
}

/* --- Header --- */
header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: #fff;
  border-bottom: 1px solid #ddd;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
  z-index: 1000;
  position: relative;
}

header h1 {
  font-size: 16px;
  font-weight: 700;
  color: #222;
  flex: 1;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.counter { font-size: 12px; color: #555; white-space: nowrap; }

#refreshBtn {
  padding: 6px 12px; font-size: 12px;
  background: #248bf2; color: #fff;
  border: none; border-radius: 5px; cursor: pointer;
  transition: background .2s;
}
#refreshBtn:hover { background: #1a7ad9; }
#refreshBtn:disabled { opacity: .6; cursor: not-allowed; }

#loginBtn, #logoutBtn {
  text-decoration: none;
  font-size: 16px;
  padding: 2px 4px;
}

/* --- Burger --- */
.burger {
  display: flex;
  flex-direction: column;
  gap: 3px;
  cursor: pointer;
  background: none;
  border: none;
  padding: 6px 4px;
  flex-shrink: 0;
}
.burger span {
  display: block;
  width: 20px;
  height: 2px;
  background: #888;
  border-radius: 2px;
  transition: background .2s;
}
.burger:hover span { background: #333; }

/* --- Layout --- */
.map-wrapper { position: relative; height: calc(100vh - 47px); }
.app-layout {
  height: 100%;
  position: relative;
}

/* --- Sidebar (overlay on mobile) --- */
.sidebar {
  position: fixed;
  top: 47px; left: 0; bottom: 0;
  width: 320px;
  max-width: 85vw;
  background: #fff;
  z-index: 900;
  transform: translateX(-100%);
  transition: transform .25s ease;
  box-shadow: 2px 0 16px rgba(0,0,0,.12);
  display: flex;
  flex-direction: column;
}

.sidebar.open { transform: translateX(0); }

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  z-index: 899;
  display: none;
}
.sidebar-backdrop.show { display: block; }

.sidebar-header {
  padding: 10px 14px;
  font-size: 13px; font-weight: 700;
  color: #444;
  border-bottom: 1px solid #eee;
  flex-shrink: 0;
}

.sidebar-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}

.sidebar-group {
  padding: 6px 14px 2px;
  font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .5px;
  color: #999;
}

.sidebar-item {
  display: flex;
  gap: 8px;
  padding: 6px 14px;
  cursor: pointer;
  transition: background .12s;
  border-left: 3px solid transparent;
}

.sidebar-item:hover { background: #f5f9ff; }
.sidebar-item.active { background: #e8f4fd; border-left-color: #248bf2; }
.sidebar-item-noloc { opacity: .5; cursor: default; }

.sidebar-thumb {
  width: 44px; height: 44px;
  border-radius: 5px;
  overflow: hidden;
  flex-shrink: 0;
  background: #f0f0f0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.sidebar-thumb-placeholder { font-size: 18px; opacity: .6; }

.sidebar-info { flex: 1; min-width: 0; }

.sidebar-item-title { font-size: 12px; font-weight: 700; color: #222; margin-bottom: 1px; }

.sidebar-item-addr {
  font-size: 11px; color: #777; line-height: 1.3;
  margin-bottom: 1px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}

.sidebar-item-price { font-size: 11px; font-weight: 600; color: #d32f2f; }

.sidebar-actions {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-self: center;
}

.sidebar-act-btn {
  width: 18px; height: 18px;
  border: 1px solid #ccc;
  border-radius: 50%;
  background: #fff;
  color: #999;
  font-size: 9px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .15s;
  line-height: 1;
  padding: 0;
}

.sidebar-act-btn:hover { border-color: #248bf2; color: #248bf2; background: #e8f4fd; }
.sidebar-act-btn:disabled { border-color: #eee; color: #ccc; background: #fafafa; cursor: not-allowed; }

/* --- Map --- */
#map {
  height: 100%;
  width: 100%;
}

/* --- Desktop --- */
@media (min-width: 768px) {
  header { padding: 10px 20px; }
  header h1 { font-size: 20px; }
  .burger { display: none; }
  .map-wrapper { height: calc(100vh - 57px); }
  .app-layout { display: flex; height: 100%; }
  .sidebar {
    position: static;
    width: 340px;
    max-width: none;
    transform: none;
    box-shadow: none;
    border-right: 1px solid #ddd;
    height: auto;
  }
  .sidebar-backdrop { display: none !important; }
  #map { flex: 1; }
  .sidebar-header { padding: 12px 16px; font-size: 14px; }
  .sidebar-item { padding: 8px 16px; }
  .sidebar-thumb { width: 52px; height: 52px; }
  .sidebar-item-title { font-size: 13px; }
  .sidebar-item-addr { font-size: 12px; }
  .sidebar-item-price { font-size: 12px; }
  .sidebar-act-btn { width: 20px; height: 20px; font-size: 10px; }
  header h1 { font-size: 20px; }
  .counter { font-size: 14px; }
  #refreshBtn { padding: 8px 18px; font-size: 14px; }
}

/* --- Empty state --- */
.empty-state {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(255,255,255,.95);
  padding: 24px 28px;
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0,0,0,.12);
  text-align: center;
  z-index: 500;
  font-size: 14px;
  color: #555;
  pointer-events: none;
}
.empty-state strong { color: #222; font-size: 16px; display: block; margin-bottom: 6px; }

@media (min-width: 768px) {
  .empty-state { padding: 30px 40px; font-size: 15px; }
  .empty-state strong { font-size: 18px; }
}

/* --- Modals --- */
.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 9998;
  align-items: center; justify-content: center;
}

.modal-card {
  background: #fff; border-radius: 12px;
  width: 92vw; max-width: 440px;
  max-height: 80vh; overflow-y: auto;
  box-shadow: 0 8px 40px rgba(0,0,0,.2);
  padding: 0;
  animation: modalIn .25s ease;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(.95) translateY(12px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header { font-size: 15px; font-weight: 700; color: #222; padding: 16px 20px 0; }
.modal-steps { padding: 12px 20px 16px; }

.step {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 6px 0; font-size: 13px; color: #555; line-height: 1.4;
  position: relative;
}

.step + .step::before {
  content: "";
  position: absolute; left: 13px; top: -4px; bottom: 50%;
  width: 2px; background: #e0e0e0;
}
.step.active + .step::before { background: #248bf2; }
.step.done + .step::before { background: #34a853; }

.step-icon {
  flex-shrink: 0; width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; border-radius: 50%; background: #f0f0f0;
  position: relative; z-index: 1;
}

.step.active .step-icon { background: #e8f4fd; animation: pulse 1.2s infinite; }
.step.done .step-icon { background: #e6f9ed; }
.step.error .step-icon { background: #fde8e8; }
.step.active .step-text { color: #1a5a7a; font-weight: 600; }
.step.done .step-text { color: #1a6a3a; }
.step.error .step-text { color: #8a1a1a; }

@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.5} }

.step[data-progress]::after {
  content: ""; display: block;
  position: absolute; bottom: 2px; left: 40px; right: 0;
  height: 4px; border-radius: 4px;
  background: #e8e8e8; overflow: hidden;
}
.step[data-progress]::before {
  content: ""; display: block;
  position: absolute; bottom: 2px; left: 40px;
  width: var(--progress,0%); height: 4px; border-radius: 4px;
  background: #248bf2; transition: width .5s ease;
  z-index: 1;
}
.step[data-progress] + .step::before { display: none; }

.modal-footer { padding: 0 20px 16px; text-align: center; }

.modal-close-btn, .modal-cancel-btn {
  padding: 8px 24px; font-size: 13px; font-weight: 600;
  border: none; border-radius: 6px; cursor: pointer; transition: background .2s;
}
.modal-close-btn { background: #248bf2; color: #fff; }
.modal-close-btn:hover { background: #1a7ad9; }
.modal-cancel-btn { background: #f5f5f5; color: #555; border: 1px solid #ddd; }
.modal-cancel-btn:hover { background: #e8e8e8; }

/* Coord modal */
.coord-body { padding: 12px 20px; }
.coord-listing-info { margin-bottom: 12px; font-size: 13px; }
.coord-listing-info strong { font-size: 14px; color: #222; }
.coord-addr { font-size: 12px; color: #777; margin-top: 2px; line-height: 1.4; }
.coord-fields { display: flex; gap: 10px; margin-bottom: 12px; }
.coord-fields label { flex: 1; font-size: 12px; font-weight: 600; color: #444; }
.coord-fields input {
  width: 100%; margin-top: 4px; padding: 7px 8px; font-size: 13px;
  border: 1px solid #ccc; border-radius: 5px; outline: none;
  transition: border-color .2s; font-family: "SF Mono", Consolas, monospace;
}
.coord-fields input:focus { border-color: #248bf2; box-shadow: 0 0 0 2px rgba(36,139,242,.15); }
.coord-yandex { margin-bottom: 4px; }
.btn-yandex { width: 100%; padding: 8px; font-size: 13px; font-weight: 600; background: #f5f5f5; color: #333; border: 1px solid #ddd; border-radius: 6px; cursor: pointer; transition: background .2s; }
.btn-yandex:hover { background: #e8e8e8; }
.coord-footer { display: flex; gap: 8px; justify-content: flex-end; }

/* --- Leaflet popup (adjusted) --- */
.custom-popup .leaflet-popup-content-wrapper { border-radius: 8px; padding: 0; overflow: hidden; }
.custom-popup .leaflet-popup-content { margin: 0; width: 300px !important; }
.popup-photo { width: 100%; max-height: 160px; overflow: hidden; background: #eee; }
.popup-photo img { width: 100%; height: auto; display: block; }
.popup-body { padding: 10px; }
.popup-title { font-size: 14px; font-weight: 700; color: #222; margin-bottom: 4px; }
.popup-addr { font-size: 12px; color: #555; margin-bottom: 6px; line-height: 1.4; }
.popup-price { font-size: 16px; font-weight: 700; color: #d32f2f; margin-bottom: 6px; }
.popup-meta { font-size: 12px; color: #666; margin-bottom: 4px; }
.popup-props { font-size: 12px; color: #444; margin-bottom: 4px; line-height: 1.5; }
.popup-org { font-size: 11px; color: #777; margin-bottom: 8px; line-height: 1.4; }
.popup-buttons { display: flex; gap: 6px; margin-top: 2px; }
.btn { flex: 1; text-align: center; padding: 6px 0; border-radius: 5px; font-size: 12px; font-weight: 600; text-decoration: none; transition: opacity .2s; }
.btn:hover { opacity: .85; }
.btn-site { background: #248bf2; color: #fff; }
.btn-tg { background: #e8e8e8; color: #333; }

@media (min-width: 768px) {
  .custom-popup .leaflet-popup-content { width: 340px !important; }
  .popup-photo { max-height: 200px; }
  .popup-body { padding: 14px; }
  .popup-title { font-size: 16px; }
  .popup-addr { font-size: 13px; }
  .popup-price { font-size: 18px; }
  .btn { padding: 8px 0; font-size: 13px; }
}

/* --- Admin page --- */
.admin-page {
  display: flex; align-items: center; justify-content: center;
  height: 100vh; background: #f0f2f5;
}

.admin-card {
  background: #fff; border-radius: 12px;
  padding: 32px; width: 340px; max-width: 90vw;
  box-shadow: 0 4px 24px rgba(0,0,0,.1);
  text-align: center;
}

.admin-card h1 { font-size: 20px; margin-bottom: 20px; color: #222; }

.admin-card label {
  display: block; text-align: left;
  margin-bottom: 12px; font-size: 13px; font-weight: 600; color: #444;
}

.admin-card input {
  width: 100%; margin-top: 4px; padding: 8px 10px;
  font-size: 14px; border: 1px solid #ccc; border-radius: 6px;
  outline: none;
}
.admin-card input:focus { border-color: #248bf2; box-shadow: 0 0 0 2px rgba(36,139,242,.15); }

.admin-card button {
  width: 100%; padding: 10px; margin-top: 8px;
  background: #248bf2; color: #fff;
  border: none; border-radius: 6px; font-size: 14px; font-weight: 600;
  cursor: pointer; transition: background .2s;
}
.admin-card button:hover { background: #1a7ad9; }

.admin-error { margin-top: 12px; padding: 8px 12px; background: #fde8e8; color: #8a1a1a; border-radius: 6px; font-size: 13px; }

.admin-back {
  display: inline-block; margin-top: 16px;
  color: #248bf2; text-decoration: none; font-size: 13px;
}
.admin-back:hover { text-decoration: underline; }

/* --- About page --- */
.about-page { background: #fff; display: flex; flex-direction: column; min-height: 100vh; }
.about-page header { box-shadow: none; border-bottom: 1px solid #eee; }
.back-link { color: #248bf2; text-decoration: none; font-size: 13px; font-weight: 600; flex-shrink: 0; }
.back-link:hover { text-decoration: underline; }
.about-content {
  flex: 1; max-width: 680px; margin: 0 auto; padding: 32px 20px 48px;
  line-height: 1.7; color: #333; font-size: 15px;
}
.about-content h2 { font-size: 18px; color: #222; margin: 28px 0 10px; }
.about-content p { margin-bottom: 10px; }
.about-content ul { padding-left: 20px; margin-bottom: 10px; }
.about-content li { margin-bottom: 6px; }
.about-content a { color: #248bf2; }
.about-content a:hover { text-decoration: none; }

/* --- Footer --- */
.site-footer {
  text-align: center; padding: 6px 12px;
  font-size: 10px; color: #999;
  background: rgba(255,255,255,.85);
  backdrop-filter: blur(4px);
  z-index: 800;
}
.site-footer a { color: #888; text-decoration: none; }
.site-footer a:hover { text-decoration: underline; }

/* footer on map page — overlay at bottom */
.map-wrapper .site-footer {
  position: absolute; bottom: 0; left: 0; right: 0;
  border-top: 1px solid rgba(0,0,0,.06);
}

/* footer on standalone pages */
.about-page .site-footer {
  border-top: 1px solid #eee;
  background: #fafafa;
}

@media (min-width: 768px) {
  .about-content { padding: 40px 20px 64px; font-size: 16px; }
  .about-content h2 { font-size: 20px; }
  .app-layout + .site-footer { padding: 8px 20px; font-size: 11px; }
  .about-page .site-footer { padding: 20px; font-size: 12px; }
}
