:root {
  --bg: #f4f6f4;
  --paper: #ffffff;
  --ink: #16201a;
  --muted: #6a766c;
  --line: #dde3da;
  --green: #1e6b4d;
  --green-2: #15543b;
  --red: #d42a30;
  --red-2: #a51f25;
  --amber: #b97714;
  --blue: #236b8e;
  --shadow: 0 14px 34px rgba(20, 30, 24, .12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  min-height: 100dvh;
  color: var(--ink);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; cursor: pointer; }
h2, h3 { margin: 0; }

/* ---------- topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 16px;
  background: rgba(255,255,255,.92); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-mark {
  display: grid; place-items: center; width: 34px; height: 34px;
  border-radius: 9px; background: var(--green); color: #fff; font-weight: 900; font-size: 14px;
}
.brand strong { font-size: 17px; }
.brand-logo { height: 42px; width: 46px; object-fit: contain; object-position: center; }
.brand-logo.big { width: 132px; height: 132px; object-fit: contain; border-radius: 18px; background: #fff; padding: 8px; box-shadow: var(--shadow); justify-self: center; }
.top-actions { display: flex; gap: 8px; }
.ghost {
  min-height: 38px; padding: 0 14px; border-radius: 9px;
  border: 1px solid var(--line); background: #fff; color: var(--ink); font-weight: 700;
}

/* ===================== VECINO ===================== */
.citizen {
  max-width: 460px; margin: 0 auto;
  display: flex; flex-direction: column; align-items: center;
  gap: 18px; padding: 18px 16px 40px;
}
.loc-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 13px; border-radius: 999px; background: #fff;
  border: 1px solid var(--line); color: var(--muted); font-size: 13px; font-weight: 700;
}
.loc-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--amber); }
.loc-dot.ok { background: var(--green); box-shadow: 0 0 0 5px rgba(30,107,77,.15); }

/* SOS gigante */
.sos {
  position: relative; display: grid; place-items: center; gap: 2px;
  width: min(78vw, 300px); height: min(78vw, 300px);
  border: 0; border-radius: 50%; color: #fff;
  background: radial-gradient(circle at 50% 38%, #e8474c, var(--red) 60%, var(--red-2));
  box-shadow: 0 22px 50px rgba(212,42,48,.38), inset 0 -10px 0 rgba(0,0,0,.14);
  touch-action: none; user-select: none;
}
.sos:active { transform: scale(.985); }
.sos.arming { background: radial-gradient(circle at 50% 38%, #f06a6e, var(--red-2) 70%); }
.sos-emoji { font-size: 64px; line-height: 1; filter: drop-shadow(0 2px 2px rgba(0,0,0,.2)); }
.sos-text { font-size: 30px; font-weight: 900; letter-spacing: .5px; }
.sos-hint { font-size: 14px; font-weight: 700; opacity: .92; }
.sos-progress {
  position: absolute; bottom: 17%; width: 56%; height: 8px;
  border-radius: 999px; background: rgba(255,255,255,.32); overflow: hidden;
}
.sos-progress i { display: block; width: 0%; height: 100%; background: #fff; }

/* categorias con dibujo */
.cats {
  width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
}
.cat {
  display: grid; place-items: center; gap: 6px;
  min-height: 112px; padding: 12px;
  border: 2px solid var(--line); border-radius: 18px; background: #fff;
  color: var(--ink); transition: transform .08s, border-color .12s;
}
.cat:active { transform: scale(.97); }
.cat.sending { border-color: var(--c); background: color-mix(in srgb, var(--c) 8%, #fff); }
.cat-emoji {
  display: grid; place-items: center; width: 60px; height: 60px; border-radius: 50%;
  background: color-mix(in srgb, var(--c) 14%, #fff); font-size: 34px; line-height: 1;
}
.cat b { font-size: 18px; font-weight: 800; }

/* voz */
.voice {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 12px;
  min-height: 88px; border: 0; border-radius: 20px; color: #fff;
  background: linear-gradient(180deg, #2a7d5d, var(--green));
  box-shadow: 0 12px 26px rgba(30,107,77,.3); touch-action: none; user-select: none;
}
.voice:active { transform: scale(.985); }
.voice.recording { background: linear-gradient(180deg, #e8474c, var(--red-2)); animation: pulse 1s infinite; }
.voice-emoji { font-size: 40px; }
.voice-text { font-size: 21px; font-weight: 900; }
.voice-time { font-size: 18px; font-weight: 800; opacity: .9; }
.cz-hint { text-align: center; color: var(--muted); font-size: 14px; font-weight: 700; margin: 2px 6px 0; line-height: 1.4; }
@keyframes pulse { 0%,100% { box-shadow: 0 12px 26px rgba(212,42,48,.4); } 50% { box-shadow: 0 12px 26px rgba(212,42,48,.7); } }

/* seguimiento del caso */
.track {
  width: 100%; padding: 16px; border-radius: 20px; background: #fff;
  border: 2px solid var(--green); box-shadow: var(--shadow);
}
.track h3 { font-size: 18px; margin-bottom: 4px; }
.track .code { color: var(--muted); font-weight: 800; font-size: 14px; }
.track-steps { display: flex; gap: 6px; margin: 14px 0 6px; }
.tstep {
  flex: 1; display: grid; place-items: center; gap: 6px; padding: 10px 4px;
  border-radius: 14px; background: var(--bg); color: var(--muted);
}
.tstep .ico { font-size: 28px; }
.tstep b { font-size: 12px; font-weight: 800; }
.tstep.done { background: color-mix(in srgb, var(--green) 16%, #fff); color: var(--green-2); }
.tstep.now { background: var(--green); color: #fff; box-shadow: 0 8px 18px rgba(30,107,77,.3); }
.track .new-btn {
  width: 100%; min-height: 50px; margin-top: 12px; border: 0; border-radius: 14px;
  background: var(--ink); color: #fff; font-weight: 800; font-size: 16px;
}
.more-alerts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.more-alerts span { padding: 5px 9px; border-radius: 999px; background: var(--bg); color: var(--muted); font-size: 12px; font-weight: 800; }
.chat { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; }
.chat-title { margin: 0 0 8px; font-size: 14px; color: var(--muted); }
.chat-msgs { display: grid; gap: 6px; max-height: 200px; overflow: auto; margin-bottom: 8px; }
.chat-empty { color: var(--muted); font-size: 13px; }
.cmsg { display: grid; gap: 1px; padding: 8px 11px; border-radius: 12px; font-size: 14px; max-width: 85%; }
.cmsg b { font-size: 11px; opacity: .7; }
.cmsg.op { background: #e9f1ff; justify-self: start; }
.cmsg.me { background: #e7f3ec; justify-self: end; text-align: right; }
.op-help { padding: 10px 14px; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; color: var(--muted); font-size: 13px; font-weight: 700; }

/* ===== Dashboard amigable ===== */
.op-head { align-items: center; }
.op-title h2 { font-size: 22px; }
.op-status { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: 13px; font-weight: 800; }
.op-status .sep { opacity: .45; }
.live-dot { width: 10px; height: 10px; border-radius: 50%; background: #22c55e; animation: livepulse 1.8s infinite; }
@keyframes livepulse { 0% { box-shadow: 0 0 0 0 rgba(34,197,94,.5); } 70% { box-shadow: 0 0 0 8px rgba(34,197,94,0); } 100% { box-shadow: 0 0 0 0 rgba(34,197,94,0); } }

.kpis { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; }
.kpi { display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 11px; align-items: center; padding: 12px 14px; background: var(--paper); border: 1px solid var(--line); border-left: 5px solid var(--line); border-radius: 14px; box-shadow: 0 2px 8px rgba(20,30,24,.04); }
.kpi-ic { grid-row: 1 / 3; font-size: 26px; }
.kpi-num { font-size: 27px; font-weight: 900; line-height: 1; }
.kpi-lbl { color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; }
.kpi.k-red { border-left-color: var(--red); }
.kpi.k-crit { border-left-color: #d42a30; background: #fff7f7; }
.kpi.k-amber { border-left-color: var(--amber); }
.kpi.k-blue { border-left-color: var(--blue); }
.kpi.k-green { border-left-color: var(--green); }
.kpi.k-gray { border-left-color: #9aa6a0; }

.incident-item { border-left: 5px solid var(--line); transition: background .15s; }
.incident-item.critical { border-left-color: var(--red); }
.incident-item.high { border-left-color: var(--amber); }
.incident-item.normal { border-left-color: var(--green); }
.incident-item.nuevo { background: #fff5f5; box-shadow: inset 0 0 0 1px rgba(212,42,48,.25); }
.incident-item.selected { border-color: var(--green); border-left-color: var(--green); background: #f1f7f1; }
.ii-top, .ii-bottom { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.ii-cat { font-weight: 900; font-size: 15px; }
.ii-time { color: var(--muted); font-size: 12px; font-weight: 700; white-space: nowrap; }
.ii-place { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.st { display: inline-flex; align-items: center; min-height: 22px; padding: 0 9px; border-radius: 999px; font-size: 11px; font-weight: 900; white-space: nowrap; }
.st-red { background: #fde8e8; color: #a51f25; }
.st-amber { background: #fbe7cf; color: #84520b; }
.st-blue { background: #e3eef5; color: #1c5878; }
.st-green { background: #e4f3ea; color: #15543b; }
.st-gray { background: var(--bg); color: var(--muted); }
@media (max-width: 980px) { .kpis { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 560px) { .kpis { grid-template-columns: repeat(2, 1fr); } }

/* flash de confirmacion */
.flash {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center;
  background: rgba(20,84,59,.97); color: #fff; animation: fade .2s ease;
}
.flash-inner { display: grid; justify-items: center; gap: 10px; text-align: center; padding: 24px; }
.flash-check {
  display: grid; place-items: center; width: 130px; height: 130px; border-radius: 50%;
  background: #fff; color: var(--green); font-size: 78px; font-weight: 900;
  animation: pop .3s cubic-bezier(.2,1.3,.5,1);
}
.flash-title { font-size: 30px; font-weight: 900; }
.flash-sub { font-size: 18px; opacity: .92; }
@keyframes pop { from { transform: scale(.3); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ===================== OPERADOR ===================== */
.operator { display: grid; gap: 14px; padding: 16px; }
.op-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 14px 16px; background: var(--paper); border: 1px solid var(--line); border-radius: 14px;
}
.op-eyebrow { color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; }
.op-head h2 { font-size: 22px; }
.op-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.op-actions select { min-height: 38px; border: 1px solid var(--line); border-radius: 9px; padding: 0 10px; background: #fff; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.stats article { padding: 14px; background: var(--paper); border: 1px solid var(--line); border-radius: 14px; }
.stats span { color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; }
.stats strong { display: block; margin-top: 6px; font-size: 26px; }
.ops-grid {
  display: grid; gap: 12px;
  grid-template-columns: minmax(320px, 1.2fr) minmax(260px, .85fr) minmax(320px, 1fr);
  align-items: start;
}
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: 14px; min-width: 0; overflow: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.panel-head h3 { font-size: 16px; }
.panel-head span { color: var(--muted); font-size: 12px; font-weight: 800; }
.map { height: 520px; width: 100%; background: #e6ece6; }
.incident-list { max-height: 520px; overflow: auto; padding: 10px; display: grid; gap: 9px; }
.incident-item {
  width: 100%; display: grid; gap: 7px; padding: 12px; text-align: left;
  border: 1px solid var(--line); border-radius: 12px; background: #fbfcfa; color: var(--ink);
}
.incident-item.selected { border-color: var(--green); background: #f1f7f1; }
.incident-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.code { color: var(--muted); font-size: 11px; font-weight: 900; }
.incident-title { font-weight: 900; font-size: 15px; }
.incident-meta { color: var(--muted); font-size: 12px; }
.priority { display: inline-flex; align-items: center; min-height: 22px; padding: 0 9px; border-radius: 999px; color: #fff; font-size: 11px; font-weight: 900; }
.priority.critical { background: var(--red); }
.priority.high { background: var(--amber); }
.priority.normal { background: var(--green); }
.detail-panel { min-height: 540px; }
.empty { margin: 14px; padding: 16px; border: 1px dashed var(--line); border-radius: 12px; color: var(--muted); }
.detail { display: grid; gap: 12px; padding: 14px; }
.detail-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.detail-top h3 { font-size: 19px; }
.detail-top p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.pill { display: inline-flex; align-items: center; min-height: 26px; padding: 0 11px; border-radius: 999px; background: var(--bg); color: var(--ink); font-size: 12px; font-weight: 800; white-space: nowrap; }
.block { padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: #fbfcfa; }
.block h4 { margin: 0 0 10px; color: var(--muted); font-size: 12px; text-transform: uppercase; }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.fact { padding: 9px; border-radius: 9px; background: var(--bg); }
.fact span { display: block; color: var(--muted); font-size: 11px; font-weight: 900; text-transform: uppercase; }
.fact strong { display: block; margin-top: 3px; font-size: 13px; overflow-wrap: anywhere; }
.nav-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.nav-actions a, .nav-actions button { min-height: 40px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--ink); text-decoration: none; font-weight: 800; }
.nav-actions a:first-child { background: var(--green); color: #fff; border-color: var(--green); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { min-height: 34px; padding: 0 10px; border: 1px solid var(--line); border-radius: 9px; background: #fff; color: var(--ink); font-size: 12px; font-weight: 800; }
.chips button.active { background: var(--green); color: #fff; border-color: var(--green); }
.assign-row { display: flex; gap: 8px; }
.assign-row select { flex: 1; min-width: 0; border: 1px solid var(--line); border-radius: 9px; padding: 0 10px; min-height: 38px; }
.assign-row button, .chat-row button { min-height: 38px; padding: 0 14px; border: 0; border-radius: 9px; background: var(--green); color: #fff; font-weight: 800; }
.media-row { display: flex; flex-wrap: wrap; gap: 10px; }
.media-chip { display: inline-flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 10px; background: var(--bg); font-size: 12px; font-weight: 800; color: var(--ink); text-decoration: none; }
.media-chip img { width: 54px; height: 54px; border-radius: 8px; object-fit: cover; }
.media-chip audio { height: 36px; }
.media-audio { width: 100%; }
.message-line { padding: 8px 0; border-bottom: 1px solid var(--line); }
.message-line:last-child { border-bottom: 0; }
.message-line strong { font-size: 12px; }
.message-line p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.message-line time { color: var(--muted); font-size: 11px; }
.chat-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.chat-row input, .assign-row input { min-height: 38px; border: 1px solid var(--line); border-radius: 9px; padding: 0 11px; }

/* toasts */
.toasts { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 50; display: grid; gap: 8px; width: min(420px, calc(100vw - 28px)); }
.toast { padding: 13px 16px; border-radius: 12px; background: #16201a; color: #fff; box-shadow: var(--shadow); font-weight: 800; text-align: center; }

/* ---------- confirmacion gigante (vecino) ---------- */
.confirm { position: fixed; inset: 0; z-index: 70; display: grid; grid-template-rows: 1fr 1fr; animation: fade .15s ease; }
.confirm-send, .confirm-cancel { border: 0; display: grid; place-items: center; gap: 6px; color: #fff; }
.confirm-send { background: #1e7d52; }
.confirm-cancel { background: #c0242a; }
.confirm .big-emoji { font-size: 84px; line-height: 1; }
.confirm-label { font-size: 32px; font-weight: 900; letter-spacing: .5px; }
.confirm-count { font-size: 22px; font-weight: 800; opacity: .9; }
.confirm-send:active, .confirm-cancel:active { filter: brightness(.92); }

/* ---------- login (panel) ---------- */
.panel-body { background: linear-gradient(160deg, #15543b, #0e3a28); }
.login { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.login-card { width: min(380px, 100%); display: grid; gap: 12px; padding: 26px 22px; background: #fff; border-radius: 18px; box-shadow: var(--shadow); }
.brand-mark.big { width: 56px; height: 56px; font-size: 20px; border-radius: 14px; justify-self: center; }
.login-card h1 { margin: 0; text-align: center; font-size: 22px; }
.login-sub { margin: 0 0 6px; text-align: center; color: var(--muted); font-size: 13px; }
.login-card label { display: grid; gap: 6px; font-size: 13px; font-weight: 800; color: var(--ink); }
.login-card input { min-height: 46px; border: 1px solid var(--line); border-radius: 11px; padding: 0 13px; font-size: 16px; }
.login-btn { min-height: 50px; border: 0; border-radius: 12px; background: var(--green); color: #fff; font-size: 17px; font-weight: 900; }
.login-btn:disabled { opacity: .6; }
.login-error { color: var(--red-2); font-weight: 800; font-size: 14px; text-align: center; }
.who { color: var(--muted); font-weight: 800; font-size: 13px; align-self: center; }

/* ---------- extras operador ---------- */
.ev { font-size: 14px; }
.out { color: var(--red-2); font-weight: 900; }
.alert-out { padding: 10px 12px; border-radius: 10px; background: #fff4f3; border: 1px solid rgba(201,45,50,.3); color: var(--red-2); font-weight: 800; font-size: 13px; }
.media-row { align-items: flex-start; }
.media-photo { display: grid; gap: 4px; text-decoration: none; color: var(--muted); font-size: 11px; font-weight: 800; text-align: center; }
.media-photo img { width: 100px; height: 100px; border-radius: 10px; object-fit: cover; border: 1px solid var(--line); }
.media-block { display: grid; gap: 4px; font-size: 12px; color: var(--ink); font-weight: 800; }
.media-block audio { width: 240px; max-width: 100%; }

/* ---------- 3 botones generales + gear ---------- */
.cats-3 { grid-template-columns: repeat(3, 1fr); }
.cats-3 .cat { min-height: 104px; padding: 10px 6px; }
.cats-3 .cat b { font-size: 15px; }
.cats-3 .cat-emoji { width: 52px; height: 52px; font-size: 28px; }
.gear { font-size: 16px; padding: 0 11px; }

/* ---------- onboarding ---------- */
.onb { position: fixed; inset: 0; z-index: 80; background: linear-gradient(165deg, #1e6b4d, #123f2d); color: #fff; display: grid; place-items: center; overflow: auto; }
.onb-step { width: min(420px, 100%); min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; text-align: center; padding: 28px 22px; }
.onb-step h1 { font-size: 24px; line-height: 1.2; margin: 0; }
.onb-step p { margin: 0; font-size: 16px; opacity: .92; }
.onb-emoji { font-size: 76px; line-height: 1; }
.onb .brand-mark.big { background: #fff; color: var(--green); }
.onb-btn { width: 100%; min-height: 56px; border: 0; border-radius: 14px; background: #fff; color: var(--green-2); font-size: 19px; font-weight: 900; }
.onb-btn:disabled { opacity: .7; }
.onb-skip { background: transparent; border: 0; color: rgba(255,255,255,.85); font-size: 15px; font-weight: 800; min-height: 40px; }
.perm { width: 100%; display: flex; align-items: center; gap: 14px; padding: 12px 14px; background: rgba(255,255,255,.12); border-radius: 14px; text-align: left; }
.perm span { font-size: 34px; }
.perm b { display: block; font-size: 17px; }
.perm small { color: rgba(255,255,255,.85); font-size: 14px; }
.onb-trust { font-size: 14px !important; opacity: .85 !important; }
.onb-lbl { width: 100%; text-align: left; font-weight: 800; font-size: 14px; }
.onb-step input { width: 100%; min-height: 52px; border: 0; border-radius: 13px; padding: 0 15px; font-size: 18px; color: var(--ink); }

/* ---------- reportado por (panel) ---------- */
.reporter { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.reporter b { font-size: 15px; }
.rphone { color: var(--muted); font-weight: 800; font-size: 13px; margin-top: 2px; }
.call-btn { display: inline-flex; align-items: center; min-height: 40px; padding: 0 16px; border-radius: 10px; background: var(--green); color: #fff; font-weight: 900; text-decoration: none; white-space: nowrap; }

/* responsive */
@media (max-width: 980px) {
  .ops-grid { grid-template-columns: 1fr; }
  .map { height: 320px; }
  .stats { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 430px) {
  .topbar { padding: 10px 12px; gap: 8px; }
  .brand strong { font-size: 15px; }
  .ghost { padding: 0 11px; font-size: 13px; min-height: 36px; }
}
