/* =========================================
   styles.css — Mapa de Calor (Finviz-style) v2
   - Responsive + Sticky header
   - Theme: dark / pastel
   - Paleta coherente con Barómetro FED / Calendario Económico (El Inversor G)
   ========================================= */

:root{
  /* Layout */
  --radius-xl: 20px;
  --radius-lg: 16px;
  --radius-md: 12px;

  --shadow: 0 12px 30px rgba(0,0,0,.28);
  --shadow-soft: 0 10px 22px rgba(0,0,0,.22);

  --header-h: 78px;
  --subbar-h: 54px;

  --gap: 12px;

  /* Base (dark default) */
  --bg: #0b0f14;
  --panel: #0f1520;
  --card: #121a26;
  --card-2: #0f1724;
  --text: #e8eef6;
  --muted: rgba(232,238,246,.70);
  --muted2: rgba(232,238,246,.55);
  --border: rgba(232,238,246,.12);

  --accent: #7dd3fc;        /* cyan */
  --accent2: #a78bfa;       /* violet */
  --good: #22c55e;
  --bad: #ef4444;
  --warn: #f59e0b;

  --chip-on: #22c55e;
  --chip-off: rgba(232,238,246,.25);

  --focus: rgba(125,211,252,.35);

  --grid-bg: radial-gradient(circle at 10px 10px, rgba(255,255,255,.035) 0 2px, transparent 3px),
             radial-gradient(circle at 40px 40px, rgba(255,255,255,.02) 0 2px, transparent 3px);

  color-scheme: dark;
}

:root[data-theme="pastel"]{
  --bg: #f7f6fb;
  --panel: rgba(255,255,255,.85);
  --card: rgba(255,255,255,.75);
  --card-2: rgba(255,255,255,.65);

  --text: #101828;
  --muted: rgba(16,24,40,.70);
  --muted2: rgba(16,24,40,.55);
  --border: rgba(16,24,40,.12);

  --accent: #2563eb;
  --accent2: #7c3aed;

  --shadow: 0 12px 30px rgba(16,24,40,.14);
  --shadow-soft: 0 10px 22px rgba(16,24,40,.12);

  --chip-off: rgba(16,24,40,.22);
  --focus: rgba(37,99,235,.22);

  color-scheme: light;
}

/* Base reset */
*{ box-sizing:border-box; }
html,body{ height:100%; }
body{
  margin:0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, "Noto Sans", "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
}

a{ color: inherit; text-decoration: none; }
a:hover{ text-decoration: underline; }

.app{
  min-height:100vh;
  display:flex;
  flex-direction:column;
}

/* =========================================
   HEADER
========================================= */
.header{
  position: sticky;
  top: 0;
  z-index: 1000;
  height: var(--header-h);
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap: var(--gap);
  padding: 10px 14px;
  background: color-mix(in oklab, var(--panel) 92%, transparent);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
}

.header__left{
  display:flex;
  align-items:center;
  gap: 12px;
  min-width: 240px;
}

.brand-logo{
  width: 44px;
  height: 44px;
  border-radius: 12px;
  object-fit: contain;
  background: color-mix(in oklab, var(--card) 70%, transparent);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-soft);
}

.title-wrap{ display:flex; flex-direction:column; line-height:1.1; }
.title{
  margin:0;
  font-size: 18px;
  letter-spacing: .2px;
}
.subtitle{
  margin-top:4px;
  font-size: 12px;
  color: var(--muted);
}
.tz{
  display:inline-flex;
  align-items:center;
  gap:6px;
}
.tz::before{
  content:"⏱";
  opacity:.85;
}

.header__right{
  display:flex;
  align-items:flex-end;
  gap: 10px;
  flex-wrap: wrap;
  justify-content:flex-end;
}

/* Control blocks */
.control{
  display:flex;
  flex-direction:column;
  gap:6px;
  min-width: 140px;
}

.control__label{
  font-size: 11px;
  color: var(--muted);
  display:flex;
  align-items:center;
  gap:6px;
  user-select:none;
}

.label-icon{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  width:16px;
  height:16px;
  color: var(--muted);
}

.select{
  appearance:none;
  -webkit-appearance:none;
  -moz-appearance:none;
  border:1px solid var(--border);
  border-radius: 14px;
  background: color-mix(in oklab, var(--card) 82%, transparent);
  color: var(--text);
  padding: 10px 34px 10px 12px;
  font-size: 12px;
  outline:none;
  box-shadow: inset 0 0 0 1px transparent;
  transition: border-color .15s ease, box-shadow .15s ease, transform .08s ease;
  position:relative;
  cursor:pointer;
}

.select:focus{
  border-color: color-mix(in oklab, var(--accent) 55%, var(--border));
  box-shadow: 0 0 0 4px var(--focus);
}

.select:active{ transform: translateY(1px); }

/* Dropdown arrow via background */
.select{
  background-image:
    linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%),
    linear-gradient(to right, transparent, transparent);
  background-position:
    calc(100% - 16px) calc(50% - 3px),
    calc(100% - 11px) calc(50% - 3px),
    0 0;
  background-size:
    6px 6px,
    6px 6px,
    100% 100%;
  background-repeat: no-repeat;
  color: var(--text);
}

/* Icon buttons */
.icon-btn{
  width: 42px;
  height: 42px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: color-mix(in oklab, var(--card) 82%, transparent);
  color: var(--text);
  display:inline-flex;
  align-items:center;
  justify-content:center;
  cursor:pointer;
  transition: transform .08s ease, border-color .15s ease, box-shadow .15s ease;
}
.icon-btn:hover{
  border-color: color-mix(in oklab, var(--accent) 55%, var(--border));
}
.icon-btn:active{ transform: translateY(1px); }
.icon-btn:focus{ outline:none; box-shadow: 0 0 0 4px var(--focus); }

.icon{ display:inline-flex; }

/* Live button */
.live-btn{
  height: 42px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: color-mix(in oklab, var(--card) 82%, transparent);
  color: var(--text);
  display:inline-flex;
  align-items:center;
  gap:8px;
  padding: 0 12px;
  cursor:pointer;
  transition: transform .08s ease, border-color .15s ease, box-shadow .15s ease;
  white-space: nowrap;
}
.live-btn:hover{
  border-color: color-mix(in oklab, var(--accent) 55%, var(--border));
}
.live-btn:active{ transform: translateY(1px); }
.live-btn:focus{ outline:none; box-shadow: 0 0 0 4px var(--focus); }

.live-chip{
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--chip-off);
  box-shadow: 0 0 0 0 rgba(34,197,94,.0);
  transition: background .15s ease, box-shadow .25s ease;
}
.live-chip.is-on{
  background: var(--chip-on);
  box-shadow: 0 0 0 6px rgba(34,197,94,.18);
}
.live-label{
  font-size: 12px;
  font-weight: 650;
}
.live-next{
  font-size: 12px;
  color: var(--muted);
}

/* =========================================
   SUBBAR (stats)
========================================= */
.subbar{
  position: sticky;
  top: var(--header-h);
  z-index: 900;
  height: var(--subbar-h);
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap: var(--gap);
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in oklab, var(--panel) 88%, transparent);
  backdrop-filter: blur(10px);
}

.subbar__left,
.subbar__right{
  display:flex;
  align-items:center;
  gap: 10px;
  flex-wrap: wrap;
}

.pill{
  display:inline-flex;
  align-items:center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: color-mix(in oklab, var(--card) 76%, transparent);
  font-size: 12px;
}
.pill__label{ color: var(--muted); }
.pill__value{ font-weight: 650; }

.stat{
  display:flex;
  flex-direction:column;
  line-height: 1.05;
  padding: 6px 10px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: color-mix(in oklab, var(--card) 76%, transparent);
}
.stat__label{
  font-size: 10px;
  color: var(--muted);
}
.stat__value{
  font-size: 12px;
  font-weight: 700;
}

/* =========================================
   MAIN + HEATMAP
========================================= */
.main{
  position:relative;
  flex: 1;
  padding: 14px;
  background-image: var(--grid-bg);
}

.heatmap{
  position:relative;
  width: 100%;
  height: calc(100vh - var(--header-h) - var(--subbar-h) - 120px);
  min-height: 520px;
  border-radius: var(--radius-xl);
  border: 1px solid var(--border);
  background: color-mix(in oklab, var(--panel) 92%, transparent);
  box-shadow: var(--shadow);
  overflow:hidden;
}

/* Tiles */
.tile{
  position:absolute;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,.14);
  overflow:hidden;
  cursor:pointer;
  box-shadow: 0 12px 22px rgba(0,0,0,.10);
  transition: filter .15s ease;
  user-select:none;
}
:root[data-theme="pastel"] .tile{
  border-color: rgba(16,24,40,.14);
}

.tile:hover{ filter: brightness(1.05); }

.tile__top{
  display:flex;
  justify-content:space-between;
  align-items:center;
  padding: 8px 8px 0 8px;
  gap: 6px;
}

.tile__brand{
  width: 28px;
  height: 28px;
  border-radius: 10px;
  display:flex;
  align-items:center;
  justify-content:center;
  background: rgba(255,255,255,.16);
  overflow:hidden;
}
:root[data-theme="pastel"] .tile__brand{ background: rgba(16,24,40,.08); }

.tile__brand img{
  width: 22px;
  height: 22px;
  object-fit: contain;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,.22));
}

.initials{
  font-size: 11px;
  font-weight: 800;
  opacity: .95;
}

.badge{
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(0,0,0,.20);
  color: rgba(255,255,255,.92);
  border: 1px solid rgba(255,255,255,.16);
}
:root[data-theme="pastel"] .badge{
  background: rgba(255,255,255,.55);
  color: rgba(16,24,40,.92);
  border-color: rgba(16,24,40,.12);
}

.tile__mid{
  padding: 8px 10px 10px 10px;
  display:flex;
  flex-direction:column;
  gap: 4px;
}

.sym{
  font-size: 14px;
  font-weight: 900;
  letter-spacing:.25px;
  color: rgba(255,255,255,.95);
  text-shadow: 0 1px 2px rgba(0,0,0,.22);
}
:root[data-theme="pastel"] .sym{
  color: rgba(16,24,40,.95);
  text-shadow: none;
}

.name{
  font-size: 11px;
  color: rgba(255,255,255,.92);
  opacity: .95;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}
:root[data-theme="pastel"] .name{
  color: rgba(16,24,40,.86);
}

.chg{
  font-size: 12px;
  font-weight: 800;
  color: rgba(255,255,255,.95);
}
:root[data-theme="pastel"] .chg{
  color: rgba(16,24,40,.92);
}

/* Small/tiny tiles */
.tile.is-small .name{ display:none; }
.tile.is-small .chg{ font-size: 11px; }
.tile.is-tiny .name,
.tile.is-tiny .chg,
.tile.is-tiny .badge{ display:none; }
.tile.is-tiny .sym{ font-size: 12px; }

/* =========================================
   OVERLAY
========================================= */
.overlay{
  position:absolute;
  inset: 0;
  display:none;
  align-items:center;
  justify-content:center;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(6px);
  z-index: 10;
}
:root[data-theme="pastel"] .overlay{
  background: rgba(16,24,40,.22);
}
.overlay.is-on{ display:flex; }

.overlay__card{
  display:flex;
  align-items:center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: color-mix(in oklab, var(--panel) 92%, transparent);
  box-shadow: var(--shadow);
}
.spinner{
  width: 18px;
  height: 18px;
  border-radius: 999px;
  border: 2px solid color-mix(in oklab, var(--text) 30%, transparent);
  border-top-color: var(--text);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.overlay__title{ font-weight: 800; font-size: 13px; }
.overlay__sub{ font-size: 12px; color: var(--muted); margin-top:2px; }

/* =========================================
   TOOLTIP
========================================= */
.tooltip{
  position: fixed;
  left: 12px;
  top: 12px;
  min-width: 220px;
  padding: 12px 12px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: color-mix(in oklab, var(--panel) 92%, transparent);
  box-shadow: var(--shadow);
  display:none;
  z-index: 2000;
  pointer-events:none;
}
.tooltip.is-visible{ display:block; }

.tooltip__top{ margin-bottom: 8px; }
.tooltip__sym{ font-weight: 900; font-size: 14px; }
.tooltip__name{ font-size: 12px; color: var(--muted); margin-top:2px; }

.tooltip__row{
  display:flex;
  justify-content:space-between;
  gap: 12px;
  padding-top: 6px;
  border-top: 1px dashed var(--border);
  margin-top: 6px;
  font-size: 12px;
}
.tooltip__row .k{ color: var(--muted); }
.tooltip__row .v{ font-weight: 800; }

/* =========================================
   FOOTER
========================================= */
.footer{
  padding: 14px 12px 18px;
  text-align:center;
  color: var(--muted);
  font-size: 12px;
}
.footer strong{ color: var(--text); }

/* =========================================
   RESPONSIVE
========================================= */
@media (max-width: 980px){
  .header{
    height: auto;
    padding: 12px 12px;
    align-items:flex-start;
  }
  .header__left{ min-width: unset; }
  .header__right{
    width:100%;
    justify-content:flex-start;
  }
  .control{ min-width: 150px; }
  .heatmap{
    height: calc(100vh - 220px);
    min-height: 520px;
  }
}

@media (max-width: 560px){
  .control{ min-width: 46%; }
  .icon-btn{ width: 40px; height: 40px; }
  .live-btn{ width: 100%; justify-content:center; }
  .subbar{
    height: auto;
    padding: 10px 12px;
  }
  .heatmap{
    min-height: 520px;
    height: calc(100vh - 260px);
  }
}
