/* ============================================================
   LeanCP Seguridad — Estilos v2
   Shell 3 paneles (rail + sidebar plegable + main + inspector)
   Charts SVG, micro-interacciones, componentes premium
   ============================================================ */

:root {
  --sidebar-w: 248px;
  --sidebar-w-collapsed: 0px;
  --inspector-w: 380px;
}

/* =============================================================
   SHELL v2 — Grid dinámico 4 columnas
   ============================================================= */
.app-shell {
  grid-template-columns: var(--rail-w) var(--sidebar-w) 1fr var(--inspector-w) !important;
  transition: grid-template-columns 260ms cubic-bezier(.2,.8,.2,1);
}
.app-shell.sidebar-collapsed {
  grid-template-columns: var(--rail-w) 0 1fr var(--inspector-w) !important;
}
.app-shell.inspector-collapsed {
  grid-template-columns: var(--rail-w) var(--sidebar-w) 1fr 0 !important;
}
.app-shell.sidebar-collapsed.inspector-collapsed {
  grid-template-columns: var(--rail-w) 0 1fr 0 !important;
}
.app-shell .app-main { grid-column: 3; }

/* Sidebar contextual */
.sidebar {
  grid-column: 2; grid-row: 1 / -1;
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  overflow: hidden;
  display: flex; flex-direction: column;
  transition: opacity 200ms ease;
}
.app-shell.sidebar-collapsed .sidebar { opacity: 0; pointer-events: none; }

.sidebar-header {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  min-height: var(--topbar-h);
  flex-shrink: 0;
}
.sidebar-title {
  font-family: var(--font-title);
  font-weight: 800;
  font-size: 13px;
  letter-spacing: -0.01em;
  color: var(--text);
}
.sidebar-collapse-btn {
  width: 24px; height: 24px;
  border-radius: 5px;
  color: var(--text-3);
  display: flex; align-items: center; justify-content: center;
  transition: var(--tr);
}
.sidebar-collapse-btn:hover { background: var(--bg-3); color: var(--text); }

.sidebar-body { flex: 1; overflow-y: auto; padding: 10px 8px 20px; }
.sidebar-section { margin-bottom: 14px; }
.sidebar-section-title {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--text-4);
  padding: 8px 10px 4px;
}
.sidebar-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px;
  margin: 1px 0;
  border-radius: var(--r-sm);
  font-size: 12.5px;
  color: var(--text-2);
  cursor: pointer;
  transition: var(--tr);
  position: relative;
}
.sidebar-item:hover { background: var(--bg-3); color: var(--text); }
.sidebar-item.active { background: var(--oro-dim); color: var(--oro); font-weight: 600; }
.sidebar-item.active::before {
  content: ""; position: absolute; left: 0; top: 6px; bottom: 6px; width: 2px;
  background: var(--oro); border-radius: 2px;
}
.sidebar-item-count {
  margin-left: auto;
  font-family: var(--font-mono); font-size: 10.5px;
  padding: 1px 6px; border-radius: 99px;
  background: var(--bg-3);
  color: var(--text-3);
}
.sidebar-item.active .sidebar-item-count { background: var(--oro); color: var(--bg); }

.sidebar-search {
  margin: 4px 6px 10px;
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  font-size: 12px;
}
.sidebar-search input {
  flex: 1; background: none; border: none; outline: none;
  color: var(--text); font-size: 12px;
}

/* Botón toggle sidebar (en topbar) */
.sidebar-toggle {
  width: 30px; height: 30px;
  border-radius: 6px;
  color: var(--text-2);
  display: flex; align-items: center; justify-content: center;
  transition: var(--tr);
}
.sidebar-toggle:hover { background: var(--bg-3); color: var(--text); }

/* =============================================================
   INSPECTOR PANE (derecha)
   ============================================================= */
.inspector {
  grid-column: 4; grid-row: 1 / -1;
  background: var(--bg-1);
  border-left: 1px solid var(--border);
  overflow: hidden;
  display: flex; flex-direction: column;
  transition: opacity 200ms ease;
}
.app-shell.inspector-collapsed .inspector { opacity: 0; pointer-events: none; }

.inspector-header {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  min-height: var(--topbar-h);
  flex-shrink: 0;
  gap: 10px;
}
.inspector-title {
  font-family: var(--font-title);
  font-weight: 700;
  font-size: 12px;
  color: var(--text-3);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.inspector-tabs {
  display: flex; gap: 0;
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.inspector-tab {
  padding: 9px 12px;
  font-size: 11.5px; font-weight: 600;
  color: var(--text-3);
  border-bottom: 2px solid transparent;
  transition: var(--tr);
}
.inspector-tab:hover { color: var(--text-2); }
.inspector-tab.active { color: var(--oro); border-bottom-color: var(--oro); }

.inspector-body {
  flex: 1; overflow-y: auto;
  padding: 16px;
}
.inspector-body::-webkit-scrollbar { width: 6px; }
.inspector-body::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.06); border-radius: 6px; }

.inspector-empty {
  text-align: center; padding: 40px 20px;
  color: var(--text-3);
}
.inspector-empty svg { width: 32px; height: 32px; margin-bottom: 10px; opacity: 0.4; }
.inspector-empty .ie-title { font-family: var(--font-title); font-weight: 700; font-size: 13px; color: var(--text-2); margin-bottom: 6px; }
.inspector-empty .ie-sub { font-size: 11.5px; line-height: 1.5; }

.inspector-section { margin-bottom: 18px; }
.inspector-section:last-child { margin-bottom: 0; }
.inspector-section-title {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--text-4);
  margin-bottom: 8px;
}
.inspector-field {
  display: flex; justify-content: space-between; gap: 10px;
  padding: 5px 0;
  font-size: 12px;
  border-bottom: 1px dashed var(--border);
}
.inspector-field:last-child { border-bottom: 0; }
.inspector-field .k { color: var(--text-3); }
.inspector-field .v { color: var(--text); font-weight: 500; text-align: right; }

/* Activity feed en inspector */
.activity-feed { display: flex; flex-direction: column; gap: 10px; }
.activity-item {
  display: flex; gap: 10px;
  position: relative;
  padding-left: 20px;
}
.activity-item::before {
  content: ""; position: absolute; left: 4px; top: 6px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--oro);
  box-shadow: 0 0 0 3px rgba(201,162,39,0.15);
}
.activity-item::after {
  content: ""; position: absolute; left: 7.5px; top: 16px; bottom: -10px;
  width: 1px; background: var(--border);
}
.activity-item:last-child::after { display: none; }
.activity-head { display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
.activity-user { font-size: 12px; font-weight: 600; color: var(--text); }
.activity-time { font-size: 10.5px; color: var(--text-4); font-family: var(--font-mono); }
.activity-action { font-size: 11.5px; color: var(--text-2); line-height: 1.4; margin-top: 2px; }

/* =============================================================
   SPARKLINES & CHARTS SVG
   ============================================================= */
.sparkline { display: block; width: 100%; height: 32px; }
.sparkline-path { fill: none; stroke: var(--oro); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.sparkline-area { fill: url(#gradSpark); opacity: 0.35; }
.sparkline-dot { fill: var(--oro); }
.sparkline.verde .sparkline-path { stroke: var(--verde); }
.sparkline.rojo .sparkline-path { stroke: var(--rojo); }
.sparkline.azul .sparkline-path { stroke: var(--azul); }

.kpi-v2 {
  display: flex; flex-direction: column;
  min-height: 120px;
}
.kpi-v2 .kpi-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.kpi-v2 .kpi-chart { margin-top: auto; opacity: 0.85; }

/* Donut */
.donut-wrap {
  display: flex; align-items: center; gap: 14px;
}
.donut { position: relative; width: 120px; height: 120px; flex-shrink: 0; }
.donut svg { transform: rotate(-90deg); }
.donut-center {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.donut-center .dv { font-family: var(--font-title); font-weight: 800; font-size: 22px; letter-spacing: -0.02em; }
.donut-center .dl { font-size: 10px; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.06em; margin-top: 2px; }
.donut-legend { flex: 1; display: flex; flex-direction: column; gap: 6px; font-size: 11.5px; }
.donut-legend-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.donut-legend-row .dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.donut-legend-row .lbl { flex: 1; color: var(--text-2); }
.donut-legend-row .val { font-family: var(--font-mono); font-weight: 700; color: var(--text); }

/* Line chart */
.line-chart { width: 100%; height: 180px; }
.line-chart .lc-grid { stroke: var(--border); stroke-width: 1; stroke-dasharray: 2 4; }
.line-chart .lc-axis-label { fill: var(--text-4); font-size: 10px; font-family: var(--font-mono); }
.line-chart .lc-path { fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.line-chart .lc-path-area { opacity: 0.18; }
.line-chart .lc-dot { stroke: var(--bg); stroke-width: 1.5; }
.line-chart-legend {
  display: flex; gap: 14px; margin-top: 8px;
  font-size: 11px; color: var(--text-3);
}
.line-chart-legend .l-item { display: flex; align-items: center; gap: 6px; }
.line-chart-legend .l-dot { width: 10px; height: 2px; border-radius: 2px; }

/* Bar chart simple (vertical) */
.bar-chart { display: flex; align-items: flex-end; gap: 4px; height: 120px; padding: 0 2px; }
.bar-chart .bc-col {
  flex: 1;
  background: linear-gradient(180deg, var(--oro), var(--oro-oscuro, #a88520));
  border-radius: 3px 3px 0 0;
  min-width: 8px;
  position: relative;
  transition: var(--tr);
  cursor: pointer;
}
.bar-chart .bc-col:hover { background: linear-gradient(180deg, var(--oro-2), var(--oro)); }
.bar-chart .bc-col::after {
  content: attr(data-v);
  position: absolute; top: -18px; left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-mono); font-size: 10px; font-weight: 600;
  color: var(--text-3);
  opacity: 0; transition: var(--tr);
}
.bar-chart .bc-col:hover::after { opacity: 1; }
.bar-chart-labels { display: flex; gap: 4px; padding: 0 2px; margin-top: 4px; }
.bar-chart-labels div { flex: 1; text-align: center; font-size: 9.5px; color: var(--text-4); min-width: 8px; font-family: var(--font-mono); }

/* Radial bar for single value */
.radial { width: 74px; height: 74px; }
.radial-track { fill: none; stroke: var(--bg-3); stroke-width: 7; }
.radial-bar { fill: none; stroke: var(--oro); stroke-width: 7; stroke-linecap: round; transition: stroke-dashoffset 600ms ease; }

/* =============================================================
   MAPA DEL SITIO
   ============================================================= */
.map-shell {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 16px;
  backdrop-filter: blur(14px);
}
.map-svg {
  width: 100%; height: 500px;
  background:
    linear-gradient(135deg, rgba(201,162,39,0.015), rgba(139,92,246,0.015)),
    var(--bg-2);
  border-radius: var(--r);
  display: block;
}
.map-bloque {
  fill: rgba(255,255,255,0.02);
  stroke: var(--border-strong);
  stroke-width: 1;
  rx: 4;
}
.map-bloque-label {
  fill: var(--text-3);
  font-size: 2.2px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  font-family: var(--font-mono);
  opacity: 0.55;
}
.map-pin {
  cursor: pointer;
  transition: var(--tr);
}
.map-pin:hover circle.pin-main { r: 12; }
.map-pin circle.pin-main {
  transition: r 150ms ease;
}
.map-pin-pulse {
  animation: mapPulse 2s ease-out infinite;
  transform-origin: center;
}
@keyframes mapPulse {
  0% { r: 10; opacity: 0.6; }
  100% { r: 22; opacity: 0; }
}
.map-legend {
  display: flex; flex-wrap: wrap; gap: 14px;
  margin-top: 14px;
  font-size: 11.5px; color: var(--text-3);
}
.map-legend-item { display: flex; align-items: center; gap: 6px; }
.map-legend-dot { width: 10px; height: 10px; border-radius: 50%; }

.map-layers {
  display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px;
}

/* =============================================================
   BBSO y reportes rápidos
   ============================================================= */
.bbso-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 14px;
  display: flex; align-items: center; gap: 14px;
  transition: var(--tr);
  cursor: pointer;
}
.bbso-card:hover { border-color: var(--border-oro-hover); transform: translateY(-1px); }
.bbso-ic {
  width: 44px; height: 44px;
  border-radius: 11px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}
.bbso-ic.seguro { background: var(--verde-dim); color: var(--verde); }
.bbso-ic.inseguro { background: var(--rojo-dim); color: var(--rojo); }

/* =============================================================
   LISTA DE ITEMS GENÉRICA (sidebar contextual)
   ============================================================= */
.item-list { display: flex; flex-direction: column; gap: 4px; }
.item-list .il-item {
  display: flex; gap: 10px; align-items: center;
  padding: 10px 10px;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: var(--tr);
  background: transparent;
  border: 1px solid transparent;
}
.item-list .il-item:hover { background: var(--bg-3); }
.item-list .il-item.selected { background: var(--oro-dim); border-color: var(--oro-border); }
.il-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-4); flex-shrink: 0; }
.il-dot.verde { background: var(--verde); }
.il-dot.amarillo { background: var(--amarillo); }
.il-dot.naranja { background: var(--naranja); }
.il-dot.rojo { background: var(--rojo); box-shadow: 0 0 6px rgba(239,68,68,0.4); }
.il-dot.azul { background: var(--azul); }
.il-content { flex: 1; min-width: 0; }
.il-title { font-size: 12px; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.il-sub { font-size: 10.5px; color: var(--text-3); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* =============================================================
   AVATAR STACKS
   ============================================================= */
.avatar-stack { display: inline-flex; }
.avatar-stack .avatar-sm {
  width: 24px; height: 24px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-title); font-weight: 700; font-size: 9.5px;
  color: #fff;
  border: 2px solid var(--bg-1);
  margin-left: -8px;
}
.avatar-stack .avatar-sm:first-child { margin-left: 0; }
.avatar-stack .avatar-sm.plus {
  background: var(--bg-3); color: var(--text-2); font-size: 10px;
}

/* =============================================================
   5 POR QUÉS
   ============================================================= */
.why-chain { position: relative; padding-left: 22px; }
.why-chain::before {
  content: ""; position: absolute; left: 10px; top: 8px; bottom: 8px;
  width: 2px; background: linear-gradient(180deg, var(--rojo), var(--naranja), var(--amarillo), var(--verde));
  border-radius: 2px;
}
.why-item {
  position: relative;
  padding: 8px 0 12px;
}
.why-item::before {
  content: attr(data-n);
  position: absolute; left: -22px; top: 8px;
  width: 20px; height: 20px;
  background: var(--bg-elev);
  border: 2px solid var(--border-strong);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-size: 10px; font-weight: 700;
  color: var(--text-2);
}
.why-item .why-q { font-size: 12px; font-weight: 600; color: var(--text); margin-bottom: 3px; }
.why-item .why-a { font-size: 11.5px; color: var(--text-2); line-height: 1.5; }

/* =============================================================
   CHECKLIST — INSPECCIÓN
   ============================================================= */
.checklist-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  margin-bottom: 6px;
  cursor: pointer;
  transition: var(--tr);
  background: var(--bg-2);
}
.checklist-item:hover { border-color: var(--border-strong); }
.checklist-item.ok { border-color: var(--verde); background: var(--verde-dim); }
.checklist-item.no { border-color: var(--rojo); background: var(--rojo-dim); }
.checklist-item.na { border-color: var(--amarillo); background: rgba(234,179,8,0.08); }
.checklist-num { font-family: var(--font-mono); font-size: 11px; color: var(--text-3); min-width: 24px; }
.checklist-text { font-size: 12.5px; color: var(--text); }
.checklist-cat { font-size: 10px; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.04em; margin-top: 2px; }
.checklist-buttons { display: flex; gap: 4px; }
.checklist-btn {
  width: 28px; height: 28px; border-radius: 6px;
  border: 1px solid var(--border);
  color: var(--text-3); font-weight: 700; font-size: 11px;
  transition: var(--tr);
}
.checklist-btn:hover { background: var(--bg-3); color: var(--text); }
.checklist-btn.active.ok { background: var(--verde); border-color: var(--verde); color: #fff; }
.checklist-btn.active.no { background: var(--rojo); border-color: var(--rojo); color: #fff; }
.checklist-btn.active.na { background: var(--amarillo); border-color: var(--amarillo); color: #000; }

/* =============================================================
   STATUS DOT EN VIVO
   ============================================================= */
.status-dot {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; color: var(--text-3);
  font-weight: 500;
}
.status-dot::before {
  content: "";
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--verde);
  box-shadow: 0 0 0 2px rgba(34,197,94,0.2);
  animation: livePulse 2s infinite;
}
@keyframes livePulse {
  0%, 100% { box-shadow: 0 0 0 2px rgba(34,197,94,0.2); }
  50% { box-shadow: 0 0 0 5px rgba(34,197,94,0); }
}

/* =============================================================
   TILES grid premium
   ============================================================= */
.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}
.tile {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 16px;
  transition: var(--tr);
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.tile::before {
  content: "";
  position: absolute; top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--oro), transparent);
  opacity: 0;
  transition: var(--tr);
}
.tile:hover { border-color: var(--border-oro-hover); transform: translateY(-2px); }
.tile:hover::before { opacity: 1; }

/* =============================================================
   HEATMAP (calendario)
   ============================================================= */
.heatmap { display: grid; grid-template-columns: repeat(14, 1fr); gap: 3px; }
.hm-cell {
  aspect-ratio: 1;
  border-radius: 2px;
  background: var(--bg-3);
  transition: var(--tr);
  cursor: pointer;
}
.hm-cell.l1 { background: rgba(34,197,94,0.25); }
.hm-cell.l2 { background: rgba(34,197,94,0.45); }
.hm-cell.l3 { background: rgba(34,197,94,0.7); }
.hm-cell.l4 { background: rgba(34,197,94,1); }
.hm-cell:hover { outline: 1px solid var(--oro); }

/* =============================================================
   TABS plegables para el layout (toggle inspector)
   ============================================================= */
.btn-toggle-inspector {
  position: fixed; top: 80px; right: 14px;
  z-index: 50;
  width: 32px; height: 32px;
  border-radius: 8px;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  color: var(--text-2);
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-md);
  transition: var(--tr);
}
.btn-toggle-inspector:hover { color: var(--oro); border-color: var(--oro); }
.app-shell:not(.inspector-collapsed) .btn-toggle-inspector { display: none; }

/* =============================================================
   RESPONSIVE v2
   ============================================================= */
@media (max-width: 1400px) {
  :root { --inspector-w: 340px; }
}
@media (max-width: 1200px) {
  .app-shell:not(.sidebar-collapsed) { grid-template-columns: var(--rail-w) 220px 1fr 0 !important; }
  .inspector { display: none; }
  .btn-toggle-inspector { display: none; }
}
@media (max-width: 900px) {
  .app-shell { grid-template-columns: var(--rail-w) 0 1fr 0 !important; }
  .sidebar {
    position: fixed; top: var(--topbar-h); left: var(--rail-w);
    bottom: 0; width: 260px; z-index: 50;
    border-right: 1px solid var(--border-strong);
    transform: translateX(-110%);
    transition: transform 240ms ease;
    opacity: 1 !important;
  }
  .app-shell.sidebar-mobile-open .sidebar { transform: none; pointer-events: auto; }
}

/* =============================================================
   PROGRESS BAR
   ============================================================= */
.progress {
  width: 100%; height: 6px;
  background: var(--bg-3); border-radius: 3px; overflow: hidden;
}
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--oro), var(--oro-2)); border-radius: 3px; transition: width 400ms ease; }
.progress-fill.verde { background: linear-gradient(90deg, #16a34a, var(--verde)); }
.progress-fill.rojo { background: linear-gradient(90deg, #b91c1c, var(--rojo)); }
.progress-fill.amarillo { background: linear-gradient(90deg, #ca8a04, var(--amarillo)); }

/* =============================================================
   TOOLTIP
   ============================================================= */
[data-tip] { position: relative; }
[data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%);
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-size: 11px; padding: 5px 9px; border-radius: 5px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 100;
  box-shadow: var(--shadow-md);
}

/* =============================================================
   SEGMENTED CONTROL
   ============================================================= */
.segment {
  display: inline-flex; padding: 2px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
}
.segment > button {
  padding: 5px 11px;
  border-radius: calc(var(--r-sm) - 2px);
  font-size: 11.5px; font-weight: 600;
  color: var(--text-3);
  transition: var(--tr);
}
.segment > button:hover { color: var(--text-2); }
.segment > button.active { background: var(--bg-4); color: var(--text); }
