:root {
  --bg: #0a0a0f;
  --bg-card: #14141f;
  --bg-card-hover: #1a1a2a;
  --bg-input: #1a1a28;
  --border: #2a2a3a;
  --text: #e8e8f0;
  --text-muted: #8888a0;
  --accent: #ff6b35;
  --accent-glow: rgba(255, 107, 53, 0.15);
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #eab308;
  --blue: #3b82f6;
  --radius: 12px;
  --radius-sm: 8px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Pull to Refresh */
.ptr-indicator {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 150;
  overflow: hidden;
  transition: height 0.2s ease;
}
.ptr-indicator .material-symbols-rounded {
  color: var(--accent);
  font-size: 24px;
  transition: transform 0.2s;
}
.ptr-indicator.pulling .material-symbols-rounded {
  transform: rotate(180deg);
}
.ptr-indicator.refreshing .material-symbols-rounded {
  animation: spin 0.8s linear infinite;
}

/* Header */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  padding-top: max(12px, var(--safe-top));
  background: rgba(10, 10, 15, 0.9);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-left .material-symbols-rounded {
  color: var(--accent);
  font-size: 24px;
}

.header h1 {
  font-size: 18px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), #ff9a6c);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-sm);
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:hover { color: var(--text); background: var(--bg-input); }

.stats-badge {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-glow);
  padding: 4px 10px;
  border-radius: 20px;
  display: none;
}
.stats-badge.show { display: flex; align-items: center; gap: 4px; }

/* Filter Bar — horizontal scroll, never wrap */
.filter-bar, .score-bar {
  display: flex;
  gap: 6px;
  padding: 8px 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  border-bottom: 1px solid var(--border);
  flex-wrap: nowrap;
}
.filter-bar::-webkit-scrollbar, .score-bar::-webkit-scrollbar { display: none; }

#profileTabs {
  display: contents;
}

.filter-tab, .score-btn {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.filter-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.score-btn {
  padding: 5px 12px;
  font-size: 12px;
}
.score-btn.active {
  background: var(--bg-card-hover);
  border-color: var(--accent);
  color: var(--text);
}

/* Deals List */
.deals-list {
  padding: 10px 12px;
  padding-bottom: calc(80px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 60px 0;
  color: var(--text-muted);
}

.spin {
  animation: spin 1.5s linear infinite;
  font-size: 28px;
  color: var(--accent);
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state .material-symbols-rounded {
  font-size: 48px;
  margin-bottom: 12px;
  opacity: 0.4;
}

/* Deal Card */
.deal-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  gap: 10px;
  -webkit-tap-highlight-color: transparent;
}
.deal-card:active { transform: scale(0.98); }
.deal-card.hot { border-color: var(--green); box-shadow: 0 0 12px rgba(34,197,94,0.08); }
.deal-card.unknown { opacity: 0.6; border-style: dashed; }

.card-left { position: relative; flex-shrink: 0; }
.card-img { width: 72px; height: 72px; border-radius: var(--radius-sm); object-fit: cover; background: var(--bg-input); display: block; }
.card-img-empty { display: flex; align-items: center; justify-content: center; color: var(--text-muted); }
.card-score { 
  position: absolute; bottom: -6px; left: 50%; transform: translateX(-50%); 
  font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 10px; 
  white-space: nowrap; display: flex; align-items: center; gap: 2px;
}

.badge-hot { background: rgba(34,197,94,0.2); color: var(--green); border: 1px solid rgba(34,197,94,0.3); }
.badge-good { background: rgba(234,179,8,0.15); color: var(--yellow); border: 1px solid rgba(234,179,8,0.2); }
.badge-mid { background: rgba(136,136,160,0.1); color: var(--text-muted); border: 1px solid var(--border); }
.badge-low { background: rgba(136,136,160,0.05); color: #666; border: 1px solid var(--border); }

.card-right { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.card-title { font-size: 13px; font-weight: 600; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.card-prices { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.card-price { font-size: 15px; font-weight: 700; color: var(--text); }
.card-market { font-size: 11px; color: var(--text-muted); text-decoration: line-through; }
.card-profit { font-size: 12px; font-weight: 700; }
.card-discount { font-size: 10px; font-weight: 600; color: var(--green); background: rgba(34,197,94,0.1); padding: 1px 5px; border-radius: 6px; }

.card-model { font-size: 11px; color: var(--blue); font-weight: 500; }

.card-trust { display: flex; align-items: center; gap: 3px; font-size: 11px; flex-wrap: wrap; }
.trust-high { color: var(--green); }
.trust-mid { color: var(--text-muted); }
.trust-low { color: var(--red); }
.trust-tag { 
  font-size: 10px; background: var(--bg-input); padding: 1px 5px; 
  border-radius: 4px; color: var(--text-muted); 
  display: inline-flex; align-items: center; gap: 2px;
}

.card-summary { font-size: 11px; color: var(--text-muted); line-height: 1.4; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

.card-footer { display: flex; align-items: center; justify-content: space-between; margin-top: 1px; }
.card-location { font-size: 10px; color: var(--text-muted); display: flex; align-items: center; gap: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60%; }
.card-tag { font-size: 10px; padding: 1px 6px; border-radius: 6px; background: var(--bg-input); color: var(--text-muted); border: 1px solid var(--border); flex-shrink: 0; }

/* Bottom Nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-around;
  background: rgba(10, 10, 15, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  padding: 6px 0;
  padding-bottom: max(6px, var(--safe-bottom));
  z-index: 100;
}

.nav-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px 12px;
  cursor: pointer;
  font-size: 10px;
  font-weight: 500;
  transition: color 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.nav-btn .material-symbols-rounded { font-size: 22px; }
.nav-btn.active { color: var(--accent); }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 200;
  display: none;
  align-items: flex-end;
  justify-content: center;
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--bg-card);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: 600px;
  max-height: 85dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  animation: slideUp 0.3s ease;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-card);
  z-index: 1;
}
.modal-header h2 {
  font-size: 15px;
  font-weight: 600;
  flex: 1;
  margin-right: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.modal-body { padding: 16px; }

.modal-img {
  width: 100%;
  max-height: 220px;
  object-fit: contain;
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
  background: var(--bg);
}

.modal-section {
  margin-bottom: 14px;
}
.modal-section h3 {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.modal-price-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 14px;
  padding: 12px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
}
.modal-price-main { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.modal-price { font-size: 24px; font-weight: 700; color: var(--text); }
.modal-market { font-size: 13px; color: var(--text-muted); text-decoration: line-through; }
.modal-price-right { text-align: right; flex-shrink: 0; }
.modal-profit { font-size: 18px; font-weight: 700; color: var(--green); line-height: 1; }
.modal-profit small { display: block; font-size: 10px; font-weight: 400; color: var(--text-muted); margin-top: 2px; }

.trust-meter { height: 5px; background: var(--bg-input); border-radius: 3px; margin-bottom: 8px; overflow: hidden; }
.trust-bar { height: 100%; border-radius: 3px; transition: width 0.5s; }
.trust-factors { display: flex; flex-wrap: wrap; gap: 4px; }
.trust-factor { font-size: 11px; padding: 3px 8px; background: var(--bg-input); border-radius: 6px; border: 1px solid var(--border); display: inline-flex; align-items: center; gap: 3px; }

.deal-score { display: inline-flex; align-items: center; gap: 3px; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 10px; }

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  flex: 1;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #e5572a; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); flex: 0; }
.btn-outline:hover { background: var(--bg-input); }

.red-flag {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 12px;
  color: var(--red);
  background: rgba(239, 68, 68, 0.1);
  padding: 4px 8px;
  border-radius: 6px;
  margin: 2px;
}

/* Views */
.view { padding: 12px 16px; padding-bottom: calc(80px + var(--safe-bottom)); }
.view.hidden { display: none; }

/* Profiles View */
.profile-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
}
.profile-card h3 { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.profile-info { font-size: 12px; color: var(--text-muted); line-height: 1.8; display: flex; flex-direction: column; gap: 2px; }

.profile-toggle {
  width: 44px;
  height: 24px;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  position: relative;
  transition: background 0.3s;
  -webkit-tap-highlight-color: transparent;
}
.profile-toggle.on { background: var(--green); }
.profile-toggle.off { background: var(--border); }
.profile-toggle::after {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  top: 3px;
  transition: left 0.3s;
}
.profile-toggle.on::after { left: 23px; }
.profile-toggle.off::after { left: 3px; }

/* Stats View */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
}
.stat-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--accent);
}
.stat-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Settings View */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.setting-label { font-size: 14px; }
.setting-desc { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* Utility */
.hidden { display: none !important; }
