:root {
  --bg: #fff7ed; --card: #ffffff; --text: #1f1a17; --muted: #7a6f66; --line: #f1e4d6;
  --brand: #f97316; --brand-dark: #c2410c; --own: #2563eb; --class: #16a34a; --school: #f59e0b; --nearby: #9ca3af; --schoolpin: #7c3aed;
  --danger: #dc2626; --ok: #15803d; --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { touch-action: manipulation; -webkit-text-size-adjust: 100%; overscroll-behavior-y: none; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; background: var(--bg); color: var(--text); display: flex; flex-direction: column; min-height: 100dvh; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
a { color: var(--brand-dark); }
hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }

.topbar { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top)); background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.15rem; }
.brand img { width: 32px; height: 32px; border-radius: 9px; }
.topbar-right { font-size: 0.9rem; color: var(--muted); }

#main { flex: 1; padding: 16px; padding-bottom: calc(80px + env(safe-area-inset-bottom)); max-width: 760px; width: 100%; margin: 0 auto; }
.view { display: flex; flex-direction: column; gap: 14px; }
.hero h1 { margin: 6px 0 8px; font-size: 1.6rem; }
.hero p { margin: 0 0 8px; line-height: 1.45; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card h2 { margin: 0 0 12px; font-size: 1.1rem; }
.stack { display: flex; flex-direction: column; gap: 10px; }

.tabs { display: flex; gap: 6px; margin-bottom: 14px; background: var(--bg); padding: 4px; border-radius: 10px; }
.tab { flex: 1; border: 0; background: transparent; padding: 10px; border-radius: 8px; font-weight: 600; color: var(--muted); cursor: pointer; }
.tab.active { background: var(--card); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.form { display: flex; flex-direction: column; gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 5px; font-size: 0.9rem; font-weight: 600; position: relative; }
.form input, .form select, .form textarea, .select { font: inherit; font-size: 16px; padding: 11px 12px; border: 1px solid #e3d5c6; border-radius: 10px; background: #fff; width: 100%; font-weight: 400; }
.form input:focus, .form select:focus, .form textarea:focus { outline: 2px solid var(--brand); border-color: transparent; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.btn { font: inherit; font-weight: 600; padding: 11px 16px; border-radius: 10px; border: 1px solid #e3d5c6; background: #fff; color: var(--text); cursor: pointer; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.danger { color: var(--danger); border-color: #fca5a5; }
.btn.wide { width: 100%; }
.btn.icon { padding: 6px 10px; }
.btn:disabled { opacity: .5; cursor: default; }
.error { color: var(--danger); margin: 0; font-size: 0.9rem; min-height: 1em; }
.ok { color: var(--ok); margin: 0; font-size: 0.9rem; min-height: 1em; }

.results { position: absolute; top: 100%; left: 0; right: 0; z-index: 30; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.12); max-height: 260px; overflow: auto; }
.results div { padding: 10px 12px; cursor: pointer; font-weight: 400; border-bottom: 1px solid var(--line); }
.results div:hover { background: var(--bg); }
.results small { display: block; color: var(--muted); }
.chosen { font-weight: 400; background: #fff3e6; border: 1px solid #fed7aa; border-radius: 10px; padding: 9px 12px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid #fed7aa; background: #fff3e6; border-radius: 999px; padding: 5px 11px; font-size: 0.85rem; cursor: pointer; }
.chip.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.pos-tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
#pos-map { height: 260px; border-radius: 12px; border: 1px solid var(--line); }

.map-controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.map-controls .select { flex: 1; min-width: 160px; }
.radius { display: flex; flex-direction: column; font-size: 0.8rem; color: var(--muted); min-width: 150px; }
.radius input { width: 100%; accent-color: var(--brand); }
#map { height: calc(100dvh - 300px); min-height: 360px; border-radius: 12px; border: 1px solid var(--line); }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 0.8rem; color: var(--muted); }
.dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; }
.dot.own { background: var(--own); } .dot.class { background: var(--class); } .dot.school { background: var(--school); } .dot.nearby { background: var(--nearby); } .dot.schoolpin { background: var(--schoolpin); border-radius: 2px; }

.item { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: flex; gap: 12px; align-items: center; }
.item .dot { width: 14px; height: 14px; flex-shrink: 0; }
.item .grow { flex: 1; min-width: 0; }
.item .title { font-weight: 700; }
.item .sub { color: var(--muted); font-size: 0.85rem; }
.tag { display: inline-block; font-size: 0.72rem; padding: 2px 7px; border-radius: 999px; background: #f3f4f6; color: #374151; margin-left: 6px; vertical-align: 1px; }
.tag.class { background: #dcfce7; color: #166534; } .tag.school { background: #fef3c7; color: #92400e; }

.popup b { font-size: 1rem; }
.popup .btn { margin-top: 8px; width: 100%; }

.bottomnav { position: fixed; bottom: 0; left: 0; right: 0; display: flex; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 20; }
.bottomnav button { flex: 1; border: 0; background: transparent; padding: 8px 0 6px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 1.2rem; color: var(--muted); position: relative; cursor: pointer; }
.bottomnav button span { font-size: 0.65rem; font-weight: 600; }
.bottomnav button.active { color: var(--brand-dark); }
.badge { position: absolute; top: 4px; right: calc(50% - 22px); background: var(--danger); color: #fff; font-size: 0.65rem; border-radius: 999px; padding: 1px 6px; font-style: normal; }

.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet-body { background: var(--card); width: 100%; max-width: 560px; border-radius: 18px 18px 0 0; padding: 16px; padding-bottom: calc(16px + env(safe-area-inset-bottom)); max-height: 85dvh; overflow: auto; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.sheet-head h3 { margin: 0; }
.contact-line { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.thread { cursor: pointer; }
.msg { padding: 10px 12px; border-radius: 12px; max-width: 85%; margin: 6px 0; white-space: pre-wrap; }
.msg.in { background: #f3f4f6; align-self: flex-start; }
.msg.out { background: #ffedd5; align-self: flex-end; }
.msg time { display: block; font-size: 0.7rem; color: var(--muted); margin-top: 3px; }
.thread-view { display: flex; flex-direction: column; }

.toast { position: fixed; bottom: calc(76px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); background: #1f1a17; color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 0.9rem; z-index: 50; }
.empty { text-align: center; padding: 30px 16px; color: var(--muted); }
.leaflet-container { font: inherit; }
@media (min-width: 700px) { #map { height: 560px; } }
