:root {
  --bg: #f2f4f8; --card: #fff; --ink: #111827; --ink-2: #374151; --muted: #6b7280; --line: #e2e6ec; --field: #fafbfc;
  --accent: #0e7c66; --accent-soft: #e2f4ef; --bubble-in: #fff; --bubble-out: #0e7c66; --bubble-out-ink: #fff;
  --bad: #c0362c; --warn: #9a6100; --warn-bg: #fff5df; --good: #16a34a; --bar: #0b1220; --bar-ink: #e5e7eb;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; color: var(--ink);
  -webkit-text-size-adjust: 100%;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0b1220; --card: #121a2b; --ink: #e5e7eb; --ink-2: #cbd2dc; --muted: #8b95a5; --line: #233049; --field: #0f1626;
    --accent: #2bb596; --accent-soft: #10342d; --bubble-in: #172238; --bubble-out: #1c7a66; --warn-bg: #3a2a07; --warn: #f5c45c; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
body { font-size: 15px; line-height: 1.4; }
[hidden] { display: none !important; }
h2 { font-size: 16px; margin: 0 0 10px; } h3 { font-size: 14px; margin: 0 0 8px; }
a { color: var(--accent); }
.muted { color: var(--muted); } .small { font-size: 12.5px; } .hint { color: var(--muted); font-weight: 400; }
.error { color: var(--bad); min-height: 1.2em; margin: 8px 0 0; font-size: 14px; }
.msg { font-size: 13.5px; color: var(--good); } .msg.err { color: var(--bad); }
.warn { background: var(--warn-bg); color: var(--warn); border-radius: 8px; padding: 9px 12px; font-size: 13.5px; }
label { display: block; font-size: 13px; font-weight: 500; color: var(--ink-2); margin: 0 0 12px; }
input, select, textarea { display: block; width: 100%; margin-top: 5px; font: inherit; font-size: 16px; padding: 9px 11px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--field); color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label.check { display: flex; gap: 10px; align-items: center; font-size: 14.5px; font-weight: 400; }
label.check input { width: 20px; height: 20px; margin: 0; accent-color: var(--accent); }
label.check.big { font-size: 16px; font-weight: 600; }
button { font: inherit; font-size: 14.5px; font-weight: 500; padding: 9px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); cursor: pointer; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.danger { color: var(--bad); }
button.small { padding: 5px 9px; font-size: 13px; }
button.block { width: 100%; }
button:disabled { opacity: .55; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin: 0 0 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.form-foot { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 6px; }
code { font-size: 13px; background: var(--field); padding: 2px 6px; border-radius: 4px; word-break: break-all; }

/* sign in */
.auth { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: min(380px, 100%); background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 26px 22px; }
.brand-big { font-size: 24px; font-weight: 700; display: flex; align-items: center; gap: 10px; }
.brand-big .dot { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 5px var(--accent-soft); }
.fine { font-size: 13px; color: var(--muted); text-align: center; }

/* status bar and tabs */
.statusbar { position: sticky; top: 0; z-index: 1000; background: var(--bar); color: var(--bar-ink); padding-top: env(safe-area-inset-top); }
.sb-row { display: flex; gap: 14px; align-items: center; padding: 8px 14px 4px; font-size: 12.5px; overflow-x: auto; white-space: nowrap; }
.sb-item { display: inline-flex; align-items: center; gap: 6px; }
.sb-item.muted { color: #9aa3b2; }
.sb-item.mode { margin-left: auto; background: #1d2a44; padding: 2px 8px; border-radius: 10px; }
.led { width: 9px; height: 9px; border-radius: 50%; background: #6b7280; display: inline-block; }
.led.ok { background: #22c55e; box-shadow: 0 0 0 3px rgba(34,197,94,.25); }
.led.wait { background: #f59e0b; } .led.bad { background: #ef4444; }
.tabs { display: flex; gap: 2px; padding: 0 8px; overflow-x: auto; }
.tabs button { background: none; border: none; border-bottom: 2px solid transparent; border-radius: 0; color: #9aa3b2; padding: 9px 10px;
  font-size: 14px; white-space: nowrap; position: relative; }
.tabs button.on { color: #fff; border-bottom-color: #2bb596; font-weight: 600; }
.badge { background: #ef4444; color: #fff; font-size: 11px; border-radius: 9px; padding: 1px 6px; margin-left: 5px; font-weight: 700; }
.page { max-width: 820px; margin: 0 auto; padding: 14px 12px 40px; }

/* messages */
.msg-layout { display: grid; grid-template-columns: 300px 1fr; height: calc(100dvh - 82px - env(safe-area-inset-top)); }
.conv-list { overflow-y: auto; border-right: 1px solid var(--line); background: var(--card); }
.conv { display: flex; gap: 10px; align-items: center; padding: 11px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.conv.on { background: var(--accent-soft); }
.conv .avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; flex: none;
  background: var(--accent-soft); color: var(--accent); font-size: 15px; }
.conv .avatar.ch { border-radius: 10px; }
.conv .meta { flex: 1; min-width: 0; }
.conv .top { display: flex; justify-content: space-between; gap: 6px; }
.conv .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .time { font-size: 12px; color: var(--muted); flex: none; }
.conv .preview { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .badge { flex: none; }
.conv-head { padding: 10px 14px 4px; font-size: 11.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.thread { display: flex; flex-direction: column; min-width: 0; }
.thread-head { display: flex; gap: 10px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--card); }
.thread-head .back { display: none; font-size: 22px; padding: 2px 12px; border: none; background: none; color: var(--accent); }
.thread-body { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.bubble { max-width: 78%; padding: 8px 12px; border-radius: 14px; background: var(--bubble-in); border: 1px solid var(--line); align-self: flex-start;
  word-wrap: break-word; white-space: pre-wrap; }
.bubble.out { background: var(--bubble-out); color: var(--bubble-out-ink); border-color: transparent; align-self: flex-end; }
.bubble .who { font-size: 12.5px; font-weight: 700; color: var(--accent); margin-bottom: 2px; }
.bubble .who.own { color: inherit; opacity: .85; }
.bubble .info { font-size: 11.5px; opacity: .75; margin-top: 4px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.bubble .info a { color: inherit; }
.bubble .info button { padding: 1px 7px; font-size: 11.5px; }
.bubble.out.queued { opacity: .7; border: 1px dashed var(--bubble-out-ink); }
.bubble.failed, .bubble.cancelled { opacity: .55; }
.day { align-self: center; font-size: 12px; color: var(--muted); margin: 6px 0; }
.composer { display: flex; gap: 8px; padding: 10px 12px; padding-bottom: max(10px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line);
  background: var(--card); align-items: flex-end; }
.composer textarea { margin: 0; resize: none; max-height: 120px; }
.composer .count { font-size: 11.5px; color: var(--muted); align-self: center; min-width: 46px; text-align: right; }
.composer .count.over { color: var(--bad); font-weight: 700; }
.composer-error { padding: 0 14px 8px; margin: 0; background: var(--card); }
.composer-error:empty { display: none; }
.empty { color: var(--muted); text-align: center; margin: 30px 10px; }

/* lists */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
table.list { width: 100%; border-collapse: collapse; font-size: 14px; }
table.list td, table.list th { padding: 9px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
table.list th { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
table.list tr:last-child td { border-bottom: none; }
.pill { font-size: 11.5px; padding: 2px 8px; border-radius: 9px; background: var(--accent-soft); color: var(--accent); font-weight: 600; white-space: nowrap; }
.pill.rep { background: #e8ecff; color: #3346c8; } .pill.room { background: #fde8f3; color: #a3266a; } .pill.pend { background: var(--warn-bg); color: var(--warn); }
@media (prefers-color-scheme: dark) { .pill.rep { background: #1d2550; color: #a6b4ff; } .pill.room { background: #3b1730; color: #f5a3cf; } }
table.kv { width: 100%; font-size: 14px; border-collapse: collapse; }
table.kv td { padding: 6px 4px; border-bottom: 1px solid var(--line); }
table.kv td:first-child { color: var(--muted); width: 40%; }
table.kv code { font-size: 11.5px; }
.audit { font-size: 13px; max-height: 360px; overflow-y: auto; }
.audit div { padding: 5px 0; border-bottom: 1px solid var(--line); }

/* map */
.map-tools { display: flex; gap: 8px; padding: 8px 12px; background: var(--card); border-bottom: 1px solid var(--line); }
.map-tools select { margin: 0; width: auto; padding: 6px 9px; font-size: 14px; }
.map-layout { display: grid; grid-template-columns: 1fr 240px; height: calc(100dvh - 82px - 50px - env(safe-area-inset-top)); }
#map { height: 100%; }
.no-loc { margin: 0; border-radius: 0; overflow-y: auto; border-width: 0 0 0 1px; }
.no-loc ul { list-style: none; padding: 0; margin: 0; font-size: 13.5px; }
.no-loc li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.leaflet-popup-content { font: 13.5px/1.4 -apple-system, BlinkMacSystemFont, sans-serif; }

.toast { position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 2000;
  background: #111827; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; box-shadow: 0 6px 20px rgba(0,0,0,.25); max-width: 92vw; }

@media (max-width: 760px) {
  .msg-layout { grid-template-columns: 1fr; }
  .msg-layout.open .conv-list { display: none; }
  .msg-layout:not(.open) .thread { display: none; }
  .thread-head .back { display: block; }
  .map-layout { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .no-loc { max-height: 150px; border-width: 1px 0 0 0; }
  .grid2 { grid-template-columns: 1fr; }
  .bubble { max-width: 88%; }
}
