:root {
  --bg: #f8f9fa;
  --surface: #ffffff;
  --text: #1a1a2e;
  --text-muted: #6b7280;
  --text-faint: #9ca3af;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --accent: #4f6ef7;
  --accent-soft: #eef1fe;
  --accent-text: #3b51c4;
  --shadow-sm: 0 1px 4px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.08);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
}
[data-theme="dark"] {
  --bg: #0f1117;
  --surface: #181b26;
  --text: #edf0f7;
  --text-muted: #8b93a8;
  --text-faint: #5c6478;
  --border: #252a3d;
  --border-strong: #353b52;
  --accent: #6b8aff;
  --accent-soft: #1a2040;
  --accent-text: #8aa3ff;
  --shadow-sm: 0 1px 4px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.45);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { color-scheme: light; }
[data-theme="dark"] { color-scheme: dark; }
body {
  transition: background-color 200ms, color 200ms;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Header */
.header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(255,255,255,0.92);
  -webkit-backdrop-filter: saturate(180%) blur(8px);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--border);
  transition: background-color 200ms, border-color 200ms;
}
[data-theme="dark"] .header { background: rgba(24,27,38,0.92); }
.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  gap: 24px;
}
.brand { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.brand h1 {
  font-size: 17px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.brand .updated {
  font-size: 12px;
  color: var(--text-muted);
}
.search-wrap {
  flex: 1;
  max-width: 520px;
  position: relative;
  margin-left: auto;
}
.search-wrap svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-faint);
}
.search {
  width: 100%;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  padding: 0 12px 0 38px;
  font-family: inherit;
  font-size: 13.5px;
  color: var(--text);
  transition: border-color 120ms, box-shadow 120ms;
}
.search::placeholder { color: var(--text-faint); }
.search:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79,110,247,0.15);
}

/* Layout */
.layout {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 28px;
  align-items: start;
}

/* Sidebar */
.sidebar {
  position: sticky;
  top: 86px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  box-shadow: var(--shadow-sm);
}
.sidebar-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  padding: 6px 8px 10px;
}
.provider-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.provider-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  border: none;
  background: transparent;
  text-align: left;
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  transition: background-color 120ms;
  width: 100%;
}
.provider-item:hover { background: #f3f4f6; }
.provider-item.active {
  background: var(--accent-soft);
  color: var(--accent-text);
  font-weight: 500;
}
.provider-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 11.5px;
  font-weight: 600;
  flex-shrink: 0;
}
.provider-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.provider-count {
  font-size: 11px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}
.provider-item.active .provider-count { color: var(--accent-text); }

/* Main */
.main { min-width: 0; }
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 16px 24px;
  align-items: center;
  margin-bottom: 20px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}
.filter-group { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.filter-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  margin-right: 4px;
}
.chip {
  font-family: inherit;
  font-size: 12.5px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: all 120ms;
  white-space: nowrap;
}
.chip:hover { border-color: var(--border-strong); }
.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.reset-btn {
  margin-left: auto;
  font-family: inherit;
  font-size: 12.5px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px 4px;
}
.reset-btn:hover { color: var(--text); }

.results-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 14px;
  padding: 0 4px;
}
.results-count {
  font-size: 13px;
  color: var(--text-muted);
}
.results-count strong { color: var(--text); font-weight: 600; }

/* Grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 16px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px 18px 16px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: border-color 120ms, box-shadow 120ms, transform 120ms;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
}
.card-head { display: flex; align-items: flex-start; gap: 12px; }
.card-head .provider-avatar { width: 32px; height: 32px; font-size: 13px; }
.card-titles { flex: 1; min-width: 0; }
.card-provider {
  font-size: 11.5px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 500;
  margin-bottom: 2px;
}
.card-name {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.price-row { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.price {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.price-suffix {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 400;
}
.price.free, .price.custom { font-size: 22px; }

.badge {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 500;
  padding: 3px 9px;
  border-radius: 999px;
  background: #f3f4f6;
  color: var(--text-muted);
  text-transform: capitalize;
  letter-spacing: 0.01em;
}
.badge.accent {
  background: var(--accent-soft);
  color: var(--accent-text);
}

.feature-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.feature-list li {
  font-size: 13px;
  color: #374151;
  padding-left: 18px;
  position: relative;
  line-height: 1.45;
}
.feature-list li::before {
  content: "";
  position: absolute;
  left: 4px;
  top: 7px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.6;
}
.feature-more {
  font-size: 12px;
  color: var(--text-faint);
  padding-left: 18px;
  font-style: italic;
}
.note {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
  border-top: 1px dashed var(--border);
  padding-top: 10px;
  line-height: 1.45;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 20, 35, 0.45);
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fade 140ms ease;
}
.modal-backdrop.open { display: flex; }
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(0,0,0,0.18);
  max-width: 540px;
  width: 100%;
  max-height: 86vh;
  overflow: auto;
  padding: 28px;
}
.modal-head {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 18px;
}
.modal-head .provider-avatar { width: 40px; height: 40px; font-size: 15px; }
.modal-titles { flex: 1; min-width: 0; }
.modal-titles .card-provider { font-size: 12px; }
.modal-titles h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.015em;
}
.modal-close {
  background: transparent;
  border: none;
  font-size: 22px;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 6px;
}
.modal-close:hover { background: #f3f4f6; color: var(--text); }
.modal-section {
  margin-top: 18px;
}
.modal-section h3 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  margin: 0 0 10px;
}
.modal .feature-list li { font-size: 13.5px; }

/* Empty state */
.empty {
  text-align: center;
  padding: 60px 20px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  color: var(--text-muted);
}
.empty h3 { margin: 0 0 6px; color: var(--text); font-weight: 600; }
.empty p { margin: 0; font-size: 13px; }

.hidden { display: none; }

/* Header controls */
.header-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.header-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  padding: 5px 10px;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: background-color 120ms, border-color 120ms, color 120ms;
  height: 32px;
  white-space: nowrap;
}
.header-btn:hover {
  background: var(--accent-soft);
  color: var(--accent-text);
  border-color: var(--accent);
}
.header-btn svg { display: block; }

.modal-website-link {
  color: var(--accent);
  font-size: 13px;
  word-break: break-all;
}

.modal-note-inline { border: none; padding: 0; }

/* Rank in sidebar */
.provider-rank-sm {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-faint);
  letter-spacing: 0.01em;
  flex-shrink: 0;
}

/* Popularity chart */
.chart-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}
.chart-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  margin-bottom: 14px;
}
.chart-row {
  display: grid;
  grid-template-columns: 36px 160px 1fr 72px;
  align-items: center;
  gap: 6px 12px;
  padding: 4px 0;
}
.chart-name {
  font-size: 12.5px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chart-name-btn {
  cursor: pointer;
  transition: color 120ms;
}
.chart-name-btn:hover { color: var(--accent); }
.chart-bar-wrap {
  height: 14px;
  background: var(--bg);
  border-radius: 3px;
  overflow: hidden;
}
.chart-bar {
  height: 100%;
  border-radius: 3px;
  opacity: 0.72;
}
.chart-bar-nd {
  width: 100%;
  opacity: 1;
  background: repeating-linear-gradient(90deg, var(--border) 0, var(--border) 4px, transparent 4px, transparent 8px);
}
.chart-val {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
@media (max-width: 640px) {
  .chart-row { grid-template-columns: 30px 1fr 58px; }
  .chart-bar-wrap { display: none; }
}

/* Rank badge (card) */
.rank-badge {
  font-size: 10.5px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  background: #f3f4f6;
  color: var(--text-muted);
  flex-shrink: 0;
  letter-spacing: 0.02em;
  align-self: flex-start;
}
.rank-badge.rank-gold { background: #fef3c7; color: #92400e; }
.rank-badge.rank-silver { background: #f1f5f9; color: #475569; }
.rank-badge.rank-bronze { background: #fff7ed; color: #9a3412; }
[data-theme="dark"] .rank-badge { background: #252a3d; color: var(--text-muted); }
[data-theme="dark"] .rank-badge.rank-gold { background: #3d2f00; color: #fbbf24; }
[data-theme="dark"] .rank-badge.rank-silver { background: #1e2235; color: #94a3b8; }
[data-theme="dark"] .rank-badge.rank-bronze { background: #2d1a0e; color: #fb923c; }

/* Usage stats (modal + provider panel) */
.usage-stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.provider-stats-grid {
  grid-template-columns: repeat(3, 1fr);
}
@media (max-width: 640px) {
  .provider-stats-grid { grid-template-columns: 1fr 1fr; }
}
.usage-stat-item {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.usage-stat-label {
  font-size: 10px;
  color: var(--text-faint);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 4px;
}
.usage-stat-value {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}
.usage-stat-note {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}
.usage-source {
  font-size: 11px;
  color: var(--text-faint);
  font-style: italic;
  margin-top: 10px;
  line-height: 1.45;
}

.disclaimer {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px 32px;
  color: var(--text-faint);
  font-size: 11.5px;
  line-height: 1.5;
}

/* Dark mode overrides for hardcoded colors */
[data-theme="dark"] .modal-backdrop { background: rgba(5,6,10,0.65); }
[data-theme="dark"] .provider-item:hover { background: #1e2235; }
[data-theme="dark"] .modal-close:hover { background: #1e2235; }
[data-theme="dark"] .feature-list li { color: #bfc5d4; }
[data-theme="dark"] .badge { background: #1e2235; }
[data-theme="dark"] .card, [data-theme="dark"] .sidebar,
[data-theme="dark"] .filters, [data-theme="dark"] .modal {
  transition: background-color 200ms, border-color 200ms;
}

/* Responsive */
@media (max-width: 880px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    padding: 8px;
  }
  .sidebar-title { display: none; }
  .provider-list {
    flex-direction: row;
    overflow-x: auto;
    gap: 6px;
    scrollbar-width: thin;
  }
  .provider-item {
    flex: 0 0 auto;
    padding: 6px 10px 6px 6px;
  }
  .provider-name { white-space: nowrap; }
  .provider-count { display: none; }
  .header-inner { flex-wrap: wrap; gap: 12px; }
  .search-wrap { margin-left: 0; max-width: 100%; flex-basis: 100%; order: 3; }
  .header-controls { margin-left: auto; }
}
@media (max-width: 540px) {
  .header-inner { padding: 14px 16px; }
  .layout { padding: 16px; }
  .grid { grid-template-columns: 1fr; }
}
