/* ═══════════════════════════════════════════════════
   Smart Tariff Comparator — Premium Mobile-First UI
   ═══════════════════════════════════════════════════ */

/* ─── Design Tokens ─── */
:root {
  --bg: #f5f6fa;
  --bg-card: #ffffff;
  --bg-hover: #f0f1f5;
  --bg-inset: #ecedf2;
  --text: #1a1d2e;
  --text-secondary: #44485c;
  --text-tertiary: #6b7085;
  --border: #e2e4ed;
  --border-subtle: #eeeff5;
  --accent: #4361ee;
  --accent-soft: rgba(67, 97, 238, 0.08);
  --accent-medium: rgba(67, 97, 238, 0.15);
  --accent-hover: #3651d4;
  --green: #0d9f6e;
  --green-soft: rgba(13, 159, 110, 0.08);
  --green-bg: rgba(13, 159, 110, 0.12);
  --red: #e53535;
  --red-soft: rgba(229, 53, 53, 0.08);
  --orange: #e07c00;
  --orange-soft: rgba(224, 124, 0, 0.08);
  --shadow-xs: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.06), 0 1px 3px rgba(0,0,0,0.04);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.08), 0 2px 8px rgba(0,0,0,0.04);
  --radius: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;
  --font: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', 'Cascadia Code', monospace;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --transition: 0.2s var(--ease);
}

[data-theme="dark"] {
  --bg: #0c1222;
  --bg-card: #151d30;
  --bg-hover: #1c2740;
  --bg-inset: #111929;
  --text: #edf0f5;
  --text-secondary: #b0b8cc;
  --text-tertiary: #7d87a0;
  --border: #232d42;
  --border-subtle: #1c2538;
  --accent: #6384f5;
  --accent-soft: rgba(99, 132, 245, 0.1);
  --accent-medium: rgba(99, 132, 245, 0.18);
  --accent-hover: #7b9af7;
  --green: #3dd9a0;
  --green-soft: rgba(61, 217, 160, 0.1);
  --green-bg: rgba(61, 217, 160, 0.12);
  --red: #f77070;
  --red-soft: rgba(247, 112, 112, 0.1);
  --orange: #f5a623;
  --orange-soft: rgba(245, 166, 35, 0.1);
  --shadow-xs: 0 1px 2px rgba(0,0,0,0.2);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.25);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.3);
}

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

html {
  font-size: 15px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  min-height: 100dvh;
  transition: background var(--transition), color var(--transition);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 16px;
}

.main-content {
  padding-bottom: 40px;
}

/* ─── Header ─── */
.header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 0;
}

[data-theme="dark"] .data-banner {
  background: rgba(21, 29, 48, 0.88);
}

[data-theme="light"] .data-banner {
  background: rgba(230, 238, 255, 0.9);
}

.header-inner {
  padding-top: 12px;
  padding-bottom: 12px;
}

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

.logo {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.03em;
  line-height: 1.2;
}

.logo-icon {
  color: var(--accent);
}

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

.last-updated {
  font-size: 0.68rem;
  color: var(--text-tertiary);
  font-family: var(--font-mono);
  white-space: nowrap;
}

.subtitle {
  font-size: 0.82rem;
  color: var(--text-tertiary);
  margin-top: 2px;
  line-height: 1.4;
}

.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: 1rem;
  transition: all var(--transition);
  color: var(--text-secondary);
  flex-shrink: 0;
}
.theme-toggle:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
.theme-toggle:active {
  transform: scale(0.92);
}

/* ─── Data Banner ─── */
.data-banner {
  margin: 16px 0 0;
  padding: 12px 14px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-medium);
  border-radius: var(--radius);
  transition: all var(--transition);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.banner-content {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.banner-icon {
  font-size: 1rem;
  line-height: 1.4;
  flex-shrink: 0;
}

.banner-text {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.45;
}
.banner-text strong {
  display: block;
  margin-bottom: 1px;
  color: var(--text);
  font-weight: 600;
  font-size: 0.82rem;
}

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

.control-row {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

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

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

.slider {
  flex: 1;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--bg-inset);
  border-radius: 3px;
  outline: none;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 3px solid var(--bg-card);
  box-shadow: var(--shadow-sm), 0 0 0 1px var(--accent-medium);
  transition: box-shadow var(--transition);
}
.slider::-webkit-slider-thumb:hover {
  box-shadow: var(--shadow-md), 0 0 0 3px var(--accent-medium);
}
.slider::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 3px solid var(--bg-card);
  box-shadow: var(--shadow-sm);
}

.slider-output {
  font-family: var(--font-mono);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--accent);
  min-width: 100px;
  text-align: right;
  white-space: nowrap;
}

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

/* ─── Toggle ─── */
.toggle-group {
  display: flex;
  background: var(--bg-inset);
  border-radius: var(--radius);
  overflow: hidden;
  padding: 3px;
  gap: 2px;
}

.toggle-btn {
  flex: 1;
  padding: 9px 16px;
  border: none;
  background: transparent;
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-tertiary);
  transition: all var(--transition);
  border-radius: calc(var(--radius) - 3px);
}
.toggle-btn.active {
  background: var(--accent);
  color: white;
  box-shadow: var(--shadow-sm);
}
.toggle-btn:not(.active):hover {
  color: var(--text);
  background: var(--bg-hover);
}
.toggle-note {
  font-size: 0.68rem;
  color: var(--text-tertiary);
  margin-top: 8px;
}

/* ─── Profile Panel ─── */
.profile-card {
  cursor: default;
}
.profile-summary {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  list-style: none;
  user-select: none;
  -webkit-user-select: none;
}
.profile-summary::-webkit-details-marker { display: none; }
.profile-summary .control-label { margin-bottom: 0; }
.profile-hint {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  flex: 1;
}
.chevron-icon {
  color: var(--text-tertiary);
  transition: transform var(--transition);
  flex-shrink: 0;
}
details[open] .chevron-icon { transform: rotate(180deg); }

.profile-content {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border-subtle);
}
.profile-note {
  font-size: 0.72rem;
  color: var(--text-tertiary);
  margin-bottom: 12px;
}

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

.profile-row {
  display: grid;
  grid-template-columns: 110px 1fr 55px;
  align-items: center;
  gap: 10px;
}

.profile-label {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text);
}
.profile-label small {
  display: block;
  font-size: 0.65rem;
  color: var(--text-tertiary);
  font-weight: 400;
  margin-top: 1px;
}

.profile-slider {
  width: 100%;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--bg-inset);
  border-radius: 2px;
  outline: none;
}
.profile-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--bg-card);
  box-shadow: var(--shadow-xs);
}
.profile-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--bg-card);
}

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

/* ─── Upload Zone ─── */
.upload-card {
  padding: 0;
  overflow: hidden;
}

.upload-zone {
  padding: 16px;
  cursor: pointer;
  transition: all var(--transition);
  border-radius: var(--radius-lg);
}
.upload-zone:hover, .upload-zone.dragover {
  background: var(--accent-soft);
}

.upload-inline {
  display: flex;
  align-items: center;
  gap: 14px;
}

.upload-icon-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  flex-shrink: 0;
}

.upload-text {
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-top: 0;
  text-align: left;
}
.upload-text strong {
  color: var(--accent);
  font-weight: 600;
}
.upload-hint {
  font-size: 0.7rem;
  color: var(--text-tertiary);
  margin-top: 4px;
  text-align: left;
}

.upload-result {
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-align: left;
  gap: 12px;
}
.upload-result[hidden] {
  display: none;
}
.upload-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.upload-check-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--green-soft);
  color: var(--green);
  flex-shrink: 0;
}

.upload-info strong {
  font-size: 0.82rem;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.upload-info p {
  font-size: 0.72rem;
  color: var(--text-tertiary);
  margin-top: 1px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-clear {
  background: var(--red-soft);
  color: var(--red);
  border: none;
  border-radius: var(--radius);
  padding: 7px 12px;
  font-size: 0.72rem;
  font-weight: 500;
  cursor: pointer;
  font-family: var(--font);
  transition: all var(--transition);
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.upload-clear:hover { background: rgba(229, 53, 53, 0.15); }
.upload-clear:active { transform: scale(0.96); }

.upload-notice {
  margin: 0 16px 16px;
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 0.75rem;
  background: var(--orange-soft);
  color: var(--orange);
  font-weight: 500;
}

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

.results-title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 12px;
  letter-spacing: -0.01em;
}

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

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

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

.results-table th {
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-tertiary);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

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

.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-soft);
}
.results-table tbody tr.cheapest:hover {
  background: var(--green-bg);
}

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

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

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

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

.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.92rem;
  color: var(--text);
}

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

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

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

.detail-row td {
  padding: 0 !important;
  border-bottom: 2px solid var(--border) !important;
  /* Constrain detail content to visible table width */
  max-width: 1px;
  width: 100%;
}

.detail-content {
  padding: 16px;
  background: var(--bg);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

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

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

.detail-section h4 {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-tertiary);
  margin-bottom: 8px;
  font-weight: 600;
}

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

.rate-table th, .rate-table td {
  padding: 6px 8px;
  border: 1px solid var(--border-subtle);
  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.68rem;
}

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

.cost-breakdown {
  list-style: none;
  font-size: 0.78rem;
}
.cost-breakdown li {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid var(--border-subtle);
  gap: 8px;
  flex-wrap: wrap;
}
.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;
  white-space: nowrap;
}
.cost-breakdown .cb-value small {
  color: var(--text-tertiary);
  font-weight: 400;
}

.plan-notes {
  margin: 0;
  padding-left: 18px;
  font-size: 0.76rem;
  color: var(--text-secondary);
}

.plan-notes li + li {
  margin-top: 6px;
}

/* ─── Footer ─── */
.footer {
  border-top: 1px solid var(--border);
  padding: 20px 0;
  text-align: center;
  font-size: 0.7rem;
  color: var(--text-tertiary);
}
.footer p + p { margin-top: 3px; }

/* ─── Stale badge ─── */
.stale-badge {
  display: inline-block;
  background: var(--orange-soft);
  color: var(--orange);
  font-size: 0.62rem;
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: 6px;
  font-weight: 600;
}

/* ═══════════════════════════════════════════════════
   Responsive — Mobile First
   ═══════════════════════════════════════════════════ */

/* Mobile: hide table columns, show key info */
@media (max-width: 640px) {
  .container { padding: 0 12px; }

  .header-inner { padding-top: 10px; padding-bottom: 10px; }

  .logo { font-size: 1.1rem; }
  .subtitle { font-size: 0.75rem; }
  .last-updated { display: none; }

  .slider-output { font-size: 0.95rem; min-width: 85px; }

  .profile-row {
    grid-template-columns: 90px 1fr 48px;
    gap: 8px;
  }
  .profile-label { font-size: 0.72rem; }
  .profile-label small { font-size: 0.6rem; }
  .profile-pct { font-size: 0.72rem; }

  .results-table { font-size: 0.78rem; }
  .results-table th { padding: 8px; font-size: 0.62rem; }
  .results-table td { padding: 10px 8px; }
  .results-table .hide-mobile { display: none; }
  .cost-value { font-size: 0.85rem; }

  .detail-content { padding: 12px; }

  .rate-table { font-size: 0.7rem; }
  .rate-table th, .rate-table td { padding: 5px 6px; }

  .cost-breakdown { font-size: 0.72rem; }
  .cost-breakdown li {
    flex-direction: column;
    gap: 2px;
  }
  .cost-breakdown .cb-value {
    font-size: 0.75rem;
  }

  .upload-info strong { font-size: 0.78rem; }
  .upload-info p { font-size: 0.68rem; }
}

/* Tablet and up */
@media (min-width: 641px) {
  .container { padding: 0 20px; }

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

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

  .upload-zone { padding: 28px 20px; }
}

/* Desktop */
@media (min-width: 960px) {
  html { font-size: 15px; }

  .header-inner { padding-top: 14px; padding-bottom: 14px; }

  .logo { font-size: 1.3rem; }

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

  .control-card { padding: 18px; }

  .results-table td { padding: 14px; }
}

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

.results-table tbody tr {
  animation: fadeIn 0.25s var(--ease) backwards;
}

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

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

.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); }
}

/* ─── Safe area for iOS ─── */
@supports (padding: env(safe-area-inset-bottom)) {
  .footer {
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
  }
}
