/**
 * Daily Totals - Wide Table with Horizontal Scroll
 * Responsive layout for 10+ columns of scoring data
 */

/* ============================================
   PANEL SUBTITLE
   ============================================ */

.panel-subtitle {
  font-family: var(--font-body);
  font-size: var(--text-small);
  color: var(--text-secondary);
  text-align: center;
  margin-top: 8px;
  margin-bottom: 24px;
  font-style: italic;
}

/* ============================================
   WIDE TABLE WRAPPER - HORIZONTAL SCROLL
   ============================================ */

.daily-totals-wrapper {
  width: 100%;
  /* No overflow - let panel-content handle all scrolling */
  position: relative;
}

/* Custom scrollbar for wide table */
.daily-totals-wrapper::-webkit-scrollbar {
  height: 12px;
}

.daily-totals-wrapper::-webkit-scrollbar-track {
  background: var(--bg-secondary);
  border-radius: 6px;
}

.daily-totals-wrapper::-webkit-scrollbar-thumb {
  background: var(--color-primary);
  border-radius: 6px;
}

.daily-totals-wrapper::-webkit-scrollbar-thumb:hover {
  background: #1585a8;
}

/* ============================================
   WIDE TABLE - COMPACT FIT ALL COLUMNS
   ============================================ */

.daily-totals-table {
  width: 100%;
  min-width: 100%; /* Fit to container */
  border-collapse: separate;
  border-spacing: 0;
  font-family: var(--font-body);
  font-size: var(--text-small); /* Smaller base font */
}

/* ============================================
   STICKY COLUMNS - STAY FIXED DURING SCROLL
   ============================================ */

.sticky-col {
  position: sticky;
  background: var(--bg-panel);
  z-index: 5; /* Below thead */
}

/* Column positions for sticky effect */
.col-rank.sticky-col {
  left: 0;
  min-width: 50px;
}

.daily-totals-table .col-team.sticky-col {
  left: 0px;
  min-width: 50px;
}

.col-driver.sticky-col {
  left: 100px;
  min-width: 180px;
}

/* Add subtle border to show sticky boundary */
.sticky-col::after {
  content: '';
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--border-primary);
  opacity: 0.3;
}

/* ============================================
   TABLE HEADER - TWO ROWS
   ============================================ */

.daily-totals-table thead {
  position: sticky;
  top: 0;
  z-index: 10;
  background: #0f1419; /* Solid dark background for dark mode */
}

.header-row-2 th {
  font-family: var(--font-heading);
  font-size: 12px;
  font-weight: var(--weight-semibold);
  color: var(--color-primary); /* Rebelle blue in dark mode */
  letter-spacing: 0.03em;
  text-transform: uppercase;
  text-align: center;
  padding: 8px 8px;
  border-bottom: 2px solid var(--border-primary);
  overflow: visible;
  white-space: nowrap;
}

/* Left-align driver header */
.header-left {
  text-align: left !important;
  padding-left: 12px !important;
}

/* Sticky header columns inherit position from .sticky-col, just need higher z-index */
.header-row-2 .sticky-col {
  background: #0f1419; /* Solid background for sticky */
  z-index: 15; /* Above thead (10) and body sticky-cols (5) */
}

/* ============================================
   SORTABLE HEADERS - CLICKABLE COLUMNS
   ============================================ */

.sort-header {
  cursor: pointer;
  position: relative;
  transition: all 0.2s;
}

.sort-header a {
  color: var(--text-accent);
  text-decoration: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 100%;
  height: 100%;
  transition: all 0.2s;
  white-space: nowrap;
}

.sort-header:hover a {
  color: var(--color-primary);
}

.sort-header.active a {
  color: var(--color-primary);
  font-weight: var(--weight-bold);
}

/* Sort icon */
.sort-icon {
  display: inline-block;
  flex-shrink: 0;
  vertical-align: middle;
  transition: all 0.2s;
  width: 24px;
  height: 24px;
}

/* Inactive sort icons - show both arrows dimmed but visible */
.sort-icon-inactive {
  opacity: 0.6;
}

/* On hover, make inactive icons more visible */
.sort-header:hover .sort-icon-inactive {
  opacity: 0.9;
}

/* Active sort icon - full opacity */
.sort-header.active .sort-icon {
  opacity: 1;
}

/* Day column sort icons - smaller */
.sort-icon-day {
  width: 20px;
  height: 20px;
}

/* ============================================
   TABLE COLUMNS - COMPACT WIDTHS
   ============================================ */

.col-rank {
  width: 50px;
  text-align: center;
}

.col-team {
  width: 50px;
  min-width: 50px;
  text-align: center;
}

.col-driver {
  width: 180px;
  text-align: left;
  padding-left: 12px !important;
  font-size: var(--text-tiny); /* Smaller driver names */
}

.col-total {
  width: 90px;
  text-align: center;
}

.col-percent {
  width: 55px;
  text-align: center;
}

.col-day {
  width: 70px;
  text-align: center;
  min-width: 70px;
  padding-left: 4px !important;
  padding-right: 4px !important;
}

/* Day column header - stacked layout */
.col-day a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.day-header-label {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 12px;
}

.day-header-total {
  font-size: 12px;
  font-weight: var(--weight-semibold);
}

/* ============================================
   TABLE ROWS
   ============================================ */

.team-row {
  cursor: pointer;
}

.team-row td {
  padding: 10px 4px;
  border-bottom: 1px solid var(--border-row);
  font-weight: var(--weight-medium);
  color: var(--text-primary);
  vertical-align: middle;
}

/* Sticky cells in rows */
.team-row .sticky-col {
  background: var(--bg-panel);
}

/* Alternating rows */
.team-row:nth-child(even) td {
  background: var(--bg-row-alternate);
}

.team-row:nth-child(even) .sticky-col {
  background: var(--bg-row-alternate);
}

/* Hover effect */
.team-row:hover td {
  background: rgba(24, 159, 218, 0.1);
}

.team-row:hover .sticky-col {
  background: rgba(24, 159, 218, 0.1);
}

/* ============================================
   CELL SPECIFIC STYLES
   ============================================ */

/* Rank */
.col-rank {
  font-weight: var(--weight-bold);
  font-size: var(--text-base);
  color: var(--color-primary);
}

/* Team number */
.col-team {
  font-weight: var(--weight-bold);
  font-size: var(--text-base);
  transition: color 0.2s ease;
}

/* Driver names */
.col-driver {
  font-weight: var(--weight-medium);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: var(--text-tiny);
  transition: color 0.2s ease;
}

/* Hover effect - team and driver turn blue */
.team-row:hover .col-team,
.team-row:hover .col-driver {
  color: var(--color-primary);
}

/* Total points */
.col-total {
  font-weight: var(--weight-bold);
  font-size: var(--text-normal);
  font-variant-numeric: tabular-nums;
}

/* Percentage */
.col-percent {
  font-weight: var(--weight-semibold);
  font-variant-numeric: tabular-nums;
  color: var(--color-primary);
  font-size: var(--text-small);
}

/* Day scores */
.col-day {
  font-variant-numeric: tabular-nums;
  font-weight: var(--weight-medium);
  font-size: var(--text-small);
}

/* ============================================
   SPECIAL STATES
   ============================================ */

/* DQ (Disqualified) */
.status-dq {
  color: #EF4444 !important;
  font-weight: var(--weight-bold) !important;
}

/* Empty scores */
.col-day:contains('-') {
  color: var(--text-muted);
}

/* ============================================
   RESPONSIVE - TABLET
   ============================================ */

@media (max-width: 1200px) {
  .daily-totals-table {
    min-width: 1000px;
    font-size: var(--text-small);
  }

  .col-day {
    width: 65px;
    min-width: 65px;
  }

  .col-driver {
    width: 160px;
  }

  .team-row td {
    padding: 10px 6px;
  }
}

/* ============================================
   MOBILE SORT BAR - Hide on desktop
   ============================================ */

.mobile-sort-bar {
  display: none; /* Hidden on desktop */
}

/* Position class tab and sort bar on same line on mobile */
@media (max-width: 768px) {
  .panel-container {
    position: relative;
  }

  .class-tab {
    position: absolute;
    top: 16px;
    left: 16px;
    z-index: 2;
  }
}

/* ============================================
   RESPONSIVE - MOBILE CARDS
   ============================================ */

@media (max-width: 768px) {
  /* Hide the table layout completely */
  .daily-totals-wrapper {
    overflow-x: visible;
  }

  .daily-totals-table {
    display: none;
  }

  /* Show cards instead */
  .daily-totals-cards {
    display: block !important;
  }

  /* Mobile sort bar - positioned to the right, aligned with title */
  .mobile-sort-bar {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    position: absolute;
    top: 52px;
    right: 20px;
    z-index: 2;
    padding: 0;
    background: transparent;
    border-radius: 0;
    margin-bottom: 0;
  }

  .mobile-sort-label {
    font-family: var(--font-heading);
    font-size: 11px;
    font-weight: var(--weight-bold);
    color: var(--text-accent);
    text-transform: uppercase;
    letter-spacing: 0.5px;
  }

  .mobile-sort-buttons {
    display: flex;
    gap: 8px;
  }

  .mobile-sort-btn {
    font-family: var(--font-heading);
    font-size: 12px;
    font-weight: var(--weight-bold);
    color: var(--text-secondary);
    text-transform: uppercase;
    text-decoration: none;
    padding: 6px 16px;
    border: 2px solid var(--border-primary);
    border-radius: 4px;
    transition: all 0.2s;
    background: transparent;
  }

  .mobile-sort-btn:hover {
    color: var(--color-primary);
    border-color: var(--color-primary);
  }

  .mobile-sort-btn.active {
    color: var(--color-primary);
    border-color: var(--color-primary);
    background: rgba(24, 159, 218, 0.1);
  }

  /* Fixed header showing daily possible points - dynamic column count */
  .mobile-day-header {
    background: var(--bg-header);
    border: 2px solid var(--color-primary);
    border-radius: 8px;
    padding: 12px 16px;
    margin-bottom: 16px;
    display: grid;
    grid-template-columns: repeat(var(--day-count, 7), 1fr);
    gap: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  }

  .mobile-day-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
  }

  .mobile-day-label {
    font-family: var(--font-heading);
    font-size: 11px;
    font-weight: var(--weight-bold);
    color: var(--text-accent);
    text-transform: uppercase;
    line-height: 1;
  }

  .mobile-day-total {
    font-family: var(--font-body);
    font-size: 12px;
    font-weight: var(--weight-semibold);
    color: var(--text-secondary);
    line-height: 1;
  }

  /* Match entries.php card styling */
  .team-card {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 20px;
    transition: background 0.15s ease;
    cursor: pointer;
  }

  .team-card:hover {
    background: rgba(24, 159, 218, 0.08);
  }

  /* Card header: Team # | Total | % */
  .card-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-row);
  }

  .card-header-left {
    display: flex;
    align-items: baseline;
    gap: 16px;
  }

  .card-stats {
    display: flex;
    align-items: baseline;
    gap: 16px;
  }

  .card-header-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
  }

  /* Left side items - left aligned */
  .card-header-left .card-header-item {
    align-items: flex-start;
  }

  /* Right side items - right aligned */
  .card-stats .card-header-item {
    align-items: flex-end;
  }

  .card-header-label {
    font-family: var(--font-heading);
    font-size: 11px;
    font-weight: var(--weight-bold);
    color: var(--text-accent);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    line-height: 1;
  }

  .card-team-num {
    font-family: var(--font-heading);
    font-size: 24px;
    font-weight: var(--weight-bold);
    color: var(--text-primary);
    line-height: 1;
  }

  .card-rank {
    font-family: var(--font-heading);
    font-size: 24px;
    font-weight: var(--weight-bold);
    color: var(--color-primary);
    line-height: 1;
  }

  .card-total {
    font-family: var(--font-heading);
    font-size: 20px;
    font-weight: var(--weight-bold);
    color: var(--text-primary);
    line-height: 1;
  }

  .card-total.status-dq {
    color: #EF4444;
  }

  .card-percent {
    font-family: var(--font-body);
    font-size: var(--text-normal);
    font-weight: var(--weight-semibold);
    color: var(--color-primary);
    line-height: 1;
  }

  /* Driver names - white in dark mode */
  .card-drivers {
    font-family: var(--font-body);
    font-size: var(--text-normal);
    font-weight: var(--weight-medium);
    color: var(--text-primary);
    margin-bottom: 20px;
  }

  /* Daily scores grid - dynamic day count */
  .card-daily-scores {
    display: grid;
    grid-template-columns: repeat(var(--day-count, 7), 1fr);
    gap: 4px;
    margin-top: 12px;
  }

  .day-score-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
  }

  .day-label {
    font-family: var(--font-heading);
    font-size: 10px;
    font-weight: var(--weight-semibold);
    color: var(--text-accent);
    text-transform: uppercase;
  }

  .day-value {
    font-family: var(--font-body);
    font-size: var(--text-small);
    font-weight: var(--weight-semibold);
    color: var(--text-primary);
    background: var(--bg-secondary);
    padding: 4px 6px;
    border-radius: 4px;
    min-width: 32px;
    text-align: center;
    font-variant-numeric: tabular-nums;
  }

  .day-value.status-dq {
    color: #EF4444;
    background: rgba(239, 68, 68, 0.1);
  }

  .day-value.empty {
    color: var(--text-muted);
    background: transparent;
  }
}

/* Tablet - keep table but more compact */
@media (min-width: 769px) and (max-width: 1024px) {
  .daily-totals-cards {
    display: none;
  }

  .daily-totals-table {
    font-size: var(--text-tiny);
  }

  .col-day {
    width: 60px;
    min-width: 60px;
  }

  .col-driver {
    width: 140px;
  }

  .team-row td {
    padding: 8px 4px;
  }
}

/* Desktop - hide cards, show table */
@media (min-width: 769px) {
  .daily-totals-cards {
    display: none !important;
  }
}

/* ============================================
   LIGHT MODE ADJUSTMENTS
   ============================================ */

:root[data-theme="light"] .daily-totals-table thead {
  background: #ffffff; /* Solid white background for light mode */
}

:root[data-theme="light"] .header-row-2 th {
  color: var(--color-navy); /* Dark text in light mode */
  background: #ffffff; /* Solid white background for light mode */
}

:root[data-theme="light"] .header-row-2 .sticky-col {
  background: #ffffff; /* Solid white for sticky columns in light mode */
}

:root[data-theme="light"] .sticky-col {
  background: white;
}

:root[data-theme="light"] .team-row:nth-child(even) .sticky-col {
  background: var(--bg-row-alternate);
}

:root[data-theme="light"] .team-row:hover .sticky-col {
  background: rgba(24, 159, 218, 0.1);
}

:root[data-theme="light"] .header-row-2 .sticky-col {
  background: var(--bg-header);
}

/* Mobile cards light mode */
@media (max-width: 768px) {
  :root[data-theme="light"] .mobile-day-header {
    background: #F9FAFB;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  }

  :root[data-theme="light"] .team-card {
    background: rgba(0, 0, 0, 0.02);
    border: 1px solid var(--border-subtle);
  }

  :root[data-theme="light"] .team-card:hover {
    background: rgba(24, 159, 218, 0.08);
  }

  :root[data-theme="light"] .day-value {
    background: #F3F4F6;
  }

  :root[data-theme="light"] .day-value.empty {
    background: transparent;
  }

  /* Driver names in light mode - use secondary color */
  :root[data-theme="light"] .card-drivers {
    color: var(--text-secondary);
  }
}
