:root {
  --ink: #1b1635; --ink2: #4a4566; --muted: #77738f; --line: #e4e2ee; --bg: #f6f5fb; --card: #fff;
  --brand: #5b3fd6; --brand-d: #4529b8; --danger: #c4302b; --ok: #1f8a4c;
  --r: 12px; --shadow: 0 6px 24px rgba(27, 22, 53, .18);
  --safe-b: env(safe-area-inset-bottom, 0px);
  font-family: -apple-system, "Segoe UI", Roboto, "Open Sans", Arial, sans-serif;
  color: var(--ink); -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small, small { font-size: .85em; }
.pad { padding: 12px; }
.grow { flex: 1; min-width: 0; }

/* ---------- кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px; padding: 8px 14px; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; cursor: pointer; text-decoration: none; color: var(--ink); white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.btn:hover { border-color: #c9c5dc; background: #faf9fe; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--brand-d); }
.btn.danger { color: var(--danger); }
.btn.big { min-height: 48px; padding: 10px 20px; font-size: 1.05em; }
.btn.sm { min-height: 34px; padding: 4px 10px; }
.btn.block { width: 100%; justify-content: flex-start; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.phone { font-weight: 600; color: var(--brand-d); }
.link { background: none; border: 0; padding: 0; color: var(--brand-d); cursor: pointer; text-align: left; font: inherit; }
.link.danger { color: var(--danger); font-size: .85em; margin-left: 6px; }
.icon-btn {
  position: relative; width: 44px; height: 44px; flex: none; border-radius: 10px; border: 1px solid var(--line);
  background: #fff; font-size: 20px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn.sm { width: 34px; height: 34px; font-size: 15px; }
.icon-btn:disabled { opacity: .35; }
.badge {
  position: absolute; top: -6px; right: -6px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px;
  background: var(--brand); color: #fff; font-size: 12px; font-weight: 700; line-height: 20px;
}
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row.tight { gap: 6px; }
.row.end { justify-content: flex-end; margin-top: 8px; }

/* ---------- вхід ---------- */
.login-page { display: grid; place-items: center; min-height: 100%; padding: 20px; background: linear-gradient(160deg, #1b1635, #403969); }
.login-box { width: 100%; max-width: 360px; background: #fff; border-radius: 18px; padding: 28px 24px; box-shadow: var(--shadow); display: grid; gap: 14px; }
.login-box h1 { margin: 0 0 4px; text-align: center; font-size: 1.4em; }
.login-logo { justify-self: center; }
.login-box label { display: grid; gap: 6px; font-weight: 600; font-size: .95em; }
.login-box input { height: 46px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; font-weight: 400; }
.msg { margin: 0; padding: 10px 12px; border-radius: 10px; font-size: .95em; }
.msg.err { background: #fdecea; color: var(--danger); }
.msg.ok { background: #e8f6ee; color: var(--ok); }

/* ---------- каркас ---------- */
#app { position: fixed; inset: 0; }
#map { position: absolute; inset: 0; }
.topbar { position: absolute; z-index: 1000; top: 10px; left: 10px; right: 10px; display: flex; gap: 8px; pointer-events: none; }
.topbar > * { pointer-events: auto; box-shadow: var(--shadow); }
.search { position: relative; flex: 1; max-width: 520px; box-shadow: none !important; }
.search input { width: 100%; height: 44px; padding: 0 14px; border: 1px solid var(--line); border-radius: 10px; background: #fff; box-shadow: var(--shadow); }
.results { position: absolute; top: 50px; left: 0; right: 0; max-height: 60vh; overflow: auto; background: #fff; border-radius: var(--r); box-shadow: var(--shadow); }
.result { display: grid; gap: 2px; width: 100%; padding: 10px 14px; border: 0; border-bottom: 1px solid var(--line); background: none; text-align: left; cursor: pointer; }
.result:hover { background: var(--bg); }
.result small { color: var(--muted); }
.offline { position: absolute; z-index: 1000; top: 62px; left: 50%; transform: translateX(-50%); background: #fff4d6; color: #7a5600; padding: 6px 12px; border-radius: 8px; font-size: .9em; box-shadow: var(--shadow); }
.fabs { position: absolute; z-index: 1000; right: 12px; bottom: calc(24px + var(--safe-b)); display: grid; gap: 12px; }
.fab { width: 56px; height: 56px; border-radius: 50%; border: 0; background: #fff; box-shadow: var(--shadow); font-size: 24px; cursor: pointer; }
.fab.primary { background: var(--brand); color: #fff; font-size: 30px; }
body.drafting .fabs, body.drafting .topbar { display: none; }

/* ---------- режим постановки точки ---------- */
.draft-bar {
  position: absolute; z-index: 1100; left: 10px; right: 10px; top: 10px; max-width: 560px; margin: 0 auto;
  background: #fff; border-radius: var(--r); box-shadow: var(--shadow); padding: 12px; display: grid; gap: 8px;
}
.draft-bar .hint { margin: 0; font-size: .9em; color: var(--ink2); }
.draft-bar .row { flex-wrap: wrap; }
.draft-bar .row .btn.primary { margin-left: auto; }
.draft-search input[type=search] { flex: 1; height: 42px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; min-width: 0; }
.draft-search gmp-place-autocomplete { width: 100%; }
.geo-results { display: grid; max-height: 30vh; overflow: auto; }
.geo-item { text-align: left; padding: 8px 6px; border: 0; border-bottom: 1px solid var(--line); background: none; cursor: pointer; font-size: .9em; }

/* ---------- картка ---------- */
.sheet {
  position: absolute; z-index: 1050; left: 0; right: 0; bottom: 0; max-height: 72vh; overflow: auto;
  background: var(--card); border-radius: 18px 18px 0 0; box-shadow: 0 -6px 24px rgba(27, 22, 53, .2);
  padding: 14px 16px calc(18px + var(--safe-b)); display: grid; gap: 10px; align-content: start;
}
.sheet-head { display: flex; gap: 10px; align-items: flex-start; position: sticky; top: -14px; background: #fff; padding-top: 4px; z-index: 2; }
.sheet-head h2 { flex: 1; margin: 6px 0 0; font-size: 1.3em; line-height: 1.25; word-break: break-word; }
.sheet h3 { margin: 6px 0 6px; font-size: .8em; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.sheet section { border-top: 1px solid var(--line); padding-top: 6px; }
.contact { font-weight: 600; color: var(--ink2); }
.addr { color: var(--ink2); }
.pre { white-space: pre-wrap; word-break: break-word; line-height: 1.45; }
.actions .btn.primary { flex: 1 1 100%; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.thumb { aspect-ratio: 1; padding: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--bg); cursor: pointer; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb.add { display: grid; place-content: center; font-size: 26px; color: var(--brand); border-style: dashed; }
.thumb.add small { font-size: 12px; }
.comment-form { display: grid; gap: 6px; margin-bottom: 8px; }
.comment-form textarea, .form input, .form select, .form textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff;
}
.comment-form .btn { justify-self: end; }
.comment { padding: 8px 0; border-bottom: 1px solid var(--line); }
.comment .meta { font-size: .82em; color: var(--muted); }
.comment .text { white-space: pre-wrap; word-break: break-word; margin-top: 2px; }
.foot { padding-top: 6px; border-top: 1px solid var(--line); }

/* ---------- модальне ---------- */
.modal { position: fixed; z-index: 2000; inset: 0; background: rgba(20, 12, 52, .45); display: grid; place-items: end center; }
.modal-box {
  width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; background: #fff;
  border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + var(--safe-b)); box-shadow: var(--shadow);
}
.form { display: grid; gap: 12px; }
.form h2 { margin: 0; font-size: 1.25em; }
.field { display: grid; gap: 5px; }
.field > span { font-weight: 600; font-size: .9em; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check { display: flex; gap: 8px; align-items: center; }
.check input { width: auto; }
.me-box { display: grid; padding: 4px 0 8px; }
.route-list { margin: 0; padding-left: 22px; display: grid; gap: 8px; }
.route-list li { display: flex; gap: 8px; align-items: center; }
.route-list .link, .near-item .link { display: grid; gap: 1px; color: var(--ink); flex: 1; min-width: 0; }
.route-list small, .near-item small, .user-row small { color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.near-list, .users { display: grid; }
.near-item, .user-row { display: flex; gap: 10px; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--line); }
.user-row > .grow { display: grid; }
.user-row.off { opacity: .55; }
.dist { font-weight: 600; color: var(--brand-d); white-space: nowrap; }
.log { display: grid; gap: 0; font-size: .92em; }
.log-row { display: grid; grid-template-columns: 9.5em 1fr; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }

/* ---------- перегляд фото ---------- */
.viewer { position: fixed; z-index: 3000; inset: 0; background: #0c0a18; display: grid; grid-template-rows: 1fr auto; }
.viewer img { width: 100%; height: 100%; object-fit: contain; min-height: 0; }
.viewer-bar { display: flex; gap: 8px; justify-content: center; align-items: center; padding: 10px 10px calc(10px + var(--safe-b)); color: #fff; flex-wrap: wrap; }

.toast {
  position: fixed; z-index: 4000; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translateX(-50%);
  max-width: calc(100% - 32px); background: #1b1635; color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow);
}
.toast.err { background: var(--danger); }

/* ---------- позначки ---------- */
.me-dot { width: 18px; height: 18px; border-radius: 50%; background: #1a73e8; border: 3px solid #fff; box-shadow: 0 0 0 6px rgba(26, 115, 232, .25); }
.lf-pin span {
  position: absolute; left: 3px; top: 0; width: 24px; height: 24px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
  background: var(--brand); border: 2px solid #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, .35);
}
.lf-pin span::after { content: ""; position: absolute; left: 7px; top: 7px; width: 6px; height: 6px; border-radius: 50%; background: #fff; }
.lf-pin.draft span { background: #e0362c; width: 30px; height: 30px; left: 0; top: -6px; }
.lf-pin.draft span::after { left: 10px; top: 10px; }
.leaflet-container { font: inherit; }

/* ---------- великий екран: картка збоку ---------- */
@media (min-width: 900px) {
  .sheet { left: auto; top: 64px; right: 10px; bottom: 10px; width: 420px; max-height: none; border-radius: 16px; }
  .sheet-head { top: -14px; }
  .modal { place-items: center; }
  .modal-box { border-radius: 18px; }
  .form.wide { min-width: 640px; }
  .modal-box:has(.wide) { max-width: 820px; }
  .toast { bottom: 30px; }
}
