/* =====================================================================
   APICE — Portal de gestión: mesa de servicio, capacitaciones, admin
   ===================================================================== */

/* ============================ ESTRUCTURA ============================ */
.app {
  display: grid;
  grid-template-columns: 258px 1fr;
  min-height: calc(100vh - var(--header-h));
  align-items: start;
}
@media (max-width: 980px) { .app { grid-template-columns: 1fr; } }

.app__lateral {
  position: sticky; top: var(--header-h);
  height: calc(100vh - var(--header-h));
  overflow-y: auto;
  padding: 24px 16px;
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex; flex-direction: column; gap: 4px;
}
@media (max-width: 980px) {
  .app__lateral {
    position: static; height: auto; border-right: 0;
    border-bottom: 1px solid var(--border);
    flex-direction: row; overflow-x: auto; padding: 12px 16px; gap: 6px;
  }
  .app__lateral .lateral__titulo, .app__lateral .lateral__pie { display: none; }
}

.lateral__titulo {
  font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.11em;
  color: var(--text-muted); font-weight: 650; padding: 14px 12px 8px;
}
.lateral__link {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: var(--r-md);
  font-family: var(--font-display); font-size: var(--fs-base); font-weight: 550;
  color: var(--text-soft); cursor: pointer; border: 0; background: none;
  width: 100%; text-align: left; white-space: nowrap;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.lateral__link:hover { background: var(--surface-3); color: var(--text); }
.lateral__link.is-activo { background: var(--surface-brand); color: var(--on-brand-soft); font-weight: 650; }
.lateral__link svg { width: 18px; height: 18px; flex: none; }
.lateral__link .cuenta {
  margin-left: auto; background: var(--surface-3); color: var(--text-muted);
  border-radius: var(--r-full); padding: 1px 8px; font-size: var(--fs-xs); font-weight: 700;
}
.lateral__link.is-activo .cuenta { background: var(--primary); color: var(--primary-fg); }
.lateral__pie { margin-top: auto; padding-top: 16px; border-top: 1px solid var(--border-soft); }

.app__cuerpo { padding: clamp(20px, 3vw, 34px); min-width: 0; }
.app__cabecera {
  display: flex; align-items: flex-start; gap: 16px; flex-wrap: wrap;
  justify-content: space-between; margin-bottom: 26px;
}
.app__cabecera h1 { font-size: clamp(1.4rem, 1.1rem + 1.1vw, 1.9rem); margin: 0 0 4px; }
.app__cabecera p { color: var(--text-muted); margin: 0; font-size: var(--fs-base); }

/* Tarjeta de bienvenida */
.hola {
  background: var(--grad-brand); color: #fff;
  border-radius: var(--r-xl); padding: clamp(22px, 3vw, 32px);
  position: relative; overflow: hidden; margin-bottom: 26px;
}
.hola::before { content: ''; position: absolute; inset: 0; background: var(--grad-hero); }
.hola > * { position: relative; }
.hola h2 { color: #fff; margin: 0 0 6px; font-size: var(--fs-xl); }
.hola p { color: rgba(255, 255, 255, 0.82); margin: 0; font-size: var(--fs-base); }

/* ============================= MÉTRICAS ============================= */
.metricas { display: grid; grid-template-columns: repeat(auto-fit, minmax(184px, 1fr)); gap: 16px; }
.metrica {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 20px;
  display: flex; gap: 14px; align-items: flex-start;
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.metrica:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.metrica.is-clickable { cursor: pointer; }
.metrica__valor {
  font-family: var(--font-display); font-weight: 800;
  font-size: 1.9rem; line-height: 1; letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}
.metrica__texto { font-size: var(--fs-sm); color: var(--text-muted); margin-top: 6px; line-height: 1.4; }
.metrica__ico {
  width: 42px; height: 42px; flex: none; border-radius: 13px;
  display: grid; place-items: center;
  background: var(--surface-brand); color: var(--on-brand-soft);
}
.metrica--peligro .metrica__ico { background: var(--danger-bg); color: var(--danger-fg); }
.metrica--peligro .metrica__valor { color: var(--danger-fg); }
.metrica--alerta .metrica__ico { background: var(--warn-bg); color: var(--warn-fg); }
.metrica--alerta .metrica__valor { color: var(--warn-fg); }
.metrica--ok .metrica__ico { background: var(--ok-bg); color: var(--ok-fg); }
.metrica--ok .metrica__valor { color: var(--ok-fg); }

/* ============================== FILTROS ============================= */
.filtros {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
  padding: 14px 16px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); margin-bottom: 18px;
}
.filtros .input, .filtros .select { min-height: 38px; padding: 7px 12px; font-size: var(--fs-sm); width: auto; }
.filtros .select { padding-right: 34px; }
.filtros .buscador { flex: 1 1 220px; min-width: 180px; }
.filtros .buscador .input { width: 100%; padding-left: 38px; }
.filtros .input-icon > svg { left: 12px; width: 16px; height: 16px; }

/* ============================== TICKETS ============================= */
.ticket-fila { cursor: pointer; }
.ticket-fila__codigo {
  font-family: var(--font-mono); font-size: var(--fs-xs);
  color: var(--text-muted); display: block; margin-bottom: 3px;
}
.ticket-fila__titulo {
  font-weight: 600; color: var(--text); display: block;
  max-width: 40ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.prio-tag {
  display: inline-flex; align-items: center; gap: 7px;
  font-weight: 700; font-family: var(--font-display); font-size: var(--fs-sm);
  white-space: nowrap;
}
.prio-tag::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.prio-tag[data-p="P1"] { color: var(--p1); }
.prio-tag[data-p="P2"] { color: var(--p2); }
.prio-tag[data-p="P3"] { color: var(--p3); }
.prio-tag[data-p="P4"] { color: var(--p4); }

/* Semáforo de SLA */
.sla-pin {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: var(--fs-xs); font-weight: 650; white-space: nowrap;
  padding: 3px 9px; border-radius: var(--r-full);
  border: 1px solid transparent;
}
.sla-pin[data-e="cumplido"]   { background: var(--ok-bg);     color: var(--ok-fg);     border-color: var(--ok-bd); }
.sla-pin[data-e="en_curso"]   { background: var(--info-bg);   color: var(--info-fg);   border-color: var(--info-bd); }
.sla-pin[data-e="por_vencer"] { background: var(--warn-bg);   color: var(--warn-fg);   border-color: var(--warn-bd); }
.sla-pin[data-e="vencido"],
.sla-pin[data-e="incumplido"] { background: var(--danger-bg); color: var(--danger-fg); border-color: var(--danger-bd); }
.sla-pin[data-e="detenido"]   { background: var(--neutral-bg);color: var(--neutral-fg);border-color: var(--neutral-bd); }

/* Tarjeta compacta de ticket (vista móvil) */
.ticket-tarjeta {
  display: block; padding: 16px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); cursor: pointer; margin-bottom: 12px;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.ticket-tarjeta:hover { border-color: var(--brand-300); box-shadow: var(--shadow-sm); }

/* ======================= CONVERSACIÓN DEL CASO ===================== */
.hilo { display: flex; flex-direction: column; gap: 18px; }
.msg { display: flex; gap: 13px; }
.msg--propio { flex-direction: row-reverse; }
.msg__avatar {
  width: 38px; height: 38px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 700; font-size: var(--fs-xs);
  background: var(--surface-3); color: var(--text-soft);
}
.msg--staff .msg__avatar { background: var(--grad-accent); color: #fff; }
.msg__burbuja {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 13px 16px; max-width: min(78%, 640px);
  font-size: var(--fs-base); line-height: 1.62;
}
.msg--propio .msg__burbuja { background: var(--surface-brand); border-color: var(--border-soft); }
.msg--interno .msg__burbuja {
  background: var(--warn-bg); border-color: var(--warn-bd); color: var(--warn-fg);
  border-style: dashed;
}
.msg__meta {
  font-size: var(--fs-xs); color: var(--text-muted);
  margin-bottom: 6px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}
.msg__meta strong { color: var(--text-soft); font-weight: 650; }
.msg--interno .msg__meta { color: var(--warn-fg); opacity: 0.9; }

/* Auditoría */
.auditoria { list-style: none; padding: 0; margin: 0; font-size: var(--fs-sm); }
.auditoria li {
  display: flex; gap: 11px; padding: 10px 0;
  border-bottom: 1px solid var(--border-soft); color: var(--text-soft);
}
.auditoria li:last-child { border-bottom: 0; }
.auditoria svg { width: 15px; height: 15px; flex: none; margin-top: 3px; color: var(--text-muted); }
.auditoria time { color: var(--text-muted); font-size: var(--fs-xs); display: block; margin-top: 2px; }

/* Ficha lateral del caso */
.ficha { display: grid; gap: 0; }
.ficha__dato {
  display: flex; justify-content: space-between; gap: 14px; align-items: center;
  padding: 11px 0; border-bottom: 1px solid var(--border-soft); font-size: var(--fs-sm);
}
.ficha__dato:last-child { border-bottom: 0; }
.ficha__dato dt { color: var(--text-muted); flex: none; }
.ficha__dato dd { margin: 0; font-weight: 600; text-align: right; }

/* Adjuntos */
.adjunto {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 13px; border: 1px solid var(--border);
  border-radius: var(--r-md); background: var(--surface-2);
  font-size: var(--fs-sm); text-decoration: none; color: var(--text);
  transition: border-color var(--dur) var(--ease), background-color var(--dur) var(--ease);
}
.adjunto:hover { border-color: var(--brand-300); background: var(--surface-3); color: var(--text); }
.adjunto svg { width: 17px; height: 17px; flex: none; color: var(--text-muted); }
.adjunto span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.adjunto small { color: var(--text-muted); flex: none; }

/* Zona de arrastre */
.soltar {
  border: 2px dashed var(--border-strong); border-radius: var(--r-md);
  padding: 20px; text-align: center; color: var(--text-muted);
  font-size: var(--fs-sm); cursor: pointer;
  transition: border-color var(--dur) var(--ease), background-color var(--dur) var(--ease);
}
.soltar:hover, .soltar.is-encima { border-color: var(--primary); background: var(--surface-brand); color: var(--on-brand-soft); }

/* ============================== PESTAÑAS =========================== */
.panel-tab { display: none; }
.panel-tab.is-activo { display: block; animation: fade-in 260ms var(--ease); }

/* ============================== GRÁFICOS =========================== */
.barras { display: flex; align-items: stretch; gap: 5px; height: 130px; }
.barras__col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; gap: 2px; min-width: 0; }
.barras__b { border-radius: 3px 3px 0 0; min-height: 2px; transition: height .5s var(--ease); }
.barras__b--a { background: var(--brand-500); }
.barras__b--b { background: var(--accent-500); }
.barras__eje { display: flex; gap: 5px; margin-top: 8px; }
.barras__eje span {
  flex: 1; text-align: center; font-size: 9px; color: var(--text-muted);
  overflow: hidden; white-space: nowrap;
}

.distrib { display: grid; gap: 12px; }
.distrib__fila { display: grid; grid-template-columns: 130px 1fr 42px; gap: 12px; align-items: center; font-size: var(--fs-sm); }
.distrib__pista { display: block; height: 9px; background: var(--surface-3); border-radius: 99px; overflow: hidden; }
.distrib__llena { display: block; height: 100%; border-radius: 99px; background: var(--grad-accent); transition: width .6s var(--ease); }
.distrib__n { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ========================== AUTENTICACIÓN ========================== */
/* La pantalla de acceso es la primera impresión del portal, así que se
   trabaja con capas de degradado: base de marca, dos focos de luz en
   diagonal y una trama fina enmascarada. El lado del formulario lleva un
   degradado muy tenue para que la tarjeta blanca no quede plana. */
.auth {
  display: grid; grid-template-columns: 1.04fr 1fr; min-height: 100vh;
  background:
    radial-gradient(120% 90% at 100% 0%, var(--surface-brand) 0%, transparent 58%),
    radial-gradient(90% 70% at 88% 100%, var(--accent-bg) 0%, transparent 62%),
    var(--surface-2);
}
@media (max-width: 960px) { .auth { grid-template-columns: 1fr; } }

.auth__panel {
  background: var(--grad-brand); color: #fff;
  padding: clamp(32px, 5vw, 64px);
  display: flex; flex-direction: column; justify-content: space-between;
  position: relative; overflow: hidden;
}
/* Capa 1 — focos de luz */
.auth__panel::before {
  content: ''; position: absolute; inset: 0; z-index: 0;
  background:
    radial-gradient(62% 55% at 10% 4%,  rgba(110, 231, 245, 0.30), transparent 62%),
    radial-gradient(52% 50% at 96% 96%, rgba(3, 150, 172, 0.34),  transparent 66%),
    var(--grad-hero);
}
/* Capa 2 — trama fina que se desvanece hacia el centro */
.auth__panel::after {
  content: ''; position: absolute; inset: 0; z-index: 0; pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.05) 1px, transparent 1px);
  background-size: 46px 46px;
  -webkit-mask-image: radial-gradient(78% 70% at 24% 16%, #000 0%, transparent 78%);
          mask-image: radial-gradient(78% 70% at 24% 16%, #000 0%, transparent 78%);
}
.auth__panel > * { position: relative; z-index: 1; }
.auth__panel h2 {
  color: #fff; font-size: clamp(1.55rem, 1.2rem + 1.5vw, 2.25rem);
  line-height: 1.15; letter-spacing: -0.015em;
}
.auth__panel p { color: rgba(255, 255, 255, 0.82); }
@media (max-width: 960px) { .auth__panel { display: none; } }

/* Ventajas — tarjetas de vidrio sobre el degradado */
.auth__ventaja {
  display: flex; gap: 13px; align-items: flex-start;
  margin-bottom: 10px; padding: 13px 14px;
  border-radius: var(--r-md);
  border: 1px solid rgba(255, 255, 255, 0.10);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.10), rgba(255, 255, 255, 0.03));
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.auth__ventaja svg { width: 20px; height: 20px; flex: none; margin-top: 2px; color: var(--accent-300); }
.auth__ventaja strong { display: block; font-family: var(--font-display); font-size: var(--fs-base); color: #fff; }
.auth__ventaja span { font-size: var(--fs-sm); color: rgba(255, 255, 255, 0.74); }

/* ---- Lado del formulario ---- */
.auth__forma {
  padding: clamp(24px, 4vw, 52px);
  display: flex; flex-direction: column; justify-content: center;
  max-width: 580px; width: 100%; margin: 0 auto;
}
/* Cada vista (ingreso / registro) va en tarjeta, con un filo de color arriba */
.auth__forma [data-vista] {
  position: relative; overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: clamp(24px, 3.2vw, 38px);
  box-shadow: var(--shadow-lg);
}
.auth__forma [data-vista]::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: var(--grad-accent);
}
.auth__forma [data-vista] > h1 { letter-spacing: -0.02em; }
/* El botón principal toma el degradado de marca */
.auth__forma [data-vista] .btn--primary {
  background: var(--grad-accent); border-color: transparent; color: #fff;
}
.auth__forma [data-vista] .btn--primary:hover { filter: brightness(1.07); }

/* ============================= REPORTES ============================
   Hoja del reporte: cabecera con logotipo (solo visible al imprimir),
   indicadores, graficos SVG y el cuadro de datos. La misma hoja es lo
   que sale en el PDF. */
.reporte-hoja { display: grid; gap: 18px; }
.reporte-hoja__cab { display: none; align-items: center; gap: 22px; padding-bottom: 12px; border-bottom: 2px solid var(--brand-500); }
.reporte-hoja__logo { width: 150px; height: auto; }
.reporte-hoja__titulo h2 { margin: 0 0 4px; font-size: 20px; }
.reporte-hoja__titulo p { margin: 0; font-size: var(--fs-sm); }
.indicadores { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.indicador {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 14px 16px; border-left: 4px solid var(--brand-500);
}
.indicador__valor { font-size: 26px; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.indicador__valor small { font-size: 13px; font-weight: 600; color: var(--text-muted); }
.indicador__texto { font-size: var(--fs-sm); color: var(--text-muted); margin-top: 5px; line-height: 1.3; }
.indicador--ok { border-left-color: var(--ok-fg); } .indicador--ok .indicador__valor { color: var(--ok-fg); }
.indicador--alerta { border-left-color: var(--warn-fg); } .indicador--alerta .indicador__valor { color: var(--warn-fg); }
.indicador--peligro { border-left-color: var(--danger-fg); } .indicador--peligro .indicador__valor { color: var(--danger-fg); }
.reporte-graficos { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.reporte-grafico {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 16px 18px; min-width: 0; break-inside: avoid;
}
.reporte-grafico h4 { margin: 0 0 12px; font-size: var(--fs-sm); text-transform: uppercase; letter-spacing: .04em; color: var(--text-soft); }
.grafico-svg { display: block; width: 100%; height: auto; font-family: inherit; }
.grafico-svg__rejilla { stroke: var(--border); stroke-width: 1; }
.grafico-svg__eje { font-size: 11px; fill: var(--text-muted); }
.grafico-svg__etq { font-size: 12px; fill: var(--text); }
.grafico-svg__val { font-size: 11.5px; font-weight: 700; fill: var(--text-soft); font-variant-numeric: tabular-nums; }
.grafico-svg__pista { fill: var(--surface-3); }
.leyenda { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 8px; font-size: var(--fs-sm); color: var(--text-soft); }
.leyenda span { display: inline-flex; align-items: center; gap: 6px; }
.leyenda i, .dona__leyenda i { display: inline-block; width: 11px; height: 11px; border-radius: 3px; flex: none; }
.dona { display: grid; grid-template-columns: 150px 1fr; gap: 16px; align-items: center; }
.dona__svg { width: 150px; height: 150px; }
.dona__centro { font-size: 24px; font-weight: 800; fill: var(--text); }
.dona__sub { font-size: 10px; fill: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
.dona__leyenda { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: var(--fs-sm); min-width: 0; }
.dona__leyenda li { display: grid; grid-template-columns: 11px 1fr auto auto; gap: 8px; align-items: center; }
.dona__leyenda span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dona__leyenda b { font-variant-numeric: tabular-nums; }
.dona__leyenda em { font-style: normal; color: var(--text-muted); font-variant-numeric: tabular-nums; min-width: 34px; text-align: right; }
.table--reporte { font-size: var(--fs-sm); }
.table--reporte th, .table--reporte td { padding: 9px 10px; white-space: nowrap; }
.table--reporte td:nth-child(2) { white-space: normal; min-width: 180px; }
@media (max-width: 760px) {
  .reporte-graficos { grid-template-columns: 1fr; }
  .dona { grid-template-columns: 1fr; justify-items: center; }
}

/* ============================= IMPRESIÓN =========================== */
@media print {
  .site-header, .site-footer, .app__lateral, .vb-respaldo,
  [data-voicebot-launcher], [data-voicebot-panel],
  .toast-host, .edit-bar, .no-imprimir { display: none !important; }
  body { background: #fff !important; }
  .app { grid-template-columns: 1fr; }

  /* La hoja del reporte: cabecera con logotipo, colores de las barras
     conservados y nada que se parta a mitad de un grafico. */
  .reporte-hoja { -webkit-print-color-adjust: exact; print-color-adjust: exact; gap: 12px; font-size: 11px; }
  .reporte-hoja__cab { display: flex; }
  .indicadores { grid-template-columns: repeat(4, 1fr); gap: 8px; }
  .indicador { padding: 8px 10px; box-shadow: none; }
  .indicador__valor { font-size: 18px; }
  .indicador__texto { font-size: 10px; }
  .reporte-graficos { gap: 10px; }
  .reporte-grafico { padding: 10px 12px; box-shadow: none; }
  .reporte-hoja .panel { box-shadow: none; break-inside: auto; }
  .reporte-hoja .table-wrap { overflow: visible; }
  /* Diecinueve columnas en una hoja apaisada: letra pequena, celdas que
     parten por palabra y solo el codigo del ticket se mantiene entero. */
  .table--reporte { font-size: 7.5px; table-layout: auto; width: 100%; }
  .table--reporte th, .table--reporte td {
    padding: 3px 2px; white-space: normal; min-width: 6em;
    overflow-wrap: anywhere; hyphens: auto; vertical-align: top;
  }
  .table--reporte th { text-transform: none; letter-spacing: 0; font-size: 7.5px; }
  .table--reporte td:first-child { white-space: nowrap; }
  .table--reporte td:nth-child(2) { min-width: 12em; }
  .table--reporte thead { display: table-header-group; }
  .table--reporte tr { break-inside: avoid; }
  .table--reporte a { color: inherit; text-decoration: none; }
}
