/* === RESET & BASE === */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --bg-card: #1a2332;
  --green-profit: #22c55e;
  --green-light: #4ade80;
  --green-bg: rgba(34, 197, 94, 0.1);
  --yellow-caution: #eab308;
  --yellow-light: #facc15;
  --yellow-bg: rgba(234, 179, 8, 0.1);
  --red-loss: #ef4444;
  --red-light: #f87171;
  --red-bg: rgba(239, 68, 68, 0.1);
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border: #334155;
  --border-light: #475569;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -2px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -4px rgba(0, 0, 0, 0.3);
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

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

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

.hidden { display: none !important; }

/* === HEADER === */
.header {
  background: linear-gradient(180deg, #0c1220 0%, var(--bg-primary) 100%);
  border-bottom: 1px solid var(--border);
  padding: 24px 0;
}

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

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

.logo-icon {
  width: 36px;
  height: 36px;
}

.logo h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--green-profit) 0%, var(--green-light) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.tagline {
  color: var(--text-secondary);
  font-size: 0.875rem;
}

/* === FILTER BAR === */
.filter-bar {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 24px 0;
  position: sticky;
  top: 0;
  z-index: 100;
}

.filter-form {
  display: flex;
  align-items: flex-end;
  gap: 24px;
  flex-wrap: wrap;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  min-width: 180px;
}

.filter-group label {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

select {
  appearance: none;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 10px 36px 10px 14px;
  border-radius: var(--radius);
  font-size: 0.95rem;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  transition: border-color 0.2s;
}

select:hover, select:focus {
  border-color: var(--green-profit);
  outline: none;
}

.slider-group {
  min-width: 220px;
}

input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: 3px;
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  background: var(--green-profit);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 8px rgba(34, 197, 94, 0.4);
  transition: transform 0.15s;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

.slider-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 2px;
}

#margin-value {
  color: var(--green-profit);
  font-weight: 700;
  font-family: var(--font-mono);
}

/* === BUTTONS === */
.btn-primary {
  background: linear-gradient(135deg, var(--green-profit) 0%, #16a34a 100%);
  color: #fff;
  border: none;
  padding: 10px 28px;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(34, 197, 94, 0.3);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
}

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

.btn-sm {
  padding: 8px 20px;
  font-size: 0.875rem;
}

/* === SPINNER === */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* === LOADING OVERLAY === */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.loading-content {
  text-align: center;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 3px solid var(--border);
  border-top-color: var(--green-profit);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 20px;
}

.loading-text {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.loading-subtext {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

/* === RESULTS === */
.results-section {
  padding: 32px 0;
}

/* Market Insights */
.market-insights {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.insight-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.insight-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.insight-value {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--green-profit);
}

/* Actions Bar */
.actions-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 12px;
}

.result-count {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.result-count span {
  color: var(--green-profit);
  font-weight: 700;
  font-family: var(--font-mono);
}

.action-buttons {
  display: flex;
  gap: 10px;
}

/* === TABLE === */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--bg-secondary);
}

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

.deals-table th {
  background: var(--bg-tertiary);
  padding: 12px 14px;
  text-align: left;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  user-select: none;
}

.deals-table th.sortable {
  cursor: pointer;
  transition: color 0.2s;
}

.deals-table th.sortable:hover {
  color: var(--green-profit);
}

.deals-table th.sort-active {
  color: var(--green-profit);
}

.sort-arrow {
  font-size: 0.7rem;
  margin-left: 4px;
}

.th-star {
  width: 40px;
}

.deals-table td {
  padding: 12px 14px;
  border-bottom: 1px solid rgba(51, 65, 85, 0.5);
  vertical-align: middle;
}

.deals-table tbody tr {
  transition: background 0.15s;
}

.deals-table tbody tr:hover {
  background: rgba(34, 197, 94, 0.03);
}

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

/* Star button */
.star-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: var(--text-muted);
  transition: all 0.2s;
  font-size: 1.1rem;
  line-height: 1;
}

.star-btn:hover {
  color: var(--yellow-caution);
  transform: scale(1.2);
}

.star-btn.active {
  color: var(--yellow-caution);
}

/* Deal title */
.deal-title {
  font-weight: 600;
  color: var(--text-primary);
  max-width: 240px;
}

/* Condition grade */
.grade-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 600;
  font-size: 0.8rem;
  font-family: var(--font-mono);
}

.grade-a-plus, .grade-a { background: var(--green-bg); color: var(--green-profit); }
.grade-b-plus, .grade-b { background: var(--yellow-bg); color: var(--yellow-caution); }
.grade-c-plus, .grade-c { background: var(--red-bg); color: var(--red-loss); }

/* Money values */
.money {
  font-family: var(--font-mono);
  font-weight: 500;
}

/* Margin coloring */
.margin-high { color: var(--green-profit); font-weight: 700; }
.margin-mid { color: var(--yellow-caution); font-weight: 700; }
.margin-low { color: var(--red-loss); font-weight: 700; }

/* Deal Score Badge */
.score-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 28px;
  border-radius: 6px;
  font-weight: 700;
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

.score-high { background: var(--green-bg); color: var(--green-profit); border: 1px solid rgba(34, 197, 94, 0.3); }
.score-mid { background: var(--yellow-bg); color: var(--yellow-caution); border: 1px solid rgba(234, 179, 8, 0.3); }
.score-low { background: var(--red-bg); color: var(--red-loss); border: 1px solid rgba(239, 68, 68, 0.3); }

/* Details button */
.details-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
}

.details-btn:hover {
  border-color: var(--green-profit);
  color: var(--green-profit);
}

/* === WATCHLIST === */
.watchlist-section {
  margin-top: 32px;
  padding-top: 32px;
  border-top: 1px solid var(--border);
}

.watchlist-section h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  font-size: 1.1rem;
}

.empty-message {
  color: var(--text-muted);
  font-size: 0.9rem;
  text-align: center;
  padding: 24px;
}

/* === CHART === */
.chart-section {
  padding: 32px 0;
}

.chart-section h3 {
  margin-bottom: 16px;
  font-size: 1.1rem;
}

.chart-container {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  max-height: 320px;
}

/* === HISTORY === */
.history-section {
  padding: 32px 0;
  border-top: 1px solid var(--border);
}

.history-section h3 {
  margin-bottom: 16px;
  font-size: 1.1rem;
}

.history-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.history-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  cursor: pointer;
  transition: all 0.2s;
}

.history-card:hover {
  border-color: var(--green-profit);
  transform: translateY(-1px);
}

.history-card .history-category {
  font-weight: 600;
  text-transform: capitalize;
  margin-bottom: 4px;
}

.history-card .history-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  gap: 12px;
}

/* === FOOTER === */
.footer {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  padding: 48px 0 32px;
  margin-top: 32px;
}

.footer-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 24px;
}

.signup-block h3 {
  font-size: 1.25rem;
  margin-bottom: 8px;
}

.signup-block p {
  color: var(--text-secondary);
  margin-bottom: 16px;
  font-size: 0.9rem;
}

.email-form {
  display: flex;
  gap: 8px;
  max-width: 400px;
  margin: 0 auto;
}

.email-form input[type="email"] {
  flex: 1;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s;
}

.email-form input[type="email"]:focus {
  border-color: var(--green-profit);
}

.email-status {
  margin-top: 8px;
  font-size: 0.85rem;
}

.email-status.success { color: var(--green-profit); }
.email-status.error { color: var(--red-loss); }

.footer-meta {
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* === MODAL === */
.modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  max-width: 600px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  transition: color 0.2s;
}

.modal-close:hover {
  color: var(--text-primary);
}

.modal-content h2 {
  font-size: 1.2rem;
  margin-bottom: 16px;
  padding-right: 24px;
}

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

.modal-detail-item {
  background: var(--bg-primary);
  border-radius: var(--radius);
  padding: 12px;
}

.modal-detail-item .label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.modal-detail-item .value {
  font-weight: 600;
  font-family: var(--font-mono);
}

.modal-risk-factors {
  margin-bottom: 16px;
}

.modal-risk-factors h4 {
  font-size: 0.85rem;
  color: var(--yellow-caution);
  margin-bottom: 8px;
}

.modal-risk-factors ul {
  list-style: none;
  padding: 0;
}

.modal-risk-factors li {
  font-size: 0.85rem;
  color: var(--text-secondary);
  padding: 4px 0 4px 16px;
  position: relative;
}

.modal-risk-factors li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--yellow-caution);
  transform: translateY(-50%);
}

.modal-sell-through,
.modal-platform {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.modal-sell-through strong,
.modal-platform strong {
  color: var(--text-primary);
}

/* === RESPONSIVE === */
@media (max-width: 768px) {
  .header-content {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .filter-form {
    flex-direction: column;
  }

  .filter-group {
    min-width: 100%;
  }

  .btn-primary {
    width: 100%;
    justify-content: center;
  }

  .actions-bar {
    flex-direction: column;
    align-items: flex-start;
  }

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

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

  .deal-title {
    max-width: 150px;
  }

  .market-insights {
    grid-template-columns: 1fr;
  }

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

  .email-form {
    flex-direction: column;
  }
}

@media (max-width: 480px) {
  .container {
    padding: 0 12px;
  }

  .header {
    padding: 16px 0;
  }

  .logo h1 {
    font-size: 1.25rem;
  }
}
