/* ============================================================
   RepoGenesis Leaderboard - Main Stylesheet
   Inspired by SWE-bench leaderboard design
   ============================================================ */

/* ---------- CSS Variables (Dark Theme Default) ---------- */
:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-sidebar: #0d1117;
  --bg-card: #161b22;
  --bg-hover: #1c2128;
  --bg-table-stripe: #1c212833;
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #484f58;
  --accent-blue: #58a6ff;
  --accent-green: #3fb950;
  --accent-orange: #d29922;
  --accent-red: #f85149;
  --accent-purple: #bc8cff;
  --border-color: #30363d;
  --border-subtle: #21262d;
  --sidebar-width: 220px;
  --header-height: 56px;
  --font-mono: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
  --submit-bg: #1f3a5f;
  --submit-hover: #264a78;
}

/* Light theme overrides */
:root.light-mode {
  --bg-primary: #ffffff;
  --bg-secondary: #f6f8fa;
  --bg-sidebar: #f6f8fa;
  --bg-card: #ffffff;
  --bg-hover: #f3f4f6;
  --bg-table-stripe: #f6f8fa55;
  --text-primary: #1f2328;
  --text-secondary: #656d76;
  --text-muted: #8b949e;
  --border-color: #d0d7de;
  --border-subtle: #e1e4e8;
  --accent-blue: #0969da;
  --accent-green: #1a7f37;
  --accent-orange: #9a6700;
  --accent-red: #cf222e;
  --accent-purple: #8250df;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
  --submit-bg: #dbeafe;
  --submit-hover: #bfdbfe;
}

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

html {
  font-size: 14px;
  scroll-behavior: smooth;
}

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

a {
  color: var(--accent-blue);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* ---------- Sidebar ---------- */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-primary);
  font-size: 16px;
  font-weight: 700;
  text-decoration: none;
}

.sidebar-logo:hover {
  text-decoration: none;
  color: var(--text-primary);
}

.sidebar-logo-icon {
  width: 28px;
  height: 28px;
  border-radius: 6px;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}

.sidebar-nav ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.sidebar-nav li {
  margin: 0;
}

.nav-section-title {
  padding: 16px 20px 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 20px;
  color: var(--text-primary);
  font-size: 14px;
  transition: background-color 0.15s ease;
  border-left: 3px solid transparent;
}

.nav-link:hover {
  background-color: var(--bg-hover);
  text-decoration: none;
}

.nav-link.active {
  color: var(--accent-blue);
  border-left-color: var(--accent-blue);
  background-color: var(--bg-hover);
}

.nav-link .fa-external-link-alt {
  font-size: 10px;
  opacity: 0.6;
}

/* Submit button in sidebar (special styling per Image 2) */
.nav-link-submit {
  display: block;
  margin: 4px 12px;
  padding: 10px 16px;
  background-color: var(--submit-bg);
  color: var(--accent-blue);
  font-size: 14px;
  font-weight: 600;
  border-radius: 8px;
  transition: background-color 0.15s ease;
  text-decoration: none;
}

.nav-link-submit:hover {
  background-color: var(--submit-hover);
  text-decoration: none;
}

.nav-link-submit.active {
  background-color: var(--submit-hover);
  color: var(--accent-blue);
}

/* Sidebar footer */
.sidebar-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.sidebar-footer a {
  color: var(--text-secondary);
  font-size: 16px;
  transition: color 0.15s ease;
}

.sidebar-footer a:hover {
  color: var(--text-primary);
  text-decoration: none;
}

.theme-toggle {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 16px;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: color 0.15s ease;
}

.theme-toggle:hover {
  color: var(--text-primary);
}

/* ---------- Main Content ---------- */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Page header */
.page-header {
  background: linear-gradient(135deg, #1a1f36 0%, #0d1117 100%);
  padding: 32px 40px;
  border-bottom: 1px solid var(--border-color);
}

.light-mode .page-header {
  background: linear-gradient(135deg, #e8f0fe 0%, #f6f8fa 100%);
}

.page-header h1 {
  font-size: 24px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 12px;
}

.page-header .subtitle {
  color: var(--text-secondary);
  font-size: 14px;
  margin-top: 4px;
}

.header-logo-small {
  width: 32px;
  height: 32px;
  border-radius: 6px;
}

/* Container */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 40px;
  width: 100%;
}

/* ---------- Announcement Banner ---------- */
.announcement-container {
  background: linear-gradient(135deg, #1a3a5c 0%, #162447 100%);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 16px 24px;
  margin-bottom: 24px;
  text-align: center;
}

.light-mode .announcement-container {
  background: linear-gradient(135deg, #dbeafe 0%, #eff6ff 100%);
}

.announcement-container p {
  font-size: 14px;
  color: var(--text-primary);
  margin: 0;
}

.announcement-container a {
  color: var(--accent-blue);
}

/* ---------- Tabs ---------- */
.leaderboard-tabs {
  margin-bottom: 16px;
}

.tab-list {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border-color);
}

.tab-button {
  padding: 10px 20px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  margin-bottom: -2px;
  white-space: nowrap;
}

.tab-button:hover {
  color: var(--text-primary);
}

.tab-button.active {
  color: var(--accent-blue);
  border-bottom-color: var(--accent-blue);
}

/* Tab description */
.tab-description {
  margin: 16px 0;
  font-size: 14px;
  color: var(--text-secondary);
}

.tab-description em {
  font-style: italic;
  color: var(--text-primary);
  font-weight: 600;
}

/* ---------- Filter Controls ---------- */
.filter-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  padding-top: 12px;
  border-top: 1px solid var(--border-subtle);
}

.filter-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.filter-select {
  background-color: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  appearance: auto;
}

.filter-checkbox {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
}

.filter-checkbox input {
  cursor: pointer;
}

/* ---------- Leaderboard Table ---------- */
.leaderboard-table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background-color: var(--bg-card);
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.leaderboard-table thead th {
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: color 0.15s ease;
}

.leaderboard-table thead th:hover {
  color: var(--text-primary);
}

.leaderboard-table thead th.sorted-asc::after {
  content: ' \25B2';
  font-size: 10px;
}

.leaderboard-table thead th.sorted-desc::after {
  content: ' \25BC';
  font-size: 10px;
}

.leaderboard-table tbody tr {
  border-bottom: 1px solid var(--border-subtle);
  transition: background-color 0.1s ease;
}

.leaderboard-table tbody tr:nth-child(even) {
  background-color: var(--bg-table-stripe);
}

.leaderboard-table tbody tr:hover {
  background-color: var(--bg-hover);
}

.leaderboard-table td {
  padding: 10px 16px;
  vertical-align: middle;
  white-space: nowrap;
}

/* Rank column */
.rank-cell {
  font-weight: 700;
  color: var(--text-muted);
  width: 40px;
  text-align: center;
}

/* Model name */
.model-cell {
  font-weight: 500;
  font-family: var(--font-mono);
  font-size: 13px;
}

/* Category badge */
.category-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.badge-agent {
  background-color: #1a3a2a;
  color: var(--accent-green);
  border: 1px solid #2a5a3a;
}

.badge-ide {
  background-color: #1a2a4a;
  color: var(--accent-blue);
  border: 1px solid #2a4a6a;
}

.badge-cli {
  background-color: #2a1a3a;
  color: var(--accent-purple);
  border: 1px solid #4a2a5a;
}

.light-mode .badge-agent {
  background-color: #dcfce7;
  color: #166534;
  border: 1px solid #bbf7d0;
}

.light-mode .badge-ide {
  background-color: #dbeafe;
  color: #1e40af;
  border: 1px solid #bfdbfe;
}

.light-mode .badge-cli {
  background-color: #f3e8ff;
  color: #6b21a8;
  border: 1px solid #e9d5ff;
}

/* Language badge */
.lang-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
}

.lang-python {
  background-color: #1a2a3a;
  color: #58a6ff;
}

.lang-java {
  background-color: #2a1a1a;
  color: #f97316;
}

.light-mode .lang-python {
  background-color: #dbeafe;
  color: #1d4ed8;
}

.light-mode .lang-java {
  background-color: #fff7ed;
  color: #c2410c;
}

/* Metric values */
.metric-value {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--accent-blue);
}

.metric-value.zero {
  color: var(--text-muted);
}

.metric-na {
  color: var(--text-muted);
  font-style: italic;
}

/* Link icon */
.link-icon {
  color: var(--text-secondary);
  font-size: 12px;
  opacity: 0.7;
  transition: opacity 0.15s ease;
}

.link-icon:hover {
  opacity: 1;
  color: var(--accent-blue);
}

/* Org icon */
.org-icon {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  display: inline-block;
  vertical-align: middle;
  object-fit: contain;
}

.org-cell {
  text-align: center;
}

/* ---------- Submit Page ---------- */
.submit-header {
  margin-bottom: 8px;
}

.submit-header h1 {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent-blue);
}

.submit-header p {
  color: var(--text-secondary);
  font-size: 14px;
  margin-top: 4px;
}

.info-banner {
  background: linear-gradient(135deg, #1a3a5c 0%, #162447 100%);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 16px 24px;
  margin: 24px 0;
  text-align: center;
  font-size: 14px;
}

.light-mode .info-banner {
  background: linear-gradient(135deg, #dbeafe 0%, #eff6ff 100%);
}

.info-banner a {
  color: var(--accent-blue);
  font-weight: 600;
}

.submit-section {
  margin: 32px 0;
}

.submit-section h2 {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 12px;
  padding-bottom: 8px;
}

.submit-section p {
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.7;
  margin-bottom: 8px;
}

.submit-section a {
  color: var(--accent-blue);
}

.submit-divider {
  border: none;
  border-top: 1px solid var(--border-color);
  margin: 32px 0;
}

/* ---------- Footer ---------- */
.page-footer {
  margin-top: auto;
  padding: 20px 40px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--text-muted);
}

.page-footer a {
  color: var(--text-secondary);
  margin-left: 16px;
}

.page-footer a:hover {
  color: var(--text-primary);
}

/* ---------- Mobile Responsive ---------- */
.mobile-header {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background-color: var(--bg-sidebar);
  border-bottom: 1px solid var(--border-color);
  padding: 0 16px;
  align-items: center;
  justify-content: space-between;
  z-index: 101;
}

.mobile-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-primary);
  font-weight: 700;
  font-size: 16px;
}

.mobile-logo:hover {
  text-decoration: none;
  color: var(--text-primary);
}

.sidebar-opener {
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 20px;
  cursor: pointer;
  padding: 8px;
}

.sidebar .mobile-nav-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
}

@media (max-width: 768px) {
  .mobile-header {
    display: flex;
  }

  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay.open {
    display: block;
  }

  .sidebar .mobile-nav-toggle {
    display: block;
  }

  .sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .main-content {
    margin-left: 0;
    margin-top: var(--header-height);
  }

  .container {
    padding: 16px;
  }

  .page-header {
    padding: 20px 16px;
  }

  .tab-list {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .page-footer {
    flex-direction: column;
    gap: 8px;
    padding: 16px;
  }
}

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

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

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

/* ---------- BibTeX Citation Modal ---------- */
.bibtex-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.bibtex-modal-overlay.open {
  display: flex;
}

.bibtex-modal {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  width: min(560px, 90vw);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.bibtex-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border-color);
}

.bibtex-modal-header h3 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}

.bibtex-modal-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
  transition: color 0.15s ease;
}

.bibtex-modal-close:hover {
  color: var(--text-primary);
}

.bibtex-modal-body {
  padding: 16px 20px;
  overflow-y: auto;
}

.bibtex-textarea {
  width: 100%;
  min-height: 200px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.6;
  padding: 12px;
  resize: vertical;
  outline: none;
}

.bibtex-modal-footer {
  padding: 10px 20px 16px;
  font-size: 12px;
  color: var(--text-secondary);
}

.bibtex-modal-footer a {
  color: var(--accent-blue);
}

/* ---------- Utility ---------- */
.text-center { text-align: center; }
.text-right { text-align: right; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
