/* MotoRace — MotoGP Inspired & Theme-Aware Stylesheet */

/* RESET & BASE VARIABLES */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root[data-theme="light"] {
  --bg: #f6f6f9;
  --bg-body: #f6f6f9;
  --surface: #ffffff;
  --surface2: #f0f0f5;
  --border: #e1e1e6;
  --primary: #e10600; /* MotoGP Red */
  --primary-hover: #b80500;
  --success: #10b981;
  --danger: #ef4444;
  --warn: #f59e0b;
  --text: #111116;
  --text-secondary: #575768;
  --muted: #8f8f9e;
  --text-on-primary: #ffffff;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.04);
}

:root[data-theme="dark"] {
  --bg: #0b0b0f;
  --bg-body: #0b0b0f;
  --surface: #12121a;
  --surface2: #1c1c27;
  --border: #282835;
  --primary: #ff453a; /* Soft High-Contrast Red */
  --primary-hover: #ff6b64;
  --success: #10b981;
  --danger: #ef4444;
  --warn: #f59e0b;
  --text: #f5f5f7;
  --text-secondary: #9c9ca9;
  --muted: #626270;
  --text-on-primary: #ffffff;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
}

/* FALLBACK/DEFAULT THEME (DARK) */
:root {
  --bg: #0b0b0f;
  --bg-body: #0b0b0f;
  --surface: #12121a;
  --surface2: #1c1c27;
  --border: #282835;
  --primary: #ff453a;
  --primary-hover: #ff6b64;
  --success: #10b981;
  --danger: #ef4444;
  --warn: #f59e0b;
  --text: #f5f5f7;
  --text-secondary: #9c9ca9;
  --muted: #626270;
  --text-on-primary: #ffffff;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
  --radius: 8px;
  --font: 'Inter', system-ui, -apple-system, sans-serif;
}

/* GLOBAL SCROLLBAR STYLES */
html {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* Chrome, Edge, Safari */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background-color: var(--border);
  border-radius: 20px;
}
::-webkit-scrollbar-thumb:hover {
  background-color: var(--text-secondary);
}

body {
  font-family: var(--font);
  background-color: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-top: 64px;
  font-size: 0.95rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.3s, color 0.3s;
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: color 0.2s, opacity 0.2s;
}
a:hover {
  color: var(--primary-hover);
  opacity: 0.9;
}

.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px;
}

/* UTILITIES */
.text-center { text-align: center; }
.text-muted { color: var(--text-secondary); }
.mb-1 { margin-bottom: 0.75rem; }
.mb-2 { margin-bottom: 1.5rem; }
.mt-1 { margin-top: 0.75rem; }
.mt-2 { margin-top: 1.5rem; }
.mobile-only { display: none !important; }
.desktop-only { display: inline-block !important; }
.flex-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

/* NAVIGATION */
.top-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: 64px;
  transition: background-color 0.3s, border-color 0.3s;
}

.nav-brand {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.03em;
  display: flex;
  align-items: center;
  gap: 8px;
  text-transform: uppercase;
}
.nav-brand span {
  color: var(--primary);
}

.nav-links {
  display: flex;
  gap: 8px;
  align-items: center;
}
.nav-links a, .nav-links span.nav-user {
  padding: 6px 12px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 0.85rem;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
}
.nav-links a:hover {
  background: var(--surface2);
  color: var(--text);
}
.nav-links a.active {
  color: var(--primary);
  background: rgba(225, 6, 0, 0.08);
}
.nav-user {
  font-weight: 500;
  color: var(--muted) !important;
}

/* FLASH MESSAGES */
.flash {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 12px;
  font-size: 0.88rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: slideDown 0.2s ease-out;
  border: 1px solid transparent;
}
.flash-success {
  background: rgba(16, 185, 129, 0.1);
  color: #10b981;
  border-color: rgba(16, 185, 129, 0.2);
}
.flash-error, .flash-danger {
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
  border-color: rgba(239, 68, 68, 0.2);
}
.flash-warning {
  background: rgba(245, 158, 11, 0.1);
  color: #f59e0b;
  border-color: rgba(245, 158, 11, 0.2);
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* PAGE HEADER */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 1.5rem;
  border-bottom: 2px solid var(--border);
  padding-bottom: 10px;
}
.page-header h1 {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 8px;
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* CARDS */
.card, .form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  animation: fadeUp 0.3s ease;
  transition: background-color 0.3s, border-color 0.3s, box-shadow 0.3s;
}
.card h2, .form-card h2 {
  margin-bottom: 12px;
  font-size: 1.15rem;
  font-weight: 700;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card h3, .form-card h3 {
  margin-bottom: 8px;
  color: var(--primary);
  font-size: 0.95rem;
  font-weight: 700;
  text-transform: uppercase;
}

/* HERO SECTION */
.home-hero {
  text-align: center;
  padding: 2.5rem 1rem;
  background: linear-gradient(180deg, var(--surface) 0%, rgba(18, 18, 26, 0) 100%);
  border-radius: var(--radius);
  margin-bottom: 2rem;
  border: 1px solid var(--border);
}
.home-hero h1 {
  font-size: 2rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: -0.03em;
  margin-bottom: 0.5rem;
}
.home-hero .subtitle {
  font-size: 1rem;
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
}

/* STATS BAR */
.stats-row {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 24px;
  text-align: center;
  min-width: 140px;
  box-shadow: var(--shadow);
}
.stat-card .num {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--primary);
}
.stat-card .label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  color: var(--muted);
}

/* GRIDS */
.home-grid, .race-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}
@media(min-width: 768px) {
  .home-grid, .race-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
@media(min-width: 1024px) {
  .home-grid, .race-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.home-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  transition: transform 0.2s, border-color 0.2s;
  cursor: pointer;
}
.home-card:hover {
  transform: translateY(-4px);
  border-color: var(--primary);
}

/* BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s, background-color 0.2s, color 0.2s, border-color 0.2s, box-shadow 0.2s;
  text-decoration: none;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.btn:active {
  transform: scale(0.97);
}
.btn-primary {
  background: var(--primary);
  color: var(--text-on-primary);
}
.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 4px 12px rgba(225, 6, 0, 0.25);
}
.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover {
  background: var(--border);
}
.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover {
  background: #dc2626;
}
.btn-success {
  background: var(--success);
  color: #fff;
}
.btn-success:hover {
  background: #059669;
}
.btn-sm {
  padding: 6px 12px;
  font-size: 0.78rem;
}
.btn-lg {
  padding: 10px 20px;
  font-size: 0.9rem;
}
.btn-block {
  display: flex;
  width: 100%;
}
.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* FORM STYLES */
.form-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.form-group {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 200px;
  margin-bottom: 12px;
}
.form-group label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
input, select, textarea {
  background-color: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-family: var(--font);
  transition: border-color 0.2s, box-shadow 0.2s;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  outline: none;
  box-shadow: 0 0 0 3px rgba(225, 6, 0, 0.15);
}
input::placeholder, textarea::placeholder {
  color: var(--muted);
}
input:disabled, select:disabled, textarea:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* BADGES */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border: 1px solid transparent;
}
.badge-upcoming {
  background: var(--surface2);
  color: var(--text-secondary);
  border-color: var(--border);
}
.badge-active {
  background: rgba(225, 6, 0, 0.1);
  color: var(--primary);
  border-color: rgba(225, 6, 0, 0.2);
}
.badge-finished {
  background: rgba(16, 185, 129, 0.1);
  color: var(--success);
  border-color: rgba(16, 185, 129, 0.2);
}
.badge-registered {
  background: var(--surface2);
  color: var(--text);
  border-color: var(--border);
}
.badge-dnf {
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger);
  border-color: rgba(239, 68, 68, 0.2);
}
.badge-dns {
  background: var(--surface2);
  color: var(--muted);
  border-color: var(--border);
}

/* TABLES */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  margin-bottom: 1.5rem;
}
table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}
th, td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
th {
  background: var(--surface2);
  color: var(--text-secondary);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
}
tr {
  transition: background-color 0.2s;
}
tr:hover {
  background-color: var(--surface2);
}
tr:last-child td {
  border-bottom: none;
}

/* STANDINGS POSITION STYLING */
.standings-pos {
  font-size: 1.1rem;
  font-weight: 800;
  width: 40px;
  text-align: center;
}
.pos-1 {
  color: #ffd700; /* Gold */
  text-shadow: 0 0 4px rgba(255, 215, 0, 0.2);
}
.pos-2 {
  color: #c0c0c0; /* Silver */
}
.pos-3 {
  color: #cd7f32; /* Bronze */
}

/* TAB NAVIGATIONS */
.tab-nav {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}
.tab-btn {
  padding: 8px 16px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  border-bottom: 3px solid transparent;
  transition: color 0.2s, border-color 0.2s;
  white-space: nowrap;
}
.tab-btn:hover {
  color: var(--text);
}
.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tab-panel {
  display: none;
}
.tab-panel.active {
  display: block;
  animation: fadeUp 0.25s ease-out;
}

/* EVENT CARDS WITH BORDER ACCENTS */
.event-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  background: var(--surface);
  margin-bottom: 16px;
  transition: transform 0.2s, border-color 0.2s;
  box-shadow: var(--shadow);
}
.event-card:hover {
  border-color: var(--primary);
}
.event-card-main {
  border-left: 4px solid var(--primary);
}

/* TRACKER GRID & RIDER CARDS */
.tracker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 1.5rem;
}

.racer-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
  position: relative;
  transition: border-color 0.2s, opacity 0.2s, transform 0.1s;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 190px;
}
.racer-card:hover {
  border-color: var(--text-secondary);
}
.racer-card.is-finished {
  border-color: var(--success);
  background: rgba(16, 185, 129, 0.03);
}

.racer-bib {
  font-size: 2.2rem;
  font-weight: 900;
  color: var(--primary);
  line-height: 1;
  font-style: italic;
  margin-bottom: 4px;
}
.racer-name {
  font-size: 0.85rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}
.racer-class {
  font-size: 0.7rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  font-weight: 600;
  margin-bottom: 6px;
}
.racer-status {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  margin-top: 4px;
}

.racer-buttons {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}
.lap-btn {
  padding: 12px 6px;
  border: none;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 800;
  cursor: pointer;
  text-transform: uppercase;
}
.lap-btn-main {
  background: var(--primary);
  color: var(--text-on-primary);
  box-shadow: 0 4px 10px rgba(225, 6, 0, 0.2);
}
.lap-btn-main:active {
  transform: scale(0.95);
}
.lap-btn-undo {
  background: var(--surface2);
  color: var(--text-secondary);
  font-size: 0.72rem;
  padding: 6px;
  border: 1px solid var(--border);
  font-weight: 600;
}

/* THEME TOGGLE BUTTON IN NAVBAR */
#theme-toggle {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s, color 0.2s;
}
#theme-toggle:hover {
  background-color: var(--surface2);
  color: var(--text);
}

:root[data-theme="light"] .theme-icon-sun { display: none; }
:root[data-theme="light"] .theme-icon-moon { display: block; }
:root[data-theme="dark"] .theme-icon-sun { display: block; }
:root[data-theme="dark"] .theme-icon-moon { display: none; }

/* PROFILE DROPDOWN */
.profile-dropdown-content {
  background-color: var(--surface) !important;
  border-color: var(--border) !important;
  box-shadow: var(--shadow) !important;
}
.profile-dropdown-content a:hover {
  background-color: var(--surface2) !important;
}

/* RESPONSIVE & MOBILE FIRST RULES */
@media(max-width: 600px) {
  body {
    padding-top: 56px;
  }
  .top-nav {
    flex-direction: row;
    height: 56px;
    padding: 8px 12px;
    align-items: center;
    justify-content: space-between;
  }
  .nav-brand {
    font-size: 0.95rem;
  }
  .nav-links {
    gap: 6px;
  }
  .nav-links a, .nav-links .profile-dropdown .btn, #theme-toggle {
    padding: 6px;
    font-size: 0.75rem;
  }
  .nav-links .btn-text {
    display: none !important; /* Sembunyikan teks tombol di hp */
  }
  .nav-user {
    display: none !important; /* Sembunyikan username di hp agar muat */
  }
  .mobile-only {
    display: inline-block !important;
  }
  .desktop-only {
    display: none !important;
  }
  
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  .page-header h1 {
    font-size: 1.25rem;
  }
  
  /* Transformasi Tabel menjadi Kartu di HP */
  .responsive-table table, 
  .responsive-table thead, 
  .responsive-table tbody, 
  .responsive-table tr, 
  .responsive-table td {
    display: block;
    width: 100%;
  }
  .responsive-table thead {
    display: none;
  }
  .responsive-table tr {
    border-bottom: 2px solid var(--border);
    padding: 16px;
    background: var(--surface);
    margin-bottom: 12px;
    border-radius: var(--radius);
  }
  .responsive-table tr:last-child {
    margin-bottom: 0;
  }
  .responsive-table td {
    border-bottom: none;
    padding: 6px 0;
    font-size: 0.85rem;
  }
  
  .responsive-table td.cell-index {
    display: none !important;
  }
  
  .responsive-table td.cell-title {
    font-size: 1.02rem;
    font-weight: 800;
    border-bottom: 1px solid var(--border);
    padding-bottom: 10px;
    margin-bottom: 10px;
    display: block;
    width: 100%;
  }
  
  .responsive-table td.cell-metric {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    width: auto;
    max-width: 100%;
    margin-right: 16px;
    padding: 6px 0;
    font-weight: 600;
  }
  .responsive-table td.cell-metric:last-of-type {
    margin-right: 0;
  }
  
  .responsive-table td.cell-actions {
    justify-content: flex-end;
    border-top: 1px solid var(--border);
    padding-top: 10px;
    margin-top: 10px;
    width: 100%;
    display: flex;
  }
  
  /* Grid Metadata Event */
  .event-meta {
    display: flex !important;
    flex-direction: column !important;
    gap: 6px !important;
  }
  .event-card .flex-between {
    flex-direction: column !important;
    align-items: stretch !important;
  }
  .event-action-btn-container {
    display: flex !important;
    justify-content: flex-end !important;
    width: 100% !important;
    margin-top: 10px !important;
    border-top: 1px solid var(--border) !important;
    padding-top: 10px !important;
  }
  
  .form-row {
    flex-direction: column;
    gap: 0;
  }
  .form-group {
    width: 100%;
    min-width: 100%;
  }
  
  .tracker-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .reset-pw-form {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    width: 100%;
    margin-bottom: 8px;
    justify-content: flex-end;
  }
  .reset-pw-form input {
    flex: 1;
    min-width: 120px;
    width: 100%;
  }

  .event-header {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 12px;
  }
  .event-header > div:last-child {
    justify-content: flex-end;
    display: flex;
  }
}

.reset-pw-form {
  display: inline-flex;
  gap: 0.25rem;
  align-items: center;
}


/* PRINT MEDIA */
@media print {
  body {
    background: #fff;
    color: #000;
    padding-top: 0;
  }
  .top-nav, .no-print, .btn, #theme-toggle {
    display: none !important;
  }
  .card, .table-wrap {
    box-shadow: none;
    border: 1px solid #ccc;
    background: #fff;
  }
  table th {
    background: #eee;
    color: #000;
  }
}