:root {
  --bg-primary: #0a0a12;
  --bg-secondary: #12121e;
  --bg-card: #1a1a2e;
  --bg-card-hover: #22223a;
  --bg-input: #16162a;
  --border: #2a2a45;
  --border-light: #3a3a55;
  --text-primary: #e8e8f0;
  --text-secondary: #9898b0;
  --text-muted: #6868880;
  --accent-red: #e63946;
  --accent-red-dark: #c5303c;
  --accent-amber: #f4a261;
  --accent-green: #2ec4b6;
  --accent-blue: #4895ef;
  --accent-purple: #7b2cbf;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 48px rgba(0, 0, 0, 0.6);
  --radius: 12px;
  --radius-sm: 8px;
  --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

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

/* ===================== HEADER ===================== */
header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 24px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--accent-red);
  text-decoration: none;
}

.logo-icon {
  width: 32px;
  height: 32px;
  background: var(--accent-red);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

nav {
  display: flex;
  gap: 4px;
}

nav a {
  color: var(--text-secondary);
  text-decoration: none;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.2s;
}

nav a:hover, nav a.active {
  color: var(--text-primary);
  background: var(--bg-card);
}

nav a.active {
  color: var(--accent-red);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.credit-display {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
}

.credit-amount {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1rem;
  color: var(--accent-amber);
}

.credit-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.user-menu {
  position: relative;
}

.user-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 6px 14px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
}

.user-btn:hover {
  border-color: var(--border-light);
  background: var(--bg-card-hover);
}

.user-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  min-width: 200px;
  z-index: 150;
  overflow: hidden;
}

.user-dropdown.hidden {
  display: none;
}

.dropdown-header {
  padding: 12px 16px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
}

.dropdown-item {
  width: 100%;
  padding: 12px 16px;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 0.9rem;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s;
  font-family: var(--font-sans);
}

.dropdown-item:hover {
  background: var(--bg-card-hover);
  color: var(--accent-red);
}

.mobile-logout-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--accent-red);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  cursor: pointer;
  font-size: 0.95rem;
  margin-top: 4px;
  font-family: var(--font-sans);
}

.mobile-logout-btn:hover {
  background: rgba(230, 57, 70, 0.1);
}

/* ===================== MAIN CONTENT ===================== */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 24px;
}

/* ===================== LOGIN PAGE ===================== */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 128px);
}

.login-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 48px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
}

.login-box h1 {
  text-align: center;
  margin-bottom: 8px;
  font-size: 1.75rem;
}

.login-box .subtitle {
  text-align: center;
  color: var(--text-secondary);
  margin-bottom: 32px;
  font-size: 0.95rem;
}

.login-logo {
  text-align: center;
  font-size: 3rem;
  margin-bottom: 16px;
}

/* ===================== FORMS ===================== */
.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

input[type="text"],
input[type="password"],
input[type="number"],
select {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 1rem;
  font-family: var(--font-sans);
  transition: border-color 0.2s;
  outline: none;
}

input:focus, select:focus {
  border-color: var(--accent-red);
}

/* ===================== BUTTONS ===================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font-sans);
}

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

.btn-primary:hover {
  background: var(--accent-red-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(230, 57, 70, 0.3);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-light);
}

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

.btn-full {
  width: 100%;
}

.btn-green {
  background: var(--accent-green);
  color: #0a0a12;
}

.btn-green:hover {
  filter: brightness(1.1);
}

.btn-amber {
  background: var(--accent-amber);
  color: #0a0a12;
}

.btn-danger {
  background: var(--accent-red);
  color: white;
}

/* ===================== PAGE TITLE ===================== */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 32px;
}

.page-header h2 {
  font-size: 1.5rem;
  font-weight: 700;
}

.page-header .badge {
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* ===================== TRAIN CARDS ===================== */
.train-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
}

.train-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
}

.train-card:hover {
  border-color: var(--border-light);
  background: var(--bg-card-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.train-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
}

.train-card.delay-none::before { background: var(--accent-green); }
.train-card.delay-low::before { background: var(--accent-amber); }
.train-card.delay-high::before { background: var(--accent-red); }
.train-card.delay-early::before { background: var(--accent-blue); }

.train-card.train-arrived {
  opacity: 0.55;
}

.train-card.train-arrived:hover {
  opacity: 0.75;
}

.train-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
}

.train-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.train-status {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.train-status.upcoming {
  background: rgba(72, 149, 239, 0.15);
  color: var(--accent-blue);
}

.train-status.in-transit {
  background: rgba(244, 162, 97, 0.15);
  color: var(--accent-amber);
}

.train-status.arrived {
  background: rgba(104, 104, 136, 0.15);
  color: var(--text-secondary);
}

.train-line {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.train-delay {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: 12px;
}

.delay-positive {
  background: rgba(230, 57, 70, 0.15);
  color: var(--accent-red);
}

.delay-zero {
  background: rgba(46, 196, 182, 0.15);
  color: var(--accent-green);
}

.delay-negative {
  background: rgba(72, 149, 239, 0.15);
  color: var(--accent-blue);
}

.train-route {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  font-size: 0.9rem;
}

.train-route .station {
  color: var(--text-primary);
  font-weight: 500;
}

.train-route .arrow {
  color: var(--text-muted);
  flex-shrink: 0;
}

.train-schedule {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 16px;
  padding: 10px 12px;
  background: var(--bg-primary);
  border-radius: 6px;
  border: 1px solid var(--border);
}

.schedule-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
}

.schedule-label {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--text-muted);
  width: 28px;
  flex-shrink: 0;
}

.schedule-time {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--text-primary);
  flex-shrink: 0;
}

.schedule-station {
  color: var(--text-secondary);
  font-size: 0.8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.train-actions {
  display: flex;
  gap: 8px;
}

.bet-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(123, 44, 191, 0.15);
  color: var(--accent-purple);
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: 600;
}

/* ===================== MODAL ===================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-overlay.hidden {
  display: none;
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-lg);
  max-height: 90vh;
  overflow-y: auto;
}

.modal h3 {
  font-size: 1.25rem;
  margin-bottom: 24px;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.5rem;
  cursor: pointer;
}

/* Bet type tabs */
.bet-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 24px;
  background: var(--bg-primary);
  border-radius: var(--radius-sm);
  padding: 4px;
}

.bet-tab {
  flex: 1;
  padding: 10px;
  text-align: center;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.9rem;
  transition: all 0.2s;
}

.bet-tab.active {
  background: var(--bg-card);
  color: var(--text-primary);
}

/* Radio buttons for simple bet */
.bet-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
}

.bet-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg-input);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
}

.bet-option:hover {
  border-color: var(--border-light);
}

.bet-option.selected {
  border-color: var(--accent-red);
  background: rgba(230, 57, 70, 0.05);
}

.bet-option input[type="radio"] {
  display: none;
}

.bet-option .radio-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
}

.bet-option.selected .radio-dot {
  border-color: var(--accent-red);
}

.bet-option.selected .radio-dot::after {
  content: '';
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent-red);
}

.bet-option-label {
  font-weight: 600;
  font-size: 0.95rem;
}

.bet-option-desc {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.payout-preview {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin: 20px 0;
  text-align: center;
}

.payout-preview .label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.payout-preview .value {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent-green);
}

/* ===================== BETS LIST ===================== */
.bets-section {
  margin-bottom: 40px;
}

.bets-section h3 {
  font-size: 1.1rem;
  margin-bottom: 16px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.bet-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.bet-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 16px;
}

.bet-info .bet-train {
  font-weight: 600;
  margin-bottom: 2px;
}

.bet-info .bet-prediction {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.bet-amount {
  font-family: var(--font-mono);
  font-weight: 700;
  text-align: right;
}

.bet-result {
  font-family: var(--font-mono);
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 0.85rem;
}

.result-win {
  background: rgba(46, 196, 182, 0.15);
  color: var(--accent-green);
}

.result-partial {
  background: rgba(244, 162, 97, 0.15);
  color: var(--accent-amber);
}

.result-lose {
  background: rgba(230, 57, 70, 0.15);
  color: var(--accent-red);
}

.result-pending {
  background: rgba(72, 149, 239, 0.15);
  color: var(--accent-blue);
}

/* ===================== LEADERBOARD ===================== */
.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
}

.leaderboard-table th {
  text-align: left;
  padding: 12px 16px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
}

.leaderboard-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.leaderboard-table tr:hover td {
  background: var(--bg-card);
}

.rank-badge {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
}

.rank-1 { background: #ffd700; color: #0a0a12; }
.rank-2 { background: #c0c0c0; color: #0a0a12; }
.rank-3 { background: #cd7f32; color: #0a0a12; }
.rank-other { background: var(--bg-card); color: var(--text-secondary); }

.profit-positive { color: var(--accent-green); }
.profit-negative { color: var(--accent-red); }

/* ===================== ADMIN ===================== */
.admin-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 24px;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  padding: 4px;
  border: 1px solid var(--border);
}

.admin-tab {
  padding: 10px 20px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.9rem;
  transition: all 0.2s;
}

.admin-tab.active {
  background: var(--bg-card);
  color: var(--text-primary);
}

.admin-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 16px;
}

.admin-card h4 {
  margin-bottom: 16px;
  font-size: 1rem;
}

.user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.user-row:last-child {
  border-bottom: none;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent-purple);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  color: white;
}

.user-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.settings-form {
  display: grid;
  gap: 16px;
  max-width: 400px;
}

/* ===================== EMPTY STATE ===================== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}

.empty-state .icon {
  font-size: 3rem;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state h3 {
  margin-bottom: 8px;
  color: var(--text-primary);
}

/* ===================== TOAST ===================== */
#toast-container {
  position: fixed;
  top: 80px;
  right: 24px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 20px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 280px;
  animation: slideIn 0.3s ease;
}

.toast.success { border-left: 4px solid var(--accent-green); }
.toast.error { border-left: 4px solid var(--accent-red); }
.toast.info { border-left: 4px solid var(--accent-blue); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

@keyframes slideOut {
  from { transform: translateX(0); opacity: 1; }
  to { transform: translateX(100%); opacity: 0; }
}

.toast.removing {
  animation: slideOut 0.3s ease forwards;
}

/* ===================== LOADING ===================== */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: var(--text-secondary);
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent-red);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 12px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===================== RESPONSIVE ===================== */
@media (max-width: 768px) {
  header { padding: 0 16px; }
  .header-left { gap: 12px; }
  nav { display: none; }
  main { padding: 20px 16px; }
  .train-grid { grid-template-columns: 1fr; }
  .bet-item { grid-template-columns: 1fr; gap: 8px; }
  .login-box { padding: 32px 24px; margin: 0 16px; }
  .modal { margin: 16px; padding: 24px; }
}

/* Mobile nav toggle */
.mobile-nav {
  display: none;
}

.mobile-menu {
  display: none;
}

@media (max-width: 768px) {
  .mobile-nav {
    display: block;
  }
  .mobile-nav-btn {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 4px;
  }
  .mobile-menu {
    position: fixed;
    top: 64px;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: 16px;
    display: none;
    flex-direction: column;
    gap: 8px;
    z-index: 99;
  }
  .mobile-menu.open {
    display: flex;
  }
  .mobile-menu a {
    color: var(--text-primary);
    text-decoration: none;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-weight: 500;
  }
  .mobile-menu a:hover, .mobile-menu a.active {
    background: var(--bg-card);
    color: var(--accent-red);
  }
}

/* ===================== SCROLLBAR ===================== */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }
