/* CARDS / GRID */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; margin-bottom: 24px; }
.kpi {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}
.kpi .label { color: var(--text2); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; margin-bottom: 8px; }
.kpi .value { font-size: 22px; font-weight: 700; }
.kpi .sub   { font-size: 11px; color: var(--text2); margin-top: 4px; }
.kpi.green .value { color: var(--green); }
.kpi.red   .value { color: var(--red); }

/* ── Dashboard configurable ─────────────────────────────────────── */
.dash-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 24px; }
.dash-grid > .loading, .dash-grid > .empty { grid-column: 1 / -1; }
.dw { min-width: 0; position: relative; }
.dw[data-size="s"] { grid-column: span 1; }
.dw[data-size="m"] { grid-column: span 2; }
.dw[data-size="l"] { grid-column: span 4; }
.dw > .kpi, .dw > .chart-card, .dw > .table-wrap { height: 100%; box-sizing: border-box; }
.dw-error { color: var(--red); font-size: 12px; }
.dw-table { max-height: 420px; overflow: auto; }
.dw-table table td, .dw-table table th { font-size: 12px; }
.dw-row { cursor: pointer; }
.dw-row:hover td { background: var(--bg3); }
#dash-select { background: var(--bg3); border: 1px solid var(--border); border-radius: 6px; color: var(--text); padding: 7px 10px; font-size: 13px; max-width: 220px; }
@media (max-width: 1100px) {
  .dash-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dw[data-size="l"] { grid-column: span 2; }
}
@media (max-width: 700px) {
  .dash-grid { grid-template-columns: minmax(0, 1fr); }
  .dw[data-size="s"], .dw[data-size="m"], .dw[data-size="l"] { grid-column: span 1; }
}
.dw-tools { display: none; position: absolute; top: 8px; right: 8px; gap: 4px; z-index: 2; }
.dash-grid.editing .dw-tools { display: flex; }
.dw-tools button { background: var(--bg3); border: 1px solid var(--border); color: var(--text2); border-radius: 6px; width: 26px; height: 26px; cursor: pointer; font-size: 12px; line-height: 1; padding: 0; }
.dw-tools button:hover { color: var(--text); border-color: var(--accent); }
.dw-tools .dw-handle { cursor: grab; }
.dash-grid.editing .dw > .kpi, .dash-grid.editing .dw > .chart-card, .dash-grid.editing .dw > .table-wrap { border-style: dashed; }
.dw.sortable-ghost { opacity: .35; }
.dash-toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px; }
.dash-toolbar input { background: var(--bg3); border: 1px solid var(--border); border-radius: 6px; color: var(--text); padding: 7px 10px; font-size: 13px; min-width: 200px; }
.dash-toolbar .toolbar-right { margin-left: auto; }
/* modal de widget */
#widget-overlay { position: fixed; inset: 0; background: var(--overlay); z-index: 650; display: none; align-items: center; justify-content: center; padding: 20px; }
#widget-overlay.open { display: flex; }
.wm-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.wm-field label { display: block; font-size: 11px; color: var(--text2); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .05em; }
.wm-field input, .wm-field select { width: 100%; background: var(--bg3); border: 1px solid var(--border); border-radius: 6px; color: var(--text); padding: 8px 10px; font-size: 13px; box-sizing: border-box; }
.wm-field input[type="checkbox"] { width: auto; margin-right: 6px; vertical-align: middle; }
.wm-field.full { grid-column: 1 / -1; }
.wm-section { font-weight: 600; margin: 14px 0 6px; }
.wm-preview { margin-top: 14px; }
.wm-preview .dw { display: block; }
@media (max-width: 700px) { .wm-grid { grid-template-columns: minmax(0, 1fr); } }
/* editor de filtros (reutilizable) */
.fe-row { display: flex; align-items: flex-start; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.fe-label { flex: 0 0 160px; font-size: 13px; padding-top: 5px; }
.fe-chips { flex: 1; display: flex; flex-wrap: wrap; gap: 6px; }
.fe-row input { width: 100px; background: var(--bg3); border: 1px solid var(--border); border-radius: 6px; color: var(--text); padding: 6px 8px; font-size: 13px; }
.fe-empty { color: var(--text2); font-size: 13px; padding: 4px 0; }
.fe-col { flex: 1; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.fe-row input.fe-buscar { width: 100%; max-width: 280px; }
.fe-cuenta { font-size: 11px; color: var(--text2); }
.chip[hidden] { display: none; }
.chip-cod { margin-left: 6px; font-size: 10.5px; opacity: .62; letter-spacing: .2px; }
.fe-add { margin: 8px 0 4px; }
.fe-add select { background: var(--bg3); border: 1px solid var(--border); border-radius: 6px; color: var(--text); padding: 6px 8px; font-size: 13px; min-width: 220px; }

.chart-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}
.chart-card h3 { font-size: 13px; color: var(--text2); margin-bottom: 14px; font-weight: 600; }

/* TABLES */
.table-wrap { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.table-toolbar { padding: 12px 16px; border-bottom: 1px solid var(--border); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.table-toolbar input, .table-toolbar select {
  padding: 7px 10px; background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-size: 13px; outline: none;
}
.table-toolbar input  { width: 240px; }
.table-toolbar select { width: 160px; }
.table-toolbar input:focus, .table-toolbar select:focus { border-color: var(--accent); }
.table-toolbar .toolbar-right { margin-left: auto; font-size: 12px; color: var(--text2); }
/* Tooltip para celdas truncadas (texto completo al pasar el ratón) */
#tip {
  position: fixed; z-index: 2000; pointer-events: none; max-width: 360px;
  background: var(--bg2); color: var(--text);
  border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: 8px; padding: 7px 11px; font-size: 12.5px; line-height: 1.35;
  box-shadow: 0 10px 30px var(--shadow); white-space: normal;
  opacity: 0; transform: translateY(5px) scale(.97);
  transition: opacity .15s ease, transform .15s ease;
}
#tip.show { opacity: 1; transform: translateY(0) scale(1); }

table { width: 100%; border-collapse: collapse; }
/* Las tablas de datos se ajustan SIEMPRE al ancho disponible (no desbordan):
   el texto largo se trunca con puntos suspensivos en vez de salirse. */
table:not(.comp-table) { table-layout: fixed; }
table:not(.comp-table) th, table:not(.comp-table) td {
  overflow: hidden; text-overflow: ellipsis;
}
thead th {
  padding: 10px 8px; text-align: left; font-size: 11px;
  color: var(--text2); text-transform: uppercase; letter-spacing: .04em;
  background: var(--bg3); border-bottom: 1px solid var(--border);
  white-space: nowrap; cursor: pointer; user-select: none;
}
thead th:hover { color: var(--text); }
thead th.sorted { color: var(--accent); }

/* ── RESPONSIVE: en pantallas estrechas las tablas se muestran como
   tarjetas (etiqueta: valor) para que quepan sin scroll lateral ── */
@media (max-width: 820px) {
  main { padding: 60px 12px 12px; }
  .table-toolbar input, .table-toolbar select { width: 100%; }
  /* que los contenedores no recorten las tarjetas */
  .table-wrap, .table-wrap > div, [style*="overflow-x"] { overflow: visible !important; }
  table:not(.comp-table) thead { display: none; }
  table:not(.comp-table), table:not(.comp-table) tbody { display: block; width: 100%; }
  table:not(.comp-table) tbody tr {
    display: block; margin-bottom: 10px; padding: 4px 10px;
    border: 1px solid var(--border); border-radius: 8px; background: var(--bg2);
  }
  table:not(.comp-table) tbody td {
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    padding: 8px 2px; text-align: right; border-bottom: 1px solid var(--border);
    white-space: normal !important; max-width: none !important;
    overflow: visible !important; text-overflow: clip !important; font-size: 13px;
  }
  table:not(.comp-table) tbody td:last-child { border-bottom: none; justify-content: flex-end; }
  table:not(.comp-table) tbody td::before {
    content: attr(data-label); color: var(--text2); font-size: 11px;
    font-weight: 600; text-transform: uppercase; letter-spacing: .03em;
    text-align: left; flex-shrink: 0;
  }
  table:not(.comp-table) tbody td[data-label=""]::before,
  table:not(.comp-table) tbody td:empty { display: none; }
  table:not(.comp-table) tbody td:empty { padding: 0; }
}
tbody tr { border-bottom: 1px solid var(--border); transition: background .1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg3); }
tbody td { padding: 9px 8px; font-size: 13px; white-space: nowrap; }
.tag {
  display: inline-block; padding: 2px 8px; border-radius: 12px;
  font-size: 11px; font-weight: 600; background: var(--bg3); color: var(--text2);
}
.tag.green  { background: var(--tint-green); color: var(--green); }
.tag.red    { background: var(--tint-red); color: var(--red); }
.tag.yellow { background: var(--tint-amber); color: var(--yellow); }
.tag.blue   { background: var(--tint-navy); color: var(--accent); }
.tag-warn{display:inline-block;font-size:11px;padding:2px 8px;border-radius:10px;background:var(--bg2);color:var(--red);border:1px solid var(--red);margin-left:8px}
.pos { color: var(--green); }
.neg { color: var(--red); }
.num { font-variant-numeric: tabular-nums; }

/* SCORE BAR */
.score-cell { display: flex; align-items: center; gap: 6px; }
.score-bar {
  width: 48px; height: 5px; border-radius: 3px;
  background: linear-gradient(90deg, #ef4444 0%, #f59e0b 50%, #22c55e 100%);
  position: relative; overflow: hidden; flex-shrink: 0;
}
.score-bar-fill {
  position: absolute; right: 0; top: 0; bottom: 0;
  background: var(--bg3);
}
.score-num { font-size: 12px; font-weight: 700; min-width: 32px; }

/* MODAL */
#modal-overlay {
  position: fixed; inset: 0; background: var(--overlay); z-index: 500;
  display: none; align-items: center; justify-content: center; padding: 20px;
}
#modal-overlay.open { display: flex; }
#picker-overlay {
  /* 700: el selector de fondos se abre DESDE el modal de operacion (640), asi que
     tiene que quedar por encima de el o el usuario no lo ve. */
  position: fixed; inset: 0; background: var(--overlay); z-index: 700;
  display: none; align-items: center; justify-content: center; padding: 20px;
}
#picker-overlay.open { display: flex; }
.picker-row { cursor: pointer; }
.picker-row:hover td { background: var(--bg3); }
.modal {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 12px;
  width: 1100px; max-width: 100%; max-height: 90vh; overflow-y: auto;
}
.modal-header { padding: 18px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.modal-header h2 { flex: 1; font-size: 16px; }
.modal-close { background: none; border: none; color: var(--text2); cursor: pointer; font-size: 20px; padding: 0 4px; }
.modal-body { padding: 20px; }
.modal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
@media (max-width: 600px) { .modal-grid { grid-template-columns: 1fr; } }
.modal-field { background: var(--bg3); border-radius: var(--radius); padding: 10px 12px; }
.modal-field .f-label { font-size: 10px; color: var(--text2); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 4px; }
.modal-field .f-val   { font-size: 14px; font-weight: 600; }

/* ENTIDAD */
.ent-vacio { padding: 20px; text-align: center; color: var(--text2); font-size: 13px; line-height: 1.6; }
.ent-sub   { font-size: 13px; color: var(--text2); margin-bottom: 12px; line-height: 1.6; }
.ent-fila  { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.ent-fila input[type=text], .ent-fila input[type=email], .ent-fila input[type=password], .ent-fila select {
  background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); padding: 8px 10px; font-size: 13px;
}
.ent-fila input[type=text] { min-width: 200px; }
.ent-chk { font-size: 12px; color: var(--text2); display: inline-flex; align-items: center; gap: 6px; }
.ent-usuarios-tabla select { background: var(--bg3); border: 1px solid var(--border); border-radius: 6px; color: var(--text); padding: 4px 6px; font-size: 12px; }

/* CONFIG */
.config-section { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 18px; }
.config-section h3 { font-size: 14px; font-weight: 700; margin-bottom: 14px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.upload-area {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 30px; text-align: center; cursor: pointer; transition: border-color .2s;
}
.upload-area:hover, .upload-area.drag { border-color: var(--accent); }
.upload-area p { color: var(--text2); margin-bottom: 10px; }
.upload-area input[type=file] { display: none; }
.upload-result { margin-top: 10px; font-size: 12px; }
.upload-result.ok  { color: var(--green); }
.upload-result.err { color: var(--red); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px; }
.status-dot.ok  { background: var(--green); }
.status-dot.err { background: var(--red); }
.status-dot.warn { background: var(--yellow); }

/* CHAT IA */
.chat-container { display: flex; flex-direction: column; height: calc(100vh - 160px); }
.chat-header { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius) var(--radius) 0 0; padding: 16px 20px; display: flex; align-items: center; gap: 12px; }
.chat-header h2 { font-size: 15px; font-weight: 700; }
.chat-header p  { font-size: 12px; color: var(--text2); margin-top: 2px; }
.chat-messages {
  flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 14px;
  background: var(--bg2); border-left: 1px solid var(--border); border-right: 1px solid var(--border);
}
.chat-msg { display: flex; gap: 10px; max-width: 85%; }
.chat-msg.user { align-self: flex-end; flex-direction: row-reverse; }
.chat-bubble {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 12px; padding: 10px 14px; font-size: 13px; line-height: 1.5;
}
.chat-msg.user .chat-bubble { background: var(--accent); border-color: var(--accent); color: #fff; }
.chat-msg.assistant .chat-bubble { background: var(--bg3); }
.chat-avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--bg3); border: 1px solid var(--border); display: flex; align-items: center; justify-content: center; font-size: 14px; flex-shrink: 0; }
.chat-msg.user .chat-avatar { background: var(--accent); }
.chat-footer {
  background: var(--bg2); border: 1px solid var(--border); border-top: none;
  border-radius: 0 0 var(--radius) var(--radius); padding: 14px 16px;
  display: flex; gap: 10px; align-items: flex-end;
}
.chat-footer textarea {
  flex: 1; background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); font-size: 13px; padding: 10px 12px; resize: none; outline: none;
  font-family: inherit; line-height: 1.5; max-height: 120px;
}
.chat-footer textarea:focus { border-color: var(--accent); }
.chat-send { padding: 10px 18px; background: var(--accent); color: #fff; border: none; border-radius: var(--radius); cursor: pointer; font-weight: 600; font-size: 13px; flex-shrink: 0; }
.chat-send:disabled { opacity: .5; cursor: not-allowed; }
.chat-suggestions { display: flex; gap: 8px; flex-wrap: wrap; padding: 0 0 10px; }
.chat-sugg { padding: 6px 12px; background: var(--bg3); border: 1px solid var(--border); border-radius: 20px; font-size: 12px; cursor: pointer; color: var(--text2); transition: border-color .15s; }
.chat-sugg:hover { border-color: var(--accent); color: var(--text); }
.chat-typing { color: var(--text2); font-size: 12px; font-style: italic; padding: 4px 0; }

/* COMPARADOR */
#comparador-panel {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 400;
  background: var(--bg2); border-top: 2px solid var(--accent);
  padding: 12px 24px; display: none; align-items: center; gap: 14px;
  box-shadow: 0 -4px 20px var(--shadow-soft);
}
#comparador-panel.visible { display: flex; }
.comp-fund-chip {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 6px 10px; font-size: 12px; max-width: 180px;
}
.comp-fund-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.comp-chip-rm { background: none; border: none; color: var(--text2); cursor: pointer; font-size: 14px; flex-shrink: 0; }
.comp-chip-rm:hover { color: var(--red); }
.comp-actions { margin-left: auto; display: flex; gap: 10px; align-items: center; }
#comp-modal {
  position: fixed; inset: 0; background: var(--overlay-strong); z-index: 600;
  display: none; align-items: center; justify-content: center; padding: 20px;
}
#comp-modal.open { display: flex; }
#comp-cli-modal {
  position: fixed; inset: 0; background: var(--overlay-strong); z-index: 600;
  display: none; align-items: center; justify-content: center; padding: 20px;
}
#comp-cli-modal.open { display: flex; }
#grupo-inf-modal {
  position: fixed; inset: 0; background: var(--overlay-strong); z-index: 600;
  display: none; align-items: center; justify-content: center; padding: 20px;
}
#grupo-inf-modal.open { display: flex; }
/* Barra de selección para comparar clientes */
.selbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--bg3); }
.selbar .sb-chip { display: inline-flex; align-items: center; gap: 6px; background: var(--bg2);
  border: 1px solid var(--accent); border-radius: 20px; padding: 4px 10px; font-size: 12px; }
.selbar .sb-chip button { background: none; border: none; color: var(--text2); cursor: pointer; font-size: 13px; }
.selbar .sb-chip button:hover { color: var(--red); }
tr.sel-cli { background: var(--tint-blue-soft); }
.btn-star{background:none;border:none;cursor:pointer;font-size:16px;color:var(--text2)} .btn-star.on{color:var(--accent)} tr.sep-fav td{font-size:11px;letter-spacing:.06em;text-transform:uppercase;color:var(--text2);background:var(--bg2)}
.comp-modal-box {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 12px;
  width: 1100px; max-width: 100%; max-height: 90vh; overflow: auto;
}
.comp-table { width: 100%; border-collapse: collapse; }
.comp-table th, .comp-table td { padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 13px; }
.comp-table th { background: var(--bg3); color: var(--text2); font-size: 11px; text-transform: uppercase; }
.comp-table td:first-child { color: var(--text2); font-size: 12px; font-weight: 600; }
.comp-best { color: var(--green); font-weight: 700; }

/* LOADING / EMPTY */
.loading, .empty { text-align: center; padding: 60px; color: var(--text2); }
.loading::after { content: ''; display: inline-block; width: 20px; height: 20px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin-left: 10px; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

/* TOGGLE */
.toggle-group { display: flex; background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.toggle-group button { padding: 6px 14px; background: none; border: none; color: var(--text2); cursor: pointer; font-size: 12px; font-weight: 500; transition: background .15s, color .15s; }
.toggle-group button.active { background: var(--accent); color: #fff; }
/* Chips seleccionables (filtros por categoria) */
.chip { display:inline-flex; align-items:center; padding:5px 11px; border-radius:999px; border:1px solid var(--border); background:var(--bg3); color:var(--text2); cursor:pointer; font-size:12px; line-height:1; user-select:none; transition:background .12s, color .12s, border-color .12s; }
.chip:hover { color:var(--text); border-color:var(--accent); }
.chip.on { background:var(--accent); border-color:var(--accent); color:#fff; }
/* Slider fluido */
input[type=range] { accent-color: var(--accent); height:4px; cursor:pointer; }

/* ORIGEN DEL DATO (hoja vs API/calculado) — tinte sutil por celda */
.src-hoja { background: var(--tint-blue-soft); }
.src-api  { background: var(--tint-amber-soft); }
.src-na   { background: repeating-linear-gradient(45deg, transparent, transparent 4px, var(--tint-gray-soft) 4px, var(--tint-gray-soft) 8px); color: var(--text2) !important; }
.origen-legend { display:flex; gap:16px; flex-wrap:wrap; align-items:center; font-size:12px; color:var(--text2); padding:8px 2px 12px; }
.origen-legend .lg { display:inline-flex; align-items:center; gap:6px; }
.origen-legend .sw { width:13px; height:13px; border-radius:3px; display:inline-block; border:1px solid var(--border); }
.origen-legend .sw.hoja { background: var(--tint-blue); }
.origen-legend .sw.api  { background: var(--tint-amber-strong); }
.origen-legend .sw.na   { background: repeating-linear-gradient(45deg, transparent, transparent 3px, var(--tint-gray) 3px, var(--tint-gray) 6px); }

/* ── TRANSVERSAL (rediseño 2026-09): foco, deshabilitado, peligro, error ── */
:root { --disabled-opacity: .45; }
:where(button, [role=button], a, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
button:disabled, .btn-sm:disabled, .btn-primary:disabled, .btn-cfg:disabled, .btn-danger:disabled {
  opacity: var(--disabled-opacity); cursor: not-allowed;
}
.btn-primary:disabled:hover { opacity: var(--disabled-opacity); }
.btn-danger { background: transparent; border: 1px solid var(--red); color: var(--red); border-radius: var(--radius); padding: 6px 12px; font-size: 12px; cursor: pointer; }
.btn-danger:hover:not(:disabled) { background: var(--tint-red); }
.zona-peligro { border: 1px solid var(--red); border-radius: var(--radius-lg); padding: 16px 18px; margin-top: 24px; background: var(--bg2); }
.zona-peligro h3 { color: var(--red); border-bottom: 1px solid var(--tint-red); font-size: 14px; font-weight: 700; margin-bottom: 12px; padding-bottom: 10px; }
.zona-peligro p { font-size: 13px; color: var(--text2); margin-bottom: 12px; line-height: 1.6; }
.estado-error { border: 1px solid var(--red); border-left: 4px solid var(--red); border-radius: var(--radius); padding: 14px 16px; color: var(--text); background: var(--bg2); display: flex; gap: 12px; align-items: center; flex-wrap: wrap; font-size: 13px; }
.estado-error .ico { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--red); color: var(--red); display: inline-grid; place-items: center; font-weight: 700; font-size: 13px; flex-shrink: 0; }
.estado-error .btn-sm { margin-left: auto; }

/* menú de acciones («⋯» por fila) */
.btn-dots { width: 30px; height: 26px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg3); color: var(--text2); cursor: pointer; font-weight: 700; letter-spacing: 1px; line-height: 1; padding: 0; }
.btn-dots:hover { color: var(--text); border-color: var(--accent); }
.menu-acciones { position: fixed; z-index: 950; min-width: 210px; background: var(--bg2); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 12px 32px var(--shadow); padding: 6px; display: flex; flex-direction: column; }
.menu-acciones button { text-align: left; background: none; border: none; color: var(--text); padding: 8px 10px; border-radius: 6px; font-size: 13px; cursor: pointer; }
.menu-acciones button:hover:not(:disabled), .menu-acciones button:focus-visible { background: var(--bg3); outline: none; }
.menu-acciones button.peligro { color: var(--red); }
.menu-acciones .menu-sep { height: 1px; background: var(--border); margin: 4px 2px; }

/* pestañas */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin: 6px 0 14px; overflow-x: auto; }
.tab { padding: 9px 14px; background: none; border: none; border-bottom: 2px solid transparent; margin-bottom: -1px; color: var(--text2); font-size: 13px; font-weight: 500; cursor: pointer; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.tab-badge { display: inline-block; min-width: 18px; padding: 1px 6px; border-radius: 999px; background: var(--bg3); font-size: 11px; color: var(--text2); }

/* banda de frescura de los datos de mercado */
.banda-frescura { display: flex; align-items: center; gap: 10px; padding: 9px 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg2); font-size: 12.5px; margin-bottom: 14px; }
.banda-frescura .bf-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text2); flex-shrink: 0; }
.banda-frescura.ok .bf-dot { background: var(--green); }
.banda-frescura.warn .bf-dot { background: var(--yellow); }
.banda-frescura.err .bf-dot { background: var(--red); }
.banda-frescura.err { border-color: var(--red); }
.banda-frescura .bf-txt { flex: 1; min-width: 0; }
.banda-frescura .bf-link { background: none; border: none; color: var(--accent-soft); font-weight: 500; cursor: pointer; font-size: 12.5px; padding: 0; white-space: nowrap; }

/* tabla única de fondos */
.tabla-scroll { overflow-x: auto; }
.tabla-fondos { min-width: 720px; }
.tabla-fondos th .th-btn { background: none; border: none; color: inherit; font: inherit; text-transform: inherit; letter-spacing: inherit; cursor: pointer; padding: 0; }
.tabla-fondos th.sorted .th-btn { color: var(--accent-soft); }
.tabla-fondos td.col-nombre { max-width: 280px; }
.tabla-fondos td.col-nombre .nombre { display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; vertical-align: middle; }
.tabla-fondos .en-cartera { color: var(--accent); margin-right: 5px; font-size: 9px; vertical-align: 2px; }
.tabla-fondos td.col-txt .txt2 { color: var(--text2); font-size: 12px; }
.tabla-fondos tr.fila-clic { cursor: pointer; }
.tabla-fondos tr.fila-clic:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.tabla-fondos th.col-acciones, .tabla-fondos td.col-acciones { width: 44px; text-align: right; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* modal genérico (modalAbrir): por encima del selector de fondos (700) */
.modal-overlay { position: fixed; inset: 0; background: var(--overlay); z-index: 760; display: none; align-items: center; justify-content: center; padding: 20px; }
.modal-overlay.open { display: flex; }
.modal.modal-s { width: 460px; }
.modal.modal-m { width: 720px; }

/* menú lateral: separador y entidad en la cabecera de la marca */
.nav-sep { height: 1px; background: var(--border); margin: 6px 8px; }
.sidebar .brand .brand-txt { min-width: 0; }
.sidebar .brand p { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 140px; }

.btn-link { background: none; border: none; color: var(--accent-soft); cursor: pointer; padding: 0; font: inherit; text-decoration: underline; text-underline-offset: 2px; }
.btn-link:hover { color: var(--text); }

/* ── B4 · Registrar operación (40-operaciones.js) y selector de fondos por teclado ── */
#op-overlay [hidden] { display: none !important; }
#op-overlay .modal-body { max-height: calc(100vh - 80px); overflow-y: auto; }
.op-tab { background: var(--bg3); border: 1px solid var(--border); color: var(--text2); border-radius: 999px; padding: 6px 12px; font-size: 12.5px; cursor: pointer; }
.op-tab:hover { color: var(--text); }
.op-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.op-tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.op-banner { background: var(--bg3); border: 1px solid var(--border); border-radius: 6px; padding: 9px 11px; font-size: 12.5px; margin-top: 10px; }
.op-fila { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; margin-bottom: 10px; align-items: start; }
.op-campo label { display: block; font-size: 11px; color: var(--text2); margin-bottom: 3px; }
.op-campo input:not([type="checkbox"]):not([type="radio"]), .op-campo select, .op-fondo {
  display: block; width: 100%; box-sizing: border-box; background: var(--bg3); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text); padding: 8px 10px; font-size: 13px; font: inherit; font-size: 13px; text-align: left;
}
.op-campo input:focus-visible, .op-campo select:focus-visible, .op-fondo:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.op-campo input[aria-invalid="true"], .op-campo select[aria-invalid="true"], .op-fondo[aria-invalid="true"] { border-color: var(--red); }
.op-campo input:disabled { opacity: .5; cursor: not-allowed; }
.op-control { position: relative; }
.op-control .op-sufijo { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); font-size: 12px; color: var(--text2); pointer-events: none; }
.op-control input { padding-right: 26px; }
.op-fondo { cursor: pointer; }
.op-fondo-txt { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.op-req { color: var(--red); font-weight: 600; }
.op-ayuda { font-size: 11px; color: var(--text2); margin-top: 3px; line-height: 1.4; }
.op-err { font-size: 11.5px; color: var(--red); margin-top: 3px; line-height: 1.4; }
.op-err:empty { display: none; }
.op-check label { font-size: 12.5px; color: var(--text); display: flex; align-items: center; gap: 6px; }
.op-check { margin-bottom: 10px; }
.op-detalles { margin: 4px 0 10px; border: 1px solid var(--border); border-radius: 6px; padding: 0 12px; }
.op-detalles summary { cursor: pointer; font-size: 12.5px; color: var(--text2); padding: 8px 0; }
.op-detalles summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.op-detalles-cuerpo { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; padding-bottom: 12px; }
.op-reparto { border: none; padding: 0; margin: 0 0 8px; display: flex; gap: 14px; flex-wrap: wrap; align-items: center; font-size: 12.5px; }
.op-reparto legend { font-size: 11px; color: var(--text2); padding: 0; margin-bottom: 4px; float: left; margin-right: 8px; }
.op-reparto label { display: flex; align-items: center; gap: 5px; }
.op-reparto .op-err { flex-basis: 100%; }
.op-destino { display: grid; grid-template-columns: 2fr 1fr 1fr auto; gap: 8px; margin-bottom: 8px; align-items: start; }
.op-destino .op-quitar { margin-top: 18px; color: var(--red); }
.op-nota { font-size: 12px; color: var(--text2); }
.op-error { background: var(--bg3); border: 1px solid var(--red); border-radius: 6px; padding: 10px 12px; font-size: 12.5px; color: var(--red); }
.op-previa { background: var(--bg3); border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; font-size: 12.5px; }
.op-previa-linea { margin-bottom: 4px; }
.op-previa-tipo { color: var(--text2); }
.op-previa-cartera { color: var(--text2); margin-top: 6px; }
.op-aviso { color: var(--yellow); font-size: 12px; margin-top: 4px; }
#op-preview { transition: opacity .15s ease; }
#op-preview.op-previa-stale { opacity: .45; }
.picker-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.picker-row:focus-visible td { background: var(--bg3); }
@media (max-width: 640px) {
  .op-fila, .op-detalles-cuerpo { grid-template-columns: 1fr; }
  .op-destino { grid-template-columns: 1fr 1fr; }
}

/* ── CRITERIOS (Fondos y Alertas) ────────────────────────────────── */
/* Una condición sobre una métrica: la misma fila filtra la tabla, pesa la
   puntuación y define una alerta. */
.crit { padding: 9px 0; border-bottom: 1px solid var(--border); }
.crit .fila { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.crit .fila.cola { margin-top: 6px; }
.crit .met { background: var(--bg3); border: 1px solid var(--border); border-radius: 7px;
  padding: 5px 9px; font-size: 12px; font-weight: 500; color: var(--text); cursor: pointer;
  display: inline-flex; gap: 6px; align-items: center; font-family: inherit; }
.crit .met:hover { border-color: var(--accent); }
.crit .met small { color: var(--text2); font-weight: 400; }
.crit .met.est, .crit .sel.est { cursor: default; }
.crit .sel { background: var(--inset); border: 1px solid var(--border); border-radius: 7px;
  padding: 5px 8px; font-size: 12px; color: var(--text); font-family: inherit; }
.crit .val { background: var(--inset); border: 1px solid var(--border); border-radius: 7px;
  padding: 5px 8px; font-size: 12px; font-family: var(--mono); width: 82px; text-align: right;
  color: var(--text); }
.crit .desc { flex: 1; min-width: 150px; background: var(--inset); border: 1px solid var(--border);
  border-radius: 7px; padding: 5px 8px; font-size: 12px; color: var(--text); font-family: inherit; }
.crit .un { color: var(--text2); font-size: 11px; }
.crit .un.cat { display: inline-flex; gap: 4px; align-items: center; cursor: pointer; }
.crit .cnt { margin-left: auto; font-size: 11px; color: var(--text2); font-family: var(--mono);
  white-space: nowrap; }
.crit .cnt.cero { color: var(--red); }
.crit .x { background: none; border: 0; color: var(--text2); cursor: pointer; padding: 2px 4px;
  font-size: 13px; border-radius: 5px; }
.crit .x:hover { color: var(--red); background: var(--bg3); }
.crit .rango { display: flex; gap: 8px; align-items: center; margin-top: 5px;
  font-size: 11px; color: var(--text2); }
.crit .chips { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 6px; }
.crit .chips .chip { cursor: pointer; font-size: 11px; padding: 2px 9px; }
.hist { display: inline-flex; gap: 1px; align-items: flex-end; height: 14px; }
.hist i { width: 5px; display: block; background: var(--border); border-radius: 1px; }
.hist i.on { background: var(--accent); }
.imp { display: inline-flex; border: 1px solid var(--border); border-radius: 7px; overflow: hidden; }
.imp button { background: none; border: 0; padding: 4px 8px; font-size: 11px; color: var(--text2);
  cursor: pointer; font-family: inherit; }
.imp button.on { background: var(--tint-blue); color: var(--accent-soft); font-weight: 600; }
.imp button:hover:not(.on) { background: var(--bg3); }
.crit .pct { font-family: var(--mono); font-size: 11px; color: var(--text2); width: 42px;
  text-align: right; }

/* Buscador de métricas: 28 métricas no se eligen en un desplegable plano. */
.buscador-metricas { position: fixed; z-index: 950; width: 380px; max-width: calc(100vw - 16px);
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: 0 16px 40px var(--shadow); font-size: 12px; }
.buscador-metricas .q { padding: 10px; }
.buscador-metricas .q input { width: 100%; background: var(--inset); border: 1px solid var(--border);
  border-radius: 7px; padding: 7px 10px; color: var(--text); font-size: 13px; font-family: inherit; }
.buscador-metricas .lista { max-height: 320px; overflow: auto; }
.buscador-metricas .grp { padding: 6px 12px 2px; color: var(--text2); font-size: 10px;
  text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.buscador-metricas .it { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px;
  padding: 7px 12px; border-top: 1px solid var(--border); cursor: pointer; }
.buscador-metricas .it.foco { background: var(--tint-blue-soft); }
.buscador-metricas .it.usada { opacity: .5; }
.buscador-metricas .it b { font-weight: 500; }
.buscador-metricas .it small { grid-column: 1 / -1; color: var(--text2); }
.buscador-metricas .it .rg { font-family: var(--mono); color: var(--text2); font-size: 11px; }
.buscador-metricas .vacio, .buscador-metricas .pie { padding: 10px 12px; color: var(--text2);
  border-top: 1px solid var(--border); font-size: 11px; }

/* Cajón lateral de criterios: se ve la tabla moverse mientras se ajusta, y por
   eso no hace falta un botón «Aplicar». */
/* Por debajo de los dialogos (700) y de la ficha de fondo: el cajon acompaña a
   la pantalla, no la bloquea, asi que un «Guardar como…» se abre encima y no
   detras. El buscador de metricas (950) sigue por encima del cajon. */
.modal-overlay.cajon-criterios { justify-content: flex-end; padding: 0; background: none;
  pointer-events: none; z-index: 690; }
.modal-overlay.cajon-criterios .modal { pointer-events: auto; width: 540px; max-width: 100%;
  height: 100vh; max-height: 100vh; border-radius: 0; border-top: 0; border-bottom: 0;
  border-right: 0; box-shadow: -12px 0 32px var(--shadow); display: flex; flex-direction: column; }
.modal-overlay.cajon-criterios .modal-body { flex: 1; overflow: auto; }
.cajon-intro { margin: 0 0 12px; font-size: 12px; color: var(--text2); }
#cajon-fondos .sec, #cajon-alertas .sec { font-size: 11px; font-weight: 600; letter-spacing: .05em;
  text-transform: uppercase; color: var(--text2); margin: 18px 0 4px; }
#cajon-fondos .sec:first-of-type, #cajon-alertas .sec:first-of-type { margin-top: 0; }
#cajon-fondos .sec small, #cajon-alertas .sec small { font-weight: 400; text-transform: none; letter-spacing: 0;
  margin-left: 6px; font-family: var(--mono); }
#cajon-fondos .vacio, #cajon-alertas .vacio { font-size: 12px; color: var(--text2); padding: 6px 0; margin: 0; }
#cajon-fondos .chip.add, #cajon-alertas .chip.add { margin-top: 8px; }
.cajon-presets { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 10px;
  font-size: 11px; color: var(--text2); }
.cajon-pie { position: sticky; bottom: 0; margin: 18px -18px -16px; padding: 12px 18px;
  background: var(--bg2); border-top: 1px solid var(--border); display: flex; gap: 8px;
  align-items: center; flex-wrap: wrap; }
.cajon-pie .btn-primary { width: auto; padding: 8px 16px; }
.cajon-pie .total { margin-left: auto; font-size: 12px; color: var(--text2);
  font-family: var(--mono); }
#cajon-alertas .fila-cfg { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.crit.destacada { background: var(--tint-blue-soft); border-radius: 8px; }

/* El boton de tema vive fijo en la esquina superior derecha, que es justo donde
   el cajon pone su ✕: tapaba el unico boton para cerrarlo. Mientras el cajon
   esta abierto se retira (el tema tambien se cambia en Ajustes · Mi cuenta). */
body.con-cajon .theme-toggle { display: none; }
