:root {
  --teal: #005056;
  --teal-deep: #04353a;
  --teal-dark: #063e43;
  --teal-soft: #4d8a8e;
  --mist: #b8cdce;
  --surface: #f5f8f8;
  --ink: #10312f;
  --ink-muted: #5a7473;
  --line: #d6e2e2;
  --amber: #ffc850;
  --red: #e05252;
  --font: "Albert Sans", "Segoe UI", sans-serif;
  --r-sm: 8px; --r-md: 12px; --r-lg: 16px;
  --shadow-1: 0 2px 8px rgba(4, 53, 58, .12);
  --shadow-2: 0 8px 32px rgba(4, 53, 58, .28);
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; font-family: var(--font); color: var(--ink); }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

#app { display: grid; grid-template-columns: 340px 1fr; height: 100vh; height: 100dvh; }
@media (max-width: 760px) {
  #app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  aside { max-height: 46dvh; }
  /* 16px inputs prevent iOS focus auto-zoom */
  .search input, .dr-body input, .dr-body select { font-size: 16px; }
}

/* keyboard focus */
:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
#drawer :focus-visible, .pp :focus-visible, #layers :focus-visible { outline-color: var(--teal); }

/* comfortable touch targets on touch devices */
@media (pointer: coarse) {
  .btn { min-height: 44px; }
  .chip { padding: 10px 14px; }
  #layers button { padding: 10px 14px; }
  .ph-cell .rm { width: 30px; height: 30px; }
  .item { padding: 14px 12px; }
  .pp .ebtns button { padding: 11px 7px; }
}

/* ============ SIDEBAR ============ */
aside {
  background: linear-gradient(168deg, var(--teal-dark) 0%, var(--teal-deep) 100%);
  color: #fff; overflow-y: auto; display: flex; flex-direction: column;
  scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.25) transparent;
}
.side-head { padding: 22px 20px 12px; }
.side-head img { height: 26px; display: block; margin-bottom: 10px; }
.side-head h1 { font-size: 15px; font-weight: 400; letter-spacing: .1em; text-transform: uppercase; }
.side-head h1 b { font-weight: 800; }

.editbar { display: flex; gap: 8px; padding: 10px 20px 6px; }
.editbar .grow { flex: 1; }
.btn {
  font-size: 12.5px; font-weight: 700; padding: 9px 14px;
  border-radius: var(--r-sm); border: 1px solid rgba(255,255,255,.3);
  background: rgba(255,255,255,.06); color: #fff;
  transition: background .15s, transform .1s;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 38px;
}
.btn:hover { background: rgba(255,255,255,.16); }
.btn:active { transform: scale(.97); }
.btn svg { width: 15px; height: 15px; flex: none; }
.btn.primary { background: #fff; color: var(--teal); border-color: #fff; }
.btn.primary:hover { background: var(--mist); border-color: var(--mist); }
.btn.amber { background: var(--amber); color: #4a3200; border-color: var(--amber); }
.btn.icon-only { padding: 9px 11px; }

.editrow { display: none; gap: 8px; padding: 6px 20px 4px; }
body.editing .editrow { display: flex; }
#editHint {
  display: none; margin: 8px 20px 4px; padding: 10px 12px; border-radius: var(--r-sm);
  background: rgba(255, 200, 80, .12); border: 1px solid rgba(255, 200, 80, .45);
  font-size: 11.5px; line-height: 1.55;
}
body.editing #editHint { display: block; }
body.placing #editHint b::after { content: " — xəritədə yer seç…"; color: var(--amber); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 12px 20px 14px; }
.stat {
  background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.08);
  border-radius: var(--r-md); padding: 10px 6px; text-align: center;
}
.stat .n { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 9.5px; letter-spacing: .08em; text-transform: uppercase; opacity: .65; margin-top: 2px; }

.search { padding: 0 20px 10px; }
.search input {
  width: 100%; font-size: 13px; padding: 9px 12px 9px 34px;
  border-radius: var(--r-sm); border: 1px solid rgba(255,255,255,.2);
  background: rgba(255,255,255,.08) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23b8cdce' stroke-width='2.5'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m21 21-4.3-4.3'/%3E%3C/svg%3E") no-repeat 11px center;
  color: #fff; outline: none;
}
.search input::placeholder { color: rgba(255,255,255,.45); }
.search input:focus { border-color: var(--mist); background-color: rgba(255,255,255,.12); }
.search input:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }

.filters { padding: 0 20px 10px; }
.filters h2 { font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; opacity: .6; margin: 8px 0 7px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; padding: 6px 11px; margin: 0 6px 6px 0;
  border-radius: 999px; border: 1px solid rgba(255,255,255,.22);
  background: rgba(255,255,255,.05); color: #fff;
  transition: opacity .15s, background .15s;
}
.chip:hover { background: rgba(255,255,255,.14); }
.chip .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.chip.off { opacity: .32; }

.list { flex: 1; overflow-y: auto; padding: 4px 12px 18px; }
.item {
  padding: 11px 12px; margin-bottom: 6px;
  background: rgba(255,255,255,.06); border-radius: var(--r-sm);
  border-left: 3px solid var(--acc, var(--mist));
  cursor: pointer; transition: background .12s, transform .12s;
}
.item:hover { background: rgba(255,255,255,.14); transform: translateX(2px); }
.item .t { font-size: 13px; font-weight: 600; line-height: 1.35; }
.item .m { font-size: 11px; opacity: .6; margin-top: 3px; }
.item .m .ph-badge { color: var(--mist); opacity: 1; }
.list-empty { text-align: center; font-size: 12.5px; opacity: .55; padding: 26px 10px; line-height: 1.6; }

/* ============ MAP ============ */
#mapwrap { position: relative; height: 100%; overflow: hidden; }
#map { height: 100%; }
body.placing #map { cursor: crosshair; }

/* layer switcher */
#layers {
  position: absolute; top: 12px; right: 12px; z-index: 800;
  display: flex; gap: 4px; padding: 4px;
  background: rgba(255,255,255,.92); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  border-radius: 999px; box-shadow: var(--shadow-1);
}
#layers button {
  font-size: 11.5px; font-weight: 700; padding: 6px 13px; border: none;
  border-radius: 999px; background: transparent; color: var(--ink-muted);
  transition: background .15s, color .15s;
}
#layers button:hover { color: var(--teal); }
#layers button.on { background: var(--teal); color: #fff; }

/* edit-mode banner on map */
#editBanner {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%) translateY(-160%);
  z-index: 800; padding: 8px 18px; border-radius: 999px;
  background: var(--amber); color: #4a3200; font-size: 12.5px; font-weight: 700;
  box-shadow: var(--shadow-1); transition: transform .25s ease;
  pointer-events: none; white-space: nowrap;
}
body.editing #editBanner { transform: translateX(-50%) translateY(0); }
body.placing #editBanner { background: var(--teal); color: #fff; }

/* ============ MARKERS ============ */
.marker-pin {
  width: 28px; height: 28px; border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  border: 2px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.35);
  transition: transform .15s;
}
.marker-pin:hover { transform: rotate(-45deg) scale(1.12); }
.marker-pin.site { border-radius: 50%; transform: none; background: var(--teal) !important; border: 4px solid #fff; outline: 2px solid var(--teal); }
.marker-pin.sales { border-radius: 6px; transform: none; background: #fff !important; border: 3px solid var(--teal); outline: none; }
body.editing .marker-pin { outline: 2px dashed rgba(255,180,40,.95); outline-offset: 2px; }

/* ============ POPUP ============ */
.leaflet-popup-content-wrapper { border-radius: var(--r-md); font-family: var(--font); box-shadow: var(--shadow-2); }
.leaflet-popup-content { margin: 13px 15px; }
.pp { width: 252px; }
.pp .ph { display: flex; gap: 4px; margin-bottom: 9px; }
.pp .ph a { flex: 1; display: block; }
.pp .ph img { width: 100%; height: 90px; object-fit: cover; border-radius: 7px; display: block; }
.pp .op { font-size: 10px; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; color: var(--teal-soft); }
.pp h3 { font-size: 14.5px; color: var(--teal); margin: 3px 0 8px; line-height: 1.3; }
.pp .kv { font-size: 12px; display: flex; justify-content: space-between; gap: 12px; padding: 2.5px 0; }
.pp .kv b { font-variant-numeric: tabular-nums; text-align: right; }
.pp .warn { font-size: 11px; color: #a33; margin-top: 6px; }
.pp .go {
  display: block; text-align: center; margin-top: 10px; padding: 8px;
  background: var(--teal); color: #fff; border-radius: 7px;
  font-size: 12px; font-weight: 700; text-decoration: none;
}
.pp .go:hover { background: var(--teal-dark); }
.pp .ebtns { display: flex; gap: 6px; margin-top: 9px; }
.pp .ebtns button {
  flex: 1; font-size: 11.5px; font-weight: 700; padding: 7px;
  border-radius: 7px; border: 1px solid var(--line); background: var(--surface);
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
}
.pp .ebtns button:hover { background: #e8f0f0; }
.pp .ebtns .del { color: var(--red); border-color: #ecc; }
.pp .ebtns .del:hover { background: #fdf0f0; }
.pp .ebtns svg { width: 13px; height: 13px; }

/* ============ EDITOR DRAWER ============ */
#drawer {
  position: absolute; top: 0; right: 0; bottom: 0; z-index: 900;
  width: 340px; max-width: 92vw;
  background: #fff; box-shadow: var(--shadow-2);
  transform: translateX(105%); transition: transform .28s cubic-bezier(.2,.8,.25,1), visibility .28s;
  display: flex; flex-direction: column;
  visibility: hidden;
}
#drawer.open { transform: translateX(0); visibility: visible; }
.dr-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px 12px; border-bottom: 1px solid var(--line);
}
.dr-head h3 { font-size: 15px; color: var(--teal); }
.dr-close { border: none; background: none; padding: 6px; border-radius: 6px; color: var(--ink-muted); }
.dr-close:hover { background: var(--surface); }
.dr-close svg { width: 18px; height: 18px; display: block; }
.dr-body { flex: 1; overflow-y: auto; padding: 14px 18px; }
.dr-body label { display: block; font-size: 10.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-muted); margin: 12px 0 4px; }
.dr-body label:first-child { margin-top: 0; }
.dr-body input, .dr-body select {
  width: 100%; font-size: 13.5px; padding: 9px 11px; min-height: 40px;
  border: 1px solid var(--line); border-radius: var(--r-sm); outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.dr-body input:focus, .dr-body select:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(0,80,86,.12); }
.dr-body .hint { font-size: 11px; color: var(--ink-muted); margin-top: 4px; line-height: 1.5; }
.dr-coords { font-size: 11.5px; color: var(--ink-muted); font-variant-numeric: tabular-nums; margin-top: 4px; }

/* photo manager */
.ph-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin-top: 6px; }
.ph-cell { position: relative; aspect-ratio: 4/3; border-radius: 7px; overflow: hidden; background: var(--surface); }
.ph-cell img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ph-cell .rm {
  position: absolute; top: 4px; right: 4px; width: 22px; height: 22px;
  border: none; border-radius: 50%; background: rgba(6,62,67,.85); color: #fff;
  font-size: 13px; line-height: 1; display: flex; align-items: center; justify-content: center;
}
.ph-cell .rm:hover { background: var(--red); }
.ph-add {
  aspect-ratio: 4/3; border: 2px dashed var(--line); border-radius: 7px;
  background: none; color: var(--ink-muted); font-size: 11px; font-weight: 700;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  transition: border-color .15s, color .15s;
}
.ph-add:hover { border-color: var(--teal); color: var(--teal); }
.ph-add svg { width: 18px; height: 18px; }

.dr-foot { display: flex; gap: 8px; padding: 13px 18px; border-top: 1px solid var(--line); }
.dr-foot button { flex: 1; font-size: 13px; font-weight: 700; padding: 11px; border-radius: var(--r-sm); border: none; min-height: 42px; }
.dr-foot .save { background: var(--teal); color: #fff; }
.dr-foot .save:hover { background: var(--teal-dark); }
.dr-foot .cancel { background: var(--surface); color: var(--ink-muted); border: 1px solid var(--line); }
.dr-foot .del { flex: 0 0 auto; background: none; border: 1px solid #ecc; color: var(--red); padding: 11px 13px; }
.dr-foot .del:hover { background: #fdf0f0; }
.dr-foot svg { width: 15px; height: 15px; vertical-align: -2px; }

/* ============ TOAST / LIGHTBOX ============ */
#toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(180%);
  z-index: 3000; padding: 11px 20px; border-radius: 999px;
  background: var(--teal-deep); color: #fff; font-size: 13px; font-weight: 600;
  box-shadow: var(--shadow-2); transition: transform .25s ease; white-space: nowrap;
}
#toast.on { transform: translateX(-50%) translateY(0); }
#lb {
  display: none; position: fixed; inset: 0; z-index: 2000;
  background: rgba(4,53,58,.93); align-items: center; justify-content: center; cursor: zoom-out;
}
#lb.on { display: flex; }
#lb img { max-width: 92vw; max-height: 92vh; border-radius: 10px; box-shadow: var(--shadow-2); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
