/* Panel del bot de tendencias. Colores de gráficos: paleta validada
   (azul, naranja, aqua) para daltonismo en modo claro y oscuro. */
:root {
  color-scheme: light;
  --page: #f6f7f9;
  --surface: #ffffff;
  --ink: #191919;
  --ink-2: #666666;
  --hair: #e7e7e7;
  --axis: #c2c2c2;
  --border: rgba(11, 11, 11, 0.10);
  --brand: #1f3a5f;
  --brand-ink: #ffffff;
  --s1: #257de0;  /* bot */
  --s2: #f47230;  /* S&P 500 */
  --s3: #00b894;  /* MSCI World */
  --up: #006c10;
  --down: #c62f30;
  --good: #0aac23;
  --warning: #fbb315;
  --critical: #dc3c3d;
  --mid: #efefef;
  --pos-pole: #1b64be;
  --neg-pole: #d23f40;
  --banner-bg: #fff4d6;
  --banner-ink: #5c4300;
  --radius: 14px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0b0b0b;
    --surface: #191919;
    --ink: #efefef;
    --ink-2: #9c9c9c;
    --hair: #303030;
    --axis: #474747;
    --border: rgba(255, 255, 255, 0.10);
    --brand: #22416a;
    --s1: #338ced;
    --s2: #e76624;
    --s3: #00a888;
    --up: #53c556;
    --down: #f07a7a;
    --mid: #383838;
    --pos-pole: #338ced;
    --neg-pole: #eb6263;
    --banner-bg: #3a2f10;
    --banner-ink: #f5dc9a;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--page); color: var(--ink); }
body {
  font-size: 15px; line-height: 1.45;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
  -webkit-text-size-adjust: 100%;
}
a { color: inherit; }
h2 { font-size: 17px; margin: 0 0 4px; font-weight: 650; }
h3 { font-size: 15px; margin: 0 0 8px; font-weight: 650; }
p { margin: 0 0 8px; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }

/* Cabecera */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--brand); color: var(--brand-ink);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { border-radius: 7px; flex: none; }
.brand-title { font-weight: 650; font-size: 16px; }
.brand-sub { font-size: 12px; opacity: 0.8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill {
  font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.16); white-space: nowrap;
}
.banner {
  background: var(--banner-bg); color: var(--banner-ink);
  padding: 10px 16px; font-size: 13px;
}

main { max-width: 980px; margin: 0 auto; padding: 14px 12px; }
.tab { display: grid; gap: 12px; }
.tab[hidden] { display: none; }

/* Tarjetas */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px;
  min-width: 0;
}
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.grid-2 { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 760px) { .grid-2 { grid-template-columns: 1fr 1fr; } }

/* Estado */
.status { display: flex; gap: 10px; align-items: flex-start; }
.status-icon {
  flex: none; width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700; font-size: 15px; color: #fff;
}
.st-ok { background: var(--good); }
.st-warn { background: var(--warning); color: #0b0b0b; }
.st-err { background: var(--critical); }
.st-info { background: var(--ink-2); }
.status-label { font-weight: 650; }

/* Tarjetas de cifras */
.tiles { display: grid; gap: 10px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 760px) { .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; min-width: 0; }
.tile-label { font-size: 12px; color: var(--ink-2); }
.tile-value { font-size: 22px; font-weight: 650; margin-top: 2px; letter-spacing: -0.01em; }
.tile-sub { font-size: 12px; color: var(--ink-2); margin-top: 2px; }
.delta-up { color: var(--up); }
.delta-down { color: var(--down); }

/* Gráficos */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart text { fill: var(--ink-2); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .label-name { fill: var(--ink); font-size: 11.5px; font-weight: 600; }
.chart .grid { stroke: var(--hair); stroke-width: 1; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .cross { stroke: var(--ink-2); stroke-width: 1; }
.chart .dot { stroke: var(--surface); stroke-width: 2; }
.chart:focus-visible { outline: 2px solid var(--s1); outline-offset: 4px; border-radius: 6px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12.5px; color: var(--ink-2); margin: 2px 0 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }

.seg { display: inline-flex; background: var(--page); border: 1px solid var(--border); border-radius: 999px; padding: 2px; gap: 2px; flex-wrap: wrap; }
.seg button {
  font: inherit; font-size: 12.5px; border: 0; background: transparent; color: var(--ink-2);
  padding: 5px 11px; border-radius: 999px; cursor: pointer;
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 0 0 1px var(--border); }

/* Tooltip */
.tooltip {
  position: fixed; z-index: 50; pointer-events: none;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.14);
  padding: 8px 10px; font-size: 12.5px; min-width: 140px; max-width: 260px;
}
.tooltip .tt-date { color: var(--ink-2); font-size: 11.5px; margin-bottom: 4px; }
.tooltip .tt-row { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.tooltip .tt-row b { font-variant-numeric: tabular-nums; }
.tooltip .tt-name { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); }
.tooltip .tt-name i { width: 10px; height: 3px; border-radius: 2px; display: inline-block; }

/* Listas */
.list { display: grid; }
.row {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; align-items: center;
  padding: 10px 0; border-top: 1px solid var(--hair);
}
.row:first-child { border-top: 0; }
.row-title { font-weight: 650; }
.row-sub { font-size: 12.5px; color: var(--ink-2); }
.row-right { text-align: right; font-variant-numeric: tabular-nums; }
.badge {
  display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 650;
  padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); background: var(--page);
}
.meter { height: 6px; background: var(--hair); border-radius: 3px; overflow: hidden; margin-top: 6px; }
.meter > i { display: block; height: 100%; background: var(--s1); border-radius: 3px; }
.meter.warn > i { background: var(--warning); }
.date-head { font-size: 12px; font-weight: 650; color: var(--ink-2); margin: 12px 0 2px; text-transform: uppercase; letter-spacing: 0.04em; }

/* Tablas */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th, td { text-align: left; padding: 7px 8px; border-top: 1px solid var(--hair); vertical-align: top; }
th { font-size: 12px; color: var(--ink-2); font-weight: 600; border-top: 0; }
td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.hl td { font-weight: 650; }

/* Pruebas */
.check { display: grid; grid-template-columns: 28px 1fr; gap: 10px; padding: 10px 0; border-top: 1px solid var(--hair); }
.check:first-child { border-top: 0; }
.check-icon { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 13px; }
.check-ok { background: var(--good); }
.check-no { background: var(--critical); }
.check-state { font-size: 12px; font-weight: 650; }

/* Mapa mensual */
.heat { display: grid; grid-template-columns: 38px repeat(12, minmax(0, 1fr)) 52px; gap: 2px; font-size: 11px; }
.heat .hh { color: var(--ink-2); text-align: center; padding: 2px 0; }
.heat .hy { color: var(--ink-2); font-variant-numeric: tabular-nums; display: flex; align-items: center; }
.heat .cell {
  border-radius: 4px; min-height: 24px; display: grid; place-items: center;
  font-variant-numeric: tabular-nums; font-size: 10px; cursor: default; outline: none;
}
.heat .cell:focus-visible { box-shadow: 0 0 0 2px var(--ink); }
.heat .tot { text-align: right; font-weight: 650; font-variant-numeric: tabular-nums; display: flex; align-items: center; justify-content: flex-end; font-size: 11.5px; }
.heat .empty { background: transparent; }
.scale { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--ink-2); margin-top: 8px; }
.scale .bar { flex: 1; max-width: 180px; height: 8px; border-radius: 4px; }

.empty-state { text-align: center; padding: 28px 12px; color: var(--ink-2); }

/* Barra de navegación */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 2px 7px; text-decoration: none; color: var(--ink-2); font-size: 11px;
}
.tabbar svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a[aria-current="page"] { color: var(--s1); font-weight: 650; }
@media (min-width: 900px) {
  body { padding-bottom: 0; }
  .tabbar { position: sticky; top: 58px; bottom: auto; max-width: 980px; margin: 0 auto; border: 0; background: transparent; padding: 8px 12px 0; display: flex; gap: 6px; }
  .tabbar a { flex-direction: row; gap: 6px; padding: 8px 14px; border-radius: 999px; font-size: 13.5px; }
  .tabbar a[aria-current="page"] { background: var(--surface); box-shadow: 0 0 0 1px var(--border); }
  .tabbar svg { width: 18px; height: 18px; }
}
