/* Cartera IyM — mobile-first, tokens light/dark del sistema de dataviz */

:root {
  color-scheme: light;
  --fondo: #f9f9f7;
  --superficie: #fcfcfb;
  --tinta: #0b0b0b;
  --tinta-2: #52514e;
  --tinta-mut: #898781;
  --hairline: #e1e0d9;
  --borde: rgba(11, 11, 11, 0.10);
  --up: #006300;
  --down: #d03b3b;
  --acento: #2a78d6;
  --s1: #2a78d6;  /* núcleo */
  --s2: #eb6834;  /* satélite */
  --s3: #1baf7a;  /* renta fija */
  --s4: #eda100;  /* cash */
  --s5: #e87ba4;
  --s6: #008300;
  --s7: #4a3aa7;
  --s8: #e34948;
  --warn: #fab219;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --fondo: #0d0d0d;
    --superficie: #1a1a19;
    --tinta: #ffffff;
    --tinta-2: #c3c2b7;
    --tinta-mut: #898781;
    --hairline: #2c2c2a;
    --borde: rgba(255, 255, 255, 0.10);
    --up: #0ca30c;
    --down: #e66767;
    --acento: #3987e5;
    --s1: #3987e5;
    --s2: #d95926;
    --s3: #199e70;
    --s4: #c98500;
    --s5: #d55181;
    --s6: #008300;
    --s7: #9085e9;
    --s8: #e66767;
    --warn: #fab219;
  }
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--fondo);
  color: var(--tinta);
  font-size: 15px;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}
.oculto { display: none !important; }
.mini { font-size: 12px; color: var(--tinta-mut); }
.centrado { text-align: center; padding: 12px 0; }

/* Setup */
.pantalla { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.setup-box { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 14px; }
.setup-box h1 { font-size: 26px; }

/* Header */
.encabezado { padding: 18px 16px 10px; }
.total-linea { display: flex; align-items: baseline; justify-content: space-between; }
.hero { font-size: 34px; font-weight: 700; letter-spacing: -0.5px; }
h2 { font-size: 20px; }

/* Cards */
.card {
  background: var(--superficie);
  border: 1px solid var(--borde);
  border-radius: 14px;
  margin: 8px 12px;
  padding: 12px 14px;
}
.card-titulo { font-size: 13px; color: var(--tinta-2); margin-bottom: 8px; display: flex; justify-content: space-between; }

/* Barra de política (stack horizontal con gaps de 2px) */
.pol-barra { display: flex; gap: 2px; height: 18px; border-radius: 5px; overflow: hidden; }
.pol-seg { height: 100%; min-width: 2px; }
.pol-seg:first-child { border-radius: 4px 0 0 4px; }
.pol-seg:last-child { border-radius: 0 4px 4px 0; }
.pol-obj { position: relative; height: 6px; margin-top: 3px; }
.pol-obj-marca { position: absolute; top: 0; width: 2px; height: 6px; background: var(--tinta-mut); }
.pol-leyenda { display: flex; flex-wrap: wrap; gap: 10px 14px; margin-top: 10px; font-size: 12px; color: var(--tinta-2); }
.pol-leyenda .cuadr { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; }

/* Filtros */
.filtros { padding: 4px 12px; display: flex; flex-direction: column; gap: 8px; }
.chips { display: flex; gap: 6px; overflow-x: auto; }
.chip {
  border: 1px solid var(--hairline); background: var(--superficie); color: var(--tinta-2);
  border-radius: 999px; padding: 6px 13px; font-size: 13px; white-space: nowrap;
}
.chip.activo { background: var(--acento); border-color: var(--acento); color: #fff; font-weight: 600; }
.filtros-fila { display: flex; gap: 8px; }
select, input, button { font: inherit; color: inherit; }
select, input[type="search"], input[type="url"], input[type="password"], input[type="text"],
input[type="number"], input[type="date"] {
  background: var(--superficie); border: 1px solid var(--hairline); border-radius: 10px;
  padding: 9px 12px; width: 100%;
}
.filtros-fila select { flex: 1; }

/* Lista de posiciones */
#lista-posiciones { margin-top: 6px; }
.fila {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 11px 16px; border-bottom: 1px solid var(--hairline);
  background: none; border-left: none; border-right: none; border-top: none; width: 100%;
  text-align: left; cursor: pointer;
}
.fila:active { background: var(--superficie); }
.fila-izq { min-width: 0; }
.fila-ticker { font-weight: 650; font-size: 15px; }
.fila-sub { font-size: 12px; color: var(--tinta-mut); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 46vw; }
.fila-der { text-align: right; flex-shrink: 0; }
.fila-valor { font-weight: 600; font-variant-numeric: tabular-nums; }
.fila-pnl { font-size: 12px; font-variant-numeric: tabular-nums; }
.up { color: var(--up); }
.down { color: var(--down); }

/* Movimientos */
.mov { padding: 10px 16px; border-bottom: 1px solid var(--hairline); }
.mov-linea1 { display: flex; justify-content: space-between; font-size: 14px; }
.mov-tipo { font-weight: 650; }
.mov-linea2 { display: flex; justify-content: space-between; font-size: 12px; color: var(--tinta-mut); margin-top: 2px; }

/* Historia */
.viz-root { width: 100%; }
.viz-root svg { display: block; width: 100%; height: auto; }
.tt {
  position: absolute; pointer-events: none; background: var(--superficie);
  border: 1px solid var(--borde); border-radius: 8px; padding: 6px 9px;
  font-size: 12px; box-shadow: 0 2px 10px rgba(0,0,0,0.18); white-space: nowrap;
}
.tabla { width: 100%; border-collapse: collapse; }
.tabla th { font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--tinta-mut); text-align: right; padding: 8px 14px 4px; font-weight: 600; }
.tabla th:first-child, .tabla td:first-child { text-align: left; }
.tabla td { padding: 7px 14px; border-top: 1px solid var(--hairline); text-align: right; font-variant-numeric: tabular-nums; font-size: 13px; }

/* Overlays */
.overlay {
  position: fixed; inset: 0; background: var(--fondo); z-index: 30;
  overflow-y: auto; padding-bottom: 24px;
}
.overlay-header { display: flex; align-items: center; gap: 10px; position: sticky; top: 0; background: var(--fondo); z-index: 2; }
.btn-icono {
  background: var(--superficie); border: 1px solid var(--hairline); border-radius: 10px;
  width: 38px; height: 38px; font-size: 18px; flex-shrink: 0; cursor: pointer; color: var(--tinta);
}
.kv { display: flex; justify-content: space-between; padding: 6px 0; font-size: 14px; }
.kv .k { color: var(--tinta-2); }
.etiquetas { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.etiqueta { font-size: 11px; border: 1px solid var(--hairline); border-radius: 999px; padding: 3px 9px; color: var(--tinta-2); }

/* Form */
.form { display: flex; flex-direction: column; gap: 12px; padding: 4px 16px; }
.form label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--tinta-2); }
.form-fila { display: flex; gap: 10px; }
.form-fila label { flex: 1; }
.btn-primario {
  background: var(--acento); color: #fff; border: none; border-radius: 12px;
  padding: 13px; font-size: 16px; font-weight: 650; cursor: pointer;
}
.btn-primario:disabled { opacity: 0.55; }

/* FAB */
.fab {
  position: fixed; right: 18px; bottom: calc(76px + env(safe-area-inset-bottom));
  width: 54px; height: 54px; border-radius: 50%; border: none;
  background: var(--acento); color: #fff; font-size: 28px; line-height: 1;
  box-shadow: 0 4px 14px rgba(0,0,0,0.3); cursor: pointer; z-index: 20;
}

/* Bottom nav */
.nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 25;
  display: flex; background: var(--superficie); border-top: 1px solid var(--hairline);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-btn {
  flex: 1; padding: 13px 0; background: none; border: none; font-size: 13.5px;
  color: var(--tinta-mut); cursor: pointer;
}
.nav-btn.activo { color: var(--acento); font-weight: 700; }

/* Día y alertas */
.dia { font-size: 14px; font-weight: 600; margin-top: 2px; }
.alerta {
  display: flex; gap: 8px; align-items: flex-start;
  margin: 6px 12px; padding: 10px 12px; border-radius: 12px;
  font-size: 13px; border: 1px solid var(--borde); background: var(--superficie);
}
.alerta .ic { flex-shrink: 0; }
.alerta-critico { border-left: 4px solid var(--down); }
.alerta-aviso { border-left: 4px solid var(--warn); }
.alerta-info { border-left: 4px solid var(--hairline); color: var(--tinta-2); }

/* Distribución */
.chips-mini .chip { padding: 4px 10px; font-size: 12px; }
.dist-leyenda { margin-top: 10px; display: flex; flex-direction: column; gap: 5px; }
.dist-item { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.dist-item .cuadr { width: 9px; height: 9px; border-radius: 2px; flex-shrink: 0; }
.dist-item .nom { flex: 1; color: var(--tinta-2); }
.dist-item .val { font-variant-numeric: tabular-nums; }
.dist-item .pct { width: 52px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

/* Toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 50;
  background: var(--tinta); color: var(--fondo); border-radius: 10px;
  padding: 10px 16px; font-size: 14px; max-width: 88vw;
}

/* Spinner del refresh */
@keyframes girar { to { transform: rotate(360deg); } }
.girando { animation: girar 1s linear infinite; }
