/* ==========================================================
   Eye Tracking Dashboard · tokens + componentes
   ========================================================== */
:root {
  color-scheme: light;
  /* superficies */
  --bg:          #eef1f0;
  --surface-1:   #ffffff;
  --surface-2:   #f6f8f7;
  --surface-3:   #edf0ef;
  --line:        #e3e7e5;
  --line-strong: #cfd5d2;
  /* texto */
  --text-primary:   #191919;
  --text-secondary: #5f6663;
  --text-muted:     #8a918e;
  /* marca (cromo, no datos) */
  --brand:       #14532d;
  --brand-soft:  #e7f1ea;
  --ink:         #1d2430;
  --grad:        linear-gradient(100deg, #e86fb3 0%, #a77cf0 55%, #5aa0f2 100%);
  --insight:     linear-gradient(165deg, #f27a66 0%, #e5527a 55%, #c93a6e 100%);
  /* series (paleta categórica validada, orden fijo) */
  --series-1: #257de0;  /* TS · TEA      */
  --series-2: #f47230;  /* TC · Sin TEA  */
  --series-3: #00b894;
  /* estado */
  --good:     #0aac23;
  --good-txt: #006c10;
  --critical: #dc3c3d;
  --crit-bg:  #fdecec;
  --warn-bg:  #fff4dc;
  --warn-txt: #8a5a00;
  /* medidas */
  --r-lg: 20px;
  --r-md: 14px;
  --r-sm: 10px;
  --gap: 18px;
  --shadow: 0 1px 2px rgba(16, 24, 20, .04), 0 6px 24px rgba(16, 24, 20, .05);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "Instrument Serif", Georgia, serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 90px; }
body {
  margin: 0;
  font: 14px/1.45 var(--font);
  color: var(--text-primary);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
button, input, select { font: inherit; color: inherit; }
a { color: inherit; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; font-weight: 400; }
.ico { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 88px 1fr; min-height: 100vh; }
.rail {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; align-items: center; gap: 18px;
  padding: 18px 0; background: var(--surface-2); border-right: 1px solid var(--line);
  z-index: 20;
}
.rail-logo {
  width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center;
  background: var(--ink); color: #fff; margin-bottom: 30px;
}
.rail-logo .ico { width: 26px; height: 26px; }
.rail-nav { display: flex; flex-direction: column; gap: 14px; }
.rail-btn {
  position: relative; width: 46px; height: 46px; border-radius: 50%;
  display: grid; place-items: center; text-decoration: none;
  background: var(--surface-1); border: 1px solid var(--line); color: var(--text-secondary);
  transition: background .15s, color .15s, transform .15s;
}
.rail-btn:hover { color: var(--text-primary); transform: translateY(-1px); }
.rail-btn.is-active { background: var(--ink); color: #fff; border-color: var(--ink); }
.rail-btn::after {
  content: attr(data-tip); position: absolute; left: 58px; top: 50%; transform: translateY(-50%);
  white-space: nowrap; padding: 6px 10px; border-radius: 8px; font-size: 12px;
  background: var(--ink); color: #fff; opacity: 0; pointer-events: none; transition: opacity .15s;
}
.rail-btn:hover::after, .rail-btn.is-active:hover::after { opacity: 1; }
.rail-bottom { margin-top: auto; }

.main { min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 15;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 28px; background: rgba(238, 241, 240, .86); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.search {
  flex: 1; max-width: 520px; display: flex; align-items: center; gap: 10px;
  padding: 10px 12px 10px 16px; border-radius: 999px; background: var(--surface-1);
  border: 1px solid var(--line); color: var(--text-muted);
}
.search input { flex: 1; border: 0; outline: 0; background: none; min-width: 0; color: var(--text-primary); }
.search:focus-within { border-color: var(--line-strong); box-shadow: 0 0 0 4px var(--brand-soft); }
kbd { font: 12px var(--font); padding: 3px 9px; border-radius: 999px; background: var(--surface-3); color: var(--text-secondary); }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.btn-grad, .btn-ghost, .btn-dark {
  display: inline-flex; align-items: center; gap: 8px; padding: 9px 16px; border-radius: 999px;
  border: 1px solid transparent; cursor: pointer; text-decoration: none; font-weight: 500; white-space: nowrap;
}
.btn-grad { background: var(--grad); color: #fff; box-shadow: 0 4px 16px rgba(167, 124, 240, .35); }
.btn-grad:hover { filter: brightness(1.05); }
.btn-ghost { background: var(--surface-1); border-color: var(--line); color: var(--text-secondary); }
.btn-ghost:hover { color: var(--text-primary); border-color: var(--line-strong); }
.btn-dark { background: var(--ink); color: #fff; }
.btn-dark:hover { filter: brightness(1.2); }
.icon-btn { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface-1); display: grid; place-items: center; cursor: pointer; }
.who { display: flex; align-items: center; gap: 10px; padding-left: 6px; }
.who b { display: block; font-size: 13px; font-weight: 600; }
.who small { display: block; font-size: 11px; color: var(--text-muted); }
.who-avatar { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: var(--brand); color: #fff; }

.content { padding: 26px 28px 60px; display: flex; flex-direction: column; gap: var(--gap); }
.section { display: flex; flex-direction: column; gap: var(--gap); }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--gap); }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--gap); }
.span-2 { grid-column: span 2; }
.span-all { grid-column: 1 / -1; }

.hello h1 { font-size: 26px; }
.hello p { margin: 4px 0 0; color: var(--text-secondary); }

.card {
  background: var(--surface-1); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow);
}
.panel { padding: 18px 20px 20px; min-width: 0; }
.panel-h { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.panel-h h2 { font-size: 15px; display: flex; align-items: center; gap: 6px; }
.panel-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tip { color: var(--text-muted); display: inline-flex; cursor: help; }
.tip .ico { width: 15px; height: 15px; }
.pill, .builder select, .fx-bar select, .filters select {
  appearance: none; padding: 6px 30px 6px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface-1) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235f6663' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 10px center / 14px;
  font-size: 12.5px; cursor: pointer;
}
.chart-box { position: relative; width: 100%; }
.h-260 { height: 260px; } .h-300 { height: 300px; } .h-360 { height: 360px; }

/* ---------- filtros ---------- */
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 14px 22px; padding: 14px 18px; }
.f-group { display: flex; flex-direction: column; gap: 6px; }
.f-label { font-size: 11.5px; font-weight: 500; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; display: flex; align-items: center; gap: 5px; }
.f-label .ico { width: 13px; height: 13px; }
.f-row { display: flex; align-items: center; gap: 6px; }
.f-unit { margin-left: auto; }
.filters input[type=date], .filters input.num {
  padding: 6px 10px; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--surface-1); font-size: 12.5px;
}
.filters input.num { width: 72px; }
.chips { display: flex; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface-1); cursor: pointer; font-size: 12.5px; color: var(--text-secondary);
}
.chip.is-on { background: var(--ink); border-color: var(--ink); color: #fff; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
.dot.s1 { background: var(--series-1); } .dot.s2 { background: var(--series-2); }
.chip.is-on .dot { box-shadow: 0 0 0 2px #fff; }
.seg { display: inline-flex; padding: 3px; border-radius: 999px; background: var(--surface-3); }
.seg button { border: 0; background: none; padding: 5px 12px; border-radius: 999px; cursor: pointer; font-size: 12.5px; color: var(--text-secondary); }
.seg button.is-on { background: var(--surface-1); color: var(--text-primary); box-shadow: var(--shadow); font-weight: 500; }

.dd { position: relative; }
.dd summary {
  list-style: none; cursor: pointer; padding: 6px 30px 6px 12px; border-radius: 999px; border: 1px solid var(--line);
  font-size: 12.5px; min-width: 120px;
  background: var(--surface-1) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235f6663' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 10px center / 14px;
}
.dd summary::-webkit-details-marker { display: none; }
.dd-panel {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 30; width: 280px; max-height: 380px; overflow: auto;
  padding: 10px; background: var(--surface-1); border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: 0 12px 40px rgba(0,0,0,.12);
}
.dd-wide { width: 420px; }
.dd-tools { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.dd-tools button { border: 1px solid var(--line); background: var(--surface-2); border-radius: 999px; padding: 3px 10px; font-size: 12px; cursor: pointer; }
.dd-list { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 8px; }
.dd-list label { display: flex; align-items: center; gap: 6px; font-size: 12.5px; padding: 3px 4px; border-radius: 6px; cursor: pointer; }
.dd-list label:hover { background: var(--surface-2); }
.adv-row { display: grid; grid-template-columns: 1fr 80px 80px; gap: 6px; align-items: center; padding: 4px 0; font-size: 12.5px; }
.adv-row input { padding: 4px 8px; border-radius: 8px; border: 1px solid var(--line); width: 100%; }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--gap); }
.kpi { display: flex; justify-content: space-between; align-items: flex-start; padding: 18px 20px; background: var(--surface-2); }
.kpi h3 { font-size: 13px; font-weight: 500; color: var(--text-secondary); }
.kpi-num { font-size: 28px; font-weight: 600; margin: 8px 0 4px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi-sub { margin: 0; font-size: 12.5px; color: var(--text-secondary); display: flex; gap: 10px; flex-wrap: wrap; }
.kpi-sub .up { color: var(--good-txt); } .kpi-sub .down { color: var(--critical); }
.kpi-ico { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--surface-1); color: var(--brand); border: 1px solid var(--line); }

/* ---------- heatmaps ---------- */
.heatmaps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.heatmaps figure { margin: 0; }
.heatmaps canvas { width: 100%; height: auto; aspect-ratio: 4 / 3; border-radius: var(--r-md); background: #0d1117; display: block; }
.heatmaps figcaption { display: flex; align-items: center; gap: 6px; margin-top: 8px; font-size: 12.5px; font-weight: 500; }
.legend-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 12px; font-size: 12px; }
.ramp { display: inline-block; width: 110px; height: 8px; border-radius: 4px; }
.ramp-seq { background: linear-gradient(90deg, #0d1117, #0f4a96, #257de0, #84b9f3, #cce3fd); }
.ramp-div { background: linear-gradient(90deg, #c93334, #ec8a8a, #efefef, #84b9f3, #1b64be); margin-left: 14px; }

/* ---------- lista de efectos (estilo alertas) ---------- */
.alerts { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.alerts li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.alerts li:last-child { border-bottom: 0; }
.alerts b { display: block; font-weight: 500; font-size: 13.5px; }
.alerts small { color: var(--text-muted); font-size: 12px; }
.badge { padding: 4px 10px; border-radius: 999px; font-size: 12px; white-space: nowrap; border: 1px solid transparent; font-variant-numeric: tabular-nums; }
.badge.big { background: var(--crit-bg); color: var(--critical); border-color: #f6c9c9; }
.badge.mid { background: var(--warn-bg); color: var(--warn-txt); border-color: #f2dfae; }
.badge.low { background: var(--surface-3); color: var(--text-secondary); }
.state { color: var(--text-muted); justify-content: center !important; padding: 30px 0 !important; }

/* ---------- tarjeta de hallazgos ---------- */
.insight {
  background: var(--insight); color: #fff; border: 0; padding: 22px 22px 24px; overflow: hidden; position: relative;
}
.insight h2 { font-size: 28px; line-height: 1.1; font-weight: 600; }
.insight h2 em { font-family: var(--serif); font-weight: 400; font-size: 32px; }
.insight-sub { margin: 6px 0 14px; opacity: .9; }
.insight ol { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 9px; font-size: 13px; line-height: 1.4; }
.insight ol b { font-weight: 600; }
.insight::after {
  content: ""; position: absolute; right: -40px; bottom: -40px; width: 160px; height: 160px; border-radius: 50%;
  background: rgba(255,255,255,.12);
}

/* ---------- constructor ---------- */
.builder { display: grid; grid-template-columns: 240px 1fr; gap: 20px; }
.builder-controls { display: flex; flex-direction: column; gap: 12px; }
.builder-controls label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--text-muted); font-weight: 500; }
.builder-controls select { border-radius: var(--r-sm); padding: 8px 30px 8px 12px; color: var(--text-primary); font-size: 13px; }
.builder-hint { margin: 0; font-size: 12px; color: var(--text-secondary); background: var(--surface-2); border-radius: var(--r-sm); padding: 10px; }
.pinned { display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: var(--gap); }
.pinned:empty { display: none; }

/* ---------- tablas ---------- */
.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.tbl th { text-align: left; font-weight: 600; font-size: 12px; color: var(--text-secondary); padding: 10px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--surface-1); }
.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl td.num, .tbl th.num { text-align: right; }
.tbl-data th { cursor: pointer; user-select: none; }
.tbl-data th[aria-sort="ascending"]::after { content: " ▲"; font-size: 9px; }
.tbl-data th[aria-sort="descending"]::after { content: " ▼"; font-size: 9px; }
.tbl-data tbody tr { cursor: pointer; }
.cls { display: inline-flex; align-items: center; gap: 6px; }
.link { color: var(--series-1); text-decoration: none; font-weight: 500; }

.corr { border-collapse: separate; border-spacing: 2px; font-size: 11.5px; font-variant-numeric: tabular-nums; }
.corr th { font-weight: 500; color: var(--text-secondary); padding: 4px 6px; white-space: nowrap; }
.corr thead th { writing-mode: vertical-rl; transform: rotate(180deg); text-align: left; height: 150px; vertical-align: bottom; }
.corr tbody th { text-align: right; }
.corr td { width: 48px; height: 32px; text-align: center; border-radius: 6px; cursor: pointer; }
.corr td:hover { outline: 2px solid var(--ink); }

/* ---------- galería ---------- */
.fx-bar { display: flex; flex-wrap: wrap; gap: 14px 22px; align-items: flex-end; padding: 12px 14px; border-radius: var(--r-md); background: var(--surface-2); margin-bottom: 16px; }
.fx-bar label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-muted); font-weight: 500; }
.fx-bar label.check { flex-direction: row; align-items: center; gap: 6px; color: var(--text-secondary); }
.fx-bar output { color: var(--text-primary); font-variant-numeric: tabular-nums; }
.fx-bar input[type=range] { width: 150px; accent-color: var(--ink); }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.tile { margin: 0; border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; cursor: pointer; background: var(--surface-2); transition: transform .15s, box-shadow .15s; }
.tile:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.tile canvas { display: block; width: 100%; aspect-ratio: 4 / 3; background: #000; }
.tile-meta { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 10px; font-size: 12px; }
.tile-meta b { font-weight: 600; }
.pager { display: flex; justify-content: center; align-items: center; gap: 6px; margin-top: 16px; flex-wrap: wrap; }
.pager button { min-width: 34px; height: 34px; padding: 0 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface-1); cursor: pointer; font-size: 12.5px; }
.pager button.is-on { background: var(--ink); color: #fff; border-color: var(--ink); }
.pager button:disabled { opacity: .4; cursor: default; }
.empty { padding: 40px; text-align: center; color: var(--text-muted); grid-column: 1 / -1; }

/* ---------- visor ---------- */
.viewer { width: min(1200px, 96vw); max-height: 94vh; border: 0; border-radius: var(--r-lg); padding: 0; box-shadow: 0 30px 80px rgba(0,0,0,.35); }
.viewer::backdrop { background: rgba(13, 17, 23, .6); backdrop-filter: blur(3px); }
.viewer > header { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.viewer > header h2 { font-size: 16px; }
.viewer .check { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; color: var(--text-secondary); }
.viewer-body { display: grid; grid-template-columns: 1fr 270px; gap: 18px; padding: 18px; overflow: auto; max-height: calc(94vh - 66px); }
.viewer-imgs { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.viewer-imgs.single { grid-template-columns: 1fr; }
.viewer-imgs figure { margin: 0; }
.viewer-imgs canvas { width: 100%; height: auto; border-radius: var(--r-md); background: #000; display: block; }
.viewer-imgs figcaption { font-size: 12px; color: var(--text-muted); margin-top: 6px; }
.viewer-meta dl { margin: 0; display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; font-size: 13px; }
.viewer-meta dt { color: var(--text-secondary); }
.viewer-meta dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; font-weight: 500; }
.viewer-meta h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); margin: 16px 0 8px; }
.viewer-meta h3:first-child { margin-top: 0; }

/* ---------- estados ---------- */
.loading { position: relative; }
.loading::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.55), transparent);
  background-size: 200% 100%; animation: shimmer 1.1s infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }
.box-msg { position: absolute; inset: 0; display: grid; place-items: center; color: var(--text-muted); font-size: 13px; text-align: center; padding: 20px; }
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translate(-50%, 20px); opacity: 0;
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 13px; transition: .2s; pointer-events: none; z-index: 100;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login form { width: min(380px, 100%); padding: 30px; display: flex; flex-direction: column; gap: 14px; }
.login h1 { font-size: 22px; }
.login input { padding: 11px 14px; border-radius: var(--r-sm); border: 1px solid var(--line); }
.login .err { color: var(--critical); font-size: 13px; margin: 0; }
.login button { justify-content: center; }

/* ---------- responsive ---------- */
@media (max-width: 1280px) {
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 .span-2 { grid-column: 1 / -1; }
}
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .rail { position: fixed; bottom: 0; top: auto; height: auto; width: 100%; flex-direction: row; justify-content: center; padding: 10px; border-right: 0; border-top: 1px solid var(--line); }
  .rail-logo, .rail-bottom { display: none; }
  .rail-nav { flex-direction: row; }
  .rail-btn::after { display: none; }
  .content { padding: 18px 14px 100px; }
  .topbar { padding: 12px 14px; }
  .topbar .who, #btnReset { display: none; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .heatmaps { grid-template-columns: 1fr; }
  .builder { grid-template-columns: 1fr; }
  .viewer-body { grid-template-columns: 1fr; }
  .f-unit { margin-left: 0; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
  html { scroll-behavior: auto; }
}
