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

body {
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  color: #333;
}

/* DuckDB SQL styles */
.duckdb-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.85rem;
}
.duckdb-table th {
  background: #222;
  color: #fff;
  position: sticky;
  top: 0;
  padding: 6px 8px;
  text-align: left;
}
.duckdb-table td {
  border-bottom: 1px solid #333;
  padding: 4px 6px;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.duckdb-meta {
  margin: 6px 0;
  font-size: 0.75rem;
  opacity: 0.8;
}
.duckdb-sql-used {
  background: #111;
  padding: 8px;
  border-radius: 6px;
  font-size: 0.7rem;
  overflow: auto;
}
.duckdb-table tr:nth-child(even) {
  background: #f2f4f7;
}

:root {
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  --radius-pill: 999px;
}

/* Tag chips retained for list table */
.tag-chips {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.tag-chip {
  background: #eef6ff;
  color: #0056b3;
  padding: 3px 8px 4px;
  font-size: 0.65rem;
  font-weight: 600;
  border-radius: 12px;
  letter-spacing: 0.5px;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s, color 0.15s;
}
.tag-chip:hover {
  background: #d9ecff;
}
.tag-chip-more {
  cursor: default;
  background: #f1f3f5;
  color: #666;
}
.tag-chip.small {
  font-size: 0.55rem;
  padding: 2px 6px 3px;
}

/* Status badges */
.status-badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: 0.7rem;
  font-weight: 600;
  border-radius: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.status-badge.status-active {
  background: #d4edda;
  color: #155724;
}

.status-badge.status-expired {
  background: #fff3cd;
  color: #856404;
}

.status-badge.status-removed-or-sold {
  background: #d1ecf1;
  color: #0c5460;
}

/* List view table (primary listing display) */
.list-table-wrapper {
  overflow: auto;
}
.listings-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.85rem;
}
.listings-table thead th {
  position: sticky;
  top: 0;
  background: #f1f5f9;
  font-weight: 600;
  font-size: 0.7rem;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: #555;
  padding: 8px 10px;
  text-align: left;
}
.listings-table td {
  padding: 6px 10px;
  border-bottom: 1px solid #eceff2;
  vertical-align: top;
}
.listings-table tbody tr:hover {
  background: #f5f9ff;
}
.listings-table tbody tr.past-row {
  opacity: 0.6;
}
.detail-table tbody tr.past-row {
  opacity: 0.55;
}

.external-wiki-link {
  color: #0d62c9;
  text-decoration: none;
  position: relative;
  font-weight: 600;
}
.external-wiki-link:hover {
  text-decoration: underline;
}
.listings-table .col-price {
  font-weight: 600;
  color: #007bff;
  white-space: nowrap;
}
.listings-table .col-qty {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.listings-table .col-tags {
  min-width: 140px;
}
.wl-ind {
  font-size: 0.7rem;
  vertical-align: middle;
}

.site-logo {
  width: 40px;
  height: 40px;
  object-fit: contain;
  vertical-align: middle;
  margin-right: 10px;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.25));
  border-radius: var(--radius-xl, 20px);
}

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

.header {
  text-align: center;
  color: white;
  margin-bottom: 30px;
}

.header h1 {
  font-size: 2.5rem;
  margin-bottom: 10px;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.header p {
  font-size: 1.1rem;
  opacity: 0.9;
}

/* Loading and Error States */
.loading-spinner {
  text-align: center;
  color: white;
  padding: 50px;
}

.spinner {
  width: 50px;
  height: 50px;
  border: 5px solid rgba(255, 255, 255, 0.3);
  border-top: 5px solid white;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 20px;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

.error-message {
  background: rgba(220, 53, 69, 0.9);
  color: white;
  padding: 30px;
  border-radius: 10px;
  text-align: center;
  margin: 20px 0;
}

.error-message h3 {
  margin-bottom: 10px;
}

.retry-btn {
  background: white;
  color: #dc3545;
  border: none;
  padding: 10px 20px;
  border-radius: 5px;
  cursor: pointer;
  font-weight: bold;
  margin-top: 15px;
}

.retry-btn:hover {
  background: #f8f9fa;
}

.hidden {
  display: none !important;
}

.last-update {
  background: rgba(255, 255, 255, 0.2);
  padding: 10px;
  border-radius: 10px;
  margin-bottom: 20px;
  text-align: center;
  color: white;
}

.tabs {
  display: flex;
  margin-bottom: 20px;
  background: white;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.tab {
  flex: 1;
  padding: 15px;
  background: #f8f9fa;
  border: none;
  cursor: pointer;
  font-size: 16px;
  transition: background 0.3s;
}

.tab:hover {
  background: #e9ecef;
}

.tab.active {
  background: #007bff;
  color: white;
}

.tab-content {
  background: white;
  padding: 20px;
  border-radius: 10px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  min-height: 500px;
}

/* Controls */
.controls {
  display: flex;
  gap: 15px;
  margin-bottom: 20px;
  align-items: center;
  flex-wrap: wrap;
}

#search-input {
  flex: 1;
  min-width: 250px;
  padding: 10px 15px;
  border: 2px solid #ddd;
  border-radius: 8px;
  font-size: 16px;
}

#search-input:focus {
  outline: none;
  border-color: #007bff;
}

.filter-controls {
  display: flex;
  gap: 15px;
  align-items: center;
}

.tag-filter-wrapper {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

#tag-filter {
  padding: 8px 12px;
  border: 2px solid #ddd;
  border-radius: 8px;
  background: #fff;
  max-width: 180px;
}

.tag-filter-clear {
  display: none; /* shown dynamically */
  background: #e9ecef;
  border: 2px solid #ddd;
  color: #555;
  width: 32px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.15s;
}
.tag-filter-clear:hover {
  background: #dcdfe3;
}

/* Controls */
.controls {
  display: flex;
  gap: 15px;
  margin-bottom: 20px;
  align-items: center;
  flex-wrap: wrap;
}

#search-input {
  flex: 1;
  min-width: 250px;
  padding: 10px 15px;
  border: 2px solid #ddd;
  border-radius: 8px;
  font-size: 16px;
}

#search-input:focus {
  outline: none;
  border-color: #007bff;
}

.filter-controls {
  display: flex;
  gap: 15px;
  align-items: center;
}

.tag-filter-wrapper {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

#tag-filter {
  padding: 8px 12px;
  border: 2px solid #ddd;
  border-radius: 8px;
  background: #fff;
  max-width: 180px;
}

.tag-filter-clear {
  display: none; /* shown dynamically */
  background: #e9ecef;
  border: 2px solid #ddd;
  color: #555;
  width: 32px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.15s;
}
.tag-filter-clear:hover {
  background: #dcdfe3;
}

/* Removed card/grid listing styles (list-only mode) */

/* Watchlist Styles */
.watchlist-item-card {
  background: #fff;
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 15px;
  border-left: 4px solid #28a745;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.watchlist-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.watchlist-name {
  font-weight: bold;
  font-size: 1.2rem;
  color: #333;
}

.watchlist-status {
  padding: 5px 10px;
  border-radius: 15px;
  font-size: 0.85rem;
  font-weight: bold;
}

.status-available {
  background: #d4edda;
  color: #155724;
}

.status-not-found {
  background: #f8d7da;
  color: #721c24;
}

/* Charts */
.chart-container {
  margin-bottom: 30px;
  background: white;
  padding: 20px;
  border-radius: 10px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.chart-title {
  font-size: 1.3rem;
  font-weight: bold;
  margin-bottom: 15px;
  color: #333;
}

.price-chart {
  max-width: 100%;
  height: 300px !important;
} /* Market Summary */
.summary-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
  margin-bottom: 30px;
}

.stat-card {
  background: white;
  padding: 20px;
  border-radius: 10px;
  text-align: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.stat-card.clickable {
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s, transform 0.15s;
  position: relative;
}

.stat-card.clickable:active {
  transform: translateY(1px);
}

.stat-card.clickable:hover {
  background: #f5f9ff;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.12);
}

.stat-number {
  font-size: 2rem;
  font-weight: bold;
  color: #007bff;
  display: block;
}

.stat-label {
  color: #666;
  margin-top: 5px;
}

.recent-activity {
  background: white;
  padding: 20px;
  border-radius: 10px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.recent-activity h3 {
  margin-bottom: 15px;
  color: #333;
}

.activity-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.activity-item {
  padding: 10px;
  background: #f8f9fa;
  border-radius: 5px;
  border-left: 3px solid #007bff;
}

.activity-item small {
  display: block;
  color: #666;
  margin-top: 5px;
}

/* Additional Styles */
.no-results {
  text-align: center;
  color: #666;
  padding: 40px;
  font-style: italic;
}

.watchlist-badge {
  background: #28a745;
  color: white;
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 0.8rem;
  margin-top: 10px;
  display: inline-block;
}

.watchlist-details {
  margin-top: 10px;
  font-size: 0.9rem;
  color: #666;
}

.watchlist-details p {
  margin-bottom: 5px;
}

/* Status Badges */
.status-badge {
  display: inline-block;
  padding: 3px 6px 4px;
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.5px;
  border-radius: 6px;
  text-transform: uppercase;
  line-height: 1;
}
.status-badge.st-active {
  background: #e6f4ff;
  color: #0864b8;
}
.status-badge.st-sold {
  background: #d9f7e8;
  color: #127a3a;
}
.status-badge.st-expired {
  background: #eceff2;
  color: #555;
}
.status-badge.st-past {
  background: #f1f3f5;
  color: #555;
}

/* Sortable Table Headers */
th.sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
th.sortable .sort-ind {
  display: inline-block;
  width: 12px;
  text-align: center;
  opacity: 0.6;
  margin-left: 4px;
  font-size: 0.6rem;
}
th.sortable.sorted-asc .sort-ind,
th.sortable.sorted-desc .sort-ind {
  opacity: 1;
}
th.sortable:hover {
  background: #e8f1ff;
}

/* Responsive Design */
@media (max-width: 768px) {
  .container {
    padding: 10px;
  }

  .header h1 {
    font-size: 2rem;
  }

  .tabs {
    flex-direction: column;
  }

  .controls {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-controls {
    justify-content: space-between;
  }

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

/* Detail Overlay */
.detail-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 60px 20px 40px;
  z-index: 1000;
  overflow-y: auto;
}

.detail-content {
  background: #ffffff;
  width: 100%;
  max-width: 960px;
  border-radius: 16px;
  padding: 30px 35px 40px;
  position: relative;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
  animation: fadeInScale 0.25s ease;
}

@keyframes fadeInScale {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.detail-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: #f1f3f5;
  border: none;
  font-size: 18px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}
.detail-close:hover {
  background: #e9ecef;
}

.detail-section {
  margin-top: 30px;
}
.detail-section h3 {
  margin-bottom: 12px;
  font-size: 1.15rem;
  color: #333;
}

.detail-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.sellers-table-wrapper {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.detail-table thead {
  background: #f1f5f9;
}
.detail-table th,
.detail-table td {
  padding: 8px 10px;
  text-align: left;
}
.detail-table tbody tr:nth-child(even) {
  background: #f9fafb;
}
.detail-table tbody tr:hover {
  background: #eef6ff;
}

/* Sellers table specific tweaks */
.sellers-table th:nth-child(1) {
  min-width: 140px;
}
.sellers-table th,
.sellers-table td {
  white-space: nowrap;
}
/* Allow some wider text columns to wrap to reduce overflow pressure */
.sellers-table td:nth-child(1),
.sellers-table th:nth-child(1) {
  white-space: normal;
  word-break: break-word;
  max-width: 180px;
}
.sellers-table td:nth-child(7),
.sellers-table td:nth-child(8) {
  white-space: normal;
  word-break: break-word;
  max-width: 160px;
}

/* Items stats table */
.items-stats-wrapper {
  width: 100%;
  overflow-x: auto;
}
.items-stats-table td:nth-child(1) {
  white-space: nowrap;
}
.items-stats-table td,
.items-stats-table th {
  white-space: nowrap;
}
@media (max-width: 900px) {
  .items-stats-table th:nth-child(8),
  .items-stats-table td:nth-child(8) {
    display: none;
  }
}
@media (max-width: 760px) {
  .items-stats-table th:nth-child(7),
  .items-stats-table td:nth-child(7) {
    display: none;
  }
}
@media (max-width: 640px) {
  .items-stats-table th:nth-child(5),
  .items-stats-table td:nth-child(5),
  .items-stats-table th:nth-child(6),
  .items-stats-table td:nth-child(6) {
    display: none;
  }
}

/* Responsive column pruning for sellers table */
@media (max-width: 1200px) {
  .sellers-table th:nth-child(9),
  .sellers-table td:nth-child(9) {
    display: none;
  }
}
@media (max-width: 1050px) {
  .sellers-table th:nth-child(7),
  .sellers-table td:nth-child(7) {
    display: none;
  }
}
@media (max-width: 900px) {
  .sellers-table th:nth-child(8),
  .sellers-table td:nth-child(8) {
    display: none;
  }
}
@media (max-width: 780px) {
  .sellers-table th:nth-child(5),
  .sellers-table td:nth-child(5),
  .sellers-table th:nth-child(6),
  .sellers-table td:nth-child(6) {
    display: none;
  }
}
@media (max-width: 650px) {
  .sellers-table th:nth-child(4),
  .sellers-table td:nth-child(4) {
    display: none;
  }
}
.sellers-table td {
  vertical-align: middle;
}
.sellers-table td button.seller-link {
  font-weight: 600;
}

.detail-table th {
  font-weight: 600;
  font-size: 0.75rem;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: #555;
}

/* Clickable Links */
.item-link,
.seller-link,
.link-inline {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  font: inherit;
  color: #0056b3;
  cursor: pointer;
  text-align: left;
  transition: color 0.15s;
}
.item-link:hover,
.seller-link:hover,
.link-inline:hover {
  color: #003d80;
  text-decoration: underline;
}
.item-link {
  font-weight: 600;
  font-size: 1.05rem;
}
.seller-link {
  font-size: 0.9rem;
}

.detail-content h2 {
  margin-bottom: 5px;
  font-size: 1.6rem;
}

@media (max-width: 600px) {
  .detail-content {
    padding: 25px 20px 35px;
  }
  .detail-table {
    font-size: 0.8rem;
  }
  .detail-content h2 {
    font-size: 1.3rem;
  }
}

/* Mini Charts Dashboard */
.mini-charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
}

.mini-chart-card {
  background: #ffffff;
  border-radius: 10px;
  padding: 10px 12px 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 140px;
}

.mini-chart-card-new {
  box-shadow: 0 0 0 2px #ffc107, 0 4px 10px rgba(0, 0, 0, 0.15);
}

.mini-chart-badge-new {
  position: absolute;
  top: 6px;
  right: 6px;
  background: linear-gradient(135deg, #ff9800, #ffc107);
  color: #222;
  font-size: 0.55rem;
  font-weight: 700;
  padding: 3px 6px 2px;
  border-radius: 4px;
  letter-spacing: 0.5px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
  pointer-events: none;
}

.mini-chart-price {
  font-size: 0.65rem;
  font-weight: 600;
  color: #007bff;
  background: #eef6ff;
  padding: 2px 6px;
  border-radius: 10px;
  line-height: 1.2;
}

.mini-chart-price-missing {
  background: #f1f3f5;
  color: #666;
}

.mini-chart-header {
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.mini-chart-card canvas {
  width: 100% !important;
  height: 90px !important;
}

.mini-chart-card:hover {
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.12);
  transform: translateY(-2px);
  transition: all 0.18s ease;
}

.mini-charts-wrapper.collapsed .mini-charts-grid {
  display: none;
}

.mini-charts-toggle {
  background: #007bff;
  color: #fff;
  border: none;
  padding: 6px 12px;
  font-size: 0.75rem;
  border-radius: 6px;
  cursor: pointer;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.mini-charts-toggle:hover {
  background: #0063cc;
}

@media (max-width: 600px) {
  .mini-charts-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }
  .mini-chart-card {
    min-height: 120px;
    padding: 8px 10px 6px;
  }
  .mini-chart-card canvas {
    height: 70px !important;
  }
}
