:root {
  --bg: #0f172a; --bg2: #1e293b; --bg3: #273449; --fg: #e2e8f0; --fg2: #94a3b8; --fg3: #64748b;
  --accent: #38bdf8; --accent2: #0ea5e9; --mine: #0369a1; --theirs: #334155; --ok: #4ade80; --warn: #fbbf24; --err: #f87171;
  --radius: 14px; --safe-top: env(safe-area-inset-top, 0px); --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); font-family: var(--font); font-size: 16px; -webkit-text-size-adjust: 100%; overscroll-behavior: none; }
#app { height: 100%; display: flex; flex-direction: column; }
.boot { padding: 40px 16px; color: var(--fg2); text-align: center; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: var(--accent2); color: #fff; padding: 10px 16px; border-radius: 10px; font-weight: 600; }
button:disabled { opacity: .5; cursor: default; }
button.ghost { background: transparent; color: var(--accent); padding: 8px 10px; }
button.danger { background: #7f1d1d; }
button.small { padding: 6px 10px; font-size: 14px; }
input[type=text], input[type=password], input[type=search], textarea, select { width: 100%; background: var(--bg2); border: 1px solid #334155; border-radius: 10px; padding: 12px; color: var(--fg); outline: none; }
input:focus, textarea:focus { border-color: var(--accent); }
a { color: var(--accent); }
.hidden { display: none !important; }

.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px; padding: calc(var(--safe-top) + 8px) 12px 8px; background: var(--bg); border-bottom: 1px solid #1e293b; min-height: 52px; }
.topbar h1 { font-size: 18px; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .sub { font-size: 12px; color: var(--fg2); font-weight: 400; display: block; }
.topbar .back { background: transparent; color: var(--accent); padding: 6px 8px 6px 0; font-size: 22px; line-height: 1; }
.conn { font-size: 11px; padding: 3px 8px; border-radius: 999px; background: var(--bg3); color: var(--fg2); white-space: nowrap; }
.conn.connected { color: var(--ok); } .conn.reconnecting { color: var(--warn); } .conn.offline { color: var(--err); }

.screen { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.tabbar { display: flex; border-top: 1px solid #1e293b; background: var(--bg); padding-bottom: var(--safe-bottom); }
.tabbar a { flex: 1; text-align: center; padding: 10px 0 8px; color: var(--fg3); text-decoration: none; font-size: 12px; }
.tabbar a.active { color: var(--accent); }
.tabbar a .ico { display: block; font-size: 20px; margin-bottom: 2px; }
.badge { display: inline-block; min-width: 20px; padding: 2px 6px; border-radius: 999px; background: var(--accent2); color: #fff; font-size: 12px; font-weight: 700; text-align: center; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid #1e293b; cursor: pointer; }
.list li:active { background: var(--bg2); }
.avatar { width: 44px; height: 44px; border-radius: 50%; background: var(--bg3); color: var(--fg); display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0; position: relative; }
.avatar.group { border-radius: 12px; background: #1d4ed8; }
.avatar .dot { position: absolute; right: -1px; bottom: -1px; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--bg); background: var(--fg3); }
.avatar .dot.on { background: var(--ok); }
.list .main { flex: 1; min-width: 0; }
.list .title { font-weight: 600; display: flex; justify-content: space-between; gap: 8px; }
.list .title .time { font-weight: 400; font-size: 12px; color: var(--fg3); }
.list .preview { font-size: 14px; color: var(--fg2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.list li.unread .preview { color: var(--fg); font-weight: 500; }
.empty { padding: 40px 24px; text-align: center; color: var(--fg2); }
.section { padding: 12px 16px 4px; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--fg3); }
.fab { position: fixed; right: 16px; bottom: calc(var(--safe-bottom) + 68px); width: 56px; height: 56px; border-radius: 50%; font-size: 26px; box-shadow: 0 6px 20px rgba(0,0,0,.4); z-index: 4; }

.messages { flex: 1; overflow-y: auto; padding: 12px 12px 8px; display: flex; flex-direction: column; gap: 4px; }
.daysep { align-self: center; font-size: 12px; color: var(--fg3); margin: 10px 0 4px; }
.msg { max-width: 82%; display: flex; flex-direction: column; }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg.theirs { align-self: flex-start; align-items: flex-start; }
.msg .sender { font-size: 12px; color: var(--accent); margin: 6px 0 2px 10px; }
.bubble { padding: 9px 12px; border-radius: var(--radius); background: var(--theirs); word-wrap: break-word; white-space: pre-wrap; line-height: 1.35; }
.msg.mine .bubble { background: var(--mine); border-bottom-right-radius: 4px; }
.msg.theirs .bubble { border-bottom-left-radius: 4px; }
.msg.important .bubble { border: 1px solid var(--warn); }
.bubble img { max-width: 100%; max-height: 320px; border-radius: 10px; display: block; }
.bubble .file { display: flex; gap: 8px; align-items: center; }
.bubble .file .fname { font-weight: 600; word-break: break-all; }
.bubble .file .fsize { font-size: 12px; color: var(--fg2); }
.meta { font-size: 11px; color: var(--fg3); margin: 2px 8px 0; display: flex; flex-wrap: wrap; gap: 2px 6px; align-items: center; }
.msg.mine .meta { justify-content: flex-end; }
.meta .status { cursor: pointer; white-space: nowrap; }
.meta .when { white-space: nowrap; }
.meta .geo { font-variant-numeric: tabular-nums; color: var(--fg2); white-space: nowrap; }
.meta .status.pending { color: var(--warn); } .meta .status.rejected { color: var(--err); } .meta .status.read { color: var(--accent); }
.msg.pending .bubble { opacity: .6; }
.composer { display: flex; gap: 8px; align-items: flex-end; padding: 8px 10px calc(var(--safe-bottom) + 8px); border-top: 1px solid #1e293b; background: var(--bg); }
.composer textarea { flex: 1; resize: none; max-height: 120px; min-height: 42px; padding: 10px 12px; border-radius: 20px; }
.composer .icon { width: 42px; height: 42px; padding: 0; border-radius: 50%; font-size: 20px; background: var(--bg3); color: var(--fg); flex-shrink: 0; }
.composer .send { width: 42px; height: 42px; padding: 0; border-radius: 50%; font-size: 18px; flex-shrink: 0; }
.attach-preview { padding: 6px 12px; font-size: 13px; color: var(--fg2); display: flex; gap: 8px; align-items: center; border-top: 1px solid #1e293b; }
.loadmore { align-self: center; margin-bottom: 8px; }

.sheet-back { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 20; display: flex; align-items: flex-end; }
.sheet { background: var(--bg2); width: 100%; max-height: 80%; overflow-y: auto; border-radius: 18px 18px 0 0; padding: 16px 16px calc(var(--safe-bottom) + 16px); }
.sheet h3 { margin: 0 0 12px; }
.sheet .row { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid #334155; gap: 12px; }
.sheet .row .st { color: var(--fg2); font-size: 14px; text-align: right; }
.sheet .row .st.delivered { color: var(--fg); } .sheet .row .st.read { color: var(--accent); } .sheet .row .st.pending { color: var(--warn); }

.form { padding: 16px; display: flex; flex-direction: column; gap: 12px; max-width: 480px; width: 100%; margin: 0 auto; }
.form label { font-size: 13px; color: var(--fg2); display: block; margin-bottom: 4px; }
.form .error { color: var(--err); font-size: 14px; }
.form .ok { color: var(--ok); font-size: 14px; }
.login { justify-content: center; }
.login h1 { text-align: center; margin: 0 0 8px; }
.login p { text-align: center; color: var(--fg2); margin: 0; }
.check { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid #1e293b; }
.check input { width: 20px; height: 20px; }
.card { background: var(--bg2); border-radius: 12px; padding: 12px 14px; margin: 8px 16px; }
.card h3 { margin: 0 0 8px; font-size: 15px; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; font-size: 14px; }
.kv .k { color: var(--fg2); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; word-break: break-all; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.pill { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--bg3); color: var(--fg2); }
.pill.on { color: var(--ok); } .pill.off { color: var(--err); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 16px; }
.chip { background: var(--bg3); border-radius: 999px; padding: 4px 10px; font-size: 13px; }
.note { font-size: 13px; color: var(--fg2); padding: 8px 16px; line-height: 1.4; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--safe-bottom) + 80px); background: #334155; color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 14px; z-index: 30; box-shadow: 0 4px 14px rgba(0,0,0,.4); }
.tabs { display: flex; border-bottom: 1px solid #1e293b; }
.tabs button { flex: 1; background: transparent; color: var(--fg2); border-radius: 0; padding: 12px 4px; font-size: 14px; }
.tabs button.active { color: var(--accent); box-shadow: inset 0 -2px 0 var(--accent); }
@media (min-width: 900px) { #app { max-width: 720px; margin: 0 auto; border-left: 1px solid #1e293b; border-right: 1px solid #1e293b; } .fab { right: calc(50% - 344px); } }

.mapwrap { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.map { flex: 1; min-height: 0; background: #0b1220; }
.leaflet-container { background: #0b1220; font-family: var(--font); }
.leaflet-container a { color: var(--accent); }
.leaflet-control-attribution { background: rgba(15,23,42,.75); color: var(--fg3); font-size: 10px; }
.leaflet-bar a { background: var(--bg2); color: var(--fg); border-color: #334155; }
.leaflet-bar a:hover { background: var(--bg3); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--bg2); color: var(--fg); box-shadow: 0 3px 14px rgba(0,0,0,.5); }
.leaflet-popup-content { font-size: 14px; line-height: 1.4; margin: 10px 14px; }
.pinwrap { background: transparent; border: 0; }
.pin { width: 36px; height: 36px; border-radius: 50%; background: var(--bg3); color: var(--fg); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; border: 3px solid var(--fg3); box-shadow: 0 2px 8px rgba(0,0,0,.5); }
.pin.fresh { border-color: var(--ok); } .pin.recent { border-color: var(--warn); } .pin.old { border-color: var(--fg3); opacity: .75; }
.pin.mine { background: var(--mine); }
.meetpin { width: 34px; height: 34px; display: flex; align-items: center; justify-content: center; font-size: 28px; line-height: 1; filter: drop-shadow(0 2px 4px rgba(0,0,0,.6)); }
.meetpin.archived { opacity: .4; }
.maptools { position: absolute; right: 10px; top: 10px; z-index: 800; display: flex; flex-direction: column; gap: 8px; }
.maptools button { width: 42px; height: 42px; padding: 0; border-radius: 10px; background: var(--bg2); color: var(--fg); font-size: 20px; box-shadow: 0 2px 8px rgba(0,0,0,.5); }
.maptools button.on { background: var(--accent2); color: #fff; }
.alertbar { position: absolute; left: 10px; right: 62px; top: 10px; z-index: 800; padding: 8px 12px; border-radius: 10px; background: #7c2d12; color: #fff; font-size: 14px; box-shadow: 0 2px 8px rgba(0,0,0,.5); cursor: pointer; }
.alertbar .when { color: #fed7aa; font-size: 12px; }
.replaybar { display: flex; gap: 8px; align-items: center; padding: 8px 12px; border-top: 1px solid #1e293b; background: var(--bg2); font-size: 13px; }
.replaybar input[type=range] { flex: 1; min-width: 0; }
.mappanel { max-height: 36%; overflow-y: auto; border-top: 1px solid #1e293b; background: var(--bg); }
.mappanel .list li { padding: 8px 16px; }
.mappanel .preview.fresh { color: var(--ok); } .mappanel .preview.recent { color: var(--warn); }
.panelhead { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 12px 6px 16px; }
.panelhead .note { padding: 0; }
.groupchips { padding: 6px 12px; overflow-x: auto; flex-wrap: nowrap; border-bottom: 1px solid #1e293b; }
.chip { white-space: nowrap; border: 0; color: var(--fg); }
.chip.active { background: var(--accent2); color: #fff; }
.sysmsg { align-self: center; max-width: 92%; text-align: center; font-size: 13px; color: var(--fg2); background: var(--bg2); border-radius: 10px; padding: 6px 12px; margin: 6px 0; }
.sysmsg.drift { background: #7c2d12; color: #fff; }
.sysmsg .when { color: var(--fg3); font-size: 11px; }
.sysmsg a { color: var(--accent); }
