/* ===================================================================
   Knowledge Map — VS Code Light Theme
   =================================================================== */

:root {
  --bg: #ffffff;
  --surface: rgba(243, 243, 243, 0.96);
  --surface-raised: #ffffff;
  --surface-glass: rgba(246, 246, 246, 0.90);
  --surface-hover: rgba(0, 0, 0, 0.04);
  --border: #e0e0e0;
  --border-hover: #c8c8c8;
  --border-active: rgba(0, 122, 204, 0.35);

  --text-primary: #1e1e1e;
  --text-secondary: #444444;
  --text-muted: #888888;

  /* VS Code Light blue */
  --accent: #007acc;
  --accent-dim: rgba(0, 122, 204, 0.08);
  --accent-border: rgba(0, 122, 204, 0.25);

  --status-live: #388a34;
  --status-warn: #bf8803;
  --status-danger: #cd3131;
  --status-danger-dim: rgba(205, 49, 49, 0.08);

  --heat-none: #e8eaed;
  --heat-low: #4caf7a;
  --heat-med: #e8a735;
  --heat-high: #d65454;
  --heat-critical: #b01c1c;

  --r-xs: 4px;
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 12px;
  --r-xl: 16px;

  --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,.10);
  --shadow-lg: 0 8px 28px rgba(0,0,0,.14);

  --ease: cubic-bezier(.4, 0, .2, 1);
  --ease-out: cubic-bezier(.0, 0, .2, 1);

  --header-h: 52px;
  --filter-h: 40px;
  --ticker-h: 34px;
  --panel-w: 380px;

  --z-map: 1;
  --z-markers: 400;
  --z-filter: 500;
  --z-panel: 600;
  --z-header: 700;
  --z-ticker: 550;
  --z-search: 800;
  --z-toast: 900;
}

/* ---- Reset ---- */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%; width: 100%;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}
ul { list-style: none; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
input[type="text"] { font-family: inherit; }

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,.15); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,.25); }

/* ---- Header ---- */

#app-header {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--header-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: var(--z-header);
}

.logo {
  display: flex; align-items: center; gap: 9px;
  font-weight: 600; font-size: 0.92rem;
  letter-spacing: -0.01em;
  white-space: nowrap;
  color: var(--text-primary);
}
.logo i {
  font-size: 1.05rem;
  color: var(--accent);
}
.logo-badge {
  font-size: .55rem;
  font-weight: 700;
  padding: 2px 6px;
  background: var(--status-danger);
  color: #fff;
  border-radius: 3px;
  letter-spacing: .06em;
  text-transform: uppercase;
  opacity: 0.9;
}

/* ---- Stats Bar ---- */

.stats-bar {
  display: flex; align-items: center; gap: 20px;
}
.stat-item {
  display: flex; align-items: center; gap: 5px;
  font-size: .72rem;
  color: var(--text-muted);
  white-space: nowrap;
}
.stat-item i {
  font-size: .62rem;
  color: var(--text-muted);
}
.stat-value {
  font-weight: 600;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}
.freshness-indicator { gap: 5px; }
.freshness-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-muted);
  transition: background .4s var(--ease);
  flex-shrink: 0;
}
.freshness-dot.green { background: var(--status-live); }
.freshness-dot.amber { background: var(--status-warn); }
.freshness-dot.red   { background: var(--status-danger); }

/* ---- Header Buttons ---- */

.header-right { display: flex; align-items: center; gap: 6px; }

.header-btn {
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--r-sm);
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: .8rem;
  transition: all .15s var(--ease);
}
.header-btn:hover {
  background: var(--surface-hover);
  color: var(--text-secondary);
  border-color: var(--border-hover);
}
.header-btn.active {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: var(--accent-border);
}
.header-btn.syncing i { animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Search ---- */

.search-container {
  position: relative;
  width: 200px;
}
.search-icon {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  font-size: .7rem; color: var(--text-muted);
  pointer-events: none;
}
#search-input {
  width: 100%; height: 34px;
  padding: 0 12px 0 30px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-primary);
  font-size: .78rem;
  outline: none;
  transition: all .15s var(--ease);
}
#search-input::placeholder { color: var(--text-muted); }
#search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.search-dropdown {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  max-height: 240px; overflow-y: auto;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  z-index: var(--z-search);
  display: none;
}
.search-dropdown.open { display: block; }
.search-dropdown li {
  padding: 9px 12px;
  font-size: .78rem;
  cursor: pointer;
  display: flex; justify-content: space-between; align-items: center;
  transition: background .12s;
  border-bottom: 1px solid var(--border);
}
.search-dropdown li:last-child { border-bottom: none; }
.search-dropdown li:hover, .search-dropdown li.highlighted {
  background: var(--accent-dim);
}
.search-dropdown li .search-score {
  font-size: .65rem; color: var(--text-muted); font-weight: 500;
  font-variant-numeric: tabular-nums;
}

/* ---- Filter Bar ---- */

.filter-bar {
  position: fixed; top: var(--header-h); left: 0; right: 0;
  height: var(--filter-h);
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 0 16px;
  background: var(--surface-glass);
  border-bottom: 1px solid var(--border);
  z-index: var(--z-filter);
  transition: transform .25s var(--ease), opacity .25s var(--ease);
}
.filter-bar.hidden { transform: translateY(-100%); opacity: 0; pointer-events: none; }

.filter-chip {
  padding: 4px 12px;
  font-size: .7rem; font-weight: 500;
  border-radius: var(--r-xs);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  transition: all .15s var(--ease);
  white-space: nowrap;
}
.filter-chip:hover {
  background: var(--surface-hover);
  color: var(--text-secondary);
}
.filter-chip.active {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: var(--accent-border);
}
.filter-chip i { margin-right: 3px; font-size: .6rem; }

.mobile-filter-toggle { display: none; }

/* ---- Map ---- */

#map-container {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: var(--z-map);
}
#map {
  width: 100%; height: 100%;
  background: #dde4ec;
}

.leaflet-control-zoom { display: none; }
.leaflet-container { background: #dde4ec !important; }
.leaflet-tile-pane { filter: saturate(.4) contrast(1.05); }

/* ---- Country Tooltip ---- */

.country-tooltip {
  background: var(--surface-raised) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--r-xs) !important;
  padding: 7px 11px !important;
  font-family: 'Inter', sans-serif !important;
  font-size: .74rem !important;
  color: var(--text-primary) !important;
  box-shadow: var(--shadow-md) !important;
  white-space: nowrap;
}
.country-tooltip::before { display: none !important; }
.tooltip-name { font-weight: 600; }
.tooltip-score { color: var(--accent); font-weight: 500; margin-left: 6px; font-size: .72rem; }
.tooltip-keyword { color: var(--text-muted); font-size: .68rem; display: block; margin-top: 2px; }

/* ---- Topic Markers ---- */

.topic-marker {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--r-xs);
  padding: 2px 8px;
  font-size: .6rem;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
  pointer-events: none;
  box-shadow: var(--shadow-sm);
  display: flex; align-items: center; gap: 4px;
  animation: marker-in .35s var(--ease-out) both;
}
@keyframes marker-in {
  from { transform: scale(.7) translateY(6px); opacity: 0; }
  to   { transform: scale(1)  translateY(0);   opacity: 1; }
}
.topic-marker .pulse-dot {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--status-danger);
  animation: pulse-dot 2s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 1;   }
  50%      { opacity: 0.35; }
}

/* ---- Detail Panel ---- */

.detail-panel {
  position: fixed; top: var(--header-h); right: 0; bottom: 0;
  width: var(--panel-w);
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: var(--z-panel);
  transform: translateX(100%);
  transition: transform .3s var(--ease);
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.detail-panel.open { transform: translateX(0); }
.panel-drag-handle { display: none; }

.panel-header {
  padding: 14px 18px 0;
  flex-shrink: 0;
}
.panel-title-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.panel-country-name {
  font-size: 1.05rem; font-weight: 700;
  letter-spacing: -.015em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 240px;
}
.panel-actions { display: flex; gap: 4px; }
.panel-btn {
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--r-xs);
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: .75rem;
  transition: all .15s var(--ease);
}
.panel-btn:hover {
  background: var(--surface-hover);
  color: var(--text-secondary);
}

/* ---- Panel Tabs ---- */

.panel-tabs {
  display: flex; gap: 0;
  border-bottom: 1px solid var(--border);
}
.panel-tab {
  padding: 8px 13px;
  font-size: .7rem; font-weight: 500;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  transition: all .15s var(--ease);
  white-space: nowrap;
}
.panel-tab:hover { color: var(--text-secondary); }
.panel-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ---- Panel Body ---- */

.panel-body {
  flex: 1; overflow-y: auto;
  padding: 16px 18px;
}
.tab-content { display: none; }
.tab-content.active { display: block; animation: fade-in .2s var(--ease-out); }
@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.empty-state {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.78rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.empty-state i {
  font-size: 1.2rem;
  opacity: 0.3;
}

/* ---- Overview Tab ---- */

.overview-score-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 18px;
  text-align: center;
  margin-bottom: 14px;
}
.score-label {
  font-size: .65rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .07em;
  margin-bottom: 4px;
}
.score-big {
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -.03em;
  line-height: 1.15;
}
.score-bar-track {
  margin-top: 12px; height: 4px;
  background: rgba(0,0,0,.06);
  border-radius: 2px; overflow: hidden;
}
.score-bar-fill {
  height: 100%; width: 0;
  background: linear-gradient(90deg, var(--accent) 0%, var(--status-warn) 65%, var(--status-danger) 100%);
  border-radius: 2px;
  transition: width .7s var(--ease);
}

.overview-delta {
  display: flex; align-items: center; gap: 6px;
  font-size: .75rem; color: var(--text-secondary);
  margin-bottom: 10px;
}
.overview-delta .delta-icon { font-size: .7rem; }
.overview-delta.up .delta-icon::before      { content: '▲'; color: var(--status-live); }
.overview-delta.down .delta-icon::before    { content: '▼'; color: var(--status-danger); }
.overview-delta.neutral .delta-icon::before { content: '—'; color: var(--text-muted); }

.overview-meta {
  font-size: .65rem; color: var(--text-muted);
}
.overview-meta i { margin-right: 3px; }

/* ---- Topics Tab ---- */

.topics-chart {
  display: flex; flex-direction: column; gap: 8px;
  width: 100%;
}
.topic-row {
  display: flex; align-items: center; gap: 8px;
  animation: stagger-in .25s var(--ease-out) both;
  width: 100%;
}
.topic-row .topic-label {
  flex: 0 0 72px;
  font-size: .7rem; font-weight: 500;
  color: var(--text-secondary);
  text-align: right;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  cursor: pointer;
}
.topic-row .topic-label:hover { color: var(--accent); }
.topic-row .topic-bar-track {
  flex: 1; height: 14px;
  min-width: 80px;
  background: rgba(0,0,0,.04);
  border-radius: 2px; overflow: hidden;
}
.topic-row .topic-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-dim) 0%, rgba(0, 122, 204, 0.35) 100%);
  border-radius: 2px;
  transition: width .5s var(--ease);
}
.topic-row .topic-score {
  flex: 0 0 36px;
  font-size: .6rem; font-weight: 600;
  color: var(--text-muted);
  text-align: left;
  font-variant-numeric: tabular-nums;
}
@keyframes stagger-in {
  from { opacity: 0; transform: translateX(-6px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ---- Sources Tab ---- */

.sources-list { display: flex; flex-direction: column; gap: 4px; }
.source-item {
  display: flex; align-items: flex-start; gap: 9px;
  padding: 9px 10px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--r-xs);
  transition: background .15s;
  animation: stagger-in .25s var(--ease-out) both;
}
.source-item:hover { background: var(--surface-hover); }
.source-badge {
  flex-shrink: 0;
  width: 20px; height: 20px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--r-xs);
  font-size: .55rem; font-weight: 700;
  margin-top: 1px;
}
.source-badge.reddit   { background: rgba(255, 69, 0, 0.10); color: #d04520; }
.source-badge.wikipedia { background: rgba(0,0,0,.06); color: #555; }
.source-info { flex: 1; min-width: 0; }
.source-title {
  font-size: .74rem; font-weight: 500;
  color: var(--text-primary);
  display: -webkit-box;
  -webkit-line-clamp: 2; line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.source-title a { color: inherit; }
.source-title a:hover { color: var(--accent); }
.source-meta {
  margin-top: 2px;
  display: flex; gap: 8px;
  font-size: .6rem; color: var(--text-muted);
}

/* ---- Neighbours Tab ---- */

.neighbours-list { display: flex; flex-direction: column; gap: 4px; }
.neighbour-item {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 10px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--r-xs);
  cursor: pointer;
  transition: background .15s;
  animation: stagger-in .25s var(--ease-out) both;
}
.neighbour-item:hover { background: var(--surface-hover); }
.neighbour-rank {
  width: 20px; height: 20px;
  display: flex; align-items: center; justify-content: center;
  font-size: .6rem; font-weight: 700;
  border-radius: var(--r-xs);
  background: var(--accent-dim);
  color: var(--accent);
}
.neighbour-name { flex: 1; font-size: .75rem; font-weight: 500; }
.neighbour-sim {
  font-size: .65rem; color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* ---- Skeleton Blocks ---- */

.skeleton-block {
  background: linear-gradient(90deg,
    rgba(0,0,0,.04) 25%,
    rgba(0,0,0,.07) 50%,
    rgba(0,0,0,.04) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.8s ease infinite;
  border-radius: var(--r-xs);
  height: 18px;
  margin-bottom: 6px;
}
.skeleton-block.short   { width: 70%; }
.skeleton-block.shorter { width: 45%; }
.skeleton-block.tall    { height: 120px; }
@keyframes shimmer {
  0%   { background-position: 200% 0;  }
  100% { background-position: -200% 0; }
}

/* ---- Trending Ticker ---- */

.trending-ticker {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--ticker-h);
  display: flex; align-items: center;
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: var(--z-ticker);
  overflow: hidden;
}
.ticker-label {
  padding: 0 12px;
  font-size: .62rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  display: flex; align-items: center; gap: 5px;
  border-right: 1px solid var(--border);
  height: 100%;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.ticker-label i { font-size: .6rem; color: var(--status-warn); }
.ticker-track {
  flex: 1; overflow: hidden; position: relative;
  mask-image: linear-gradient(to right, transparent, black 30px, black calc(100% - 30px), transparent);
  -webkit-mask-image: linear-gradient(to right, transparent, black 30px, black calc(100% - 30px), transparent);
}
.ticker-content {
  display: flex; align-items: center; gap: 16px;
  animation: scroll-ticker 45s linear infinite;
  white-space: nowrap;
  padding: 0 16px;
}
.ticker-content:hover { animation-play-state: paused; }
@keyframes scroll-ticker {
  0%   { transform: translateX(0);    }
  100% { transform: translateX(-50%); }
}
.ticker-item {
  font-size: .65rem; font-weight: 500;
  color: var(--text-muted);
  padding: 2px 8px;
  border-radius: var(--r-xs);
  background: transparent;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all .15s var(--ease);
  flex-shrink: 0;
}
.ticker-item:hover {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: var(--accent-border);
}
.ticker-item .ticker-hash { color: var(--text-muted); margin-right: 1px; }

/* ---- Toasts ---- */

.toast-container {
  position: fixed; top: calc(var(--header-h) + 10px); right: 14px;
  display: flex; flex-direction: column; gap: 6px;
  z-index: var(--z-toast);
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 14px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-md);
  font-size: .74rem;
  color: var(--text-primary);
  pointer-events: auto;
  animation: toast-in .3s var(--ease-out);
  max-width: 320px;
}
.toast.exit { animation: toast-out .2s var(--ease) forwards; }
@keyframes toast-in {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateX(20px); }
}
.toast-icon { font-size: .8rem; flex-shrink: 0; }
.toast.success .toast-icon { color: var(--status-live); }
.toast.warning .toast-icon { color: var(--status-warn); }
.toast.error   .toast-icon { color: var(--status-danger); }
.toast.info    .toast-icon { color: var(--accent); }

/* ---- Tablet (769px – 1024px) ---- */

@media (max-width: 1024px) {
  :root {
    --panel-w: 340px;
  }
  .stats-bar { gap: 14px; }
  .stat-label { display: none; }
  .search-container { width: 170px; }
}

/* ---- Mobile (≤768px) ---- */

@media (max-width: 768px) {
  :root {
    --panel-w: 100%;
    --header-h: 48px;
    --ticker-h: 32px;
  }

  #app-header { padding: 0 10px; }

  .header-center { display: none; }
  .logo-text { display: none; }
  .search-container { width: 140px; }
  .mobile-filter-toggle { display: flex; }

  .header-btn {
    width: 38px; height: 38px;
    font-size: .85rem;
  }

  .filter-bar {
    display: none;
    flex-wrap: wrap;
    height: auto;
    padding: 8px 10px;
    gap: 6px;
  }
  .filter-bar.show-mobile { display: flex; }
  .filter-chip {
    padding: 6px 14px;
    font-size: .72rem;
  }

  .detail-panel {
    top: auto; right: 0; left: 0; bottom: 0;
    width: 100%;
    max-height: 70vh;
    border-left: none;
    border-top: 1px solid var(--border);
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    transform: translateY(100%);
  }
  .detail-panel.open { transform: translateY(0); }
  .panel-drag-handle {
    display: flex; justify-content: center; padding: 10px 0 4px;
    cursor: grab;
  }
  .drag-bar {
    width: 36px; height: 4px;
    background: rgba(0,0,0,.12);
    border-radius: 3px;
  }
  .panel-country-name { max-width: 200px; }

  .trending-ticker { font-size: .6rem; }
  .ticker-label { padding: 0 6px; font-size: .55rem; }

  .toast-container { right: 10px; left: 10px; }
  .toast { max-width: 100%; }
}

/* ---- Small Phone (≤480px) ---- */

@media (max-width: 480px) {
  .search-container { width: 110px; }
  #search-input { font-size: .72rem; height: 36px; }
  .panel-tab { padding: 8px 10px; font-size: .68rem; }
  .panel-body { padding: 14px; }
  .header-btn { width: 36px; height: 36px; }

  .filter-chip {
    padding: 5px 10px;
    font-size: .65rem;
  }
}
