/* ===== CSS Variables for Light/Dark Mode ===== */
.scoreboard-scope {
  --bg-primary: #ffffff;
  --bg-secondary: #f8fafc;
  --bg-card: #ffffff;
  --bg-hover: #f1f5f9;
  --border: #e2e8f0;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --shadow: rgba(0, 0, 0, 0.1);
  --chart-grid: #e2e8f0;
  --chart-text: #64748b;
}

.scoreboard-scope[data-theme="dark"] {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-card: #1e293b;
  --bg-hover: #334155;
  --border: #334155;
  --text-primary: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #64748b;
  --accent: #60a5fa;
  --accent-hover: #3b82f6;
  --success: #34d399;
  --warning: #fbbf24;
  --danger: #f87171;
  --shadow: rgba(0, 0, 0, 0.3);
  --chart-grid: #334155;
  --chart-text: #94a3b8;
}

/* ===== Base Reset (scoped to scoreboard only) ===== */
.scoreboard-scope, .scoreboard-scope * , .scoreboard-scope *::before, .scoreboard-scope *::after {
  box-sizing: border-box;
}

.scoreboard-scope * {
  margin: 0;
  padding: 0;
}

.scoreboard-scope {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.scoreboard-scope {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  transition: background-color 0.3s ease, color 0.3s ease;
  min-height: 100vh;
}

/* ===== Layout ===== */
.scoreboard-scope .container {
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 24px;
}

@media (max-width: 768px) {
  .scoreboard-scope .container {
    padding: 0 16px;
  }
}

/* ===== Header ===== */
.scoreboard-scope header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 32px 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 32px;
  gap: 24px;
  flex-wrap: wrap;
}

.scoreboard-scope header h1 {
  font-size: 32px;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0;
}

.scoreboard-scope header h1 svg {
  color: var(--accent);
}

.scoreboard-scope .subtitle {
  font-size: 15px;
  color: var(--text-secondary);
  margin-top: 6px;
}

.scoreboard-scope .header-content {
  flex: 1;
  min-width: 200px;
}

.scoreboard-scope .header-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

@media (max-width: 640px) {
  .scoreboard-scope header h1 {
    font-size: 24px;
  }
  
  .scoreboard-scope .subtitle {
    font-size: 14px;
  }
}

/* ===== Theme Toggle Button ===== */
.scoreboard-scope .theme-toggle {
  position: relative;
  width: 64px;
  height: 32px;
  background: var(--border);
  border: none;
  border-radius: 16px;
  cursor: pointer;
  transition: background-color 0.3s ease;
  padding: 0;
  overflow: hidden;
}

.scoreboard-scope .theme-toggle:hover {
  background: var(--text-muted);
}

.scoreboard-scope .theme-toggle:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.scoreboard-scope .theme-toggle-slider {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 26px;
  height: 26px;
  background: var(--bg-card);
  border-radius: 50%;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  box-shadow: 0 2px 4px var(--shadow);
}

.scoreboard-scope[data-theme="dark"] .theme-toggle-slider {
  transform: translateX(32px);
}

/* ===== Cards ===== */
.scoreboard-scope .card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  margin-bottom: 32px;
  box-shadow: 0 1px 3px var(--shadow);
  transition: box-shadow 0.3s ease;
}

.scoreboard-scope .card:hover {
  box-shadow: 0 4px 12px var(--shadow);
}

.scoreboard-scope .card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}

.scoreboard-scope .card-header h3 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

@media (max-width: 768px) {
  .scoreboard-scope .card {
    padding: 20px;
    border-radius: 12px;
  }
}

/* ===== Table ===== */
.scoreboard-scope .table-wrapper {
  overflow-x: auto;
  margin: -8px;
  border-radius: 12px;
}

/* Support either wrapper class */
.scoreboard-scope .table-container {
  overflow-x: auto;
  margin: -8px;
  border-radius: 12px;
}

.scoreboard-scope .table {
  width: 100%;
  border-collapse: collapse;
  min-width: 900px;
}

.scoreboard-scope .table thead {
  background: var(--bg-secondary);
  position: sticky;
  top: 0;
  z-index: 10;
}

.scoreboard-scope .table th {
  padding: 16px 20px;
  text-align: center;
  font-weight: 600;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

.scoreboard-scope .table td {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 14px;
  text-align: center;
}

/* Tighter padding for rank columns */
.scoreboard-scope .table td[data-col="state-rank"],
.scoreboard-scope .table td[data-col="general-rank"] {
  padding: 10px 12px;
}

/* Center align numeric/short columns to match provided design */
.scoreboard-scope .table td[data-col="team-number"],
.scoreboard-scope .table td[data-col="img-total"],
.scoreboard-scope .table td[data-col="play-time"],
.scoreboard-scope .table td[data-col="score-time"],
.scoreboard-scope .table td[data-col="state-rank"],
.scoreboard-scope .table td[data-col="general-rank"] {
  text-align: center;
}

.scoreboard-scope .table td[data-col^="img-"] {
  text-align: center;
}

.scoreboard-scope .table tbody tr {
  transition: background-color 0.2s ease;
}

.scoreboard-scope .table tbody tr:hover {
  background: var(--bg-hover);
}

.scoreboard-scope .table tbody tr:last-child td {
  border-bottom: none;
}

/* Sortable headers */
.scoreboard-scope .th-sortable {
  cursor: pointer;
  user-select: none;
  position: relative;
  padding-right: 20px !important;
  transition: color 0.2s ease;
}

.scoreboard-scope .th-sortable:hover {
  color: var(--accent);
}

.scoreboard-scope .th-sortable .arrow {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  opacity: 0.4;
  transition: all 0.2s ease;
  font-size: 10px;
}

.scoreboard-scope .th-sortable:hover .arrow {
  opacity: 0.8;
}

.scoreboard-scope .th-sortable.asc .arrow {
  transform: translateY(-50%) rotate(180deg);
  opacity: 1;
  color: var(--accent);
}

.scoreboard-scope .th-sortable.desc .arrow {
  opacity: 1;
  color: var(--accent);
}

/* Row highlighting based on percentile */
.scoreboard-scope .row-blue {
  background: rgba(59, 130, 246, 0.15) !important;
  border-left: 4px solid #3b82f6;
}

.scoreboard-scope .row-blue:hover {
  background: rgba(59, 130, 246, 0.22) !important;
}

.scoreboard-scope[data-theme="dark"] .row-blue {
  background: rgba(96, 165, 250, 0.18) !important;
  border-left: 4px solid #60a5fa;
}

.scoreboard-scope[data-theme="dark"] .row-blue:hover {
  background: rgba(96, 165, 250, 0.25) !important;
}

.scoreboard-scope .row-gold {
  background: rgba(245, 158, 11, 0.15) !important;
  border-left: 4px solid #f59e0b;
}

.scoreboard-scope .row-gold:hover {
  background: rgba(245, 158, 11, 0.22) !important;
}

.scoreboard-scope[data-theme="dark"] .row-gold {
  background: rgba(251, 191, 36, 0.18) !important;
  border-left: 4px solid #fbbf24;
}

.scoreboard-scope[data-theme="dark"] .row-gold:hover {
  background: rgba(251, 191, 36, 0.25) !important;
}

.scoreboard-scope .row-gray {
  opacity: 0.65;
  border-left: 4px solid var(--border);
}

.scoreboard-scope .row-gray:hover {
  opacity: 0.8;
}

/* Negative score styling for Cisco column */
.scoreboard-scope .score-negative { color: #e25555; }

@media (max-width: 1024px) {
  .scoreboard-scope .table {
    min-width: 800px;
    font-size: 13px;
  }
  
  .scoreboard-scope .table th,
  .scoreboard-scope .table td {
    padding: 12px 16px;
  }
}

/* Fit table to desktop viewport to match provided design */
@media (min-width: 1025px) {
  .scoreboard-scope .table {
    table-layout: fixed;
    font-size: 14px;
  }
  .scoreboard-scope .table th,
  .scoreboard-scope .table td {
    padding: 10px 12px;
  }
  .scoreboard-scope td[data-col="team"] {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 320px;
  }
  /* Add extra separation between Packet Tracer and Mint */
  .scoreboard-scope td[data-col="packet-tracer"] { padding-right: 20px; }
  .scoreboard-scope td[data-col="mint"] { padding-left: 20px; }
  /* Ensure clear separation between Packet Tracer and Total */
  .scoreboard-scope th[data-col="packet-tracer"] { padding-right: 20px; }
  .scoreboard-scope th[data-col="img-total"], .scoreboard-scope td[data-col="img-total"] {
    padding-left: 20px;
  }
}

/* ===== Links ===== */
.scoreboard-scope a {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.2s ease;
  font-weight: 500;
}

.scoreboard-scope a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

/* ===== Badges & Pills ===== */
.scoreboard-scope .badge {
  display: inline-block;
  padding: 4px 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
}

.scoreboard-scope .pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  gap: 4px;
}

.scoreboard-scope .pill-blue {
  background: rgba(59, 130, 246, 0.1);
  color: #3b82f6;
}

.scoreboard-scope[data-theme="dark"] .pill-blue {
  background: rgba(96, 165, 250, 0.15);
  color: #60a5fa;
}

.scoreboard-scope .pill-gold {
  background: rgba(245, 158, 11, 0.1);
  color: #f59e0b;
}

.scoreboard-scope[data-theme="dark"] .pill-gold {
  background: rgba(251, 191, 36, 0.15);
  color: #fbbf24;
}

.scoreboard-scope .pill-gray {
  background: rgba(100, 116, 139, 0.1);
  color: #64748b;
}

.scoreboard-scope .pill-green {
  background: rgba(16, 185, 129, 0.1);
  color: #10b981;
}

.scoreboard-scope[data-theme="dark"] .pill-green {
  background: rgba(52, 211, 153, 0.15);
  color: #34d399;
}

/* ===== Rank Badges ===== */
.scoreboard-scope .rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  padding: 2px 8px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
}

.scoreboard-scope .rank-top {
  background: rgba(16, 185, 129, 0.1);
  border-color: var(--success);
  color: var(--success);
}

/* ===== Buttons ===== */
.scoreboard-scope .btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 500;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
  white-space: nowrap;
}

.scoreboard-scope .btn:hover {
  transform: translateY(-1px);
  text-decoration: none;
}

.scoreboard-scope .btn-primary {
  background: var(--accent);
  color: white;
}

.scoreboard-scope .btn-primary:hover {
  background: var(--accent-hover);
}

.scoreboard-scope .btn-secondary {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.scoreboard-scope .btn-secondary:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.scoreboard-scope .btn-sm {
  padding: 6px 14px;
  font-size: 13px;
}

/* ===== Utility Classes ===== */
.scoreboard-scope .small {
  font-size: 13px;
  color: var(--text-secondary);
}

.scoreboard-scope .muted {
  color: var(--text-muted);
}

.scoreboard-scope .nowrap {
  white-space: nowrap;
}

.scoreboard-scope .footer {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.8;
}

.scoreboard-scope .nav-links {
  display: flex;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
}

.scoreboard-scope .back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 12px;
  transition: color 0.2s ease;
}

.scoreboard-scope .back-link:hover {
  color: var(--accent);
}

.scoreboard-scope .rankpct {
  display: flex;
  gap: 6px;
  align-items: center;
}

.scoreboard-scope .pct {
  opacity: 1;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--bg-secondary);
  padding: 2px 6px;
  border-radius: 6px;
  border: 1px solid var(--border);
}

/* Time highlighting */
.scoreboard-scope .time-green {
  color: var(--success);
  font-weight: 600;
}
.scoreboard-scope .time-blue {
  color: #38bdf8;
  font-weight: 600;
}
.scoreboard-scope .time-yellow {
  color: #fbbf24;
  font-weight: 600;
}
.scoreboard-scope .time-orange {
  color: #fb923c;
  font-weight: 600;
}
.scoreboard-scope .time-red {
  color: #f87171;
  font-weight: 600;
}

/* ===== Score Highlighting ===== */
.scoreboard-scope .score-positive {
  color: var(--success);
  font-weight: 600;
}

.scoreboard-scope .score-zero {
  color: var(--text-muted);
}

/* ===== Loading States ===== */
.scoreboard-scope .loading {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 48px;
  color: var(--text-muted);
}

.scoreboard-scope .status-indicator {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-secondary);
}

.scoreboard-scope .status-dot {
  width: 8px;
  height: 8px;
  background: var(--success);
  border-radius: 50%;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

/* ===== Chart Container ===== */
.scoreboard-scope .chart-container {
  position: relative;
  width: 100%;
  height: 400px;
  margin-top: 20px;
}

@media (max-width: 768px) {
  .scoreboard-scope .chart-container {
    height: 300px;
  }
}

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

.scoreboard-scope .fade-in {
  animation: fadeIn 0.4s ease;
}

/* ===== Responsive Utilities ===== */
@media (max-width: 768px) {
  .scoreboard-scope .hide-mobile {
    display: none !important;
  }
}

@media (min-width: 769px) {
  .scoreboard-scope .show-mobile {
    display: none !important;
  }
}

/* ===== Icon Styles ===== */
.scoreboard-scope .icon {
  width: 20px;
  height: 20px;
  display: inline-block;
}

/* ===== Scrollbar Styling ===== */
.scoreboard-scope ::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

.scoreboard-scope ::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

.scoreboard-scope ::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 5px;
}

.scoreboard-scope ::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ===== Focus Styles ===== */
.scoreboard-scope *:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}


