/* ── CICOM Design System ─────────────────────────────────── */
:root {
  --app-nav-height: 108px;
  --bg-base: #060d1a;
  --bg-panel: #0d1b2e;
  --bg-card: #112236;
  --bg-hover: #162d45;
  --border: #1e3a56;
  --border-glow: #00d4ff33;
  --text-primary: #e8f4ff;
  --text-secondary: #7da8c8;
  --text-muted: #4a7090;
  --cyan: #00d4ff;
  --cyan-dim: #00d4ff22;
  --gold: #ffd700;
  --font: 'Inter', sans-serif;
  --mono: 'Share Tech Mono', monospace;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 4px 24px #00000060;
  --shadow-glow: 0 0 20px #00d4ff18;

  /* ── Colores por categoría ─────────────────────────────── */
  --cat-emergencia:    #ff2244;
  --cat-robo:          #ff6600;
  --cat-atraco:        #ff4400;
  --cat-hurto:         #ff8800;
  --cat-disparos:      #cc0033;
  --cat-heridos:       #ff3366;
  --cat-fallecidos:    #880022;
  --cat-accidente:     #ff9900;
  --cat-explosion:     #ff4500;
  --cat-protesta:      #9933ff;
  --cat-incidencia:    #0099ff;
  --cat-atencion:      #00cc88;
  --cat-denuncia:      #ffcc00;
  --cat-infraccion:    #ff6699;
}

[data-theme="light"] {
  --bg-base: #f0f4f8;
  --bg-panel: #ffffff;
  --bg-card: #f8fafc;
  --bg-hover: #e2e8f0;
  --border: #cbd5e1;
  --border-glow: #00d4ff33;
  --text-primary: #0f172a;
  --text-secondary: #334155;
  --text-muted: #64748b;
  --shadow: 0 4px 12px rgba(0,0,0,0.05);
  --shadow-glow: 0 0 15px rgba(2, 132, 199, 0.15);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; min-height: 100%; background: var(--bg-base); color: var(--text-primary); font-family: var(--font); overflow: hidden; }
body { min-width: 0; }

/* ── Scrollbar ──────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--bg-base); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }

/* ── Modal ──────────────────────────────────────────── */
.modal-overlay { position: fixed; inset: 0; background: #000000dd; z-index: 4000; display: none; align-items: center; justify-content: center; padding: 16px; }
.modal-overlay.active { display: flex; }
.modal-box { background: var(--bg-panel); border: 1px solid var(--border); border-radius: 16px; max-width: 640px; width: 95%; max-height: 90vh; overflow-y: auto; box-shadow: 0 0 60px #00d4ff18, var(--shadow); }
.modal-header { padding: 24px 28px 16px; border-bottom: 1px solid var(--border); text-align: center; }
.modal-header h2 { font-size: 1.4rem; color: var(--cyan); letter-spacing: 2px; margin: 10px 0 4px; }
.modal-subtitle { font-size: .75rem; color: var(--text-secondary); }
.modal-logo { display: flex; justify-content: center; margin-bottom: 8px; }
.modal-body { padding: 20px 28px; font-size: .85rem; line-height: 1.7; color: var(--text-secondary); }
.modal-body p { margin-bottom: 10px; }
.modal-body ul { margin: 10px 0 10px 20px; }
.modal-body li { margin-bottom: 8px; }
.modal-body strong { color: var(--text-primary); }
.modal-body em { color: var(--cyan); }
.modal-actions { padding: 16px 28px 24px; display: flex; justify-content: center; }
.disclaimer-flag { display: flex; height: 6px; border-radius: 3px; overflow: hidden; margin-bottom: 16px; }
.flag-stripe { flex: 1; }
.flag-stripe.yellow { background: #ffd700; }
.flag-stripe.blue   { background: #003087; }
.flag-stripe.red    { background: #cf142b; }
.disclaimer-footer { font-size: .75rem; text-align: center; color: var(--text-muted); margin-top: 12px; }
.author-link { color: var(--cyan); text-decoration: none; font-weight: 600; }
.author-link:hover { text-decoration: underline; }

/* ── Buttons ──────────────────────────────────────── */
.btn-primary { background: linear-gradient(135deg, #0090c8, #00d4ff); color: #000; border: none; border-radius: var(--radius); padding: 12px 28px; font-weight: 700; cursor: pointer; font-size: .9rem; transition: all .2s; }
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 8px 24px #00d4ff44; }
.btn-primary.small { padding: 7px 16px; font-size: .8rem; }
.btn-secondary { background: transparent; color: var(--cyan); border: 1px solid var(--cyan); border-radius: var(--radius-sm); padding: 8px 18px; cursor: pointer; font-size: .82rem; transition: all .2s; }
.btn-secondary:hover { background: var(--cyan-dim); }
.btn-secondary.small { padding: 5px 12px; font-size: .78rem; }
.close-btn { background: none; border: none; color: var(--text-muted); font-size: 1.2rem; cursor: pointer; padding: 4px 8px; border-radius: 4px; }
.close-btn:hover { color: var(--text-primary); background: var(--bg-hover); }
.pulse-btn { animation: pulseShadow 2s infinite; }
@keyframes pulseShadow { 0%,100% { box-shadow: 0 0 0 0 #00d4ff44; } 50% { box-shadow: 0 0 0 12px #00d4ff00; } }

/* ── Sound Toggle ─────────────────────────────────── */
.sound-toggle { position: fixed; bottom: 20px; right: 20px; z-index: 999; background: var(--bg-card); border: 1px solid var(--border); border-radius: 50%; width: 44px; height: 44px; font-size: 1.1rem; cursor: pointer; transition: all .2s; }
.sound-toggle:hover { border-color: var(--cyan); }
.floating-actions { position: fixed; bottom: 20px; right: 20px; z-index: 999; display: flex; gap: 10px; }

/* ── Top Nav ──────────────────────────────────────── */
.topnav { display: flex; flex-direction: column; justify-content: center; padding: 10px 20px; min-height: var(--app-nav-height); background: var(--bg-panel); border-bottom: 1px solid var(--border); position: fixed; top: 0; left: 0; right: 0; z-index: 2200; gap: 10px; }
.topnav-primary { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 12px; width: 100%; min-width: 0; }
.topnav-left { display: flex; align-items: center; min-width: 0; }
.topnav-status { display: flex; justify-content: center; min-width: 0; }
.topnav-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; min-width: 0; }
.nav-menu-toggle { display: none; background: transparent; color: var(--cyan); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 12px; cursor: pointer; font-size: 1rem; }
.nav-logo { display: flex; align-items: center; gap: 10px; min-width: 0; }
.nav-logo > div { min-width: 0; }
.nav-title { font-size: 1.2rem; font-weight: 800; color: var(--cyan); letter-spacing: 3px; font-family: var(--mono); }
.nav-subtitle { font-size: .6rem; color: var(--text-muted); display: block; max-width: 240px; line-height: 1.3; }
.system-status { display: inline-flex; align-items: center; gap: 8px; font-size: .78rem; color: var(--text-secondary); font-family: var(--mono); padding: 8px 12px; border: 1px solid var(--border); border-radius: 999px; background: var(--bg-card); white-space: nowrap; }
.live-clock { color: var(--cyan); font-size: .82rem; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #44ff88; box-shadow: 0 0 8px #44ff88; animation: blink 1.5s infinite; }
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: .4; } }
.topnav-secondary { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; min-width: 0; padding-top: 10px; border-top: 1px solid var(--border); }
.nav-tabs {
  display: flex;
  gap: 4px;
  align-items: center;
  flex-wrap: nowrap;
  justify-content: flex-end;
  flex: 1 1 auto;
  min-width: 0;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
}
.nav-tabs::-webkit-scrollbar { display: none; }
.nav-tab { background: none; border: 1px solid transparent; color: var(--text-secondary); padding: 6px 12px; border-radius: var(--radius-sm); cursor: pointer; font-size: .8rem; transition: all .2s; white-space: nowrap; flex: 0 0 auto; }
.nav-tab:hover { color: var(--text-primary); background: var(--bg-hover); }
.nav-tab.active { color: var(--cyan); border-color: var(--cyan); background: var(--cyan-dim); }
.alert-badge-nav { position: relative; cursor: pointer; font-size: 1.1rem; flex: 0 0 auto; }
.territory-selectors {
  display: grid;
  grid-template-columns: repeat(3, minmax(140px, 1fr));
  gap: 8px;
  min-width: 0;
  flex: 0 1 460px;
  align-items: start;
  align-content: start;
  grid-auto-rows: min-content;
}
.territory-selectors .filter-select {
  min-width: 0;
  width: 100%;
  height: 32px;
  min-height: 32px;
  align-self: start;
  box-sizing: border-box;
}
.badge { 
  position: absolute; top: -5px; right: -5px; background: #ff4444; color: #fff; 
  font-size: 10px; font-weight: 700; border-radius: 10px; padding: 2px 6px; 
  min-width: 18px; height: 18px; display: none; align-items: center; justify-content: center;
  border: 2px solid var(--bg-panel);
}

/* ── Main Layout ──────────────────────────────────── */
#app { height: 100dvh; min-height: 100dvh; display: flex; flex-direction: column; }
#app.hidden { display: none; }
.main-content { flex: 1; margin-top: var(--app-nav-height); overflow: hidden; height: calc(100dvh - var(--app-nav-height)); min-width: 0; }
.view { display: none; height: 100%; overflow-y: auto; padding: 16px; min-width: 0; }
.view.active { display: block; }

/* ── Dashboard Grid ──────────────────────────────── */
.dashboard-grid { display: flex; flex-direction: column; gap: 14px; }
.stats-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.stat-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; display: flex; align-items: center; gap: 12px; transition: all .2s; min-width: 0; }
.stat-card:hover { border-color: var(--cyan); transform: translateY(-2px); }
.stat-icon { font-size: 1.6rem; }
.stat-info { min-width: 0; }
.stat-label { font-size: .72rem; color: var(--text-muted); display: block; }
.stat-value { font-size: 1.8rem; font-weight: 800; font-family: var(--mono); color: var(--cyan); }
.stat-card.emergency .stat-value { color: var(--cat-emergencia); }
.stat-card.complaint .stat-value  { color: var(--cat-denuncia); }
.stat-card.infraction .stat-value { color: var(--cat-infraccion); }
.stat-card.resolved .stat-value   { color: #44ff88; }

/* ── Dashboard Middle ──────────────────────────────── */
.dashboard-middle { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; height: 280px; }
.panel-header { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border-bottom: 1px solid var(--border); gap: 10px; flex-wrap: wrap; min-width: 0; }
.panel-header h3 { font-size: .9rem; color: var(--text-primary); }
.panel-badge { font-size: .72rem; background: var(--cat-emergencia); color: #fff; padding: 2px 10px; border-radius: 99px; font-weight: 600; }
.panel-badge.pulse { animation: pulseShadow 2s infinite; }
.alert-feed-panel, .mini-map-panel { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.alert-feed { flex: 1; overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.alert-item { border-radius: var(--radius-sm); padding: 8px 12px; font-size: .8rem; border-left: 3px solid; display: flex; align-items: flex-start; gap: 8px; animation: slideIn .3s ease; }
@keyframes slideIn { from { opacity: 0; transform: translateX(-10px); } to { opacity: 1; transform: translateX(0); } }
.alert-item .alert-time { font-size: .7rem; color: var(--text-muted); white-space: nowrap; font-family: var(--mono); }
.mini-map {
  flex: 1;
  min-height: 220px;
  height: 220px;
  max-height: 300px;
  background: #0d1b2e;
}

/* ── Incidents Panel ──────────────────────────────── */
.incidents-panel { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.panel-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; min-width: 0; }
.panel-actions > * { min-width: 0; }
.search-input, .filter-select { background: var(--bg-base); border: 1px solid var(--border); color: var(--text-primary); border-radius: var(--radius-sm); padding: 6px 10px; font-size: .8rem; outline: none; max-width: 100%; }
.search-input:focus, .filter-select:focus { border-color: var(--cyan); }
.table-wrapper { overflow-x: auto; max-height: 220px; overflow-y: auto; }
.incidents-table { width: 100%; border-collapse: collapse; font-size: .78rem; }
.incidents-table th, .incidents-table td { white-space: nowrap; }
.incidents-table td:nth-child(3),
.incidents-table td:nth-child(5),
.incidents-table td:nth-child(6) { white-space: normal; }
.incidents-table th { background: var(--bg-base); color: var(--text-muted); padding: 8px 12px; text-align: left; font-weight: 600; font-size: .72rem; text-transform: uppercase; letter-spacing: 1px; position: sticky; top: 0; }
.incidents-table td { padding: 8px 12px; border-bottom: 1px solid var(--border); color: var(--text-secondary); }
.incidents-table tr:hover td { background: var(--bg-hover); }

/* ── Category Colors: chip & border ─────────────── */
.cat-chip { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: .7rem; font-weight: 700; text-transform: uppercase; }

.cat-Emergencia    { background: var(--cat-emergencia)22;    color: var(--cat-emergencia);    border: 1px solid var(--cat-emergencia); }
.cat-Robo          { background: var(--cat-robo)22;          color: var(--cat-robo);          border: 1px solid var(--cat-robo); }
.cat-Atraco        { background: var(--cat-atraco)22;        color: var(--cat-atraco);        border: 1px solid var(--cat-atraco); }
.cat-Hurto         { background: var(--cat-hurto)22;         color: var(--cat-hurto);         border: 1px solid var(--cat-hurto); }
.cat-Disparos      { background: var(--cat-disparos)22;      color: var(--cat-disparos);      border: 1px solid var(--cat-disparos); }
.cat-Heridos       { background: var(--cat-heridos)22;       color: var(--cat-heridos);       border: 1px solid var(--cat-heridos); }
.cat-Fallecidos    { background: var(--cat-fallecidos)22;    color: var(--cat-fallecidos);    border: 1px solid var(--cat-fallecidos); }
.cat-Accidente     { background: var(--cat-accidente)22;     color: var(--cat-accidente);     border: 1px solid var(--cat-accidente); }
.cat-Explosión     { background: var(--cat-explosion)22;     color: var(--cat-explosion);     border: 1px solid var(--cat-explosion); }
.cat-Protesta      { background: var(--cat-protesta)22;      color: var(--cat-protesta);      border: 1px solid var(--cat-protesta); }
.cat-Incidencia    { background: var(--cat-incidencia)22;    color: var(--cat-incidencia);    border: 1px solid var(--cat-incidencia); }
.cat-Atención      { background: var(--cat-atencion)22;      color: var(--cat-atencion);      border: 1px solid var(--cat-atencion); }
.cat-Denuncia\.Vecinal { background: var(--cat-denuncia)22; color: var(--cat-denuncia);      border: 1px solid var(--cat-denuncia); }
.cat-Infracción    { background: var(--cat-infraccion)22;    color: var(--cat-infraccion);    border: 1px solid var(--cat-infraccion); }

/* ── Priority badges ────────────────────────────── */
.priority-Alta   { color: var(--cat-emergencia); font-weight: 700; }
.priority-Media  { color: var(--cat-accidente); font-weight: 600; }
.priority-Baja   { color: #44ff88; font-weight: 500; }

/* ── Status badges ──────────────────────────────── */
.status-Activo     { color: var(--cat-emergencia); }
.status-En\.proceso { color: var(--cat-accidente); }
.status-Resuelto   { color: #44ff88; }

/* ── Incidents Full View ────────────────────────── */
.incidents-full-layout { display: flex; flex-direction: column; gap: 14px; height: 100%; }
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; overflow-y: auto; padding-bottom: 20px; min-width: 0; }
.incident-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; transition: all .2s; cursor: pointer; border-left: 4px solid; min-width: 0; }
.incident-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-glow); }
.incident-card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 8px; gap: 8px; flex-wrap: wrap; }
.incident-card-id { font-family: var(--mono); font-size: .7rem; color: var(--text-muted); }
.incident-card-desc { font-size: .82rem; color: var(--text-secondary); line-height: 1.5; margin: 8px 0; }
.incident-card-meta { display: flex; flex-wrap: wrap; gap: 6px; font-size: .72rem; color: var(--text-muted); }
.incident-card-meta span { display: flex; align-items: center; gap: 3px; }
.incident-actions { display: flex; gap: 6px; margin-top: 10px; }
.btn-status { background: none; border: 1px solid var(--border); color: var(--text-secondary); border-radius: var(--radius-sm); padding: 4px 10px; font-size: .72rem; cursor: pointer; transition: all .2s; }
.btn-status:hover { border-color: var(--cyan); color: var(--cyan); }

/* ── Chat View ──────────────────────────────────── */
.chat-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr) 260px; height: 100%; gap: 0; min-width: 0; }
.chat-sidebar { background: var(--bg-panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; }
.chat-sidebar-header { padding: 14px; border-bottom: 1px solid var(--border); }
.chat-sidebar-header h3 { font-size: .85rem; }
.channel-list { flex: 1; overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 4px; }
.channel-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: var(--radius-sm); cursor: pointer; transition: all .2s; border: 1px solid transparent; }
.channel-item:hover { background: var(--bg-hover); }
.channel-item.active { background: var(--cyan-dim); border-color: var(--cyan); }
.channel-icon { font-size: 1.2rem; }
.channel-name { font-size: .82rem; color: var(--text-primary); display: block; }
.channel-status { font-size: .7rem; color: var(--text-muted); display: block; }
.channel-info { min-width: 0; }
.chat-sidebar-footer { padding: 12px; border-top: 1px solid var(--border); }
.ai-status { display: flex; align-items: center; gap: 6px; font-size: .75rem; color: var(--text-secondary); }
.chat-main { display: flex; flex-direction: column; overflow: hidden; }
.chat-topbar { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--bg-panel); gap: 10px; flex-wrap: wrap; }
.chat-contact { display: flex; align-items: center; gap: 10px; min-width: 0; }
.contact-avatar { width: 36px; height: 36px; background: var(--bg-hover); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 1.1rem; }
.contact-name { font-size: .9rem; font-weight: 600; display: block; }
.contact-channel { font-size: .72rem; color: var(--text-muted); }
.chat-contact > div { min-width: 0; }
.contact-name, .contact-channel { overflow-wrap: anywhere; }
.channel-badge { font-size: .7rem; padding: 3px 10px; border-radius: 99px; font-weight: 600; }
.whatsapp-badge { background: #25D36622; color: #25D366; border: 1px solid #25D366; }
.telegram-badge { background: #229ED922; color: #229ED9; border: 1px solid #229ED9; }
.chat-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.chat-bubble { max-width: 75%; padding: 10px 14px; border-radius: 12px; font-size: .85rem; line-height: 1.5; animation: slideIn .2s ease; }
.chat-bubble.user { background: var(--bg-hover); border-bottom-right-radius: 3px; align-self: flex-end; }
.chat-bubble.ai { background: linear-gradient(135deg, #0d2a3e, #112236); border: 1px solid var(--border); border-bottom-left-radius: 3px; align-self: flex-start; color: var(--text-primary); }
.chat-bubble.system { background: #ffd70011; border: 1px solid #ffd70033; color: var(--gold); align-self: center; text-align: center; font-size: .78rem; border-radius: 8px; max-width: 90%; }
.bubble-meta { font-size: .68rem; color: var(--text-muted); margin-top: 4px; }
.message-body { display: flex; flex-direction: column; gap: 8px; }
.message-text { overflow-wrap: anywhere; }
.message-attachment,
.message-location { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--bg-base); }
.message-attachment.media-image img,
.message-attachment.media-video video,
.message-attachment.media-audio audio { display: block; width: 100%; }
.message-attachment.media-image img { max-height: 240px; object-fit: contain; background: #000; }
.message-attachment.media-video video { background: #000; max-height: 240px; }
.message-attachment.media-audio audio { min-height: 42px; }
.message-attachment.file,
.message-attachment.document { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; }
.message-attachment-icon { font-size: 1.2rem; line-height: 1; }
.message-attachment-body,
.message-location-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.message-attachment-title,
.message-location-title { color: var(--text-primary); font-weight: 600; font-size: .8rem; overflow-wrap: anywhere; }
.message-attachment-subtitle,
.message-location-address,
.message-location-coords { color: var(--text-muted); font-size: .7rem; overflow-wrap: anywhere; }
.message-location { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; background: #00d4ff10; border-color: #00d4ff33; }
.message-location-pin { font-size: 1.05rem; line-height: 1; }
.message-link { color: var(--cyan); text-decoration: none; font-size: .72rem; }
.message-link:hover { text-decoration: underline; }
.chat-input-area { padding: 12px 16px; border-top: 1px solid var(--border); background: var(--bg-panel); }
.chat-input-row { display: flex; gap: 8px; align-items: center; min-width: 0; }
.chat-input { flex: 1; background: var(--bg-card); border: 1px solid var(--border); color: var(--text-primary); border-radius: var(--radius); padding: 10px 14px; font-size: .85rem; outline: none; font-family: var(--font); }
.chat-input:focus { border-color: var(--cyan); }
.attach-btn { background: none; border: 1px solid var(--border); color: var(--text-secondary); border-radius: var(--radius-sm); padding: 9px 12px; cursor: pointer; font-size: .95rem; transition: all .2s; }
.attach-btn:hover { border-color: var(--cyan); color: var(--cyan); }
.send-btn { background: linear-gradient(135deg, #0090c8, #00d4ff); color: #000; border: none; border-radius: var(--radius); padding: 10px 18px; font-weight: 700; cursor: pointer; font-size: .85rem; transition: all .2s; }
.send-btn:hover { transform: translateY(-1px); }
.attachment-preview { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 12px; margin-bottom: 8px; font-size: .78rem; color: var(--text-secondary); display: flex; align-items: center; gap: 8px; }
.chat-detail-panel { background: var(--bg-panel); border-left: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.report-preview { flex: 1; overflow-y: auto; padding: 12px; font-size: .8rem; color: var(--text-secondary); }
.report-field { margin-bottom: 10px; }
.report-field label { font-size: .7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; display: block; margin-bottom: 3px; }
.report-field span { color: var(--text-primary); font-size: .82rem; }
.no-data { color: var(--text-muted); font-size: .82rem; text-align: center; margin-top: 40px; }

/* ── Map ────────────────────────────────────────── */
#view-map {
  height: 100%;
  overflow: hidden;
}
.map-layout {
  position: relative;
  height: 100%;
  min-height: 100%;
}
.full-map {
  width: 100%;
  height: 100%;
  min-height: 100%;
  background: #0d1b2e;
}
.mini-map { width: 100%; height: 100%; }
.map-legend-toggle { display: none; position: absolute; top: 20px; right: 20px; z-index: 1001; background: var(--bg-panel); color: var(--cyan); border: 1px solid var(--border); border-radius: 999px; padding: 8px 14px; cursor: pointer; box-shadow: var(--shadow); }
.map-legend { position: absolute; top: 20px; right: 20px; background: var(--bg-panel)ee; border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; z-index: 1000; max-width: min(320px, calc(100vw - 40px)); }
.map-legend h4 { font-size: .78rem; margin-bottom: 8px; color: var(--text-primary); }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: .75rem; color: var(--text-secondary); margin-bottom: 5px; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; }
.legend-dot.emergency  { background: var(--cat-emergencia); }
.legend-dot.complaint  { background: var(--cat-denuncia); }
.legend-dot.infraction { background: var(--cat-infraccion); }

/* ── Incident Detail Modal ──────────────────────── */
#incidentModal .modal-box {
  display: flex;
  flex-direction: column;
  height: min(90vh, calc(100dvh - 32px));
  overflow: hidden;
}
#incidentModal .modal-header {
  flex: 0 0 auto;
}
#incidentModal .modal-body {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}
.incident-body { padding: 0; }
.incident-scroll-content {
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 20px 28px;
}
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.detail-grid, .detail-field { min-width: 0; }
.detail-field label { font-size: .7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; display: block; margin-bottom: 2px; }
.detail-field span { color: var(--text-primary); font-size: .85rem; overflow-wrap: anywhere; }
.incident-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.incident-actions-sticky {
  position: sticky;
  bottom: 0;
  z-index: 2;
  margin-top: 0;
  padding: 12px 0 0;
  background: linear-gradient(to top, var(--bg-panel) 70%, rgba(13, 27, 46, 0));
}
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-group { min-width: 0; }
.form-group label { font-size: .7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; display: block; margin-bottom: 4px; }
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  background: var(--bg-base);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: .82rem;
  font-family: var(--font);
  outline: none;
}
.form-group textarea {
  resize: vertical;
  min-height: 96px;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { border-color: var(--cyan); }
.detail-desc { grid-column: 1 / -1; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; margin-top: 15px; }
.media-thumb { width: 100%; height: 100px; object-fit: cover; border-radius: 6px; cursor: pointer; border: 1px solid rgba(255,255,255,0.1); transition: transform 0.2s; }
.media-thumb:hover { transform: scale(1.05); border-color: var(--cyan); }
.video-thumb { background: #000; display: flex; align-items: center; justify-content: center; font-size: 0.8rem; color: #fff; position: relative; overflow: hidden; }
.video-thumb::after { content: '▶'; font-size: 1.5rem; opacity: 0.7; }
.audio-thumb { background: #162a45; display: flex; align-items: center; justify-content: center; font-size: 0.8rem; color: var(--cyan); position: relative; overflow: hidden; }
.audio-thumb::after { content: '🔊'; font-size: 1.5rem; opacity: 0.7; }


/* ── Typing indicator ──────────────────────────── */
.typing-indicator { display: flex; gap: 4px; padding: 12px 16px; }
.typing-indicator span { width: 7px; height: 7px; border-radius: 50%; background: var(--text-muted); animation: typing .9s infinite; }
.typing-indicator span:nth-child(2) { animation-delay: .15s; }
.typing-indicator span:nth-child(3) { animation-delay: .3s; }
@keyframes typing { 0%,80%,100% { transform: scale(1); opacity: .5; } 40% { transform: scale(1.3); opacity: 1; } }

/* ── Monitoring View (Cameras & Sensors) ───────────── */
.monitoring-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; height: 100%; min-width: 0; }
.cameras-grid-panel { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.cameras-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; padding: 16px; overflow-y: auto; flex: 1; background: var(--bg-panel); }
.camera-card { background: var(--bg-card); border: 2px solid var(--border); border-radius: var(--radius); overflow: hidden; cursor: pointer; transition: all .2s; min-width: 0; }
.camera-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-glow); border-color: var(--cyan); }
.camera-card.selected { border-color: var(--cat-emergencia); box-shadow: 0 0 15px var(--cat-emergencia); }
.camera-feed { height: 160px; background-size: cover; background-position: center; position: relative; background-color: #000; }
.camera-status { position: absolute; top: 10px; right: 10px; width: 10px; height: 10px; border-radius: 50%; box-shadow: 0 0 5px #000; }
.camera-status.online { background: #44ff88; }
.camera-status.offline { background: #ff4444; }
.camera-label { position: absolute; top: 8px; left: 8px; background: rgba(0,0,0,0.6); color: #fff; padding: 2px 6px; font-family: var(--mono); font-size: .7rem; border-radius: 3px; border: 1px solid rgba(255,255,255,0.2); }
.camera-rec { position: absolute; bottom: 8px; right: 8px; color: #ff2244; font-family: var(--mono); font-weight: bold; font-size: .8rem; animation: blink 1s infinite; text-shadow: 0 0 3px #000; }
.camera-info { padding: 10px 12px; }
.camera-info h4 { font-size: .85rem; color: var(--text-primary); margin-bottom: 4px; }
.camera-info p { font-size: .7rem; color: var(--text-muted); font-family: var(--mono); }

/* ── Camera Modal Responsive ── */
.camera-modal-box {
  width: min(96vw, 1180px);
  max-width: 1180px;
}
.camera-modal-layout {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) 420px !important;
  align-items: stretch;
  overflow: hidden !important;
  max-height: min(82vh, 760px) !important;
}
.camera-modal-feed {
  min-width: 0;
  min-height: 320px;
  height: min(64vh, 500px);
  max-height: min(64vh, 500px);
  overflow: hidden;
}
.camera-modal-feed img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.camera-modal-side {
  width: 420px;
  min-width: 420px;
  max-width: 420px;
  max-height: min(64vh, 500px);
  overflow-y: auto !important;
}
@media (max-width: 768px) {
  .camera-modal-box {
    width: 95vw;
  }
  .camera-modal-layout {
    grid-template-columns: 1fr !important;
    max-height: 90vh !important;
    overflow-y: auto !important;
  }
  .camera-modal-feed,
  .camera-modal-side {
    max-height: none;
    height: auto;
  }
  .camera-modal-side {
    width: auto;
    min-width: 0;
    max-width: none;
  }
  .camera-modal-side {
    border-left: none !important;
    border-top: 1px solid var(--border) !important;
  }
}

.sensors-panel { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; padding: 12px; overflow-y: auto; min-width: 0; }
.sensors-list { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.sensor-item { display: flex; align-items: center; gap: 12px; padding: 10px; background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.sensor-icon { font-size: 1.4rem; background: var(--bg-base); width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; border-radius: 50%; }
.sensor-details { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.sensor-name { font-size: .75rem; color: var(--text-secondary); margin-bottom: 2px; }
.sensor-value { font-size: .95rem; font-weight: 700; color: var(--cyan); font-family: var(--mono); }
.sensor-status { width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); }
.sensor-status.active { background: #44ff88; box-shadow: 0 0 5px #44ff88; }

.users-table-wrapper { max-height: none; }
#view-users .cameras-grid-panel,
#view-users .sensors-panel { min-width: 0; }

#cameraManageModal .modal-box,
#userModal .modal-box,
#qrModal .modal-box,
#cameraModal .modal-box,
#incidentModal .modal-box,
#mediaModal .modal-box { max-width: min(95vw, 100%); }

.camera-manage-layout { min-width: 0; }
.camera-manage-list-column,
.camera-manage-form-column { min-width: 0; }
.camera-manage-actions { flex-wrap: wrap; }
.camera-manage-actions > * { min-width: 0; }

/* ── Responsive ────────────────────────────────── */
@media (max-width: 1200px) {
  :root { --app-nav-height: 148px; }
  .stats-row { grid-template-columns: repeat(3, 1fr); }
  .dashboard-middle { grid-template-columns: 1fr; height: auto; }
  .topnav { padding: 10px 16px; }
  .topnav-primary { grid-template-columns: minmax(0, 1fr) auto; }
  .topnav-status { grid-column: 1 / -1; justify-content: flex-start; }
  .topnav-secondary {
    flex-direction: column;
    align-items: stretch;
  }
  .nav-tabs {
    width: 100%;
    justify-content: flex-start;
    gap: 6px;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    max-width: none;
  }
  .territory-selectors {
    width: 100%;
    flex: 0 0 auto;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .territory-selectors .filter-select {
    width: 100%;
  }
  .chat-layout { grid-template-columns: 220px minmax(0, 1fr); }
  .chat-detail-panel { display: none; }
  .monitoring-layout { grid-template-columns: 1fr; height: auto; }
  .cameras-grid-panel, .sensors-panel { min-width: 0; }
  .sensors-panel { order: 2; max-height: none; }
  .table-wrapper { max-height: none; }
}
@media (min-width: 1201px) and (max-width: 1440px) {
  :root { --app-nav-height: 112px; }
  .topnav { padding: 10px 16px; }
  .topnav-primary { grid-template-columns: minmax(0, 1fr) auto auto; }
  .nav-tabs {
    justify-content: flex-start;
  }
  .territory-selectors {
    flex: 0 1 420px;
  }
}
@media (max-width: 960px) {
  :root { --app-nav-height: 164px; }
  .topnav-primary { grid-template-columns: 1fr auto; }
  .topnav-status { grid-column: 1 / -1; }
  .nav-menu-toggle { display: none; }
  .territory-selectors { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .nav-tabs { position: static; display: flex; flex-direction: row; }
  .cards-grid { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
  .chat-layout { grid-template-columns: 1fr; gap: 12px; height: auto; }
  .chat-sidebar,
  .chat-detail-panel {
    display: flex;
    min-width: 0;
    border-radius: var(--radius);
  }
  .chat-sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .chat-main {
    min-height: 420px;
    border-radius: var(--radius);
  }
  .chat-detail-panel {
    border-left: none;
    border-top: 1px solid var(--border);
  }
  .channel-list {
    padding: 10px;
    gap: 6px;
  }
  .channel-item {
    padding: 10px 12px;
  }
}
@media (max-width: 700px) {
  :root { --app-nav-height: 72px; }
  .topnav {
    padding: 0 12px;
    min-height: var(--app-nav-height);
    align-items: center;
    justify-content: center;
    gap: 0;
  }
  .topnav-primary { grid-template-columns: minmax(0, 1fr) auto; }
  .topnav-status { display: none; }
  .nav-menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .topnav-secondary {
    position: fixed;
    top: 76px;
    right: 12px;
    min-width: min(92vw, 360px);
    max-height: calc(100vh - 88px);
    overflow-y: auto;
    display: none;
    gap: 0;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 10px 12px;
    box-shadow: var(--shadow);
    z-index: 2300;
    border-top: 1px solid var(--border);
  }
  .topnav.menu-open .topnav-secondary { display: block; }
  .territory-selectors {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
    width: 100%;
    gap: 4px;
    margin-bottom: 6px;
  }
  .territory-selectors .filter-select {
    box-sizing: border-box;
    height: 30px;
    min-height: 30px;
    padding: 2px 8px;
    font-size: .7rem;
    line-height: 1;
    border-radius: 5px;
  }
  .nav-tabs {
    width: 100%;
    display: flex;
    flex-direction: column;
    flex: 0 0 auto;
    justify-content: flex-start;
    gap: 6px;
    overflow: visible;
  }
  .nav-tab {
    width: 100%;
    text-align: left;
    padding: 10px 12px;
  }
  .nav-subtitle { display: none; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .stat-card { padding: 12px; }
  .stat-value { font-size: 1.45rem; }
  .map-legend-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    top: 12px;
    right: 12px;
  }
  .map-legend {
    display: none;
    top: 56px;
    right: 12px;
    left: 12px;
    max-height: 42vh;
    overflow-y: auto;
    padding: 10px 12px;
  }
  .map-layout.legend-open .map-legend {
    display: block;
  }
  .monitoring-layout { gap: 12px; }
  .cameras-grid { grid-template-columns: 1fr; padding: 12px; }
  .incidents-full-layout, .chat-layout, .monitoring-layout { min-width: 0; }
  .panel-actions { width: 100%; }
  .panel-actions .search-input,
  .panel-actions .filter-select,
  .panel-actions .btn-primary,
  .panel-actions .btn-secondary { width: 100%; }
  .chat-topbar { align-items: flex-start; }
  .chat-topbar-actions { width: 100%; display: flex; justify-content: flex-start; }
  #dispatchControls { flex-wrap: wrap; }
  #dispatchControls .filter-select,
  #dispatchControls .btn-secondary { width: 100%; }
  .chat-input-row { flex-wrap: wrap; }
  .chat-input { width: 100%; order: 1; }
  .attach-btn { flex: 0 0 auto; }
  .send-btn { width: 100%; order: 2; }
  .chat-bubble { max-width: 100%; }
  .chat-sidebar-footer { padding: 10px 12px; }
  .chat-detail-panel .panel-header { padding: 12px 16px; }
  .detail-grid { grid-template-columns: 1fr; }
  .incident-actions { flex-wrap: wrap; }
  .incident-actions > * { flex: 1 1 100%; }
  .floating-actions { right: 12px; bottom: 12px; flex-direction: column; }
  .modal-header,
  .modal-body,
  .modal-actions { padding-left: 16px; padding-right: 16px; }
  .modal-actions { flex-wrap: wrap; }
  .modal-actions .btn-primary,
  .modal-actions .btn-secondary { width: 100%; }
  #cameraManageModal .modal-body,
  #cameraModal .modal-header,
  #incidentModal .modal-header,
  #userModal .modal-header { padding-left: 16px !important; padding-right: 16px !important; }
  .camera-manage-layout { grid-template-columns: 1fr !important; gap: 16px !important; }
  .camera-manage-list-column { border-right: none !important; padding-right: 0 !important; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
  .camera-manage-coords { grid-template-columns: 1fr !important; }
  .camera-manage-actions > * { width: 100%; }
  #manageCamsList { max-height: 260px !important; }
  .users-table-wrapper { max-height: 50vh; }
  .table-wrapper { max-height: none; }
  .incidents-table { min-width: 720px; }
  #view-users .incidents-table { min-width: 640px; }
  .map-legend-toggle { max-width: calc(100vw - 24px); }
  .form-grid { grid-template-columns: 1fr; }
}
@media (max-width: 480px) {
  .view { padding: 12px; }
  .stats-row { grid-template-columns: 1fr; }
  .nav-title { font-size: 1rem; letter-spacing: 2px; }
  .panel-header { padding: 10px 12px; }
  .cards-grid { grid-template-columns: 1fr; }
  .cameras-grid { padding: 10px; }
  .camera-info p { overflow-wrap: anywhere; }
  .mini-map { min-height: 200px; height: 200px; }
  .modal-box { width: calc(100vw - 16px); max-height: calc(100vh - 16px); }
  #incidentModal .modal-box {
    width: calc(100vw - 32px);
    height: calc(100dvh - 32px);
    max-height: calc(100dvh - 32px);
  }
  #incidentModal .modal-header {
    padding: 16px 16px 12px;
  }
  .incident-scroll-content {
    padding: 16px;
  }
  .incident-actions-sticky {
    padding-top: 10px;
  }
  #qrModal #qrImage { width: min(100%, 220px); }
  .territory-selectors .filter-select {
    height: 28px;
    min-height: 28px;
    padding: 2px 8px;
    font-size: .68rem;
    line-height: 1;
  }
}

/* ═══════════════════════════════════════════════════════════
   SISTEMA PANEL — Sub-tabs
═══════════════════════════════════════════════════════════ */
.system-panel-layout {
  display: flex;
  flex-direction: column;
  height: 100%;
  gap: 0;
  min-width: 0;
}
.system-subtabs {
  display: flex;
  gap: 4px;
  padding: 12px 16px 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
  flex-wrap: wrap;
  flex: 0 0 auto;
}
.system-subtab {
  background: none;
  border: 1px solid transparent;
  color: var(--text-secondary);
  padding: 8px 16px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  cursor: pointer;
  font-size: .82rem;
  font-family: var(--font);
  transition: all .2s;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  position: relative;
  bottom: -1px;
}
.system-subtab:hover { color: var(--text-primary); background: var(--bg-hover); }
.system-subtab.active {
  color: var(--cyan);
  border-color: var(--border) var(--border) var(--bg-panel);
  background: var(--bg-panel);
  font-weight: 600;
}
.subtab-icon { font-size: 1rem; }
.system-subtab-content {
  display: none;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}
.system-subtab-content.active { display: flex; flex-direction: column; }

/* ═══════════════════════════════════════════════════════════
   CONVERSACIONES
═══════════════════════════════════════════════════════════ */
.conv-layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  height: 100%;
  min-height: 0;
  overflow: hidden;
}
.conv-sidebar {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  overflow: hidden;
}
.conv-type-selector {
  display: flex;
  gap: 4px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  background: var(--bg-base);
}
.conv-type-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: .73rem;
  font-family: var(--font);
  transition: all .15s;
  white-space: nowrap;
}
.conv-type-btn:hover { border-color: var(--cyan); color: var(--cyan); }
.conv-type-btn.active { background: var(--cyan-dim); border-color: var(--cyan); color: var(--cyan); font-weight: 600; }
.conv-filters {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
}
.conv-threads-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.conv-thread-item {
  display: flex;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid transparent;
  transition: all .15s;
  min-width: 0;
}
.conv-thread-item:hover { background: var(--bg-hover); border-color: var(--border); }
.conv-thread-item.active { background: var(--cyan-dim); border-color: var(--cyan); }
.conv-thread-icon { font-size: 1.3rem; flex: 0 0 auto; line-height: 1.2; }
.conv-thread-info { min-width: 0; flex: 1; }
.conv-thread-name { font-size: .82rem; color: var(--text-primary); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-thread-preview { font-size: .73rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin: 2px 0; }
.conv-thread-meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.conv-thread-count { background: var(--bg-base); color: var(--text-muted); font-size: .62rem; padding: 1px 5px; border-radius: 99px; border: 1px solid var(--border); }

/* Main message view */
.conv-main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-base);
}
.conv-main-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
  gap: 12px;
  flex: 0 0 auto;
}
.conv-contact-info { display: flex; align-items: center; gap: 12px; min-width: 0; }
.conv-contact-avatar { font-size: 1.6rem; }
.conv-messages-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.conv-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  font-size: .9rem;
  text-align: center;
  padding: 40px;
}
.conv-msg {
  display: flex;
  max-width: 70%;
  animation: slideIn .2s ease;
}
.conv-msg-in  { align-self: flex-start; }
.conv-msg-out { align-self: flex-end; flex-direction: row-reverse; }
.conv-msg-bubble {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  max-width: 100%;
  min-width: 0;
}
.conv-msg-out .conv-msg-bubble {
  background: linear-gradient(135deg, #0a2540, #0d3060);
  border-color: #00d4ff33;
}
.conv-msg-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 5px;
  flex-wrap: wrap;
}
.conv-msg-sender-in  { font-size: .72rem; color: #44ff88; font-weight: 600; }
.conv-msg-sender-out { font-size: .72rem; color: #00d4ff; font-weight: 600; }
.conv-msg-content {
  font-size: .83rem;
  color: var(--text-primary);
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.conv-msg-time { font-size: .65rem; color: var(--text-muted); margin-top: 5px; text-align: right; }
.conv-msg-media { margin-top: 6px; font-size: .78rem; }
.conv-msg-media a { color: var(--cyan); text-decoration: none; }
.conv-incident-badge {
  background: #ffd70015;
  color: var(--gold);
  border: 1px solid #ffd70033;
  font-size: .62rem;
  padding: 2px 7px;
  border-radius: 99px;
  cursor: pointer;
  font-weight: 600;
  transition: all .15s;
}
.conv-incident-badge:hover { background: #ffd70030; }
.conv-export-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 18px;
  border-top: 1px solid var(--border);
  background: var(--bg-panel);
  flex: 0 0 auto;
}

/* Session status indicators in chat sidebar */
.session-status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
}
.session-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ffb84d;
  flex: 0 0 auto;
}
.session-status-dot.connected { background: #44ff88; box-shadow: 0 0 5px #44ff88; }
.session-status-dot.qr { background: #00d4ff; }
.session-status-dot.error { background: #ff6b6b; }

/* ═══════════════════════════════════════════════════════════
   ALERTAS ENVIADAS
═══════════════════════════════════════════════════════════ */
.alertlogs-layout {
  display: flex;
  flex-direction: column;
  padding: 16px;
  height: 100%;
  overflow: hidden;
  gap: 0;
}
.alertlogs-layout .table-wrapper {
  flex: 1;
  overflow-y: auto;
  max-height: none;
}
.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0 0;
  flex: 0 0 auto;
  flex-wrap: wrap;
  gap: 8px;
}
.pagination-info { font-size: .78rem; color: var(--text-muted); }
.pagination-controls { display: flex; gap: 8px; }

/* ═══════════════════════════════════════════════════════════
   SESIONES
═══════════════════════════════════════════════════════════ */
.sessions-layout {
  padding: 20px;
  height: 100%;
  overflow-y: auto;
}
.sessions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}
.session-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: all .2s;
}
.session-card:hover { border-color: var(--cyan); box-shadow: var(--shadow-glow); }
.session-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.session-card-icon { font-size: 1.8rem; flex: 0 0 auto; }
.session-card-title { flex: 1; min-width: 0; }
.session-card-title strong { font-size: .9rem; display: block; }
.session-card-key { font-size: .7rem; color: var(--text-muted); font-family: var(--mono); }
.session-status-pill {
  font-size: .7rem;
  padding: 4px 10px;
  border-radius: 99px;
  border: 1px solid;
  font-weight: 600;
  white-space: nowrap;
  flex: 0 0 auto;
}
.session-card-info { font-size: .73rem; color: var(--text-muted); display: flex; flex-direction: column; gap: 2px; }
.session-card-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.session-card-error {
  font-size: .72rem;
  color: #ff6b6b;
  background: #ff6b6b15;
  border: 1px solid #ff6b6b33;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ═══════════════════════════════════════════════════════════
   ESTADÍSTICAS AVANZADAS
═══════════════════════════════════════════════════════════ */
.stats-adv-layout {
  padding: 16px;
  overflow-y: auto;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.stats-kpi-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
}
.stats-kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: all .2s;
  min-width: 0;
}
.stats-kpi-card:hover { border-color: var(--cyan); }
.stats-kpi-card.emergency { border-left: 3px solid var(--cat-emergencia); }
.stats-kpi-card.resolved  { border-left: 3px solid #44ff88; }
.kpi-icon { font-size: 1.4rem; }
.kpi-value { font-size: 1.8rem; font-weight: 800; font-family: var(--mono); color: var(--cyan); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kpi-label { font-size: .72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; }
.kpi-change { font-size: .72rem; color: var(--text-secondary); margin-top: 2px; }
.stats-charts-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  padding-bottom: 20px;
}
.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  min-width: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.chart-card-wide {
  grid-column: span 2;
}
.chart-canvas-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 220px;
  height: clamp(220px, 30vw, 280px);
}
.chart-canvas-wrap-wide {
  height: clamp(220px, 24vw, 320px);
}
.chart-card canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
}
.chart-title {
  font-size: .82rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
}

/* ═══════════════════════════════════════════════════════════
   RESPONSIVE — Admin Panel
═══════════════════════════════════════════════════════════ */
@media (max-width: 1200px) {
  .stats-kpi-row { grid-template-columns: repeat(3, 1fr); }
  .stats-charts-grid { grid-template-columns: 1fr; }
  .chart-card-wide { grid-column: span 1; }
}
@media (max-width: 960px) {
  .conv-layout { grid-template-columns: 260px minmax(0, 1fr); }
  .stats-kpi-row { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 700px) {
  .conv-layout { grid-template-columns: 1fr; grid-template-rows: 280px minmax(0, 1fr); }
  .conv-sidebar { border-right: none; border-bottom: 1px solid var(--border); }
  .conv-main { min-height: 300px; }
  .conv-msg { max-width: 90%; }
  .stats-kpi-row { grid-template-columns: repeat(2, 1fr); }
  .sessions-grid { grid-template-columns: 1fr; }
  .system-subtabs { padding: 8px 12px 0; }
  .system-subtab { padding: 6px 10px; font-size: .75rem; }
}
@media (max-width: 480px) {
  .stats-charts-grid { grid-template-columns: 1fr; }
  .stats-adv-layout { padding: 12px; gap: 12px; }
  .chart-card { padding: 12px; }
  .chart-canvas-wrap,
  .chart-canvas-wrap-wide { height: 220px; }
  .stats-kpi-row { grid-template-columns: 1fr; }
  .conv-msg { max-width: 95%; }
}

