/* ===== Components ===== */

/* Panel card */
.panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  transition: all var(--transition-base);
  display: flex;
  flex-direction: column;
}

.panel:hover {
  border-color: var(--border-hover);
  box-shadow: var(--shadow-lg);
}

.panel-header {
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border-default);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.panel-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.panel-title svg {
  width: 16px;
  height: 16px;
  color: var(--accent-cyan);
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.panel-body {
  padding: var(--space-5);
  flex: 1;
  min-height: 0;
}

/* KPI Card */
.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  display: flex;
  align-items: flex-start;
  gap: var(--space-4);
  box-shadow: var(--shadow-md);
  transition: all var(--transition-base);
  border-top: 3px solid transparent;
}

.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  border-color: var(--border-hover);
}

.kpi-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.kpi-icon svg {
  width: 22px;
  height: 22px;
}

.kpi-content {
  flex: 1;
  min-width: 0;
}

.kpi-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: var(--space-2);
}

.kpi-value {
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -1px;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.kpi-trend {
  font-size: 12px;
  font-weight: 600;
  margin-top: var(--space-2);
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.kpi-trend.up { color: var(--accent-green); }
.kpi-trend.down { color: var(--accent-red); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
}

.btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-primary {
  background: var(--accent-blue);
  color: white;
  border-color: var(--accent-blue);
  box-shadow: 0 2px 8px rgba(91, 141, 239, 0.25);
}

.btn-primary:hover {
  background: #6a9af2;
  box-shadow: 0 4px 12px rgba(91, 141, 239, 0.35);
}

.btn-sm {
  padding: var(--space-1) var(--space-3);
  font-size: 12px;
}

.btn-icon {
  padding: var(--space-2);
  width: 32px;
  height: 32px;
}

.btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.btn-icon svg {
  width: 16px;
  height: 16px;
}

/* Filter pills */
.filter-pills {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.filter-pill {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-full);
  border: 1px solid var(--border-default);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.filter-pill:hover {
  border-color: var(--border-hover);
  color: var(--text-primary);
}

.filter-pill.active {
  background: var(--accent-blue);
  border-color: var(--accent-blue);
  color: white;
}

/* Inputs */
.input {
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-default);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
  transition: all var(--transition-fast);
  min-width: 180px;
}

.input:focus {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 0 3px rgba(79, 209, 255, 0.1);
}

.input::placeholder {
  color: var(--text-muted);
}

.select {
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-default);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
  cursor: pointer;
  min-width: 140px;
}

.select:focus {
  border-color: var(--accent-cyan);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
  border: 1px solid transparent;
}

.badge-blue {
  background: rgba(91, 141, 239, 0.12);
  color: var(--accent-blue);
  border-color: rgba(91, 141, 239, 0.25);
}

.badge-cyan {
  background: rgba(79, 209, 255, 0.12);
  color: var(--accent-cyan);
  border-color: rgba(79, 209, 255, 0.25);
}

.badge-green {
  background: rgba(126, 231, 135, 0.12);
  color: var(--accent-green);
  border-color: rgba(126, 231, 135, 0.25);
}

.badge-amber {
  background: rgba(245, 183, 93, 0.12);
  color: var(--accent-amber);
  border-color: rgba(245, 183, 93, 0.25);
}

.badge-red {
  background: rgba(255, 123, 138, 0.12);
  color: var(--accent-red);
  border-color: rgba(255, 123, 138, 0.25);
}

.badge-gray {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-muted);
  border-color: var(--border-default);
}

/* Tables */
.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}

.data-table th {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border-hover);
  background: var(--bg-elevated);
  position: sticky;
  top: 0;
  z-index: 10;
  white-space: nowrap;
}

.data-table td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-default);
  color: var(--text-primary);
  vertical-align: middle;
  white-space: nowrap;
}

.data-table tbody tr:hover td {
  background: rgba(79, 209, 255, 0.04);
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.data-table .sticky-col {
  position: sticky;
  left: 0;
  background: var(--bg-surface);
  z-index: 5;
  box-shadow: 2px 0 4px rgba(0, 0, 0, 0.2);
}

.data-table .sticky-col-2 {
  position: sticky;
  left: 50px;
  background: var(--bg-surface);
  z-index: 5;
  box-shadow: 2px 0 4px rgba(0, 0, 0, 0.2);
}

.data-table .cell-wrap {
  white-space: normal;
  word-break: break-word;
  line-height: 1.5;
  min-width: 200px;
}

/* Table scroll wrapper */
.table-scroll {
  overflow: auto;
  max-height: 520px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-default);
}

/* Rank badge */
.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
  border: 1px solid transparent;
  line-height: 1;
}

.rank-1 {
  background: rgba(245, 183, 93, 0.16);
  color: var(--accent-amber);
  border-color: rgba(245, 183, 93, 0.35);
}

.rank-2 {
  background: rgba(91, 141, 239, 0.16);
  color: var(--accent-blue);
  border-color: rgba(91, 141, 239, 0.35);
}

.rank-3 {
  background: rgba(126, 231, 135, 0.16);
  color: var(--accent-green);
  border-color: rgba(126, 231, 135, 0.35);
}

.rank-other {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-secondary);
  border-color: var(--border-default);
  border-radius: 5px;
  font-size: 10px;
}

.rank-none {
  background: transparent;
  color: var(--text-muted);
  border: none;
  font-size: 12px;
  opacity: 0.4;
}

.mention-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-cyan);
  box-shadow: 0 0 6px rgba(79, 209, 255, 0.5);
}

/* Heatmap */
.heatmap {
  display: grid;
  grid-template-columns: minmax(180px, 2fr) 70px repeat(4, 1fr);
  gap: 4px;
  font-size: 11px;
  min-width: 620px;
}

.heatmap-header {
  padding: 8px 6px;
  background: var(--bg-elevated);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  font-weight: 600;
  color: var(--text-secondary);
  text-align: center;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.heatmap-header:first-child {
  text-align: left;
  padding-left: var(--space-3);
  border-radius: var(--radius-sm) 0 0 0;
}

.heatmap-header:last-child {
  border-radius: 0 var(--radius-sm) 0 0;
}

.heatmap-kw {
  padding: 8px var(--space-3);
  display: flex;
  align-items: center;
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  transition: background var(--transition-fast);
  overflow: hidden;
  font-size: 12px;
}

.heatmap-kw:hover {
  background: var(--bg-hover);
  color: var(--accent-cyan);
}

.heatmap-coverage {
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 3px;
  background: rgba(255, 255, 255, 0.02);
  border-radius: var(--radius-sm);
}

.coverage-track {
  width: 70%;
  height: 3px;
  background: var(--bg-hover);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.coverage-bar {
  height: 100%;
  border-radius: var(--radius-full);
  transition: width 0.6s ease;
}

.coverage-text {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-secondary);
}

.heatmap-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid transparent;
}

.heatmap-cell:hover {
  background: var(--bg-hover);
  border-color: var(--border-hover);
}

.heatmap-cell.rank-mentioned {
  background: rgba(79, 209, 255, 0.05);
}

.heatmap-cell.rank-mentioned:hover {
  background: rgba(79, 209, 255, 0.1);
}

.heatmap-cell .not-mentioned {
  color: var(--text-muted);
  font-size: 12px;
  opacity: 0.35;
}

/* Drawer */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 100;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-base);
}

.drawer-backdrop.open {
  opacity: 1;
  visibility: visible;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: 480px;
  max-width: 100%;
  height: 100vh;
  background: var(--bg-surface);
  border-left: 1px solid var(--border-default);
  box-shadow: var(--shadow-xl);
  z-index: 101;
  transform: translateX(100%);
  transition: transform var(--transition-slow);
  display: flex;
  flex-direction: column;
}

.drawer.open {
  transform: translateX(0);
}

.drawer-header {
  padding: var(--space-6);
  border-bottom: 1px solid var(--border-default);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
}

.drawer-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.4;
}

.drawer-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: var(--space-1);
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-6);
}

.drawer-section {
  margin-bottom: var(--space-6);
}

.drawer-section-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: var(--space-3);
}

.drawer-platform {
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  margin-bottom: var(--space-3);
}

.drawer-platform-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-3);
}

.drawer-platform-name {
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.drawer-platform-status {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.drawer-source-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.drawer-source-item {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  background: var(--bg-surface);
  border-radius: var(--radius-sm);
  font-size: 12px;
  border: 1px solid var(--border-default);
}

.drawer-source-item a {
  color: var(--text-primary);
  text-decoration: none;
  flex: 1;
  word-break: break-all;
}

.drawer-source-item a:hover {
  color: var(--accent-cyan);
}

.drawer-source-item a svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  margin-left: 4px;
  vertical-align: middle;
}

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-10) var(--space-6);
  color: var(--text-muted);
  text-align: center;
}

.empty-state svg {
  width: 48px;
  height: 48px;
  margin-bottom: var(--space-4);
  opacity: 0.5;
}

.empty-state h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: var(--space-2);
}

/* Loading overlay */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-base);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  flex-direction: column;
  gap: var(--space-4);
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border-default);
  border-top-color: var(--accent-cyan);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-text {
  color: var(--text-secondary);
  font-size: 14px;
}

/* Article list */
.article-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.article-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  transition: all var(--transition-fast);
}

.article-card:hover {
  border-color: var(--border-hover);
  background: var(--bg-hover);
}

.article-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.5;
  margin-bottom: var(--space-2);
}

.article-meta {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}

/* Chart wrapper */
.chart-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 280px;
}

.chart-wrapper canvas {
  width: 100% !important;
  height: 100% !important;
}

/* Progress ring */
.progress-ring {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.progress-ring svg {
  transform: rotate(-90deg);
}

.progress-ring-bg {
  fill: none;
  stroke: var(--bg-hover);
  stroke-width: 8;
}

.progress-ring-fill {
  fill: none;
  stroke: var(--accent-cyan);
  stroke-width: 8;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.8s ease;
}

.progress-ring-text {
  position: absolute;
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}

/* Platform stat card in grid */
.platform-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  transition: all var(--transition-base);
  border-left: 4px solid transparent;
}

.platform-card:hover {
  border-color: var(--border-hover);
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.platform-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}

.platform-card-name {
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.platform-card-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  box-shadow: 0 0 10px currentColor;
}

/* Chart legend (HTML, replaces Chart.js built-in legend) */
.chart-legend {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  margin-left: auto;
  font-size: 12px;
  color: var(--text-secondary);
}

.chart-legend-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.chart-legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  box-shadow: 0 0 10px currentColor;
}

.platform-card-main {
  font-size: 36px;
  font-weight: 800;
  line-height: 1;
  margin-bottom: var(--space-3);
  font-variant-numeric: tabular-nums;
}

.platform-card-grid {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-2);
}

.platform-card-metric {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--space-1);
  padding: var(--space-2) 0;
  border-top: 1px solid var(--border-default);
}

.platform-card-metric-label {
  font-size: 11px;
  color: var(--text-muted);
}

.platform-card-metric-value {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
}

/* Platform cards row in overview */
.platform-cards-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-4);
}

.platform-cards-row .platform-card {
  width: 100%;
  min-width: 0;
}

@media (max-width: 1200px) {
  .platform-cards-row {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 640px) {
  .platform-cards-row {
    grid-template-columns: 1fr;
  }
}

/* Source grid */
.source-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: var(--space-4);
}

.source-item {
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  text-align: center;
  transition: all var(--transition-fast);
}

.source-item:hover {
  border-color: var(--accent-cyan);
  transform: translateY(-2px);
  box-shadow: 0 0 16px rgba(79, 209, 255, 0.1);
}

.source-item-name {
  font-size: 12px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: var(--space-2);
}

.source-item-count {
  font-size: 24px;
  font-weight: 800;
  color: var(--accent-cyan);
}

/* Stats summary row */
.stats-summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-5);
  margin-bottom: var(--space-5);
}

@media (max-width: 1200px) {
  .stats-summary { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
  .stats-summary { grid-template-columns: 1fr; }
  .heatmap { grid-template-columns: minmax(160px, 2fr) 70px repeat(4, 1fr); font-size: 11px; }
  .platform-card-grid { grid-template-columns: repeat(2, 1fr); }
}
