/* =============================================
   NEIX REFERIDOS -- components.css
   Botones, inputs, tabla. Estilo formal y compacto.
   ============================================= */

/* ---- form ---- */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px 16px;
}
.form-grid .full { grid-column: 1 / -1; }
.form-grid .half { grid-column: span 2; }

@media (max-width: 900px) {
  .form-grid { grid-template-columns: 1fr 1fr; }
  .form-grid .half { grid-column: span 1; }
}
@media (max-width: 560px) {
  .form-grid { grid-template-columns: 1fr; gap: 8px; }
}

.field { display: flex; flex-direction: column; gap: 3px; }
.field label {
  font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase;
  color: #6A6A6A; font-weight: 600;
}
.field label .req { color: #AB1930; margin-left: 2px; font-weight: 700; }

.field input[type="text"],
.field input[type="email"],
.field input[type="tel"],
.field input[type="date"],
.field input[type="search"],
.field select,
.field textarea {
  font: inherit;
  background: #FDFCFA;
  border: 1px solid #DCD6CC;
  padding: 7px 11px;
  color: #2A2A2A;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
  width: 100%;
  border-radius: 3px;
  font-size: 13px;
}
.field input::placeholder,
.field textarea::placeholder {
  color: #B8B2A8; font-style: italic; font-size: 12.5px;
}
.field input:hover,
.field select:hover,
.field textarea:hover {
  border-color: #B8B2A8; background: #FFFFFF;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  background: #FFFFFF;
  border-color: #AB1930;
  box-shadow: 0 0 0 3px rgba(171, 25, 48, 0.10);
}
.field textarea { min-height: 50px; resize: vertical; line-height: 1.5; }
.field .help { font-size: 10.5px; color: #9A8E7D; font-style: italic; }
.field input[readonly] {
  background: #F7F5F3; color: #6A6A6A; cursor: not-allowed;
  border-color: #EAE6E0;
}

.subsection {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid #EFEBE4;
}
.subsection:first-of-type { border-top: none; margin-top: 2px; padding-top: 0; }
.subsection h3 {
  position: relative;
  margin-bottom: 8px; padding-left: 12px;
  color: #3D3D3D;
}
.subsection h3::before {
  content: ''; position: absolute; left: 0; top: 50%;
  transform: translateY(-50%);
  width: 4px; height: 4px;
  background: #AB1930;
}

/* Barra de acciones al pie del form. */
.form-actions {
  display: flex; justify-content: flex-end; gap: 10px;
  margin-top: 14px; padding-top: 10px;
  border-top: 1px solid #EFEBE4;
}

/* ---- buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-size: 11px; letter-spacing: 0.1em;
  text-transform: uppercase; font-weight: 700;
  padding: 9px 18px; cursor: pointer; border: 1px solid transparent;
  border-radius: 2px;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.btn-primary {
  background: #AB1930; color: #FFFFFF; border-color: #AB1930;
}
.btn-primary:hover { background: #8E1326; border-color: #8E1326; }
.btn-primary:disabled { opacity: 0.5; cursor: wait; background: #AB1930; }
.btn-ghost {
  background: #FFFFFF; color: #3D3D3D; border-color: #D6D2CB;
}
.btn-ghost:hover { border-color: #AB1930; color: #AB1930; }
.btn-sm { padding: 6px 12px; font-size: 10px; }

/* Boton "danger" en estilo ghost: para acciones destructivas
   (borrar referido). Rojo discreto en reposo, llenado en hover. */
.btn-danger-ghost {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-size: 11px; letter-spacing: 0.1em;
  text-transform: uppercase; font-weight: 700;
  padding: 9px 18px; cursor: pointer;
  background: #FFFFFF; color: #AB1930;
  border: 1px solid #E6CFD3;
  border-radius: 2px;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.btn-danger-ghost:hover {
  background: #AB1930; color: #FFFFFF; border-color: #AB1930;
}
.btn-danger-ghost:disabled { opacity: 0.5; cursor: wait; }

/* ---- filtros ---- */
.filters {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
  padding: 6px 0 10px;
}
.filters select,
.filters input {
  font: inherit; font-size: 12px; padding: 6px 9px;
  border: 1px solid #D6D2CB; background: #FFFFFF;
  border-radius: 2px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.filters select:focus, .filters input:focus {
  outline: none; border-color: #AB1930;
  box-shadow: 0 0 0 2px rgba(171, 25, 48, 0.12);
}

/* ---- tabla ----
   Sin scroll horizontal: la tabla se adapta al ancho del .table-wrap.
   El scroll vertical pasa adentro de .table-wrap (max-height + overflow:
   auto) con thead sticky, asi la pagina no scrollea.
   El min-width=0 permite que la tabla se contraiga dentro de su contenedor. */
.table-wrap {
  border: 1px solid #EAE6E0;
  background: #FFFFFF;
  max-height: calc(100vh - 240px);
  overflow: auto;
  /* Scrollbar mas discreto */
  scrollbar-width: thin;
  scrollbar-color: #D6D2CB transparent;
}
.table-wrap::-webkit-scrollbar { width: 8px; height: 8px; }
.table-wrap::-webkit-scrollbar-thumb { background: #D6D2CB; border-radius: 4px; }
.table-wrap::-webkit-scrollbar-thumb:hover { background: #B8B2A8; }

table.grid {
  width: 100%; border-collapse: collapse; background: #FFFFFF;
  table-layout: auto;
}
table.grid th,
table.grid td {
  padding: 7px 10px; text-align: left; vertical-align: middle;
  border-bottom: 1px solid #F0EDE8; font-size: 12px;
  /* Por defecto NO nowrap: dejamos que el navegador acomode el texto.
     Las celdas de fecha/banca/selects no necesitan wrap porque su
     contenido es corto. Para emails largos usamos ellipsis (clase .ellip). */
}
table.grid td.nowrap { white-space: nowrap; }
table.grid td.ellip {
  max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
table.grid thead th {
  background: #F7F5F3; color: #5A5A5A;
  font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase;
  font-weight: 700;
  white-space: nowrap;
  position: sticky; top: 0; z-index: 2;
  border-bottom: 1px solid #EAE6E0;
}
table.grid tbody tr:nth-child(even) td { background: #FBFAF8; }
table.grid tbody tr:hover td { background: #F4EFE9; }

/* Celda de Contacto: email en una linea, telefono debajo en gris claro. */
.contacto-multi { line-height: 1.4; display: block; }
.contacto-multi .tel {
  display: block; color: #7A7A7A; font-size: 11px;
  font-variant-numeric: tabular-nums;
}

/* Celda editable: indicador sutil al margen izquierdo en vez de
   fondo amarillento. Limpio y se ve recien al hover. */
table.grid td.editable {
  position: relative;
}
table.grid td.editable::before {
  content: ''; position: absolute; left: 0; top: 8px; bottom: 8px;
  width: 2px; background: transparent;
  transition: background 0.15s;
}
table.grid tbody tr:hover td.editable::before { background: #E2D5BF; }
table.grid td.editable:focus-within::before { background: #AB1930; }

table.grid input,
table.grid select,
table.grid textarea {
  font: inherit; font-size: 11.5px;
  border: 1px solid transparent; background: transparent;
  padding: 3px 18px 3px 5px; outline: none;
  border-radius: 2px;
  transition: border-color 0.15s, background 0.15s;
  min-width: 0; max-width: 100%;
}
table.grid input, table.grid textarea {
  width: 100%; padding-right: 5px;
}
table.grid select {
  /* Ancho natural segun el option mas largo, no 100%. */
  width: auto; max-width: 100%;
  appearance: none; -webkit-appearance: none; -moz-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'><path fill='%238A8A8A' d='M6 8L0 0h12z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 5px center;
  background-size: 7px;
  cursor: pointer;
  /* Truncamos el texto de la option visible; el dropdown abierto
     muestra completo (limit del propio <select>). */
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
table.grid input:focus,
table.grid select:focus,
table.grid textarea:focus {
  border-color: #AB1930; background-color: #FFF;
  box-shadow: 0 0 0 2px rgba(171, 25, 48, 0.10);
}

table.grid .pill {
  display: inline-block; font-size: 10px; letter-spacing: 0.06em;
  text-transform: uppercase; padding: 2px 8px; border-radius: 2px;
  background: #F0EDE8; color: #5A5A5A; font-weight: 700;
}
table.grid .pill.privada                   { background: #F2E0E4; color: #8E1326; }
table.grid .pill.corporativa               { background: #DDE9DA; color: #3F6A36; }
table.grid .pill.productores-independientes{ background: #DEDAEC; color: #3F3F7A; }

table.grid .empty {
  text-align: center; color: #8A8A8A; padding: 28px 16px;
  background: #FBFAF8; font-size: 12.5px;
}

table.grid .dash { color: #C9C4BB; }

/* ---- KPIs por referente ----
   Tabla de agregados (no editable). Numeros alineados a la derecha,
   columna de "% abiertas" destacada porque es la metrica que se usa
   para liquidacion. */
table.grid.kpis td.num,
table.grid.kpis th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.grid.kpis th.kpi-th-ref { width: 38%; }
table.grid.kpis tbody tr:hover td { background: #F4EFE9; cursor: default; }
table.grid.kpis td.pct {
  font-weight: 600; color: #3F6A36;
}
table.grid.kpis td.pct.zero { color: #B8B2A8; font-weight: 400; }
table.grid.kpis td.zero { color: #C9C4BB; }
table.grid.kpis tfoot th,
table.grid.kpis tfoot td {
  background: #F4EFE9; border-top: 2px solid #D6D2CB;
  font-weight: 700; color: #3D3D3D;
}

/* Celda "Contacto oficial" con dot de alerta a la izquierda. */
.contacto-cell {
  display: inline-flex; align-items: center; gap: 8px;
}

/* Dot de "dias sin contactar" — solo aparece a partir de 3 dias. */
.warn-dot {
  flex-shrink: 0; width: 8px; height: 8px; border-radius: 50%;
  background: #E2D5BF; cursor: help;
  box-shadow: 0 0 0 3px rgba(226, 213, 191, 0.25);
}
.warn-dot.warn   { background: #E8A93A; box-shadow: 0 0 0 3px rgba(232, 169, 58, 0.20); }
.warn-dot.danger { background: #C12A40; box-shadow: 0 0 0 3px rgba(193, 42, 64, 0.22); }

/* Cursor pointer sobre filas clickeables. */
table.grid tbody tr.clickable { cursor: pointer; }

/* Indicador "guardando" mientras un UPDATE de celda esta en vuelo.
   Un badge chico abajo a la derecha + leve glow al borde de la celda. */
@keyframes saving-pulse {
  0%, 100% { opacity: 0.7; }
  50%      { opacity: 1; }
}
table.grid td.editable.saving::after {
  content: 'guardando';
  position: absolute;
  bottom: 1px; right: 4px;
  font-size: 8.5px; letter-spacing: 0.06em; text-transform: uppercase;
  color: #FFFFFF; font-weight: 700;
  background: #AB1930;
  padding: 1px 6px;
  border-radius: 8px;
  pointer-events: none;
  z-index: 4;
  white-space: nowrap;
  animation: saving-pulse 0.9s ease-in-out infinite;
  box-shadow: 0 1px 3px rgba(35, 30, 25, 0.18);
}
table.grid td.editable.saving::before { background: #AB1930; }
table.grid td.editable.saving select:disabled,
table.grid td.editable.saving input:disabled {
  opacity: 0.55; cursor: progress;
}

/* ---- drawer (panel lateral de detalle) ---- */
.drawer-overlay {
  position: fixed; inset: 0;
  background: rgba(35, 30, 25, 0.32);
  opacity: 0; transition: opacity 0.2s ease;
  z-index: 90;
}
.drawer-overlay.open { opacity: 1; }

.drawer {
  position: fixed; top: 0; right: 0; height: 100vh;
  width: min(540px, 92vw);
  background: #FFFFFF;
  border-left: 3px solid #AB1930;
  box-shadow: -8px 0 32px rgba(35, 30, 25, 0.12);
  transform: translateX(100%);
  transition: transform 0.22s cubic-bezier(0.32, 0.72, 0.24, 1);
  z-index: 100;
  display: flex; flex-direction: column;
}
.drawer.open { transform: translateX(0); }

.drawer-head {
  padding: 18px 22px 14px;
  border-bottom: 1px solid #EFEBE4;
  background: linear-gradient(to right, #FBF8F4, #FFFFFF);
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; flex-shrink: 0;
}
.drawer-head h2 {
  font-size: 18px; line-height: 1.25; margin: 0;
  letter-spacing: -0.005em;
}
.drawer-subtitle {
  font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase;
  color: #8A8A8A; margin-top: 4px; font-weight: 600;
}
.drawer-close {
  background: transparent; border: 1px solid transparent;
  width: 32px; height: 32px; cursor: pointer;
  font-size: 22px; line-height: 1; color: #8A8A8A;
  border-radius: 50%;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
.drawer-close:hover {
  background: #F4EFE9; color: #AB1930; border-color: #EAE6E0;
}
.drawer-close:focus { outline: none; border-color: #AB1930; }

.drawer-body {
  flex: 1; overflow-y: auto;
  padding: 8px 22px 22px;
}

.drawer-section {
  padding: 16px 0;
  border-bottom: 1px solid #F0EDE8;
}
.drawer-section:last-child { border-bottom: none; }
.drawer-section-title {
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-size: 10px; letter-spacing: 0.16em; text-transform: uppercase;
  font-weight: 700; color: #AB1930;
  margin: 0 0 12px; padding-left: 0;
}

.drawer-field {
  display: grid; grid-template-columns: 160px 1fr;
  gap: 12px; padding: 6px 0;
  align-items: start;
}
.drawer-label {
  font-size: 10.5px; letter-spacing: 0.06em; text-transform: uppercase;
  color: #8A8A8A; font-weight: 600;
  padding-top: 5px;
}
.drawer-value {
  font-size: 13px; color: #2A2A2A; word-break: break-word;
}

.drawer-input {
  font: inherit; font-size: 12.5px;
  padding: 6px 10px;
  border: 1px solid #DCD6CC; background: #FDFCFA;
  border-radius: 3px;
  width: 100%; max-width: 280px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
.drawer-input:hover { background: #FFFFFF; border-color: #B8B2A8; }
.drawer-input:focus {
  background: #FFFFFF; border-color: #AB1930;
  box-shadow: 0 0 0 3px rgba(171, 25, 48, 0.10);
}
.drawer-input:disabled { opacity: 0.6; cursor: wait; }

@media (max-width: 540px) {
  .drawer-field { grid-template-columns: 1fr; gap: 4px; }
  .drawer-label { padding-top: 0; }
  .drawer-head { padding: 14px 16px 12px; }
  .drawer-body { padding: 8px 16px 16px; }
}

/* Seccion de acciones destructivas en el drawer (borrar referido).
   Indentacion sutil para diferenciar del resto del contenido. */
.drawer-section.drawer-danger {
  padding-top: 20px;
  margin-top: 8px;
  border-top: 1px solid #EFEBE4;
  display: flex; align-items: center; gap: 14px;
}
.drawer-section.drawer-danger .drawer-danger-hint {
  font-size: 11px; color: #9A8E7D; letter-spacing: 0.04em;
  font-style: italic;
}

/* ---- modal centrado (Vincular cuenta existente) ---- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(35, 30, 25, 0.42);
  opacity: 0; transition: opacity 0.18s ease;
  z-index: 110;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 6vh 16px 24px;
  overflow-y: auto;
}
.modal-overlay.open { opacity: 1; }
.modal-overlay[hidden] { display: none; }

.modal {
  background: #FFFFFF;
  border: 1px solid #EAE6E0;
  border-top: 3px solid #AB1930;
  width: min(960px, 100%);
  box-shadow: 0 24px 64px rgba(35, 30, 25, 0.22);
  display: flex; flex-direction: column;
  max-height: calc(100vh - 12vh);
  transform: translateY(-12px);
  opacity: 0;
  transition: transform 0.22s cubic-bezier(0.32, 0.72, 0.24, 1), opacity 0.18s;
}
.modal-overlay.open .modal { transform: translateY(0); opacity: 1; }

.modal-head {
  padding: 18px 22px 14px;
  border-bottom: 1px solid #EFEBE4;
  background: linear-gradient(to right, #FBF8F4, #FFFFFF);
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; flex-shrink: 0;
}
.modal-head h2 { font-size: 18px; line-height: 1.25; margin: 0; }
.modal-head .modal-sub {
  font-size: 12px; color: #8A8A8A; margin-top: 4px; max-width: 580px;
  line-height: 1.45;
}
.modal-close {
  background: transparent; border: 1px solid transparent;
  width: 32px; height: 32px; cursor: pointer;
  font-size: 22px; line-height: 1; color: #8A8A8A;
  border-radius: 50%;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
.modal-close:hover {
  background: #F4EFE9; color: #AB1930; border-color: #EAE6E0;
}

.modal-body {
  flex: 1; overflow-y: auto;
  padding: 12px 22px 14px;
}

.modal-foot {
  padding: 12px 22px;
  border-top: 1px solid #EFEBE4;
  background: #FBFAF8;
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; flex-shrink: 0;
}
.modal-foot .modal-foot-actions { display: flex; gap: 10px; }
.modal-foot .modal-foot-info { font-size: 11.5px; color: #6A6A6A; }

/* Filas dinamicas del modal de vincular. Grid compacto. */
.vincular-rows {
  display: flex; flex-direction: column; gap: 8px;
}
.vincular-row {
  display: grid;
  grid-template-columns: 1fr 1.1fr 1.6fr 30px;
  gap: 10px; align-items: end;
  padding: 10px 12px;
  border: 1px solid #EFEBE4;
  background: #FDFCFA;
  border-radius: 3px;
  transition: border-color 0.15s, background 0.15s;
}
.vincular-row:hover { border-color: #DCD6CC; background: #FFFFFF; }
.vincular-row.invalid {
  border-color: #C12A40;
  background: #FBEFF1;
}
/* Sub-fila inline para "+ Agregar nuevo manager".
   Se inserta como ultima fila del grid de .vincular-row y ocupa
   todas las columnas. Apellido / Nombre / Email + ✓ ✕. */
.vincular-new-manager {
  grid-column: 1 / -1;
  margin-top: 4px;
  padding-top: 10px;
  border-top: 1px dashed #DCD6CC;
  display: grid;
  grid-template-columns: 1fr 1fr 1.4fr auto auto;
  gap: 8px; align-items: end;
}
.vincular-new-manager .field label {
  font-size: 9px; letter-spacing: 0.12em; color: #8A8A8A;
}
.vincular-new-manager .new-confirm,
.vincular-new-manager .new-cancel {
  border: 1px solid #DCD6CC; background: #FFFFFF;
  width: 32px; height: 32px; padding: 0;
  font-size: 14px; font-weight: 700; line-height: 1;
  cursor: pointer; border-radius: 2px;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.vincular-new-manager .new-confirm { color: #3F6A36; }
.vincular-new-manager .new-confirm:hover {
  border-color: #3F6A36; background: #EEF6EB;
}
.vincular-new-manager .new-cancel { color: #9A8E7D; }
.vincular-new-manager .new-cancel:hover {
  border-color: #AB1930; color: #AB1930;
}
@media (max-width: 760px) {
  .vincular-new-manager {
    grid-template-columns: 1fr 1fr;
  }
}
.vincular-row .field { gap: 2px; }
.vincular-row .field label {
  font-size: 9px; letter-spacing: 0.12em; color: #8A8A8A;
}
.vincular-row .field input,
.vincular-row .field select {
  font-size: 12.5px; padding: 6px 9px;
}

.vincular-row .row-remove {
  align-self: end;
  background: transparent; border: 1px solid #EAE6E0;
  width: 28px; height: 32px; padding: 0;
  cursor: pointer; color: #9A8E7D;
  font-size: 18px; line-height: 1;
  border-radius: 2px;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.vincular-row .row-remove:hover {
  color: #AB1930; border-color: #AB1930; background: #FFFFFF;
}
.vincular-row .row-remove:disabled {
  opacity: 0.3; cursor: not-allowed;
}

.modal-add-row {
  margin-top: 12px;
}

@media (max-width: 760px) {
  .vincular-row {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .vincular-row .row-remove {
    grid-column: 2; justify-self: end;
    width: auto; padding: 0 12px; height: 28px;
  }
}

/* ---- mini-boton al lado del titulo (section-head) ---- */
.btn.btn-link-action {
  background: transparent;
  border: 1px dashed #C9C4BB;
  color: #6A6A6A;
  font-size: 10.5px; letter-spacing: 0.1em;
  padding: 7px 14px;
  font-weight: 700;
}
.btn.btn-link-action:hover {
  border-color: #AB1930; border-style: solid;
  color: #AB1930; background: #FBF8F4;
}
