/* ─── RESET & BASE ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg:            #0a0e27;
  --bg-panel:      #0f172a;
  --bg-alt:        #0d1220;
  --bg-hover:      #1e3048;
  --border:        #334155;
  --accent:        #22d3ee;
  --accent-dim:    #164e63;
  --green:         #10b981;
  --green-bright:  #34d399;
  --green-deep-bg: #052e16;
  --green-mid-bg:  #0a2e1a;
  --green-dim:     #065f46;
  --red:           #ef4444;
  --red-bright:    #fca5a5;
  --red-deep-bg:   #1f0505;
  --red-mid-bg:    #2d0a0a;
  --red-dim:       #7f1d1d;
  --amber:         #f59e0b;
  --amber-bg:      #291800;
  --amber-border:  #78350f;
  --white:         #f1f5f9;
  --grey:          #94a3b8;
  --grey-hi:       #cbd5e1;
  --font: 'Lato', -apple-system, BlinkMacSystemFont, sans-serif;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--white);
  font-family: var(--font);
  font-size: 13px;
  line-height: 1;
  user-select: none;
}

/* ─── APP SHELL ─────────────────────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ─── HEADER BAR ────────────────────────────────────────────────────────────── */
#headerBar {
  display: flex;
  align-items: center;
  gap: 0;
  height: 36px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  padding: 0;
  overflow: hidden;
}
.hb-home {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  color: var(--grey);
  text-decoration: none;
  border-right: 1px solid var(--border);
  flex-shrink: 0;
  transition: color 0.15s;
}
.hb-home:hover { color: var(--accent); }
.hb-logo {
  font-size: 13px;
  font-weight: bold;
  color: var(--accent);
  letter-spacing: 0.10em;
  padding: 0 14px 0 12px;
  border-right: 1px solid var(--border);
  white-space: nowrap;
  flex-shrink: 0;
}
.hb-tag {
  background: var(--accent);
  color: var(--bg);
  font-weight: bold;
  font-size: 10px;
  padding: 2px 6px;
  letter-spacing: 0.1em;
  margin: 0 10px 0 12px;
  flex-shrink: 0;
  white-space: nowrap;
}
.hb-label {
  font-size: 11px;
  color: var(--grey-hi);
  padding-right: 14px;
  border-right: 1px solid var(--border);
  margin-right: 0;
  flex-shrink: 0;
  white-space: nowrap;
}
.hb-spacer { flex: 1; }
.hb-stat {
  font-size: 11px;
  color: var(--grey);
  padding: 0 12px;
  border-left: 1px solid var(--border);
  white-space: nowrap;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}
.hb-stat .v { font-weight: bold; }
.hb-stat .v-bull { color: var(--green-bright); }
.hb-stat .v-neut { color: var(--amber); }
.hb-stat .v-bear { color: var(--red); }
.hb-stat .v-acc  { color: var(--accent); }
.hb-divider {
  width: 1px;
  height: 18px;
  background: var(--border);
  flex-shrink: 0;
  margin: 0 2px;
}
.hb-status {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
  margin: 0 12px 0 10px;
  flex-shrink: 0;
}
.hb-status.loading { background: var(--amber); box-shadow: 0 0 6px var(--amber); animation: pulse 0.7s infinite alternate; }
.hb-status.err     { background: var(--red);   box-shadow: 0 0 6px var(--red); }
@keyframes pulse { to { opacity: 0.35; } }

/* ─── TOOLBAR ───────────────────────────────────────────────────────────────── */
#toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  padding: 5px 12px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  min-height: 32px;
}
.tb-label {
  font-size: 10px;
  color: var(--grey);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  white-space: nowrap;
}
.tb-sep {
  width: 1px;
  height: 18px;
  background: var(--border);
  flex-shrink: 0;
}
#smSearch {
  background: var(--bg);
  color: var(--white);
  border: 1px solid var(--border);
  font-family: var(--font);
  font-size: 12px;
  padding: 3px 7px;
  height: 22px;
  width: 140px;
  outline: none;
  transition: border-color 0.15s;
}
#smSearch:focus         { border-color: var(--accent); }
#smSearch::placeholder  { color: var(--grey); }

.sm-select {
  background: var(--bg);
  color: var(--white);
  border: 1px solid var(--border);
  font-family: var(--font);
  font-size: 11px;
  padding: 2px 22px 2px 6px;
  height: 22px;
  outline: none;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%2394a3b8' d='M0 0l5 6 5-6z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
  transition: border-color 0.15s;
}
.sm-select:focus { border-color: var(--accent); }
.sm-select option { background: var(--bg-panel); color: var(--white); }

/* Sentiment toggle buttons */
.sent-btn {
  background: var(--bg);
  color: var(--grey);
  border: 1px solid var(--border);
  font-family: var(--font);
  font-size: 10px;
  padding: 2px 10px;
  height: 22px;
  cursor: pointer;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  transition: all 0.15s;
  white-space: nowrap;
}
.sent-btn:hover { color: var(--grey-hi); border-color: var(--grey-hi); }
.sent-btn.active                 { color: var(--bg); border-color: transparent; }
.sent-btn.active[data-sent="all"]     { background: var(--accent); color: var(--bg); }
.sent-btn.active[data-sent="bullish"] { background: var(--green-bright); color: #0a0e27; }
.sent-btn.active[data-sent="neutral"] { background: var(--amber); color: #0a0e27; }
.sent-btn.active[data-sent="bearish"] { background: var(--red); color: #fff; }

/* Legend chips */
.legend-strip {
  display: flex;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
}
.lg-chip {
  font-size: 9px;
  letter-spacing: 0.04em;
  padding: 2px 6px;
  border-radius: 2px;
  white-space: nowrap;
  font-weight: 600;
}
.lg-chip.lc5 { background: rgba(52,211,153,0.15);  color: var(--green-bright); border: 1px solid #065f46; }
.lg-chip.lc4 { background: rgba(16,185,129,0.12);  color: var(--green);        border: 1px solid #047857; }
.lg-chip.lc3 { background: rgba(245,158,11,0.12);  color: var(--amber);        border: 1px solid #78350f; }
.lg-chip.lc2 { background: rgba(239,68,68,0.12);   color: var(--red);          border: 1px solid #991b1b; }
.lg-chip.lc1 { background: rgba(252,165,165,0.10); color: var(--red-bright);   border: 1px solid #7f1d1d; }

#tbRight { margin-left: auto; display: flex; align-items: center; gap: 8px; }
#smCount { font-size: 11px; color: var(--grey-hi); white-space: nowrap; }

/* ─── MAP AREA ──────────────────────────────────────────────────────────────── */
#mapArea {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(82px, 1fr));
  gap: 5px;
  align-content: flex-start;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
#mapArea::-webkit-scrollbar       { width: 4px; }
#mapArea::-webkit-scrollbar-track { background: transparent; }
#mapArea::-webkit-scrollbar-thumb { background: var(--border); }

.sm-loading, .sm-error {
  width: 100%;
  padding: 60px 20px;
  text-align: center;
  font-size: 13px;
  color: var(--grey);
  letter-spacing: 0.08em;
}
.sm-error { color: var(--red); }

/* ─── TILES ─────────────────────────────────────────────────────────────────── */
.sm-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 68px;
  padding: 6px 4px 5px;
  border: 1px solid transparent;
  text-decoration: none;
  position: relative;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s, border-color 0.12s, filter 0.12s;
  animation: tileIn 0.3s backwards ease-out;
  gap: 3px;
}
@keyframes tileIn {
  from { opacity: 0; transform: scale(0.88); }
  to   { opacity: 1; transform: scale(1); }
}
.sm-tile:hover {
  transform: scale(1.08);
  z-index: 5;
  filter: brightness(1.2);
  text-decoration: none;
}

/* Ticker symbol */
.sm-ticker {
  font-size: 11px;
  font-weight: 700;
  color: rgba(255,255,255,0.80);
  letter-spacing: 0.04em;
  line-height: 1;
}
/* Score number */
.sm-score {
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
}
/* Sentiment label */
.sm-label {
  font-size: 7.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  opacity: 0.70;
  line-height: 1;
}

/* ── Tile hover (colours set via inline styles by JS gradient) ─────────────── */
.sm-tile:hover { box-shadow: 0 0 14px var(--tile-glow, rgba(255,255,255,0.2)); }

/* ─── TOOLTIP ───────────────────────────────────────────────────────────────── */
#smTooltip {
  position: fixed;
  z-index: 9999;
  width: 360px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  padding: 16px 18px 14px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.75);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.10s;
}
#smTooltip.visible { opacity: 1; }

.tt-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 7px;
}
.tt-tick {
  font-size: 21px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.06em;
  flex: 1;
}
.tt-score-num {
  font-size: 34px;
  font-weight: 700;
  line-height: 1;
}
.tt-badge {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.10em;
  padding: 3px 7px;
}
.tt-badge.badge-bullish { background: rgba(52,211,153,0.15);  color: var(--green-bright); border: 1px solid #065f46; }
.tt-badge.badge-neutral { background: rgba(245,158,11,0.15);  color: var(--amber);        border: 1px solid #78350f; }
.tt-badge.badge-bearish { background: rgba(239,68,68,0.15);   color: var(--red);          border: 1px solid #991b1b; }

/* score num inherits band colour via JS class on parent */
.tt-header.band-very-high .tt-score-num { color: var(--green-bright); }
.tt-header.band-high      .tt-score-num { color: var(--green); }
.tt-header.band-neutral   .tt-score-num { color: var(--amber); }
.tt-header.band-low       .tt-score-num { color: var(--red); }
.tt-header.band-very-low  .tt-score-num { color: var(--red-bright); }

.tt-company {
  font-size: 15px;
  color: var(--grey-hi);
  margin-bottom: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tt-meta {
  font-size: 13px;
  color: var(--grey);
  margin-bottom: 9px;
  letter-spacing: 0.04em;
}
.tt-divider {
  height: 1px;
  background: var(--border);
  margin: 8px 0;
}
.tt-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 7px;
  line-height: 1.4;
}
.tt-reasoning {
  font-size: 14px;
  color: var(--grey-hi);
  line-height: 1.6;
  margin-bottom: 10px;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.tt-themes {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.tt-theme {
  font-size: 13px;
  padding: 3px 9px;
  letter-spacing: 0.03em;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tt-theme.theme-positive { background: rgba(16,185,129,0.12); color: var(--green); border: 1px solid #065f46; }
.tt-theme.theme-negative { background: rgba(239,68,68,0.12);  color: var(--red);   border: 1px solid #991b1b; }
.tt-theme.theme-neutral  { background: rgba(148,163,184,0.1); color: var(--grey);  border: 1px solid var(--border); }

/* ─── STATUS BAR ────────────────────────────────────────────────────────────── */
#statusBar {
  height: 20px;
  background: var(--bg-alt);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 10px;
  font-size: 10px;
  color: var(--grey);
  flex-shrink: 0;
}
#statusBar .sb-key {
  display: inline-block;
  border: 1px solid var(--border);
  padding: 0 4px;
  font-size: 9px;
  color: var(--grey-hi);
  letter-spacing: 0.04em;
}
#sbMsg { margin-left: auto; color: var(--grey); font-size: 10px; }

/* ─── RESPONSIVE ────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  #mapArea { grid-template-columns: repeat(auto-fill, minmax(68px, 1fr)); }
  .sm-tile { width: 100%; height: 62px; }
  .sm-score { font-size: 18px; }
  .sm-ticker { font-size: 10px; }
  .hb-stat:not(.hb-primary) { display: none; }
  .legend-strip { display: none; }
  #smSearch { width: 100px; }
}
