:root {
  --bg: #0b0f1a;
  --panel: #111a2e;
  --panel2: #0b1325;
  --txt: #e8eefc;
  --muted: #9bb0d1;

  --bd: rgba(255, 255, 255, .10);
  --ok: rgba(46, 204, 113, .12);
  --warn: rgba(241, 196, 15, .14);
  --bad: rgba(231, 76, 60, .14);
  --end: rgba(149, 165, 166, .14);
}

body {
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial;
  margin: 0;
  background: var(--bg);
  color: var(--txt);
}

.wrap {
  max-width: 1200px;
  margin-inline: auto;
  padding-inline: clamp(16px, 3vw, 24px);
  padding-block: 18px;
  box-sizing: border-box;
}

.card {
  background: var(--panel);
  border: 1px solid var(--bd);
  border-radius: 14px;
  padding: 14px;
}

.row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

input,
select,
button {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--bd);
  background: var(--panel2);
  color: var(--txt);
  box-sizing: border-box;
}

button {
  cursor: pointer;
}

.muted {
  color: var(--muted);
  font-size: 16px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, .08);
  text-align: left;
  font-size: 16px;
  vertical-align: middle;
}

/* Estados, libre/sonando/en llamada */
.badge {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid rgba(255, 255, 255, .14);
  display: inline-block;
}

.idle {
  background: var(--ok);
  color: #b9f6cf;
}

.ringing {
  background: var(--warn);
  color: #ffeaa7;
}

.busy {
  background: var(--bad);
  color: #ffb3b3;
}

.ended {
  background: var(--end);
  color: #dfe6e9;
}

/* Espacio superior de los botones de las pestañas */
.tabsBar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  margin-top: 22px;
}

/* Grupo de botones en la columna del centro */
.tabs {
  grid-column: 2;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* Tamaño del texto de los botones principales */
.tab {
  padding: 12px 18px;
  width: 160px;
  text-align: center;
  font-size: 17px;
  font-weight: 400;
  line-height: 1;
  text-align: center;
}

.tab.active {
  background: #1b2a4a;
}

/* Tamaño y espacios entre tabla derecha e izquierda  */
.grid2 {
  display: grid;
  grid-template-columns: 0.80fr 1fr;
  gap: 12px;
}

@media(max-width:900px) {
  .grid2 {
    grid-template-columns: 1fr;
  }
}

.grid2>.card {
  overflow: hidden;
}

.grid2>.card .row {
  min-width: 0;
}

#filterExt,
#btnClearFilter {
  max-width: 180px;
}

#rightBody {
  min-width: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

#rightBody table {
  width: 100%;
  border-collapse: collapse;
}

#rightBody table:not(.callsTable):not(.eventsTable) {
  min-width: 680px;
}

.hidden {
  display: none !important;
}

.titleIcon {
  height: 80px;
  width: auto;
  display: block;
}

/* Titulo agentes */
.titleInline {
  display: flex;
  align-items: center;
  gap: 16px;
  font-weight: 700;
  font-size: 22px;
}

.rightHeader {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.desc {
  font-size: 16px;
  color: var(--muted);
  line-height: 1.35;
}

/* Grid de agentes tipo tarjetas (3 por fila) */
.agentsGrid {
  display: grid;
  gap: 10px;
  margin-top: 10px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

@media (max-width: 980px) {
  .agentsGrid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 520px) {
  .agentsGrid {
    grid-template-columns: 1fr;
  }
}

.agentCard {
  background: var(--panel2);
  border: 1px solid var(--bd);
  border-radius: 12px;
  padding: 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.agentTop {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.agentExt {
  font-weight: 700;
  font-size: 15px;
  opacity: .95;
}

.agentName {
  color: var(--txt);
  font-size: 15px;
  line-height: 1.15;
  white-space: normal;
  overflow-wrap: anywhere;
}

/* Fecha inline (Resumen) */
.dtInline {
  white-space: nowrap;
}

/* Header derecho en columna */
.rightTop {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/*  Barra: filtro (izq) + paginación (der) */
.filterPagerRow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.filterRow {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

/* =========================
   KPI layout:
   ========================= */
.kpis {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

/* responsive */
@media (max-width: 500px) {
  .kpis {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 520px) {
  .kpis {
    grid-template-columns: 1fr;
  }
}

.kpi {
  background: var(--panel2);
  border: 1px solid var(--bd);
  border-radius: 14px;

  min-height: 75px;
  padding: 10px 12px;

  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto 6px auto;
  column-gap: 10px;
  align-items: start;
  padding-left: 16px;
}

/* Icono*/
.kpi>img.kpiImg {
  grid-column: 1;
  grid-row: 1;
  justify-self: start;
  align-self: start;
  display: block;
  height: 55px;
  width: auto;
  object-fit: contain;
  transform: translate(-5px, 5px);
}

.kpi b,
.kpi span {
  position: relative;
  right: 10px;
}

.kpi b {
  grid-column: 2;
  grid-row: 1;
  justify-self: end;
  align-self: start;
  text-align: right;
  font-size: 26px;
  line-height: 1;
  font-weight: 500;
  letter-spacing: .2px;
  opacity: .95;
  transform: none;
}

/* Texto */
.kpi span {
  grid-column: 2;
  grid-row: 2;
  justify-self: end;
  text-align: right;
  font-size: 18px;
  color: var(--muted);
  transform: translateY(-26px);
  white-space: nowrap;
}

/* Colores por estado */
.kpi.kpi-idle {
  background: rgba(46, 204, 113, .10);
  border-color: rgba(46, 204, 113, .22);
}

.kpi.kpi-ringing {
  background: rgba(241, 196, 15, .12);
  border-color: rgba(241, 196, 15, .24);
}

.kpi.kpi-busy {
  background: rgba(231, 76, 60, .10);
  border-color: rgba(231, 76, 60, .22);
}

#rightTitle {
  font-size: 20px;
}

#rightDesc {
  font-size: 16px;
}

/* Header centrado (título siempre al centro) */
.topBar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
}

#btnLogout {
  grid-column: 1;
  justify-self: start;
}

.topLeft {
  grid-column: 2;
  justify-self: center;
  text-align: center;
  min-width: 0;
}

.topRightSpacer {
  grid-column: 3;
  justify-self: end;
  width: 78px;
}

.appTitle {
  margin: 0;
  font-weight: 700;
  font-size: 26px;
}

.appWho {
  margin-top: 6px;
  font-size: 14px;
}

@media (max-width: 700px) {
  .appTitle {
    font-size: 20px;
    line-height: 1.1;
  }

  .appWho {
    font-size: 13px;
  }

  .muted {
    font-size: 14px;
  }

  .tab {
    font-size: 15px;
    font-weight: 600;
    width: 150px;
  }
}

/* =========================
   Responsive: colapsar / expandir agentes
   ========================= */
.btnAgentsToggle {
  display: none;
  width: 42px;
  height: 38px;
  padding: 0;
  border-radius: 12px;
  line-height: 1;
}

.btnAgentsToggle .chev {
  display: inline-block;
  transform: translateY(-1px);
  font-size: 18px;
  transition: transform .15s ease;
}

#agentsCard.agentsCollapsed #agents {
  display: none;
}

#agentsCard.agentsCollapsed .btnAgentsToggle .chev {
  transform: rotate(-90deg) translateY(0);
}

@media (max-width: 900px) {
  .btnAgentsToggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .agentsHeaderRow {
    flex-wrap: nowrap;
  }

  .agentsHeaderRight {
    gap: 8px;
  }

  .agentsHeaderRight .muted {
    display: none;
  }
}

/*  Distinguir llamadas en "Registro" */
.callMark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 18px;
  margin-right: 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, .18);
  background: rgba(255, 255, 255, .05);
  vertical-align: middle;
}

.callMark.b-solid { border-style: solid; }
.callMark.b-dashed { border-style: dashed; }
.callMark.b-double { border-style: double; }

.callGlyph {
  width: 11px;
  height: 11px;
  background: var(--c);
  border: 1px solid rgba(255, 255, 255, .22);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, .06);
}

.g-circle { border-radius: 999px; }
.g-square { border-radius: 2px; }
.g-diamond { transform: rotate(45deg); border-radius: 2px; }

.g-triangle {
  width: 0;
  height: 0;
  background: transparent;
  box-shadow: none;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-bottom: 12px solid var(--c);
  border-radius: 0;
  border-top: 0;
}

/* =========================================================
   SOLO DESKTOP/TABLET: layout fijo + ellipsis
   ========================================================= */
@media (min-width: 621px) {
  /* Calls: icono pequeño + 4 columnas */
  #rightBody table.callsTable {
    width: 100% !important;
    min-width: 0 !important;
    table-layout: fixed !important;
    border-collapse: collapse;
  }

  #rightBody table.callsTable th,
  #rightBody table.callsTable td {
    text-align: left !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #rightBody table.callsTable col.call-col-icon { width: 44px !important; }
  #rightBody table.callsTable col.call-col-ext { width: 14% !important; }
  #rightBody table.callsTable col.call-col-start { width: 28% !important; }
  #rightBody table.callsTable col.call-col-end { width: 28% !important; }
  #rightBody table.callsTable col.call-col-dur { width: auto !important; }

  #rightBody table.callsTable th:nth-child(1),
  #rightBody table.callsTable td:nth-child(1) {
    text-align: center !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
  }

  #rightBody table.callsTable td:nth-child(1) .callMark {
    width: 30px;
    height: 30px;
    margin: 0 auto;
    position: relative;
  }

  #rightBody table.callsTable td:nth-child(1) .callGlyph,
  #rightBody table.callsTable td:nth-child(1) .g-triangle {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
  }

  /* REGISTRO table */
  #rightBody table.eventsTable {
    width: 100% !important;
    min-width: 0 !important;
    table-layout: fixed !important;
    border-collapse: collapse !important;
  }

  #rightBody table.eventsTable col.ev-col-when { width: 34% !important; }
  #rightBody table.eventsTable col.ev-col-ext { width: 16% !important; }
  #rightBody table.eventsTable col.ev-col-act { width: 50% !important; }

  #rightBody table.eventsTable th,
  #rightBody table.eventsTable td {
    padding: 10px 12px !important;
    white-space: nowrap !important;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #rightBody table.eventsTable {
    --extShiftHead: -11px;
    --extShiftBody: -30px;
  }

  #rightBody table.eventsTable th:nth-child(2) {
    padding-left: 0 !important;
    padding-right: 10px !important;
    position: relative !important;
    left: var(--extShiftHead) !important;
  }

  #rightBody table.eventsTable td:nth-child(2) {
    padding-left: 0 !important;
    padding-right: 10px !important;
    position: relative !important;
    left: var(--extShiftBody) !important;
  }

  #rightBody table.eventsTable td:nth-child(2) .extPill {
    min-width: 44px !important;
    height: 30px !important;
    padding: 0 10px !important;
    font-size: 16px !important;
    display: inline-flex !important;
    justify-content: center !important;
    text-align: center !important;
  }

  #rightBody table.eventsTable td:nth-child(3) {
    display: grid;
    grid-template-columns: 30px 1fr;
    column-gap: 10px;
    align-items: center;
    min-width: 0;
    min-height: 44px;
  }

  #rightBody table.eventsTable td:nth-child(3) .callMark {
    width: 30px;
    height: 30px;
    margin: 0;
    align-self: center;
    position: relative;
  }

  #rightBody table.eventsTable td:nth-child(3) .callGlyph,
  #rightBody table.eventsTable td:nth-child(3) .g-triangle {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
  }
}

/* =========================
   Paginación
   ========================= */
.pager {
  display: flex;
  justify-content: flex-end;
  user-select: none;
}

#pagerTop .pager {
  margin: 0;
}

.pagerBottom {
  margin: 12px 0 6px;
}

.pagerGroup {
  display: inline-flex;
  align-items: center;
  gap: 1px;
}

.pagerBtn {
  appearance: none;
  background: transparent;
  border: none;
  padding: 6px 6px;
  min-width: auto;
  height: auto;

  border-radius: 8px;
  color: rgba(232, 238, 252, .78);
  font-size: 15px;
  font-weight: 500;

  display: inline-flex;
  align-items: center;
  justify-content: center;

  transition: background .15s ease, color .15s ease, opacity .15s ease;
}

.pagerBtn:hover {
  background: rgba(255, 255, 255, .06);
  color: rgba(232, 238, 252, .92);
}

.pagerBtn:disabled {
  opacity: .35;
  cursor: not-allowed;
}

.pagerBtn.isActive {
  color: rgba(232, 238, 252, .98);
  background: rgba(27, 42, 74, .35);
}

.pagerArrow {
  font-size: 20px;
  padding: 6px 10px;
  line-height: 1;
}

/* Botón Salir  */
#btnLogout {
  width: auto;
  padding: 8px 12px;
  height: 38px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  justify-self: end;
}

.btnGhost {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, .16);
  color: rgba(232, 238, 252, .9);
}

.btnGhost:hover {
  background: rgba(255, 255, 255, .06);
}

/*  Botón de actualizar nombres de extensiones */
.btnRefreshAgents {
  width: auto;
  padding: 8px 12px;
  height: 38px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 700;
  background: rgba(11, 19, 37, .55);
  border: 1px solid rgba(255, 255, 255, .16);
  color: rgba(232, 238, 252, .95);
  transition: background .15s ease, border-color .15s ease, transform .08s ease;
}

.btnRefreshAgents:hover {
  background: rgba(11, 19, 37, .72);
  border-color: rgba(255, 255, 255, .22);
}

.btnRefreshAgents:active {
  transform: translateY(1px);
}

.btnRefreshAgents:disabled {
  opacity: .55;
  cursor: not-allowed;
  transform: none;
}

/* Fila derecha del header de agentes */
.agentsHeaderRight {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
  text-align: right;
}

/* =========================================================
   MÓVIL: quitar espacios gigantes entre columnas
   - mantiene scroll horizontal si hace falta
   ========================================================= */
@media (max-width: 620px) {
  #rightBody {
    overflow-x: auto !important;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
  }

  /* 1) QUITAR widths del colgroup (esto es lo que te está separando TODO) */
  #rightBody table.callsTable col,
  #rightBody table.eventsTable col {
    width: auto !important;
  }

  /* 2) NO forzar una tabla gigante: deja que mida el contenido */
  #rightBody table.callsTable,
  #rightBody table.eventsTable {
    width: max-content !important;
    min-width: 0 !important;          /* <-- clave */
    table-layout: auto !important;
    border-collapse: collapse !important;
  }

  /* 3) Compacto + sin ellipsis en móvil */
  #rightBody table.callsTable th,
  #rightBody table.callsTable td,
  #rightBody table.eventsTable th,
  #rightBody table.eventsTable td {
    white-space: nowrap !important;
    overflow: visible !important;
    text-overflow: clip !important;

    padding: 6px 8px !important;
    font-size: 13px !important;
    line-height: 1.1 !important;
  }

  /* 4) Actividad más compacta (tu td era grid, lo apretamos más) */
  #rightBody table.eventsTable td:nth-child(3) {
    grid-template-columns: 22px max-content !important;
    column-gap: 6px !important;
    min-height: 0 !important;
  }

  /* 5) Si “Cuando” te queda muy ancho por el formato, fuerza 1 línea */
  #rightBody table.eventsTable td:nth-child(1) {
    white-space: nowrap !important;
  }
}