/* ═══════════════════════════════════════════════════
   Smart Tariff Comparator — Styles
   ═══════════════════════════════════════════════════ */

:root {
  --bg: #f8f9fa;
  --bg-card: #ffffff;
  --bg-hover: #f1f3f5;
  --text: #1a1a2e;
  --text-muted: #6c757d;
  --text-light: #adb5bd;
  --border: #dee2e6;
  --border-light: #e9ecef;
  --accent: #2563eb;
  --accent-light: #dbeafe;
  --accent-dark: #1d4ed8;
  --green: #059669;
  --green-bg: #d1fae5;
  --green-light: #ecfdf5;
  --red: #dc2626;
  --red-bg: #fee2e2;
  --orange: #d97706;
  --orange-bg: #fef3c7;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --radius: 8px;
  --radius-lg: 12px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Cascadia Code', 'Fira Code', monospace;
  --transition: 0.2s ease;
}

[data-theme="dark"] {
  --bg: #0f172a;
  --bg-card: #1e293b;
  --bg-hover: #334155;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --text-light: #64748b;
  --border: #334155;
  --border-light: #1e293b;
  --accent: #3b82f6;
  --accent-light: #1e3a5f;
  --accent-dark: #60a5fa;
  --green: #34d399;
  --green-bg: #064e3b;
  --green-light: #022c22;
  --red: #f87171;
  --red-bg: #450a0a;
  --orange: #fbbf24;
  --orange-bg: #451a03;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow: 0 1px 3px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.4);
}

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

html {
  font-size: 15px;
  -webkit-text-size-adjust: 100%;
}

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

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

/* ─── Header ─── */
.header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 20px 0;
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 100;
}

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

.logo {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.02em;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.last-updated {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

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

.theme-toggle {
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: all var(--transition);
  color: var(--text);
}
.theme-toggle:hover {
  background: var(--accent-light);
  border-color: var(--accent);
}

/* ─── Data Banner ─── */
.data-banner {
  margin: 20px 0 0;
  padding: 12px 16px;
  background: var(--accent-light);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  transition: all var(--transition);
}

.banner-content {
  display: flex;
  align-items: center;
  gap: 12px;
}

.banner-icon { font-size: 1.2rem; }
.banner-text { font-size: 0.85rem; }
.banner-text strong { display: block; margin-bottom: 2px; }

/* ─── Controls ─── */
.controls {
  margin: 20px 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.control-row {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 16px;
}

.control-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  box-shadow: var(--shadow-sm);
  transition: all var(--transition);
}

.control-label {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  display: block;
  margin-bottom: 10px;
}

/* Slider */
.slider-value-row {
  display: flex;
  align-items: center;
  gap: 16px;
}

.slider {
  flex: 1;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border);
  border-radius: 3px;
  outline: none;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--bg-card);
  box-shadow: var(--shadow);
}
.slider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--bg-card);
  box-shadow: var(--shadow);
}

.slider-output {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--accent);
  min-width: 110px;
  text-align: right;
}

.slider-range {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--text-light);
  margin-top: 4px;
}

/* Toggle */
.toggle-group {
  display: flex;
  background: var(--bg-hover);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}

.toggle-btn {
  flex: 1;
  padding: 8px 16px;
  border: none;
  background: transparent;
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-muted);
  transition: all var(--transition);
}
.toggle-btn.active {
  background: var(--accent);
  color: white;
}
.toggle-note {
  font-size: 0.72rem;
  color: var(--text-light);
  margin-top: 6px;
}

/* Profile Panel */
.profile-card {
  cursor: default;
}
.profile-summary {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  list-style: none;
}
.profile-summary::-webkit-details-marker { display: none; }
.profile-hint {
  font-size: 0.8rem;
  color: var(--text-light);
  flex: 1;
}
.chevron {
  font-size: 0.7rem;
  color: var(--text-light);
  transition: transform var(--transition);
}
details[open] .chevron { transform: rotate(180deg); }

.profile-content {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border-light);
}
.profile-note {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.profile-sliders {
  display: grid;
  gap: 10px;
}

.profile-row {
  display: grid;
  grid-template-columns: 130px 1fr 70px;
  align-items: center;
  gap: 12px;
}

.profile-label {
  font-size: 0.82rem;
  font-weight: 500;
}
.profile-label small {
  display: block;
  font-size: 0.7rem;
  color: var(--text-light);
  font-weight: 400;
}

.profile-slider {
  width: 100%;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border);
  border-radius: 2px;
  outline: none;
}
.profile-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}
.profile-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

.profile-pct {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 500;
  text-align: right;
  color: var(--accent);
}

/* Upload Zone */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
}
.upload-zone:hover, .upload-zone.dragover {
  border-color: var(--accent);
  background: var(--accent-light);
}

.upload-icon { font-size: 2rem; }
.upload-text { font-size: 0.85rem; margin-top: 8px; color: var(--text-muted); }
.upload-hint { font-size: 0.75rem; color: var(--text-light); margin-top: 4px; }

.upload-result {
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-align: left;
}
.upload-info {
  display: flex;
  align-items: center;
  gap: 12px;
}
.upload-file-icon { font-size: 1.5rem; }
.upload-info strong { font-size: 0.9rem; }
.upload-info p { font-size: 0.78rem; color: var(--text-muted); margin-top: 2px; }

.upload-clear {
  background: var(--red-bg);
  color: var(--red);
  border: 1px solid var(--red);
  border-radius: var(--radius);
  padding: 6px 12px;
  font-size: 0.78rem;
  cursor: pointer;
  font-family: var(--font);
  transition: opacity var(--transition);
}
.upload-clear:hover { opacity: 0.8; }

.upload-notice {
  margin-top: 10px;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 0.8rem;
  background: var(--orange-bg);
  color: var(--orange);
  border: 1px solid var(--orange);
}

/* ─── Results ─── */
.results {
  margin: 24px 0 40px;
}

.results-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 12px;
}

.results-table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  background: var(--bg-card);
}

.results-table thead {
  background: var(--bg-hover);
  position: sticky;
  top: 0;
}

.results-table th {
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

.results-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: top;
}

.results-table .num-col {
  text-align: right;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.results-table tbody tr {
  transition: background var(--transition);
  cursor: pointer;
}
.results-table tbody tr:hover {
  background: var(--bg-hover);
}

.results-table tbody tr.cheapest {
  background: var(--green-light);
}
.results-table tbody tr.cheapest:hover {
  background: var(--green-bg);
}

.rank-col { width: 40px; text-align: center !important; }

.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  font-weight: 700;
  font-size: 0.78rem;
  font-family: var(--font-mono);
}

.rank-1 {
  background: var(--green);
  color: white;
}
.rank-other {
  background: var(--bg-hover);
  color: var(--text-muted);
}

.provider-name {
  font-weight: 600;
  font-size: 0.85rem;
}

.plan-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}
.plan-link:hover {
  text-decoration: underline;
}

.cost-value {
  font-weight: 700;
  font-size: 0.95rem;
}

.diff-zero {
  color: var(--green);
  font-weight: 600;
}
.diff-positive {
  color: var(--red);
}

.stale-badge {
  display: inline-block;
  background: var(--orange-bg);
  color: var(--orange);
  font-size: 0.65rem;
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: 6px;
  font-weight: 600;
}

/* ─── Expanded Row Detail ─── */
.detail-row {
  display: none;
}

.detail-row.open {
  display: table-row;
}

.detail-row td {
  padding: 0 !important;
  border-bottom: 2px solid var(--border) !important;
}

.detail-content {
  padding: 20px;
  background: var(--bg);
}

.detail-content.collapsed {
  display: none;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.detail-section h4 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.rate-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.rate-table th, .rate-table td {
  padding: 6px 10px;
  border: 1px solid var(--border-light);
  text-align: right;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}
.rate-table th {
  background: var(--bg-hover);
  font-weight: 600;
  text-align: left;
  font-family: var(--font);
  font-size: 0.75rem;
}

.rate-free {
  color: var(--green);
  font-weight: 700;
}

.cost-breakdown {
  list-style: none;
  font-size: 0.82rem;
}
.cost-breakdown li {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
  border-bottom: 1px solid var(--border-light);
}
.cost-breakdown li:last-child {
  border-bottom: none;
  font-weight: 700;
  padding-top: 8px;
  margin-top: 4px;
  border-top: 2px solid var(--border);
}
.cost-breakdown .cb-value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* ─── Footer ─── */
.footer {
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  padding: 20px 0;
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-light);
}
.footer p + p { margin-top: 4px; }

/* ─── Responsive ─── */
@media (max-width: 768px) {
  html { font-size: 14px; }

  .control-row {
    grid-template-columns: 1fr;
  }

  .results-table {
    font-size: 0.8rem;
  }

  .results-table th,
  .results-table td {
    padding: 8px 10px;
  }

  /* Hide some columns on mobile */
  .results-table .hide-mobile {
    display: none;
  }

  .detail-grid {
    grid-template-columns: 1fr;
  }

  .profile-row {
    grid-template-columns: 100px 1fr 60px;
    gap: 8px;
  }
}

@media (max-width: 480px) {
  .header-top {
    flex-wrap: wrap;
  }
  .logo { font-size: 1.2rem; }
  .slider-output { font-size: 0.95rem; min-width: 90px; }
}

/* ─── Animations ─── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.results-table tbody tr {
  animation: fadeIn 0.2s ease forwards;
}

.results-table tbody tr:nth-child(n) {
  animation-delay: calc(var(--row-index, 0) * 30ms);
}

/* Loading state */
.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
}

.loading-spinner {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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