/* ========================================
   Kalshi Pivot Table - Dark Fintech Theme
   ======================================== */

/* CSS Variables - Kalshi Brand Colors */
:root {
  /* Brand Colors */
  --kalshi-primary: #09C285;
  --kalshi-primary-dark: #003221;
  --kalshi-primary-glow: rgba(9, 194, 133, 0.4);

  /* Trading Colors */
  --predict-yes: #265CFF;
  --predict-no: #AA00FF;
  --increase: #0AC285;
  --decrease: #D91616;

  /* Neutral Palette */
  --bg-primary: #0a0e17;
  --bg-secondary: #0f1419;
  --bg-tertiary: #151c25;
  --bg-elevated: #1a222d;
  --bg-card: rgba(21, 28, 37, 0.8);
  --bg-glass: rgba(21, 28, 37, 0.6);

  /* Text Colors */
  --text-primary: rgba(255, 255, 255, 0.95);
  --text-secondary: rgba(255, 255, 255, 0.65);
  --text-tertiary: rgba(255, 255, 255, 0.4);
  --text-muted: rgba(255, 255, 255, 0.25);

  /* Border Colors */
  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-default: rgba(255, 255, 255, 0.1);
  --border-hover: rgba(255, 255, 255, 0.15);
  --border-glow: rgba(9, 194, 133, 0.3);

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  /* Shadows */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 40px rgba(9, 194, 133, 0.15);

  /* Typography */
  --font-sans: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', monospace;

  /* Transitions */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

/* App Container */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  position: relative;
}

/* Background Effects */
.bg-gradient {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(9, 194, 133, 0.15), transparent 50%),
    radial-gradient(ellipse 60% 40% at 100% 0%, rgba(38, 92, 255, 0.1), transparent 40%),
    radial-gradient(ellipse 50% 50% at 0% 100%, rgba(170, 0, 255, 0.08), transparent 40%);
  pointer-events: none;
  z-index: 0;
}

.bg-noise {
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
  opacity: 0.03;
  pointer-events: none;
  z-index: 0;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) var(--space-xl);
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left,
.header-right {
  flex: 1;
}

.header-right {
  display: flex;
  justify-content: flex-end;
}

.header-center {
  flex: 2;
  display: flex;
  justify-content: center;
}

/* Logo */
.logo {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

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

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

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

/* Series Selector */
.series-selector {
  position: relative;
  display: flex;
  align-items: center;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 0 var(--space-md);
  min-width: 320px;
  transition: var(--transition-base);
}

.series-selector:hover {
  border-color: var(--border-hover);
  background: var(--bg-elevated);
}

.series-selector:focus-within {
  border-color: var(--kalshi-primary);
  box-shadow: 0 0 0 3px var(--kalshi-primary-glow);
}

.selector-icon {
  width: 18px;
  height: 18px;
  color: var(--text-tertiary);
  flex-shrink: 0;
}

.selector-icon svg {
  width: 100%;
  height: 100%;
}

.series-select {
  flex: 1;
  appearance: none;
  background: transparent;
  border: none;
  padding: var(--space-sm) var(--space-md);
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
  outline: none;
}

.series-select option {
  background: var(--bg-elevated);
  color: var(--text-primary);
  padding: var(--space-sm);
}

.selector-arrow {
  width: 20px;
  height: 20px;
  color: var(--text-tertiary);
  flex-shrink: 0;
  transition: var(--transition-fast);
}

.selector-arrow svg {
  width: 100%;
  height: 100%;
}

.series-selector:focus-within .selector-arrow {
  color: var(--kalshi-primary);
}

/* Live Badge */
.live-badge {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-xs) var(--space-md);
  background: rgba(9, 194, 133, 0.1);
  border: 1px solid rgba(9, 194, 133, 0.2);
  border-radius: var(--radius-xl);
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--kalshi-primary);
  letter-spacing: 0.02em;
}

.live-dot {
  width: 8px;
  height: 8px;
  background: var(--kalshi-primary);
  border-radius: 50%;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.9); }
}

/* Main Content */
.main {
  flex: 1;
  padding: var(--space-xl);
  position: relative;
  z-index: 1;
}

.content {
  max-width: 100%;
  animation: fadeIn 0.5s ease-out;
}

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

/* Empty State */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  text-align: center;
  animation: fadeIn 0.6s ease-out;
}

.empty-state-icon {
  width: 120px;
  height: 120px;
  margin-bottom: var(--space-xl);
  color: var(--text-tertiary);
  opacity: 0.6;
}

.empty-state-icon svg {
  width: 100%;
  height: 100%;
}

.empty-state-title {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: var(--space-sm);
  letter-spacing: -0.02em;
}

.empty-state-text {
  font-size: 1rem;
  color: var(--text-secondary);
  max-width: 400px;
}

/* Loading State */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  gap: var(--space-lg);
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 3px solid var(--border-default);
  border-top-color: var(--kalshi-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

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

/* Series Header */
.series-header {
  margin-bottom: var(--space-xl);
  animation: slideDown 0.4s ease-out;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}

.series-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: var(--space-xs);
  letter-spacing: -0.02em;
}

.series-meta {
  font-size: 0.875rem;
  color: var(--text-tertiary);
}

/* Stats Grid */
.stats-grid {
  display: flex;
  gap: var(--space-md);
  margin-bottom: var(--space-xl);
  flex-wrap: wrap;
}

.stat-card {
  flex: 1;
  min-width: 140px;
  background: var(--bg-card);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  transition: var(--transition-base);
  animation: scaleIn 0.4s ease-out backwards;
}

.stat-card:nth-child(1) { animation-delay: 0.1s; }
.stat-card:nth-child(2) { animation-delay: 0.15s; }
.stat-card:nth-child(3) { animation-delay: 0.2s; }

@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.stat-card:hover {
  border-color: var(--border-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 2rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.2;
  margin-bottom: var(--space-xs);
}

.stat-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* Table Container */
.table-container {
  background: var(--bg-card);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  animation: fadeIn 0.5s ease-out 0.2s backwards;
}

.table-wrapper {
  overflow-x: auto;
  max-height: calc(100vh - 360px);
  overflow-y: auto;
}

/* Scrollbar Styling */
.table-wrapper::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.table-wrapper::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

.table-wrapper::-webkit-scrollbar-thumb {
  background: var(--border-default);
  border-radius: 4px;
}

.table-wrapper::-webkit-scrollbar-thumb:hover {
  background: var(--border-hover);
}

.table-wrapper::-webkit-scrollbar-corner {
  background: var(--bg-secondary);
}

/* Table */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

th, td {
  padding: var(--space-sm) var(--space-md);
  text-align: left;
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
}

th {
  background: var(--bg-tertiary);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  position: sticky;
  top: 0;
  z-index: 10;
}

th.sortable {
  cursor: pointer;
  user-select: none;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}

th.sortable:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

th.sortable.sorted {
  color: var(--kalshi-primary);
  background: rgba(9, 194, 133, 0.1);
}

.sort-indicator {
  display: inline-block;
  width: 1em;
  text-align: center;
  opacity: 0.3;
  font-size: 0.65em;
  vertical-align: middle;
  margin-left: var(--space-xs);
}

th.sortable:hover .sort-indicator {
  opacity: 0.6;
}

.sort-indicator.sort-asc,
.sort-indicator.sort-desc {
  opacity: 1;
  color: var(--kalshi-primary);
}

th:first-child {
  position: sticky;
  left: 0;
  z-index: 20;
  background: var(--bg-tertiary);
}

td:first-child {
  position: sticky;
  left: 0;
  background: var(--bg-elevated);
  font-weight: 500;
  color: var(--text-primary);
  z-index: 5;
  border-right: 1px solid var(--border-subtle);
}

tr:hover td {
  background: var(--bg-elevated);
}

tr:hover td:first-child {
  background: var(--bg-card);
}

/* Cell States */
.cell-yes {
  background: rgba(38, 92, 255, 0.2) !important;
  color: #6B9FFF !important;
  font-weight: 600;
  font-family: var(--font-mono);
}

.cell-no {
  background: rgba(170, 0, 255, 0.2) !important;
  color: #D580FF !important;
  font-weight: 600;
  font-family: var(--font-mono);
}

.cell-likely-yes {
  background: rgba(10, 194, 133, 0.15) !important;
  color: var(--kalshi-primary) !important;
  font-weight: 500;
  font-family: var(--font-mono);
}

.cell-likely-no {
  background: rgba(217, 22, 22, 0.15) !important;
  color: #FF6B6B !important;
  font-weight: 500;
  font-family: var(--font-mono);
}

.cell-uncertain {
  background: rgba(255, 193, 7, 0.12) !important;
  color: #FFD54F !important;
  font-weight: 500;
  font-family: var(--font-mono);
}

.cell-active {
  background: rgba(9, 194, 133, 0.1) !important;
  color: var(--kalshi-primary) !important;
  font-weight: 500;
}

.cell-empty {
  color: var(--text-muted) !important;
}

.cell-other {
  color: var(--text-tertiary) !important;
}

/* Error State */
.error {
  background: rgba(217, 22, 22, 0.1);
  border: 1px solid rgba(217, 22, 22, 0.3);
  color: #FF6B6B;
  padding: var(--space-lg);
  border-radius: var(--radius-md);
  text-align: center;
}

/* Footer / Legend */
.footer {
  padding: var(--space-md) var(--space-xl);
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  border-top: 1px solid var(--border-subtle);
  position: sticky;
  bottom: 0;
  z-index: 100;
}

.legend {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
  flex-wrap: wrap;
}

.legend-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.legend-items {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  flex-wrap: wrap;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.legend-color {
  width: 12px;
  height: 12px;
  border-radius: 3px;
}

.legend-yes { background: rgba(38, 92, 255, 0.6); }
.legend-no { background: rgba(170, 0, 255, 0.6); }
.legend-likely-yes { background: rgba(10, 194, 133, 0.5); }
.legend-uncertain { background: rgba(255, 193, 7, 0.5); }
.legend-likely-no { background: rgba(217, 22, 22, 0.5); }
.legend-active { background: rgba(9, 194, 133, 0.4); }

/* Responsive */
@media (max-width: 768px) {
  .header {
    flex-wrap: wrap;
    gap: var(--space-md);
    padding: var(--space-md);
  }

  .header-left,
  .header-right {
    flex: auto;
  }

  .header-center {
    flex: 100%;
    order: 3;
  }

  .series-selector {
    min-width: 100%;
  }

  .main {
    padding: var(--space-md);
  }

  .stats-grid {
    flex-direction: column;
  }

  .stat-card {
    min-width: 100%;
  }

  .stat-value {
    font-size: 1.5rem;
  }

  .legend {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-sm);
  }

  .legend-items {
    gap: var(--space-sm);
  }
}

/* Hover transitions for cells */
td {
  transition: background-color var(--transition-fast);
}

/* Selection highlight */
::selection {
  background: rgba(9, 194, 133, 0.3);
  color: var(--text-primary);
}

/* ========================================
   Breadcrumbs Navigation
   ======================================== */
.breadcrumbs {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.breadcrumb-item {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-xs) var(--space-md);
  background: var(--bg-tertiary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition-base);
}

.breadcrumb-item:hover {
  background: var(--bg-elevated);
  border-color: var(--kalshi-primary);
  color: var(--kalshi-primary);
}

.breadcrumb-item svg {
  flex-shrink: 0;
}

.breadcrumb-separator {
  color: var(--text-tertiary);
  display: flex;
  align-items: center;
}

.breadcrumb-current {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ========================================
   Market Cards Grid
   ======================================== */
.markets-grid {
  display: flex;
  flex-direction: column;
  gap: var(--space-2xl);
}

.category-section {
  animation: fadeIn 0.5s ease-out backwards;
}

.category-section:nth-child(1) { animation-delay: 0.05s; }
.category-section:nth-child(2) { animation-delay: 0.1s; }
.category-section:nth-child(3) { animation-delay: 0.15s; }
.category-section:nth-child(4) { animation-delay: 0.2s; }
.category-section:nth-child(5) { animation-delay: 0.25s; }

.category-header {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}

.category-icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  flex-shrink: 0;
}

.category-icon svg {
  width: 24px;
  height: 24px;
}

.category-icon.earnings {
  background: rgba(10, 194, 133, 0.15);
  color: var(--kalshi-primary);
}

.category-icon.politics {
  background: rgba(38, 92, 255, 0.15);
  color: var(--predict-yes);
}

.category-icon.media {
  background: rgba(170, 0, 255, 0.15);
  color: var(--predict-no);
}

.category-icon.sports {
  background: rgba(255, 193, 7, 0.15);
  color: #FFD54F;
}

.category-icon.other {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-secondary);
}

.category-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.category-count {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-tertiary);
  background: var(--bg-tertiary);
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-sm);
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-md);
}

.market-card {
  background: var(--bg-card);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  cursor: pointer;
  transition: var(--transition-base);
  position: relative;
  overflow: hidden;
}

.market-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--kalshi-primary), var(--predict-yes));
  opacity: 0;
  transition: var(--transition-base);
}

.market-card:hover {
  border-color: var(--border-hover);
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg), var(--shadow-glow);
}

.market-card:hover::before {
  opacity: 1;
}

.market-card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--space-sm);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.market-card-meta {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  font-size: 0.75rem;
  color: var(--text-tertiary);
}

.market-card-ticker {
  font-family: var(--font-mono);
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-tertiary);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}

.market-card-updated {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.market-card-updated svg {
  width: 12px;
  height: 12px;
}

.market-card-arrow {
  position: absolute;
  bottom: var(--space-lg);
  right: var(--space-lg);
  width: 24px;
  height: 24px;
  color: var(--text-tertiary);
  opacity: 0;
  transform: translateX(-8px);
  transition: var(--transition-base);
}

.market-card:hover .market-card-arrow {
  opacity: 1;
  transform: translateX(0);
  color: var(--kalshi-primary);
}

/* Page header for card grid */
.page-header {
  margin-bottom: var(--space-xl);
  animation: slideDown 0.4s ease-out;
}

.page-title {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: var(--space-xs);
  letter-spacing: -0.02em;
}

.page-subtitle {
  font-size: 1rem;
  color: var(--text-secondary);
}

/* Responsive adjustments for cards */
@media (max-width: 768px) {
  .breadcrumbs {
    flex-wrap: wrap;
    justify-content: center;
  }

  .breadcrumb-current {
    max-width: 200px;
  }

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

  .page-title {
    font-size: 1.5rem;
  }

  .category-header {
    flex-wrap: wrap;
  }
}
