:root {
  --navy: #0a2540; --deep: #0b3d6b; --sea: #0a6cc4; --sky: #e8f2fb; --foam: #f7fafd; --line: #d5e3f1;
  --ink: #12263a; --muted: #5b7186; --white: #fff; --warn: #b4540a; --ok: #0b7a5a;
  --r: 12px; --shadow: 0 6px 24px rgba(10, 37, 64, .14);
  font-family: "Avenir Next", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--foam); }
body { display: grid; grid-template-columns: 76px 1fr; font-size: 15px; line-height: 1.4; }
a { color: var(--sea); }
button, select, input { font: inherit; color: inherit; }

/* left rail */
.rail { background: var(--navy); color: #cfe2f5; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 0; height: 100vh; position: sticky; top: 0; }
.rail a { width: 60px; padding: 9px 0 7px; display: flex; flex-direction: column; align-items: center; gap: 3px; border-radius: 12px; color: inherit; text-decoration: none; font-size: 11px; letter-spacing: .02em; position: relative; }
.rail a:hover { background: rgba(255,255,255,.08); }
.rail a.active { background: var(--sea); color: #fff; }
.rail .brand { color: #fff; margin-bottom: 10px; }
.rail .brand:hover { background: none; }
.badge { position: absolute; top: 2px; right: 6px; background: #fff; color: var(--deep); border-radius: 99px; font-size: 11px; min-width: 18px; padding: 0 5px; text-align: center; }
.live { margin-top: auto; font-size: 10.5px; display: flex; flex-direction: column; align-items: center; gap: 4px; color: #9fbad4; text-align: center; padding: 0 4px; }
.live i { width: 9px; height: 9px; border-radius: 50%; background: #5b7186; transition: box-shadow .4s; }
.live.on i { background: #38d6a0; }
.live.off i { background: #e0a23a; }
.live.pulse i { box-shadow: 0 0 0 7px rgba(56,214,160,.35); }

main { min-width: 0; height: 100vh; overflow: auto; position: relative; }
.page-map main { display: grid; grid-template-columns: 1fr 420px; overflow: hidden; }
.mapwrap { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; background: #cfe3f5; }
#map.drawing, .drawing { cursor: crosshair; }

.maptools { position: absolute; z-index: 500; top: 12px; left: 56px; display: flex; gap: 8px; flex-wrap: wrap; }
.maptools button { background: var(--white); border: 1px solid var(--line); border-radius: 99px; padding: 8px 14px; box-shadow: var(--shadow); cursor: pointer; color: var(--deep); font-weight: 600; font-size: 14px; }
.maptools button:hover { background: var(--sky); }
.maptools button#finishBtn { background: var(--sea); color: #fff; border-color: var(--sea); }
.drawhint { position: absolute; z-index: 500; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 9px 16px; border-radius: 99px; box-shadow: var(--shadow); font-size: 14px; max-width: 90%; text-align: center; }

/* the panel */
.panel { background: var(--white); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.panel header { padding: 18px 20px 6px; background: linear-gradient(180deg, var(--sky), var(--white)); }
.panel h1 { margin: 0; font-size: 22px; color: var(--navy); letter-spacing: -.01em; }
.panel h1 small { font-size: 12px; font-weight: 600; color: var(--sea); text-transform: uppercase; letter-spacing: .08em; margin-left: 6px; }
.sub { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.filters { padding: 10px 20px 14px; border-bottom: 1px solid var(--line); display: grid; gap: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { cursor: pointer; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span { display: inline-block; padding: 6px 12px; border-radius: 99px; border: 1px solid var(--line); background: var(--foam); font-weight: 600; font-size: 13.5px; color: var(--deep); }
.chip input:checked + span { background: var(--sea); border-color: var(--sea); color: #fff; }
.chip input:focus-visible + span { outline: 2px solid var(--navy); outline-offset: 2px; }
.chip em { font-style: normal; font-size: 12px; color: var(--muted); margin-left: 4px; }
.depth, .follow { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 14px; color: var(--muted); }
.follow { justify-content: flex-start; }
select { border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; background: #fff; }
.areas { display: flex; gap: 6px; flex-wrap: wrap; }
.area { background: var(--sky); color: var(--deep); border-radius: 99px; padding: 3px 4px 3px 12px; font-size: 13px; font-weight: 600; }
.area button { border: 0; background: none; cursor: pointer; font-size: 16px; padding: 0 8px; color: var(--deep); }
.actions { display: flex; gap: 8px; }
.actions button, .btn, .saveform button { border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 8px 14px; cursor: pointer; font-weight: 600; color: var(--deep); text-decoration: none; display: inline-block; font-size: 14px; }
button.primary { background: var(--deep); color: #fff; border-color: var(--deep); }
button.primary:hover { background: var(--navy); }
.btn.danger { color: #a3261b; }
.saveform { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.saveform input { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; min-width: 0; }
.saveform .hint { grid-column: 1 / -1; margin: 0; font-size: 12.5px; color: var(--muted); }
.status { margin: 12px 20px 0; padding: 10px 12px; border-radius: 10px; background: var(--sky); color: var(--deep); font-size: 14px; }
.status.error { background: #fdecea; color: #8a1f15; }

/* cards */
.cards { list-style: none; margin: 0; padding: 12px 14px 24px; overflow: auto; flex: 1; display: grid; gap: 10px; align-content: start; }
.card { border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; background: #fff; cursor: pointer; transition: box-shadow .15s, border-color .15s; }
.card:hover, .card.flash { border-color: var(--sea); box-shadow: 0 4px 16px rgba(10,108,196,.16); }
.cardtop { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.card h2 { margin: 0; font-size: 16.5px; color: var(--navy); }
.where { color: var(--muted); font-size: 13px; }
.dist { text-align: right; white-space: nowrap; color: var(--sea); line-height: 1.1; }
.dist b { font-size: 21px; font-variant-numeric: tabular-nums; }
.dist small { display: block; font-size: 11px; color: var(--muted); }
.facts { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 8px; font-size: 13.5px; }
.fact { color: var(--ink); text-decoration: none; }
a.fact { color: var(--sea); }
.services { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.services li { background: var(--foam); border: 1px solid var(--line); border-radius: 8px; padding: 3px 9px; font-size: 12.5px; display: flex; gap: 6px; }
.services em { font-style: normal; color: var(--muted); font-variant-numeric: tabular-nums; }

/* map marks */
.pin span { display: block; width: 26px; height: 26px; margin: 2px; border-radius: 50% 50% 50% 4px; transform: rotate(-45deg); background: var(--deep); border: 3px solid #fff; box-shadow: 0 2px 8px rgba(0,0,0,.35); }
.pin.hot span { background: var(--sea); transform: rotate(-45deg) scale(1.25); }
.cell { display: flex; align-items: center; justify-content: center; }
.cell span { width: 100%; height: 100%; border-radius: 50%; background: rgba(10,108,196,.88); color: #fff; font-weight: 700; display: flex; align-items: center; justify-content: center; border: 4px solid rgba(255,255,255,.85); box-shadow: 0 2px 10px rgba(0,0,0,.3); font-variant-numeric: tabular-nums; }

/* toasts */
#toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 2000; max-width: min(380px, 90vw); }
.toast { background: var(--navy); color: #fff; padding: 11px 14px; border-radius: 12px; box-shadow: var(--shadow); font-size: 14px; animation: in .25s ease-out; transition: opacity .5s; }
.toast.match { background: var(--sea); }
.toast.error { background: #8a1f15; }
.toast.out { opacity: 0; }
@keyframes in { from { transform: translateY(10px); opacity: 0; } }

/* saved page */
.doc { max-width: 820px; padding: 32px 36px 60px; }
.doc h1 { margin: 0 0 4px; color: var(--navy); font-size: 28px; }
.doc h2 { margin: 30px 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: .1em; color: var(--sea); }
.matchlist, .savedlist { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.matchlist li, .savedlist li { background: #fff; border: 1px solid var(--line); border-radius: var(--r); padding: 12px 16px; }
.matchlist li.fresh { border-color: var(--sea); box-shadow: inset 4px 0 0 var(--sea); }
.savedlist li { display: flex; justify-content: space-between; gap: 16px; align-items: center; }
.rowactions { display: flex; gap: 8px; align-items: center; }
.rowactions form { margin: 0; }
.muted { color: var(--muted); font-size: 13.5px; }
.tag { font-size: 11.5px; font-weight: 700; padding: 2px 8px; border-radius: 99px; margin-left: 6px; }
.tag.ok { background: #dff5ec; color: var(--ok); }
.tag.warn { background: #fdebd9; color: var(--warn); }
.empty { color: var(--muted); background: #fff; border: 1px dashed var(--line); border-radius: var(--r); padding: 18px; }
.notice.error { background: #fdecea; color: #8a1f15; padding: 10px 14px; border-radius: 10px; }

@media (max-width: 900px) {
  body { grid-template-columns: 1fr; grid-template-rows: 1fr 58px; }
  .rail { order: 2; flex-direction: row; height: 58px; position: static; justify-content: center; padding: 0 8px; gap: 18px; }
  .rail .brand, .live span { display: none; }
  .live { margin: 0; }
  .rail a { flex-direction: row; width: auto; padding: 6px 14px; }
  main { height: auto; min-height: 0; }
  .page-map main { grid-template-columns: 1fr; grid-template-rows: 48vh 1fr; overflow: auto; }
  .page-map .panel { overflow: visible; }
  .cards { overflow: visible; }
  .doc { padding: 20px 16px 40px; }
  .savedlist li { flex-direction: column; align-items: flex-start; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
