/* Layout: one narrow civic-service column; map on top, form below. */
:root {
  --bg: #EDEFF2; --surface: #FFFFFF; --ink: #1B2128; --muted: #5B6672; --line: #D3D9E0;
  --accent: #E8A317; --accent-ink: #1B2128; --soft: #F6F7F9;
  --s1: #5E8F6A; --s2: #8A9E3C; --s3: #C9940F; --s4: #DB6418; --s5: #C42F28;
  --ok: #2F7D4F; --danger: #B3261E;
  --f-display: "Unbounded", "Segoe UI", system-ui, sans-serif;
  --f-body: "Onest", "Segoe UI", system-ui, sans-serif;
  --f-mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) { :root {
  --bg: #11151A; --surface: #1A2028; --ink: #E6E9ED; --muted: #97A2AE; --line: #2C3541;
  --accent: #F0B23B; --accent-ink: #11151A; --soft: #151A21;
  --s1: #74AE82; --s2: #A8BD55; --s3: #E2AE2C; --s4: #F07F38; --s5: #EE5A50;
  --ok: #5FBF85; --danger: #F07167; color-scheme: dark } }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--f-body); }
.wrap { max-width: 760px; margin: 0 auto; padding: 20px 16px 48px; }
.wrap.wide { max-width: 1200px; }
header { display: flex; flex-direction: column; gap: 6px; }
h1 { font: 700 26px/1.15 var(--f-display); margin: 0; letter-spacing: -0.01em; }
.sub { color: var(--muted); margin: 0; max-width: 60ch; }
.hazard { height: 6px; border-radius: 3px; margin-top: 12px;
  background: repeating-linear-gradient(-45deg, var(--accent) 0 12px, var(--ink) 12px 24px); }

.tabs { display: flex; gap: 4px; margin: 18px 0 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 4px; }
.tabs button { flex: 1; border: 0; background: transparent; color: var(--muted); font: 600 14px var(--f-body); padding: 10px 8px; border-radius: 7px; cursor: pointer; }
.tabs button[aria-selected="true"] { background: var(--ink); color: var(--bg); }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
h2 { font: 500 16px/1.3 var(--f-display); margin: 0; }
label.f { display: flex; flex-direction: column; gap: 6px; font-weight: 500; font-size: 14px; }
.hint { color: var(--muted); font-size: 13px; font-weight: 400; }
input[type=text], textarea, select { width: 100%; font: 15px var(--f-body); color: var(--ink); background: var(--soft); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
textarea { min-height: 72px; resize: vertical; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

#map, #dmap { height: 320px; border-radius: 10px; border: 1px solid var(--line); z-index: 0; }
#dmap { height: 420px; }
.geo-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.geo-row .hint { flex: 1 1 220px; }

.drop { position: relative; border: 2px dashed var(--line); border-radius: 12px; min-height: 160px; display: grid; place-items: center; text-align: center; padding: 16px; cursor: pointer; background: var(--soft); overflow: hidden; }
.drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.drop img { max-height: 320px; border-radius: 8px; max-width: 100%; }
.drop .big { font: 500 15px var(--f-display); }

.btn { border: 0; border-radius: 9px; padding: 12px 18px; font: 600 15px var(--f-body); cursor: pointer; background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.small { padding: 7px 12px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.btns { display: flex; gap: 10px; flex-wrap: wrap; }

.ai { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.ai-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; background: var(--soft); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.ai-body { padding: 14px; display: grid; grid-template-columns: 140px 1fr; gap: 8px 14px; font-size: 14px; margin: 0; }
.ai-body dt { color: var(--muted); }
.ai-body dd { margin: 0; min-width: 0; }
@media (max-width: 480px) { .ai-body { grid-template-columns: 1fr; } .ai-body dt { margin-top: 6px; } }

.sev { display: inline-flex; align-items: center; gap: 6px; font: 600 12px var(--f-mono); padding: 3px 8px; border-radius: 99px; border: 1.5px solid currentColor; white-space: nowrap; }
.sev i { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.sev[data-s="1"] { color: var(--s1); } .sev[data-s="2"] { color: var(--s2); } .sev[data-s="3"] { color: var(--s3); }
.sev[data-s="4"] { color: var(--s4); } .sev[data-s="5"] { color: var(--s5); }
.chip { font: 500 12px var(--f-body); padding: 3px 9px; border-radius: 99px; background: var(--soft); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.chip.emer { background: var(--s5); color: #fff; border-color: transparent; }
.chip.st-resolved { color: var(--ok); border-color: var(--ok); }
.chip.st-rejected { text-decoration: line-through; }
.chip.st-in_progress, .chip.st-assigned { color: var(--accent-ink); background: var(--accent); border-color: transparent; }
.mono { font-family: var(--f-mono); font-size: 13px; }
.note { padding: 12px 14px; border-radius: 10px; background: var(--soft); border: 1px solid var(--line); font-size: 14px; }
.note.good { border-color: var(--ok); }
.note.bad { border-color: var(--danger); }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
@media (max-width: 560px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.stat b { display: block; font: 700 24px var(--f-display); font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.stat.alert b { color: var(--s5); }
.filters { display: flex; gap: 10px; flex-wrap: wrap; }
.filters select, .filters input { width: auto; flex: 1 1 180px; }

.card { background: var(--surface); border: 1px solid var(--line); border-left: 5px solid var(--line); border-radius: 10px; display: grid; grid-template-columns: 92px 1fr; gap: 12px; padding: 12px; }
.card[data-s="1"] { border-left-color: var(--s1); } .card[data-s="2"] { border-left-color: var(--s2); } .card[data-s="3"] { border-left-color: var(--s3); }
.card[data-s="4"] { border-left-color: var(--s4); } .card[data-s="5"] { border-left-color: var(--s5); }
.thumb { width: 92px; height: 92px; border-radius: 8px; object-fit: cover; background: var(--soft); }
.card-main { min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.card-top { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.card h3 { margin: 0; font: 600 15px/1.3 var(--f-body); }
.meta { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.overdue { color: var(--s5); font-weight: 600; }
details.more summary { cursor: pointer; color: var(--muted); font-size: 13px; }
details.more[open] { display: flex; flex-direction: column; gap: 8px; }
.hist { list-style: none; margin: 0; padding: 0; font-size: 13px; display: flex; flex-direction: column; gap: 4px; }
.hist li { display: flex; gap: 8px; } .hist .mono { color: var(--muted); font-size: 12px; white-space: nowrap; }
.big-photo { border-radius: 8px; max-height: 360px; max-width: 100%; object-fit: contain; align-self: flex-start; }
@media (max-width: 420px) { .card { grid-template-columns: 64px 1fr; } .thumb { width: 64px; height: 64px; } }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; }
.empty b { display: block; color: var(--ink); font: 500 15px var(--f-display); margin-bottom: 6px; }
.dgrid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 900px) { .dgrid { grid-template-columns: 1fr; } }
.dgrid .sticky { position: sticky; top: 12px; }

/* Чат з диспетчером */
.contact-btn { align-self: flex-start; margin-top: 10px; }
.chat { display: flex; flex-direction: column; gap: 8px; max-height: 420px; min-height: 160px; overflow-y: auto; padding: 12px; background: var(--soft); border: 1px solid var(--line); border-radius: 10px; }
.msg { max-width: 82%; padding: 8px 12px; border-radius: 12px; font-size: 14px; overflow-wrap: anywhere; white-space: pre-wrap; }
.msg small { display: block; color: var(--muted); font: 11px var(--f-mono); margin-top: 4px; }
.msg.me { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 4px; }
.msg.me small { color: inherit; opacity: .7; }
.msg.them { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg .ref { font: 600 11px var(--f-mono); opacity: .8; display: block; margin-bottom: 2px; }
.composer { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { min-height: 48px; flex: 1; }
.badge { display: inline-block; min-width: 18px; padding: 0 6px; margin-left: 6px; border-radius: 99px; background: var(--s5); color: #fff; font: 600 11px/18px var(--f-body); text-align: center; }
.threads { display: flex; flex-direction: column; gap: 6px; }
.thread { text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px; cursor: pointer; color: var(--ink); font: 14px var(--f-body); display: flex; flex-direction: column; gap: 2px; }
.thread[aria-current="true"] { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.thread .meta { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Photos and AI verdicts in chat */
.msg-photo { display: block; max-width: 100%; max-height: 260px; border-radius: 8px; margin: 4px 0; }
.ai-mini { margin-top: 6px; padding: 8px 10px; border-radius: 8px; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-left: 4px solid var(--line); display: flex; flex-direction: column; gap: 4px; font-size: 13px; white-space: normal; }
.ai-mini[data-s="1"] { border-left-color: var(--s1); } .ai-mini[data-s="2"] { border-left-color: var(--s2); } .ai-mini[data-s="3"] { border-left-color: var(--s3); }
.ai-mini[data-s="4"] { border-left-color: var(--s4); } .ai-mini[data-s="5"] { border-left-color: var(--s5); }
.ai-mini.pending { color: var(--muted); font-style: italic; }
.ai-mini-top { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.msg.me .ai-mini .meta { color: var(--muted); }
.attach { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: 13px; }
.attach label.check { display: inline-flex; gap: 6px; align-items: center; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.pending-photo { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--muted); }
.pending-photo img { width: 56px; height: 56px; object-fit: cover; border-radius: 6px; }
.live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); margin-right: 6px; vertical-align: middle; }
.live-dot.on { background: var(--ok); }

/* Video call */
.call { position: fixed; inset: 0; z-index: 1000; background: #0b0e12; color: #fff; display: flex; flex-direction: column; }
.call video.remote { flex: 1; min-height: 0; width: 100%; object-fit: contain; background: #000; }
.call video.local { position: absolute; right: 12px; top: calc(12px + env(safe-area-inset-top, 0px)); width: 28vw; max-width: 180px; border-radius: 10px; border: 2px solid rgba(255,255,255,.6); background: #222; }
.call video.local.main { position: static; flex: 1; min-height: 0; width: 100%; max-width: none; border: 0; border-radius: 0; object-fit: cover; }
.call-bar { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; align-items: center; padding: 14px 16px calc(14px + env(safe-area-inset-bottom, 0px)); background: rgba(0,0,0,.6); }
.call-status { position: absolute; left: 12px; top: calc(12px + env(safe-area-inset-top, 0px)); background: rgba(0,0,0,.55); padding: 6px 12px; border-radius: 99px; font-size: 14px; }
.btn.danger { background: #C42F28; color: #fff; }
.btn.light { background: rgba(255,255,255,.15); color: #fff; }
/* Incoming call: covers the whole screen so it cannot be missed */
.ring { position: fixed; inset: 0; z-index: 900; background: rgba(20, 10, 0, .92); color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; padding: 24px; text-align: center; }
.ring[hidden] { display: none; }
.ring .ring-icon { width: 140px; height: 140px; border-radius: 50%; background: var(--accent); display: grid; place-items: center; font-size: 64px; }
.ring #ring-title { font-size: clamp(28px, 5vw, 56px); line-height: 1.15; }
.ring #ring-sub { color: #f3e3c3; font-size: clamp(16px, 2.2vw, 24px); }
.ring .btns { gap: 18px; justify-content: center; }
.ring .btn { font-size: 22px; padding: 18px 40px; border-radius: 999px; }
.ring #accept-btn { background: #1f9d4c; border-color: #1f9d4c; color: #fff; }
.ring #decline-btn { background: #c62828; border-color: #c62828; color: #fff; }
@media (prefers-reduced-motion: no-preference) { .ring .ring-icon { animation: pulse 1s ease-in-out infinite; } @keyframes pulse { 50% { box-shadow: 0 0 0 28px rgba(232,163,23,.35); transform: scale(1.06); } } }
.alert-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.inbox { display: grid; grid-template-columns: minmax(220px, 320px) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 760px) { .inbox { grid-template-columns: 1fr; } }
.inbox .chat { max-height: 520px; min-height: 280px; }

/* Video and chat together during a call */
.call { flex-direction: row; }
.call-main { position: relative; flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.call-side { width: min(400px, 38vw); flex: none; background: var(--bg); color: var(--ink); display: flex; flex-direction: column; gap: 8px; padding: 12px; padding-top: calc(12px + env(safe-area-inset-top, 0px)); min-height: 0; }
.call-side h3 { margin: 0; font: 500 15px var(--f-display); }
.call-side .chat { flex: 1; max-height: none; min-height: 0; }
.call-side #thread-view, .call-side .call-chat { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 8px; }
.call-side .btns:empty { display: none; }
@media (max-width: 760px) {
  .call { flex-direction: column; }
  .call-main { flex: 1 1 58%; }
  .call-side { width: auto; flex: 1 1 42%; padding-top: 10px; padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
  .call-side .composer textarea { min-height: 40px; }
  .call .call-bar { padding-bottom: 10px; }
}
