/**
 * Flow Chart - Wide Table with Horizontal Scroll
 * Shows team ranking evolution across rally days
 */

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

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

/* Custom scrollbar */
.flow-chart-wrapper::-webkit-scrollbar {
  height: 12px;
}

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

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

.flow-chart-wrapper::-webkit-scrollbar-thumb:hover {
  background: #1585a8;
}

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

.flow-chart-table {
  width: 100%;
  min-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-family: var(--font-body);
  font-size: var(--text-small);
}

/* ============================================
   STICKY RANK COLUMN
   ============================================ */

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

.col-rank.sticky-col {
  min-width: 60px;
  width: 60px;
}

/* 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
   ============================================ */

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

.header-row-1 th,
.header-row-2 th {
  font-family: var(--font-heading);
  font-weight: var(--weight-semibold);
  color: var(--color-primary); /* Rebelle blue in dark mode */
  letter-spacing: 0.03em;
  text-transform: uppercase;
  text-align: center;
}

.header-row-1 th {
  font-size: 12px;
  font-weight: var(--weight-bold);
  letter-spacing: 0.05em;
  padding: 8px 4px;
  border-bottom: 1px solid var(--border-row);
}

.header-row-2 th {
  font-size: 10px;
  padding: 6px 4px;
  border-bottom: 2px solid var(--border-primary);
}

/* Day header spans 2 columns */
.col-day-header {
  border-left: 1px solid var(--border-subtle);
  border-right: 1px solid var(--border-subtle);
}

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

/* Center align headers */
.header-center {
  text-align: center !important;
}

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

.col-rank {
  width: 60px;
  text-align: center;
  font-weight: var(--weight-bold);
  font-size: var(--text-normal);
  color: var(--color-primary);
}

.col-team {
  width: 70px;
  text-align: center;
  font-weight: var(--weight-semibold);
  font-size: var(--text-small);
  padding: 10px 6px !important;
}

.col-diff {
  width: 55px;
  text-align: center;
  font-weight: var(--weight-medium);
  font-size: var(--text-small);
  color: var(--text-secondary);
  padding: 10px 6px !important;
}

/* Driver names in last day column */
.driver-names {
  display: block;
  font-size: var(--text-tiny);
  color: var(--text-secondary);
  font-weight: var(--weight-normal);
  margin-top: 4px;
  white-space: nowrap;
}

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

.team-row {
  cursor: pointer;
}

.team-row td {
  padding: 12px 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);
}

/* Leader row (first place) */
.leader-row td {
  background: rgba(24, 159, 218, 0.08);
  font-weight: var(--weight-semibold);
}

.leader-row .sticky-col {
  background: rgba(24, 159, 218, 0.08);
}

.leader-row .col-rank {
  color: var(--color-primary);
  font-size: var(--text-large);
}

/* 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);
}

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

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

  .flow-chart-table {
    display: none;
  }

  /* Show cards instead */
  .flow-chart-cards {
    display: block !important;
  }

  /* Fixed header showing rally days - 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;
  }

  /* Team cards */
  .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);
  }

  .leader-card {
    background: rgba(24, 159, 218, 0.12);
    border: 2px solid var(--color-primary);
  }

  /* Card header: Rank | Team */
  .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-header-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
    align-items: flex-start;
  }

  .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-rank {
    font-family: var(--font-heading);
    font-size: 24px;
    font-weight: var(--weight-bold);
    color: var(--color-primary);
    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;
  }

  /* 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 progression grid - dynamic day count */
  .card-daily-progression {
    display: grid;
    grid-template-columns: repeat(var(--day-count, 7), 1fr);
    gap: 4px;
    margin-top: 12px;
  }

  .day-progression-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;
    line-height: 1;
  }

  .day-position {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    background: var(--bg-secondary);
    padding: 4px 6px;
    border-radius: 4px;
    width: 100%;
    min-width: 32px;
    justify-content: center;
  }

  .day-car {
    font-family: var(--font-heading);
    font-size: var(--text-small);
    font-weight: var(--weight-bold);
    color: var(--text-primary);
    line-height: 1;
  }

  .day-diff {
    font-family: var(--font-body);
    font-size: var(--text-tiny);
    font-weight: var(--weight-semibold);
    color: var(--text-secondary);
    line-height: 1;
  }

  .day-diff.leader {
    color: var(--color-primary);
    font-weight: var(--weight-bold);
  }
}

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

/* Tablet - keep table but more compact */
@media (min-width: 769px) and (max-width: 1024px) {
  .flow-chart-table {
    font-size: var(--text-tiny);
  }

  .col-team {
    width: 65px;
  }

  .col-diff {
    width: 50px;
  }

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

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

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

:root[data-theme="light"] .header-row-1 th,
: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-1 .sticky-col,
: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"] .leader-row .sticky-col {
  background: rgba(24, 159, 218, 0.08);
}

:root[data-theme="light"] .header-row-1 .sticky-col,
: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"] .leader-card {
    background: rgba(24, 159, 218, 0.08);
    border: 2px solid var(--color-primary);
  }

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

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