/* World Rankings Styles */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body.world-rankings {
  font-family: 'Raleway', sans-serif;
  background: #f8f9fa;
  color: #626262;
  line-height: 1.6;
  margin: 0;
  padding: 0;
}

body.world-rankings.iframe-mode {
  min-height: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

body.world-rankings:not(.iframe-mode) {
  min-height: 100vh;
}

/* Mobile-specific iframe fixes */
@media (max-width: 768px) {
  body.world-rankings.iframe-mode .container {
    padding: 10px !important;
    box-sizing: border-box;
  }
  
  /* Ensure search container doesn't break iframe on mobile */
  body.world-rankings.iframe-mode .searched-athlete-container {
    min-width: auto !important;
  }
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 30px;
}

.title {
  font-family: 'Raleway', sans-serif;
  font-size: 2.5rem;
  font-weight: 700;
  color: #000000;
  text-transform: uppercase;
}

.subtitle {
  font-family: 'Raleway', sans-serif;
  font-size: 1.1rem;
  color: #000000;
  margin-top: 5px;
  text-transform: uppercase;
}

.gender-toggle {
  display: flex;
  gap: 10px;
}

.gender-btn {
  font-family: 'Josefin Sans', sans-serif;
  padding: 12px 24px;
  border: 1px solid transparent;
  background: white;
  color: #626262;
  border-radius: 0;
  text-decoration: none;
  font-weight: 700;
  text-transform: uppercase;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.gender-btn:hover {
  background: #f8f9fa;
}

.gender-btn.active {
  border: 1px solid #000000;
  background: white;
  color: #000000;
}

/* Search Styles */
.search-container {
  margin: 20px 0;
  position: relative;
  max-width: 400px;
}

.search-input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid #e9ecef;
  border-radius: 6px;
  font-family: 'Raleway', sans-serif;
  font-size: 1rem;
  background: white;
  transition: border-color 0.3s ease;
}

.search-input:focus {
  outline: none;
  border-color: #000000;
}

.search-input::placeholder {
  color: #999;
}

.search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: white;
  border: 1px solid #e9ecef;
  border-radius: 6px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  z-index: 1000;
  max-height: 300px;
  overflow-y: auto;
  display: none;
}

.search-results.show {
  display: block;
}

.search-result-item {
  padding: 12px 16px;
  border-bottom: 1px solid #f8f9fa;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: background-color 0.2s ease;
}

.search-result-item:hover {
  background: #f8f9fa;
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-flag {
  width: 20px;
  height: 15px;
  border-radius: 2px;
  flex-shrink: 0;
}

.search-result-info {
  flex: 1;
}

.search-result-name {
  font-weight: 600;
  color: #000;
  margin-bottom: 2px;
}

.search-result-rank {
  font-size: 0.9rem;
  color: #666;
}

/* Rankings Table Styles */
.rankings-table {
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  overflow: visible;
  width: 100%;
}

.table-header {
  background: #f8f9fa;
  padding: 20px;
  border-bottom: 2px solid #e9ecef;
}

.table-header-row {
  display: grid;
  grid-template-columns: 80px 200px 1fr 1fr 1fr 120px;
  gap: 20px;
  align-items: center;
  font-family: 'Raleway', sans-serif;
  font-weight: 700;
  color: #000000;
  text-transform: uppercase;
}

.table-header-row > div:first-child {
  text-align: center;
}

.table-header-row > div:nth-child(3),
.table-header-row > div:nth-child(4),
.table-header-row > div:nth-child(5) {
  text-align: center;
}

.table-header-row > div:last-child {
  text-align: center;
}

.table-body {
  height: auto;
  overflow: visible;
}

.table-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 20px;
  align-items: center;
  padding: 20px;
  border-bottom: 1px solid #e9ecef;
  transition: background 0.2s ease;
  font-family: 'Raleway', sans-serif;
  color: #626262;
  cursor: pointer;
}

/* Desktop layout for athlete header */
.athlete-header {
  display: contents;
}

/* Desktop layout for race results */
.race-results-section {
  display: contents;
}

/* Hide mobile-only elements on desktop */
.total-label {
  display: none;
}

.total-value {
  display: block;
}

/* Desktop grid override with responsive columns */
@media (min-width: 769px) {
  .table-row {
    grid-template-columns: minmax(60px, 80px) minmax(150px, 200px) 1fr 1fr 1fr minmax(100px, 120px);
  }

  .race-info {
    display: block;
  }
}

/* Smaller desktop - more compressed but still horizontal */
@media (min-width: 650px) and (max-width: 768px) {
  .table-row {
    grid-template-columns: 60px minmax(120px, 180px) 1fr 1fr 1fr 100px;
  }
}

/* Simple approach: searched athlete cards behave exactly like regular cards */

.table-row:hover {
  background: #f8f9fa;
}

.table-row.expanded {
  background: #f0f7ff;
  border-bottom: none;
}

/* Athlete Dropdown Styles */
.athlete-dropdown {
  display: none;
  background: #f9fbff;
  border-bottom: 1px solid #e9ecef;
  padding: 0;
  grid-column: 1 / -1;
}

.athlete-dropdown.show {
  display: block;
  animation: slideDown 0.3s ease-out;
}

.dropdown-content {
  padding: 20px;
}

.dropdown-header {
  font-weight: 700;
  color: #000;
  margin-bottom: 15px;
  font-size: 1.1rem;
}

.results-table {
  width: 100%;
  border-collapse: collapse;
}

.results-table th {
  background: #e3f2fd;
  padding: 10px;
  text-align: left;
  font-weight: 700;
  color: #000;
  border-bottom: 2px solid #2196f3;
}

.results-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #e9ecef;
}

.results-table tr:nth-child(even) {
  background: #f8f9fa;
}

.top-three-result {
  background: #fff3e0 !important;
}

.top-three-result td {
  background: #fff3e0;
  font-weight: 600;
}

.race-points {
  color: #e67e22;
  font-weight: 600;
}

@keyframes slideDown {
  from {
    opacity: 0;
    max-height: 0;
  }
  to {
    opacity: 1;
    max-height: 500px;
  }
}

/* Rank Badge Styles */
.rank-cell {
  text-align: center;
  font-weight: 700;
  font-size: 1.1rem;
}

.rank-badge {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
  color: white;
  font-weight: 700;
}

.rank-1 { background: #f1c40f; }
.rank-2 { background: #95a5a6; }
.rank-3 { background: #cd7f32; }
.rank-other { background: #6c757d; }

/* Athlete Cell Styles */
.athlete-cell {
  display: flex;
  align-items: center;
  gap: 12px;
}

.country-flag {
  width: 24px;
  height: 18px;
  border-radius: 2px;
  display: inline-block;
  position: relative;
  overflow: hidden;
}

.flag-icon:not(:empty) span {
  display: none;
}

.flag-icon {
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}

.athlete-name {
  font-family: 'Raleway', sans-serif;
  font-weight: 400;
  color: #626262;
}

/* Race Cell Styles */
.race-cell {
  text-align: center;
}

.race-cell::before {
  display: none;
}

.race-info {
  display: block;
}

.race-name {
  font-family: 'Raleway', sans-serif;
  font-weight: 400;
  color: #626262;
  font-size: 0.9rem;
  margin-bottom: 2px;
}

.race-position {
  font-family: 'Raleway', sans-serif;
  color: #626262;
  font-size: 0.8rem;
  margin-bottom: 2px;
}

.race-time-behind {
  font-family: 'Raleway', sans-serif;
  color: #e67e22;
  font-size: 0.8rem;
  font-weight: 500;
  margin-bottom: 2px;
}

.race-points {
  font-family: 'Raleway', sans-serif;
  color: #626262;
  font-weight: 400;
  font-size: 1rem;
}

/* Total Score Styles */
.total-score {
  text-align: center;
  font-family: 'Raleway', sans-serif;
  font-weight: 400;
  font-size: 1.2rem;
  color: #626262;
  background: #e3f2fd;
  padding: 8px 16px;
  border-radius: 20px;
}

/* Pagination Styles (legacy - no longer used) */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 20px;
  margin-top: 30px;
}

.pagination-btn {
  padding: 10px 20px;
  border: 2px solid #6c5ce7;
  background: white;
  color: #6c5ce7;
  border-radius: 6px;
  text-decoration: none;
  font-weight: 600;
  transition: all 0.3s ease;
}

.pagination-btn:hover:not(.disabled) {
  background: #6c5ce7;
  color: white;
}

.pagination-btn.disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.pagination-info {
  color: #6c757d;
  font-weight: 600;
}

/* AI Chatbot Styles */
.ai-chatbot {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 2000;
  font-family: 'Raleway', sans-serif;
}

.chatbot-toggle {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  color: white;
  font-size: 24px;
}

.chatbot-toggle:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

.chatbot-window {
  position: absolute;
  bottom: 80px;
  right: 0;
  width: 350px;
  height: 500px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  display: none;
  flex-direction: column;
  overflow: hidden;
}

.chatbot-window.show {
  display: flex;
  animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chatbot-header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chatbot-title {
  font-weight: 700;
  font-size: 16px;
}

.chatbot-close {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  font-size: 20px;
  padding: 0;
}

.chatbot-messages {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  background: #f8f9fa;
}

.chat-message {
  margin-bottom: 12px;
  display: flex;
  gap: 8px;
}

.chat-message.user {
  justify-content: flex-end;
}

.chat-message.ai {
  justify-content: flex-start;
}

.message-bubble {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.4;
}

.message-bubble.user {
  background: #667eea;
  color: white;
}

.message-bubble.ai {
  background: white;
  color: #333;
  border: 1px solid #e9ecef;
}

.message-bubble.loading {
  background: white;
  border: 1px solid #e9ecef;
  color: #666;
  font-style: italic;
}

.chatbot-input-area {
  padding: 16px;
  border-top: 1px solid #e9ecef;
  background: white;
}

.chatbot-input-container {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.chatbot-input {
  flex: 1;
  padding: 12px;
  border: 1px solid #e9ecef;
  border-radius: 20px;
  font-size: 14px;
  resize: none;
  max-height: 80px;
  min-height: 40px;
  font-family: 'Raleway', sans-serif;
}

.chatbot-input:focus {
  outline: none;
  border-color: #667eea;
}

.chatbot-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #667eea;
  border: none;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease;
}

.chatbot-send:hover:not(:disabled) {
  background: #5a67d8;
}

.chatbot-send:disabled {
  background: #ccc;
  cursor: not-allowed;
}

.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.suggestion-chip {
  background: #e9ecef;
  border: none;
  padding: 8px 12px;
  border-radius: 16px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.2s ease;
  color: #666;
}

.suggestion-chip:hover {
  background: #667eea;
  color: white;
}

/* Search Results Section */
.searched-athlete-section {
  margin-top: 30px;
  padding-top: 20px;
  border-top: 2px solid #e9ecef;
}

.search-section-title {
  font-family: 'Raleway', sans-serif;
  font-size: 1.5rem;
  font-weight: 700;
  color: #000000;
  text-align: center;
  margin-bottom: 20px;
  text-transform: uppercase;
}

.searched-athlete-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 90%;
  margin: 0 auto;
}

/* Only apply min-width on desktop */
@media (min-width: 769px) {
  .searched-athlete-container {
    min-width: 600px;
  }
}

.searched-athlete-container .table-row {
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  margin-bottom: 15px;
}

/* Searched athlete card uses same styles as regular cards */
.searched-athlete-card {
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  border: none;
}


/* Mobile Responsive Styles */
@media (max-width: 768px) {
  .container {
    padding: 15px;
  }

  .header {
    flex-direction: column;
    gap: 20px;
    text-align: center;
    margin-bottom: 20px;
  }

  .title {
    font-size: 1.5rem;
    line-height: 1.2;
  }

  .subtitle {
    font-size: 0.9rem;
  }

  .gender-toggle {
    width: 100%;
    display: flex;
    flex-direction: row;
    gap: 10px;
  }

  .gender-btn {
    flex: 1;
    padding: 10px 20px;
    font-size: 0.9rem;
  }

  /* Hide table header on mobile */
  .table-header {
    display: none;
  }

  /* Mobile card layout */
  .table-row {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 15px;
    background: white;
    margin-bottom: 15px;
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    border-bottom: none;
  }

  /* Mobile athlete header */
  .athlete-header {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
  }

  /* Mobile race results section */
  .race-results-section {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
  }

  .table-body {
    background: transparent;
  }

  .rankings-table {
    background: transparent;
    box-shadow: none;
  }

  /* Mobile race labels - remove background styling */
  .race-cell::before {
    content: attr(data-race);
    display: none;
  }

  /* Add race numbers as plain text */
  .race-cell[data-race="1"] .race-name::before {
    content: "1. ";
    font-weight: 400;
    color: #626262;
    margin-right: 4px;
  }

  .race-cell[data-race="2"] .race-name::before {
    content: "2. ";
    font-weight: 400;
    color: #626262;
    margin-right: 4px;
  }

  .race-cell[data-race="3"] .race-name::before {
    content: "3. ";
    font-weight: 400;
    color: #626262;
    margin-right: 4px;
  }


  .rank-cell {
    width: auto;
  }

  .athlete-cell {
    flex: 1;
  }

  .athlete-name {
    font-size: 1rem;
    font-weight: 400;
    color: #626262;
  }

  /* Mobile race cards layout */
  .race-cell {
    background: white;
    padding: 10px;
    border-radius: 6px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    text-align: left;
    border: none;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  }

  .race-info {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
  }

  .race-cell .race-name {
    font-weight: 400;
    color: #626262;
    margin-bottom: 2px;
    font-size: 0.75rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 180px;
  }

  .race-cell .race-position {
    display: block;
    font-size: 0.65rem;
    color: #666;
    margin-bottom: 0;
  }

  .race-cell .race-time-behind {
    display: block;
    font-size: 0.6rem;
    color: #e67e22;
    font-weight: 500;
  }

  .race-cell .race-points {
    background: #e3f2fd;
    color: #000000;
    padding: 4px 8px;
    border-radius: 12px;
    font-weight: 400;
    white-space: nowrap;
    font-size: 0.75rem;
    margin-left: 4px;
  }

  /* Total score on mobile */
  .total-score {
    width: 100%;
    text-align: center;
    font-size: 1.1rem;
    font-weight: 700;
    padding: 12px;
    background: #e3f2fd;
    color: #626262;
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    border: none;
  }

  .total-label {
    display: none;
  }

  .total-value {
    display: block;
    font-size: 1.4rem;
    color: #626262;
    font-weight: 400;
  }

  /* Search on mobile */
  .search-container {
    max-width: 100%;
    margin: 15px 0;
  }

  .search-input {
    font-size: 16px; /* Prevents zoom on iOS */
  }

  /* Dropdown on mobile */
  .athlete-dropdown {
    margin: 0 -15px;
    border-radius: 0;
    background: white;
    border: 1px solid #e9ecef;
  }

  .dropdown-content {
    padding: 15px;
  }

  .results-table {
    font-size: 0.7rem;
    width: 100%;
    overflow-x: auto;
    display: block;
    white-space: nowrap;
  }

  .results-table thead,
  .results-table tbody,
  .results-table th,
  .results-table td,
  .results-table tr {
    display: block;
  }

  .results-table thead tr {
    position: absolute;
    top: -9999px;
    left: -9999px;
  }

  .results-table tr {
    border: 1px solid #e9ecef;
    margin-bottom: 8px;
    padding: 8px;
    border-radius: 4px;
    background: #f8f9fa;
  }

  .results-table td {
    border: none !important;
    padding: 4px 0;
    position: relative;
    padding-left: 25% !important;
  }

  .results-table td:before {
    content: attr(data-label) ": ";
    position: absolute;
    left: 6px;
    width: 20%;
    padding-right: 10px;
    white-space: nowrap;
    font-weight: 600;
    color: #333;
    font-size: 0.65rem;
  }

  /* Chatbot on mobile */
  .chatbot-window {
    width: calc(100vw - 20px);
    height: 60vh;
    right: 10px;
    bottom: 70px;
  }

  .ai-chatbot {
    right: 10px;
    bottom: 10px;
  }

  .chatbot-toggle {
    width: 50px;
    height: 50px;
  }

}

/* Smaller mobile devices */
@media (max-width: 480px) {
  .title {
    font-size: 1.3rem;
  }

  .subtitle {
    font-size: 0.85rem;
  }

  .gender-btn {
    padding: 8px 16px;
    font-size: 0.85rem;
  }

  .table-row {
    padding: 12px;
  }

  .athlete-name {
    font-size: 0.95rem;
  }

  .race-cell {
    padding: 6px;
    font-size: 0.8rem;
  }

  .race-cell .race-name {
    font-size: 0.7rem;
    max-width: 150px;
  }

  .race-cell .race-position {
    font-size: 0.6rem;
  }

  .race-cell .race-time-behind {
    font-size: 0.55rem;
  }

  .race-cell .race-points {
    font-size: 0.7rem;
    padding: 3px 6px;
    background: #e3f2fd;
    color: #000000;
  }

  .total-score {
    font-size: 1rem;
  }

  /* Search section on mobile */
  .search-section-title {
    font-size: 1.2rem;
  }


}
