/* ============================================================
   NPM Package Comparator — Styles
   Theme: Dark mode with Emerald Green palette
   ============================================================ */

/* --- Design Tokens --- */
:root {
  --primary: #00B894;
  --primary-hover: #00D2A4;
  --secondary: #55EFC4;
  --accent: #FDCB6E;
  --bg: #0A1A14;
  --bg-card: #0F2A1F;
  --bg-glass: rgba(15, 42, 31, 0.65);
  --bg-input: #0D221A;
  --border: rgba(0, 184, 148, 0.18);
  --border-hover: rgba(0, 184, 148, 0.4);
  --text: #E8F5F0;
  --text-muted: #8CBFAD;
  --text-dim: #5A9A84;
  --danger: #FF7675;
  --success: #00B894;
  --warning: #FDCB6E;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --transition: 200ms ease;
  --transition-slow: 300ms ease;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
  --shadow-glow: 0 0 20px rgba(0, 184, 148, 0.12);
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

/* --- App Wrapper --- */
.app-wrapper {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px 60px;
}

/* --- Header --- */
.app-header {
  padding: 28px 0 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 32px;
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo-group {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo-icon {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-glass);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  backdrop-filter: blur(12px);
}

h1 {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

.subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 1px;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 0 16px rgba(0, 184, 148, 0.3);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  border-color: var(--border-hover);
  color: var(--text);
}

.btn-compare {
  background: linear-gradient(135deg, var(--primary), #00D2A4);
  color: #fff;
  padding: 12px 28px;
  font-size: 0.95rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow-glow);
}

.btn-compare:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 0 28px rgba(0, 184, 148, 0.25);
}

.btn-compare:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* --- Search Section --- */
.search-section {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 32px;
}

.search-bar-row {
  display: flex;
  gap: 10px;
}

.search-input-wrapper {
  position: relative;
  flex: 1;
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  pointer-events: none;
}

#packageInput {
  width: 100%;
  padding: 12px 16px 12px 44px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.95rem;
  outline: none;
  transition: border-color var(--transition);
}

#packageInput:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0, 184, 148, 0.12);
}

#packageInput::placeholder {
  color: var(--text-dim);
}

/* Suggestions Dropdown */
.suggestions-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  max-height: 240px;
  overflow-y: auto;
  z-index: 100;
  display: none;
  box-shadow: var(--shadow);
}

.suggestions-dropdown.visible {
  display: block;
}

.suggestion-item {
  padding: 10px 14px;
  cursor: pointer;
  transition: background var(--transition);
  border-bottom: 1px solid rgba(0, 184, 148, 0.06);
}

.suggestion-item:last-child {
  border-bottom: none;
}

.suggestion-item:hover,
.suggestion-item.active {
  background: rgba(0, 184, 148, 0.1);
}

.suggestion-name {
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--text);
}

.suggestion-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Package Tags */
.package-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 20px;
}

.package-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg-glass);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 0.825rem;
  font-weight: 500;
  color: var(--secondary);
  backdrop-filter: blur(8px);
  animation: tagIn 200ms ease;
}

@keyframes tagIn {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

.tag-remove {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 2px;
  font-size: 1rem;
  line-height: 1;
  transition: color var(--transition);
  display: flex;
}

.tag-remove:hover {
  color: var(--danger);
}

/* --- Loading Overlay --- */
.loading-overlay {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 60px 20px;
}

.loading-overlay[hidden] {
  display: none;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* --- Results Section --- */
.results-section[hidden] {
  display: none;
}

.results-section {
  animation: fadeUp 400ms ease;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Summary Cards */
.summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}

.summary-card {
  background: var(--bg-glass);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  backdrop-filter: blur(12px);
  transition: border-color var(--transition);
}

.summary-card:hover {
  border-color: var(--border-hover);
}

.summary-card-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.summary-card-name {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}

.summary-card-version {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.summary-card-stat {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-top: 10px;
}

.summary-card-stat .stat-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--secondary);
}

.summary-card-stat .stat-label {
  font-size: 0.75rem;
  color: var(--text-dim);
}

/* --- Comparison Table --- */
.comparison-table-wrapper {
  overflow-x: auto;
  margin-bottom: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
}

.comparison-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.comparison-table thead th {
  padding: 14px 16px;
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  background: rgba(0, 184, 148, 0.04);
  position: sticky;
  top: 0;
  white-space: nowrap;
}

.comparison-table thead th:first-child {
  color: var(--text-dim);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.comparison-table tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid rgba(0, 184, 148, 0.06);
  color: var(--text);
  vertical-align: middle;
}

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

.comparison-table tbody tr:hover td {
  background: rgba(0, 184, 148, 0.04);
}

.comparison-table tbody td:first-child {
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Winner highlight */
.cell-best {
  color: var(--secondary) !important;
  font-weight: 700;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 600;
}

.badge-yes {
  background: rgba(0, 184, 148, 0.15);
  color: var(--primary);
}

.badge-no {
  background: rgba(255, 118, 117, 0.12);
  color: var(--danger);
}

.badge-unknown {
  background: rgba(253, 203, 110, 0.12);
  color: var(--warning);
}

/* Score bar */
.score-bar-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
}

.score-bar {
  flex: 1;
  height: 6px;
  background: rgba(0, 184, 148, 0.1);
  border-radius: 3px;
  overflow: hidden;
  max-width: 80px;
}

.score-bar-fill {
  height: 100%;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--primary), var(--secondary));
  transition: width var(--transition-slow);
}

.score-value {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
  min-width: 32px;
}

/* --- Chart Section --- */
.chart-section {
  margin-bottom: 32px;
  background: var(--bg-glass);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  backdrop-filter: blur(12px);
}

.section-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 18px;
}

#downloadsChart {
  width: 100%;
  max-height: 280px;
}

/* --- Result Actions --- */
.result-actions {
  display: flex;
  justify-content: center;
}

/* --- Empty State --- */
.empty-state {
  text-align: center;
  padding: 60px 20px;
}

.empty-state[hidden] {
  display: none;
}

.empty-illustration {
  margin-bottom: 20px;
  opacity: 0.7;
}

.empty-state h2 {
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text);
}

.empty-state p {
  color: var(--text-muted);
  font-size: 0.9rem;
  max-width: 420px;
  margin: 0 auto;
}

/* --- Responsive --- */
@media (max-width: 768px) {
  .app-wrapper {
    padding: 0 14px 40px;
  }
  .search-bar-row {
    flex-direction: column;
  }
  .summary-cards {
    grid-template-columns: 1fr;
  }
  .comparison-table {
    font-size: 0.8rem;
  }
  .comparison-table thead th,
  .comparison-table tbody td {
    padding: 10px 10px;
  }
}

@media (max-width: 480px) {
  h1 {
    font-size: 1.15rem;
  }
  .btn-compare {
    width: 100%;
    justify-content: center;
  }
}
