/* ─── Reset & base ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --navy:       #0d1f3c;
  --navy-mid:   #1a3c6e;
  --navy-light: #254d8a;
  --gold:       #c8a84b;
  --gold-light: #e8c96a;
  --bg:         #f5f6f8;
  --surface:    #ffffff;
  --surface2:   #f0f2f5;
  --border:     rgba(0,0,0,.08);
  --border-mid: rgba(0,0,0,.13);
  --text-1:     #0d1f3c;
  --text-2:     #4a5568;
  --text-3:     #8a94a6;
  --pos:        #16a34a;
  --pos-bg:     #dcfce7;
  --neg:        #dc2626;
  --neg-bg:     #fee2e2;
  --neu:        #6b7280;
  --neu-bg:     #f3f4f6;
  --sidebar-w:  230px;
  --topbar-h:   56px;
  --radius:     10px;
  --radius-sm:  6px;
  --shadow:     0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --font-main:  'Inter', system-ui, sans-serif;
  --font-mono:  'JetBrains Mono', monospace;
}

html { font-size: 14px; }
body {
  font-family: var(--font-main);
  background: var(--bg);
  color: var(--text-1);
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ─── Sidebar ───────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--navy);
  display: flex;
  flex-direction: column;
  height: 100vh;
  flex-shrink: 0;
  transition: transform .25s ease;
  z-index: 50;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.brand-emblem {
  width: 36px;
  height: 36px;
  background: var(--gold);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 13px;
  color: var(--navy);
  letter-spacing: .5px;
  flex-shrink: 0;
}

.brand-name  { display: block; font-size: 13px; font-weight: 600; color: #fff; }
.brand-sub   { display: block; font-size: 10px; color: rgba(255,255,255,.45); letter-spacing: .3px; }

.sidebar-nav {
  flex: 1;
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: rgba(255,255,255,.55);
  font-size: 13px;
  font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }
.nav-item:hover  { background: rgba(255,255,255,.07); color: rgba(255,255,255,.9); }
.nav-item.active { background: var(--gold); color: var(--navy); }
.nav-item.active svg { stroke: var(--navy); }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,.08);
}

.live-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}
.live-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #4ade80;
  animation: blink 1.6s infinite;
}
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:.25} }
.live-text   { font-size: 11px; color: #4ade80; font-weight: 500; }
.last-update { font-size: 10px; color: rgba(255,255,255,.3); font-family: var(--font-mono); }

/* ─── Layout ────────────────────────────────────────────── */
.main-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  flex-shrink: 0;
}

.menu-btn {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: var(--text-2);
}
.menu-btn svg { width: 20px; height: 20px; }

.topbar-center { flex: 1; }

.search-wrap {
  position: relative;
  max-width: 380px;
}
.search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 15px; height: 15px;
  color: var(--text-3);
  pointer-events: none;
}
.search-input {
  width: 100%;
  padding: 7px 12px 7px 34px;
  border: 1px solid var(--border-mid);
  border-radius: 20px;
  font-family: var(--font-main);
  font-size: 13px;
  background: var(--bg);
  color: var(--text-1);
  outline: none;
  transition: border-color .15s;
}
.search-input:focus { border-color: var(--navy-light); background: #fff; }

.topbar-actions { display: flex; align-items: center; gap: 8px; }

.platform-status { display: flex; gap: 6px; }
.plat-pill {
  width: 8px; height: 8px;
  border-radius: 50%;
  cursor: default;
  transition: transform .15s;
}
.plat-pill:hover { transform: scale(1.4); }

.btn-refresh, .btn-export {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-family: var(--font-main);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
}
.btn-refresh {
  background: var(--navy);
  color: #fff;
  border: none;
}
.btn-refresh:hover { background: var(--navy-light); }
.btn-refresh.spinning svg { animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.btn-refresh svg, .btn-export svg { width: 14px; height: 14px; }

.btn-export {
  background: none;
  border: 1px solid var(--border-mid);
  color: var(--text-2);
}
.btn-export:hover { background: var(--bg); }

/* ─── Content area ──────────────────────────────────────── */
.content {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px 24px;
}

.view { display: none; }
.view.active { display: block; }

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 8px;
}

.view-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--navy);
}

.date-range {
  font-size: 11px;
  color: var(--text-3);
  font-family: var(--font-mono);
}

.section-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: .6px;
  margin: 16px 0 8px;
}

/* ─── Cards ─────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--navy);
}

/* ─── Stats strip ───────────────────────────────────────── */
.stats-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
}
.stat-lbl { font-size: 10px; color: var(--text-3); font-weight: 600; text-transform: uppercase; letter-spacing: .4px; margin-bottom: 4px; }
.stat-val { font-size: 22px; font-weight: 600; color: var(--navy); line-height: 1.1; }
.stat-delta { font-size: 10px; margin-top: 3px; display: flex; align-items: center; gap: 3px; }
.delta-up   { color: var(--pos); }
.delta-dn   { color: var(--neg); }

/* ─── Sentiment strip ───────────────────────────────────── */
.sentiment-strip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow);
  flex-wrap: wrap;
}
.sent-label { font-size: 11px; color: var(--text-3); white-space: nowrap; }
.sent-bar-wrap { flex: 1; min-width: 120px; }
.sent-bar-track { height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; display: flex; }
.sent-fill-pos  { background: var(--pos);  height: 8px; transition: width .5s; }
.sent-fill-neg  { background: var(--neg);  height: 8px; transition: width .5s; }
.sent-fill-neu  { background: var(--neu);  height: 8px; transition: width .5s; }
.sent-pct { font-size: 11px; font-family: var(--font-mono); white-space: nowrap; }
.pct-pos { color: var(--pos); }
.pct-neg { color: var(--neg); }
.pct-neu { color: var(--neu); }

/* ─── Platform grid ─────────────────────────────────────── */
.platform-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.plat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.plat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.plat-id {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-1);
}
.plat-icon { width: 18px; height: 18px; border-radius: 4px; display: flex; align-items: center; justify-content: center; }
.plat-badge {
  font-size: 11px;
  font-family: var(--font-mono);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2px 8px;
  color: var(--text-2);
}

.plat-tabs { display: flex; border-bottom: 1px solid var(--border); }
.ptab {
  flex: 1;
  text-align: center;
  padding: 6px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-3);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all .15s;
}
.ptab.on { color: var(--navy); border-bottom-color: var(--gold); }

.plat-feed { max-height: 240px; overflow-y: auto; }
.plat-feed::-webkit-scrollbar { width: 3px; }
.plat-feed::-webkit-scrollbar-thumb { background: var(--border-mid); border-radius: 2px; }

.post-item {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .1s;
}
.post-item:last-child { border-bottom: none; }
.post-item:hover { background: var(--bg); }

.post-meta { display: flex; justify-content: space-between; align-items: center; margin-bottom: 3px; }
.post-user { font-size: 11px; font-weight: 600; color: var(--text-1); }
.post-time { font-size: 10px; color: var(--text-3); font-family: var(--font-mono); }
.post-text { font-size: 11px; color: var(--text-2); line-height: 1.55; margin-bottom: 5px; }
.post-text .kw-hit { color: var(--navy-light); font-weight: 600; }
.post-foot { display: flex; align-items: center; gap: 8px; }

.sent-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 20px;
  font-weight: 500;
}
.chip-pos { background: var(--pos-bg); color: var(--pos); }
.chip-neg { background: var(--neg-bg); color: var(--neg); }
.chip-neu { background: var(--neu-bg); color: var(--neu); }

.post-stats { font-size: 10px; color: var(--text-3); display: flex; gap: 8px; }

.plat-chart-wrap { padding: 10px 12px 12px; }
.plat-chart-wrap canvas { max-height: 110px; }

/* ─── Bottom row ────────────────────────────────────────── */
.bottom-row {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 10px;
}

.chart-card .chart-wrap { padding: 12px 14px; }
.chart-wrap canvas { max-height: 200px; }

.legend-row { display: flex; gap: 10px; flex-wrap: wrap; }
.leg-item { display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--text-2); }
.leg-dot { width: 8px; height: 8px; border-radius: 2px; }

.kw-rank-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
}
.kw-rank-item:last-child { border-bottom: none; }
.kw-rank-num { font-size: 11px; color: var(--text-3); font-family: var(--font-mono); width: 16px; }
.kw-rank-word { flex: 1; font-size: 12px; color: var(--text-1); font-weight: 500; }
.kw-rank-bar-wrap { width: 80px; height: 4px; background: var(--bg); border-radius: 2px; }
.kw-rank-bar { height: 4px; background: var(--gold); border-radius: 2px; }
.kw-rank-count { font-size: 11px; font-family: var(--font-mono); color: var(--text-2); min-width: 28px; text-align: right; }

/* ─── Mentions view ─────────────────────────────────────── */
.filter-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid var(--border-mid);
  background: var(--surface);
  cursor: pointer;
  font-family: var(--font-main);
  color: var(--text-2);
  transition: all .15s;
}
.chip.on { background: var(--navy); color: #fff; border-color: var(--navy); }

.mentions-list { display: flex; flex-direction: column; gap: 8px; }
.mention-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: pointer;
  transition: box-shadow .15s;
}
.mention-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,.1); }
.mention-top { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.mention-plat-dot { width: 10px; height: 10px; border-radius: 50%; }
.mention-plat-name { font-size: 11px; font-weight: 600; color: var(--text-3); }
.mention-user { font-size: 12px; font-weight: 600; color: var(--text-1); margin-left: auto; }
.mention-time { font-size: 10px; color: var(--text-3); font-family: var(--font-mono); }
.mention-text { font-size: 13px; color: var(--text-2); line-height: 1.6; margin-bottom: 8px; }
.mention-foot { display: flex; align-items: center; gap: 8px; }

/* ─── Sentiment view ────────────────────────────────────── */
.sentiment-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.neg-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.neg-item:last-child { border-bottom: none; }
.neg-sev { width: 3px; border-radius: 2px; align-self: stretch; background: var(--neg); flex-shrink: 0; }
.neg-text { font-size: 12px; color: var(--text-2); line-height: 1.5; }
.neg-meta { font-size: 10px; color: var(--text-3); margin-top: 3px; font-family: var(--font-mono); }

/* ─── News view ─────────────────────────────────────────── */
.news-grid { display: flex; flex-direction: column; gap: 8px; }
.news-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  cursor: pointer;
  transition: box-shadow .15s;
}
.news-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,.1); }
.news-source-badge {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .4px;
  text-transform: uppercase;
  color: var(--navy-light);
  background: rgba(26,60,110,.08);
  border-radius: 4px;
  padding: 3px 6px;
  white-space: nowrap;
  flex-shrink: 0;
}
.news-body { flex: 1; }
.news-title-text { font-size: 13px; font-weight: 500; color: var(--text-1); line-height: 1.5; margin-bottom: 4px; }
.news-title-text .kw-hit { color: var(--navy-light); font-weight: 700; }
.news-foot { display: flex; align-items: center; gap: 8px; }
.news-time { font-size: 10px; color: var(--text-3); font-family: var(--font-mono); }

/* ─── Keywords view ─────────────────────────────────────── */
.kw-manager { }
.kw-count { font-size: 11px; color: var(--text-3); font-family: var(--font-mono); }
.kw-add-row { display: flex; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.kw-input {
  flex: 1;
  padding: 7px 12px;
  border: 1px solid var(--border-mid);
  border-radius: var(--radius-sm);
  font-family: var(--font-main);
  font-size: 13px;
  color: var(--text-1);
  outline: none;
  background: var(--bg);
}
.kw-input:focus { border-color: var(--navy-light); background: #fff; }

.btn-primary {
  background: var(--navy);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 7px 16px;
  font-family: var(--font-main);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s;
}
.btn-primary:hover { background: var(--navy-light); }

.kw-grid { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 14px; }
.kw-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg);
  border: 1px solid var(--border-mid);
  border-radius: 20px;
  padding: 5px 10px 5px 12px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-1);
  cursor: default;
}
.kw-rm {
  font-size: 10px;
  color: var(--text-3);
  cursor: pointer;
  padding: 1px 2px;
  border-radius: 50%;
  line-height: 1;
}
.kw-rm:hover { color: var(--neg); background: var(--neg-bg); }

.kw-perf-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
}
.kw-perf-row:last-child { border-bottom: none; }
.kw-perf-word { flex: 1; font-size: 12px; font-weight: 500; }
.kw-perf-bar-wrap { width: 100px; height: 4px; background: var(--bg); border-radius: 2px; }
.kw-perf-bar { height: 4px; background: var(--navy-light); border-radius: 2px; }
.kw-perf-n { font-size: 11px; font-family: var(--font-mono); color: var(--text-2); min-width: 32px; text-align: right; }
.kw-perf-delta { font-size: 10px; min-width: 40px; text-align: right; }

/* ─── Reports view ──────────────────────────────────────── */
.reports-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}
.report-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: all .15s;
  box-shadow: var(--shadow);
}
.report-card:hover { border-color: var(--navy-light); box-shadow: 0 2px 8px rgba(13,31,60,.12); }
.report-icon { font-size: 24px; }
.report-info { flex: 1; }
.report-name { font-size: 13px; font-weight: 600; color: var(--text-1); margin-bottom: 3px; }
.report-desc { font-size: 11px; color: var(--text-3); line-height: 1.5; }
.report-dl { font-size: 18px; color: var(--text-3); font-weight: 300; }

.report-log-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.report-log-row:last-child { border-bottom: none; }
.rl-name { font-weight: 500; color: var(--text-1); }
.rl-time { font-size: 10px; color: var(--text-3); font-family: var(--font-mono); }
.rl-dl { font-size: 11px; color: var(--navy-light); cursor: pointer; }

/* ─── Modal ─────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,.2);
  width: 480px;
  max-width: 100%;
  max-height: 85vh;
  overflow-y: auto;
}
.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-platform { font-size: 10px; font-weight: 700; color: var(--text-3); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 2px; }
.modal-user { font-size: 14px; font-weight: 600; color: var(--navy); }
.modal-close {
  background: none; border: none; cursor: pointer;
  font-size: 16px; color: var(--text-3); padding: 2px 6px; line-height: 1;
}
.modal-close:hover { color: var(--text-1); }
.modal-body { padding: 14px 16px; font-size: 13px; color: var(--text-2); line-height: 1.7; }
.modal-body .kw-hit { color: var(--navy-light); font-weight: 600; }
.modal-footer { padding: 10px 16px; border-top: 1px solid var(--border); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ─── Toast ─────────────────────────────────────────────── */
.toast-container { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 6px; z-index: 300; }
.toast {
  background: var(--navy);
  color: #fff;
  font-size: 12px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
  animation: slideIn .2s ease;
}
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ─── Responsive ────────────────────────────────────────── */
@media (max-width: 780px) {
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); }
  .menu-btn { display: block; }
  .bottom-row { grid-template-columns: 1fr; }
  .sentiment-grid { grid-template-columns: 1fr; }
  .topbar-actions .btn-export { display: none; }
}

@media (max-width: 500px) {
  .stats-strip { grid-template-columns: repeat(2, 1fr); }
  .platform-grid { grid-template-columns: 1fr; }
  .search-input { font-size: 12px; }
}
