:root {
  --fondo: #f4f6f9;
  --panel: #ffffff;
  --borde: #dfe3ea;
  --borde-suave: #edf0f4;
  --texto: #1d2430;
  --texto-suave: #5b6576;
  --acento: #1f6feb;
  --acento-suave: #e8f0fe;
  --cebra: #fafbfd;
  --hover: #eef4ff;
  --ok: #1a7f37;
  --alerta: #b35900;
  --error: #c62828;
  --pii: #7c3aed;
  --fila: 30px;
  --ancho-num: 56px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  font-size: 13px;
  color: var(--texto);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { display: grid; grid-template-rows: auto auto 1fr auto; background: var(--fondo); overflow: hidden; }

button, input, select { font: inherit; color: inherit; }
.btn {
  border: 1px solid var(--borde); background: var(--panel); border-radius: 6px;
  padding: 5px 10px; cursor: pointer; white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: #b9c2d0; background: #f7f9fc; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primario { background: var(--acento); border-color: var(--acento); color: #fff; }
.btn.primario:hover { background: #1a5fd0; }
.espacio { flex: 1; }

/* ── barra superior ─────────────────────────────────────────────────────── */
.barra {
  display: flex; align-items: center; gap: 18px; padding: 8px 16px;
  background: #16213a; color: #e9eef7;
}
.marca { display: flex; align-items: center; gap: 10px; min-width: 230px; }
.logo { font-size: 22px; color: #7fb0ff; }
.marca h1 { font-size: 15px; margin: 0; font-weight: 600; }
.marca p { margin: 0; font-size: 11px; color: #9fb0cc; }
.pestanas { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.pestana {
  border: 0; background: transparent; color: #c9d4e6; padding: 7px 12px; border-radius: 6px;
  cursor: pointer; display: flex; flex-direction: column; align-items: flex-start; line-height: 1.2;
}
.pestana:hover { background: rgba(255, 255, 255, .08); }
.pestana.activa { background: #fff; color: var(--texto); }
.pestana b { font-size: 13px; font-weight: 600; }
.pestana small { font-size: 11px; opacity: .8; }
.pestana .punto { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 5px; background: #8a94a6; }
.punto.ok { background: #3fb950; } .punto.viejo { background: #d29922; } .punto.error { background: #f85149; }

.mascara { background: transparent; color: #e9eef7; border-color: rgba(255, 255, 255, .25); }
.mascara:hover:not(:disabled) { background: rgba(255, 255, 255, .08); border-color: rgba(255, 255, 255, .4); }
.mascara.activa { background: #233454; }
.mascara:not(.activa) { background: #7a2e0e; border-color: #c2410c; }
.mascara .icono { margin-right: 6px; }

/* ── herramientas ───────────────────────────────────────────────────────── */
.herramientas {
  display: flex; align-items: center; gap: 10px; padding: 8px 16px;
  background: var(--panel); border-bottom: 1px solid var(--borde);
}
.buscar input {
  width: 340px; padding: 6px 10px; border: 1px solid var(--borde); border-radius: 6px; background: #fbfcfe;
}
.buscar input:focus, .grilla thead input:focus, .ficha input:focus, .popover input:focus {
  outline: 2px solid var(--acento-suave); border-color: var(--acento);
}
.chk { display: inline-flex; align-items: center; gap: 5px; color: var(--texto-suave); cursor: pointer; white-space: nowrap; }
.frescura { color: var(--texto-suave); font-size: 12px; white-space: nowrap; }

/* ── grilla ─────────────────────────────────────────────────────────────── */
.contenedor { position: relative; min-height: 0; padding: 0; }
.grilla { position: absolute; inset: 0; overflow: auto; background: var(--panel); outline: none; }
.grilla table { border-collapse: separate; border-spacing: 0; table-layout: fixed; width: max-content; }
.grilla th, .grilla td {
  border-right: 1px solid var(--borde-suave); border-bottom: 1px solid var(--borde-suave);
  padding: 0 8px; height: var(--fila); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  text-align: left;
}
.grilla thead th { position: sticky; background: #f0f3f8; z-index: 2; font-weight: 600; }
.grilla thead tr.nombres th { top: 0; height: 32px; user-select: none; cursor: pointer; }
.grilla thead tr.filtros th { top: 32px; padding: 3px 4px; cursor: default; background: #f7f9fc; border-bottom: 1px solid var(--borde); }
.grilla thead tr.nombres th:hover { background: #e7ecf4; }
.grilla thead th .nom { overflow: hidden; text-overflow: ellipsis; display: block; padding-right: 14px; }
.grilla thead th .flecha { position: absolute; right: 10px; top: 9px; color: var(--acento); font-size: 11px; }
.grilla thead th .pii { color: var(--pii); font-size: 11px; margin-right: 3px; }
.grilla thead th .fija { color: var(--texto-suave); font-weight: 500; font-style: italic; }
.grilla thead input {
  width: 100%; height: 24px; border: 1px solid var(--borde); border-radius: 4px; padding: 0 6px;
  background: #fff; font-size: 12px;
}
.grilla thead input.con-valor { border-color: var(--acento); background: var(--acento-suave); }
.redim { position: absolute; top: 0; right: -3px; width: 7px; height: 100%; cursor: col-resize; z-index: 3; }
.redim:hover, .redim.activo { background: var(--acento); opacity: .4; }

.grilla th.num, .grilla td.num {
  position: sticky; left: 0; z-index: 1; background: #f0f3f8; color: var(--texto-suave);
  text-align: right; font-variant-numeric: tabular-nums; font-size: 11px;
}
.grilla thead th.num { z-index: 4; }
.grilla th.fijo-id, .grilla td.fijo-id {
  position: sticky; left: var(--ancho-num); z-index: 1; border-right: 1px solid var(--borde);
}
.grilla td.fijo-id { background: inherit; font-family: Consolas, "Cascadia Mono", monospace; font-size: 12px; }
.grilla thead th.fijo-id { z-index: 4; }

.grilla tbody tr { background: var(--panel); cursor: pointer; }
.grilla tbody tr:nth-child(even) { background: var(--cebra); }
.grilla tbody tr:hover { background: var(--hover); }
.grilla tbody tr.seleccionada { background: #dbe7fd; }
.grilla tbody td.fijo-id { background: inherit; }
.grilla td.t-numero { text-align: right; font-variant-numeric: tabular-nums; }
.grilla td.t-fecha { font-variant-numeric: tabular-nums; color: #2b3445; }
.grilla td.vacia { color: #b4bcc8; }
.grilla td .borrado { color: var(--error); font-weight: 600; }
.grilla td .estado-OK { color: var(--ok); font-weight: 600; }
.grilla td .estado-ERROR { color: var(--error); font-weight: 600; }
.grilla td .estado-EN_CURSO { color: var(--alerta); font-weight: 600; }

.vacio { padding: 40px; text-align: center; color: var(--texto-suave); }
.cargando {
  position: absolute; top: 80px; left: 50%; transform: translateX(-50%); background: #16213a; color: #fff;
  padding: 8px 14px; border-radius: 20px; font-size: 12px; box-shadow: 0 4px 16px rgba(0, 0, 0, .2); z-index: 10;
}
.spinner {
  display: inline-block; width: 11px; height: 11px; border: 2px solid rgba(255, 255, 255, .35);
  border-top-color: #fff; border-radius: 50%; animation: gira .7s linear infinite; vertical-align: -1px; margin-right: 6px;
}
@keyframes gira { to { transform: rotate(360deg); } }

/* ── pie ────────────────────────────────────────────────────────────────── */
.pie {
  display: flex; align-items: center; gap: 16px; padding: 6px 16px;
  background: var(--panel); border-top: 1px solid var(--borde); color: var(--texto-suave);
}
.pie select { margin-left: 6px; border: 1px solid var(--borde); border-radius: 5px; padding: 2px 4px; background: #fff; }
.paginador { display: flex; align-items: center; gap: 4px; }
.paginador .btn { padding: 2px 9px; }
#pag-texto { min-width: 120px; text-align: center; color: var(--texto); }

/* ── ficha ──────────────────────────────────────────────────────────────── */
.ficha {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 92vw); background: var(--panel);
  box-shadow: -8px 0 28px rgba(15, 23, 42, .18); display: flex; flex-direction: column; z-index: 20;
}
.ficha-cab { display: flex; justify-content: space-between; align-items: flex-start; padding: 14px 16px 8px; }
.ficha-fuente { font-size: 11px; font-weight: 700; color: var(--acento); letter-spacing: .06em; }
.ficha-id { font-family: Consolas, "Cascadia Mono", monospace; font-size: 15px; font-weight: 600; margin-top: 2px; word-break: break-all; }
.cerrar { padding: 2px 9px; }
.ficha-meta { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 16px 10px; }
.sesion { display: inline-flex; align-items: center; gap: 8px; font-size: 12px; color: var(--texto-suave); }
.sesion b { color: var(--texto); }
.sesion .btn { padding: 4px 10px; }

.chip { background: #f0f3f8; border-radius: 12px; padding: 2px 9px; font-size: 11px; color: var(--texto-suave); }
.chip b { color: var(--texto); font-weight: 600; }
.chip.rojo { background: #fdecec; color: var(--error); }
.ficha-tabs { display: flex; gap: 2px; padding: 0 16px; border-bottom: 1px solid var(--borde); }
.tab { border: 0; background: transparent; padding: 8px 12px; cursor: pointer; color: var(--texto-suave); border-bottom: 2px solid transparent; }
.tab.activa { color: var(--acento); border-bottom-color: var(--acento); font-weight: 600; }
.ficha-cuerpo { overflow: auto; padding: 10px 16px 24px; flex: 1; }
.ficha-cuerpo input[type=search] { width: 100%; padding: 6px 9px; border: 1px solid var(--borde); border-radius: 6px; margin-bottom: 6px; }
.campos { display: grid; grid-template-columns: minmax(140px, 38%) 1fr; margin: 8px 0 0; }
.campos dt, .campos dd { margin: 0; padding: 5px 6px; border-bottom: 1px solid var(--borde-suave); }
.campos dt { color: var(--texto-suave); font-size: 12px; word-break: break-word; }
.campos dd { word-break: break-word; white-space: pre-wrap; }
.campos dd.vacia { color: #b4bcc8; }
.campos dt .pii { color: var(--pii); }
.historial { list-style: none; padding: 0; margin: 4px 0; }
.historial li { border-left: 2px solid var(--acento); padding: 2px 0 12px 14px; position: relative; }
.historial li::before { content: ""; position: absolute; left: -6px; top: 5px; width: 10px; height: 10px; border-radius: 50%; background: #fff; border: 2px solid var(--acento); }
.historial li.volatil { border-left-color: #c3cad6; }
.historial li.volatil::before { border-color: #c3cad6; }
.historial .cuando { font-weight: 600; }
.historial .cuando small { color: var(--texto-suave); font-weight: 400; margin-left: 6px; }
.cambio { display: grid; grid-template-columns: minmax(110px, 30%) 1fr; gap: 2px 8px; margin-top: 5px; font-size: 12px; }
.cambio .col { color: var(--texto-suave); word-break: break-word; }
.cambio .antes { text-decoration: line-through; color: #a33; word-break: break-word; }
.cambio .despues { color: var(--ok); word-break: break-word; }
.sin-historial { color: var(--texto-suave); padding: 16px 0; }
#ficha-cotizaciones h4 { margin: 14px 0 4px; font-size: 13px; }
#ficha-cotizaciones h4:first-child { margin-top: 4px; }
.nota-cot { color: var(--texto-suave); margin: 2px 0 6px; font-size: 12px; }
.por-fuente { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0 6px; }
.cotizaciones { border-collapse: collapse; width: 100%; font-size: 12px; margin-bottom: 8px; }
.cotizaciones th { text-align: left; color: var(--texto-suave); font-weight: 600; border-bottom: 1px solid var(--borde); padding: 4px 6px; white-space: nowrap; }
.cotizaciones td { border-bottom: 1px solid var(--borde-suave); padding: 4px 6px; word-break: break-word; }
.cotizaciones tbody tr { cursor: pointer; }
.cotizaciones tbody tr:hover { background: var(--hover); }
.cotizaciones tbody tr.actual { background: var(--acento-suave); cursor: default; font-weight: 600; }

/* ── popovers y avisos ──────────────────────────────────────────────────── */
.popover {
  position: fixed; background: var(--panel); border: 1px solid var(--borde); border-radius: 8px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, .18); z-index: 30; width: 340px; max-height: 70vh;
  display: flex; flex-direction: column;
}
.pop-cab { display: flex; gap: 6px; padding: 8px; border-bottom: 1px solid var(--borde); }
.pop-cab input { flex: 1; min-width: 0; padding: 5px 8px; border: 1px solid var(--borde); border-radius: 5px; }
.col-lista { list-style: none; margin: 0; padding: 4px 0; overflow: auto; }
.col-lista li label { display: flex; gap: 8px; padding: 4px 12px; cursor: pointer; }
.col-lista li label:hover { background: var(--hover); }
.ayuda { padding: 12px 16px; width: 420px; }
.ayuda h3 { margin: 0 0 8px; font-size: 14px; }
.ayuda table { border-collapse: collapse; width: 100%; }
.ayuda td { padding: 4px 6px; border-bottom: 1px solid var(--borde-suave); vertical-align: top; }
.ayuda code, .ayuda kbd { background: #f0f3f8; padding: 1px 5px; border-radius: 4px; font-family: Consolas, monospace; }
.ayuda p { color: var(--texto-suave); margin: 10px 0 0; line-height: 1.45; }
.ayuda .nota { color: var(--pii); }
.aviso {
  position: fixed; bottom: 54px; left: 50%; transform: translateX(-50%); background: #3b1d1d; color: #fff;
  padding: 9px 16px; border-radius: 8px; z-index: 40; max-width: 70vw; box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
}
.aviso.info { background: #16213a; }
.historial li.sin-historial { border-left: 0; padding-left: 0; }
.historial li.sin-historial::before { display: none; }
.cambio .antes, .cambio .despues { display: inline; }
.volatil { color: #a16207; font-weight: 700; margin-right: 3px; }
#ficha-ruido-l { margin-bottom: 6px; white-space: normal; }

.campos dd .procedencia { display: block; font-size: 11px; color: var(--texto-suave); white-space: normal; margin-top: 2px; }
