/* Base styles */
body {
  font-family: Arial, sans-serif;
  margin: 20px;
}

.stats-container {
  display: flex;
  gap: 20px;
  margin-bottom: 30px;
  width: fit-content;
}

.stat-box {
  border: 1px solid #ddd;
  padding: 15px;
  border-radius: 5px;
  flex: 1;
}

.stat-box h3 {
  margin-top: 0;
}

.stat-value {
  font-size: 24px;
  font-weight: bold;
}

/* Responsive design for mobile devices */
@media (max-width: 768px) {
  body {
    margin: 10px;
  }

  .stats-container {
    flex-direction: column;
    gap: 10px;
  }

  .stat-box {
    padding: 10px;
  }

  .stat-value {
    font-size: 20px;
  }

  th, td {
    padding: 10px 8px;
    font-size: 12px;
  }

  .chart-legend {
    font-size: 10px;
    line-height: 1.5;
  }

  .date-filter-section {
    padding: 10px;
  }

  .date-filter-section div[style*="display: flex"] {
    flex-direction: column;
    gap: 10px;
  }

  .date-filter-section input[type="date"],
  .date-filter-section button {
    width: 100%;
    box-sizing: border-box;
  }
}

/* Table container for horizontal and vertical scrolling with sticky headers/columns */
.table-container {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
  max-height: 60vh; /* Limit height to enable vertical scrolling */
  margin-bottom: 20px;
  position: relative;
}

table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  table-layout: auto;
}

th, td {
  position: relative;
  border: 1px solid;
  border-color: var(--color-border);
  color: var(--color-text);
  padding: 8px 12px;
  text-align: left;
  white-space: nowrap;
  font-size: 14px;
}

/* Sticky table header */
thead th {
  position: sticky;
  top: 0;
  z-index: 20;
  background-color: var(--color-table-header) !important;
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

/* Sticky first column */
th:first-child, td:first-child {
  position: sticky;
  left: 0;
  z-index: 10;
  background-color: var(--color-table-header) !important;
  box-shadow: 2px 0 5px rgba(0,0,0,0.1);
}

/* Sticky first header cell (intersection of sticky header and sticky column) */
th:first-child {
  z-index: 30 !important;
}

/* Ensure proper background for sticky cells in even rows */
tr:nth-child(even) td:first-child {
  background-color: var(--color-table-even) !important;
}

.header-with-logo {
  display: flex;
  align-items: center;
  gap: 15px;
  margin-bottom: 20px;
}

.ter-logo {
  height: 60px;
}

/* Theme system */
:root {
  --color-background: #ffffff;
  --color-text: #333333;
  --color-border: #dddddd;
  --color-stat-box-bg: #f9f9f9;
  --color-table-header: #f2f2f2;
  --color-table-even: #f9f9f9;

  --chart-color-on-time: #4CAF50;
  --chart-color-delay-5min: #8BC34A;
  --chart-color-delay-15min: #FFEB3B;
  --chart-color-delay-45min: #FF9800;
  --chart-color-delay-over-45min: #F44336;
  --chart-color-delay-unknown: #9E9E9E;
}

.dark-theme {
  --color-background: #1a1a1a;
  --color-text: #e0e0e0;
  --color-border: #333333;
  --color-stat-box-bg: #2d2d2d;
  --color-table-header: #252525;
  --color-table-even: #2d2d2d;

  --chart-color-on-time: #4CAF50;
  --chart-color-delay-5min: #8BC34A;
  --chart-color-delay-15min: #FFEB3B;
  --chart-color-delay-45min: #FF9800;
  --chart-color-delay-over-45min: #F44336;
  --chart-color-delay-unknown: #757575;
}

body {
  background-color: var(--color-background);
  color: var(--color-text);
  transition: background-color 0.3s, color 0.3s;
}

.stat-box {
  border-color: var(--color-border);
  background-color: var(--color-stat-box-bg);
}

table {
  border-color: var(--color-border);
}

th, td {
  border: 1px solid;
  border-color: var(--color-border);
  color: var(--color-text);
  padding: 8px 12px;
  text-align: left;
  white-space: nowrap;
  font-size: 14px;
}

th {
  background-color: var(--color-table-header);
}

tr:nth-child(even) {
  background-color: var(--color-table-even);
}

/* Chart colors */
[data-chart-segment="on-time"] {
  background-color: var(--chart-color-on-time);
}
[data-chart-segment="delay-5min"] {
  background-color: var(--chart-color-delay-5min);
}
[data-chart-segment="delay-15min"] {
  background-color: var(--chart-color-delay-15min);
}
[data-chart-segment="delay-45min"] {
  background-color: var(--chart-color-delay-45min);
}
[data-chart-segment="delay-over-45min"] {
  background-color: var(--chart-color-delay-over-45min);
}
[data-chart-segment="delay-unknown"] {
  background-color: var(--chart-color-delay-unknown);
}

/* Legend colors */
.chart-legend span {
  color: var(--color-text);
}


/* Dark Reader detection message */
.dark-reader-warning {
  background-color: #FFCDD2;
  color: #C62828;
  padding: 15px;
  border-radius: 5px;
  margin-bottom: 20px;
  display: none;
}

.dark-reader-warning.show {
  display: block;
}

/* Timestamp */
.timestamp {
  margin-top: 20px;
  font-size: 14px;
  color: var(--color-text);
}

/* Commit info */
.commit-info {
  margin-top: 10px;
  font-size: 12px;
  color: var(--color-text);
  opacity: 0.7;
  text-align: right;
}

#commit-sha {
  font-family: monospace;
  font-size: 11px;
}

/* Live view specific styles */
.live-trips-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 20px;
}

.live-trips-table th,
.live-trips-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text);
}

.live-trips-table th {
  background-color: var(--color-table-header);
  font-weight: bold;
  position: sticky;
  top: 0;
}

.live-trip-row:hover {
  background-color: rgba(0, 0, 0, 0.05);
}

/* Past trip styling - greyed out */
.live-trip-row.past-trip {
  opacity: 0.6;
  filter: grayscale(30%);
}

.live-trip-row.past-trip:hover {
  opacity: 0.8;
  filter: grayscale(20%);
}

.live-trip-line {
  font-weight: bold;
  width: 80px;
}

.live-trip-departure,
.live-trip-arrival {
  width: 150px;
}

.live-trip-delay {
  width: 120px;
  font-size: 12px;
}

.delay-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: middle;
}

.delay-dot.on-time {
  background-color: var(--chart-color-on-time);
}

.delay-dot.delay-5min {
  background-color: var(--chart-color-delay-5min);
}

.delay-dot.delay-15min {
  background-color: var(--chart-color-delay-15min);
}

.delay-dot.delay-45min {
  background-color: var(--chart-color-delay-45min);
}

.delay-dot.delay-over-45min {
  background-color: var(--chart-color-delay-over-45min);
}

.delay-dot.delay-unknown {
  background-color: var(--chart-color-delay-unknown);
}

.live-direction-table {
  margin-bottom: 30px;
}

.live-direction-table .chart-legend {
  width: 100%;
}

.live-trip-header-item {
  padding: 10px 12px;
  text-align: left;
}
