:root {
  --primary: #1a5276;
  --primary-light: #2980b9;
  --accent: #e74c3c;
  --success: #27ae60;
  --warning: #f39c12;
  --bg: #0f1419;
  --bg-card: #1a2332;
  --bg-card-hover: #1f2d3d;
  --text: #ecf0f1;
  --text-muted: #95a5a6;
  --border: #2c3e50;
  --trending-up: #2ecc71;
  --trending-down: #e74c3c;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

header {
  background: linear-gradient(135deg, var(--primary), #0d3446);
  padding: 1rem 2rem;
  border-bottom: 2px solid var(--primary-light);
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 1400px;
  margin: 0 auto;
}

.header-content h1 { font-size: 1.5rem; }

.header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.status-badge {
  padding: 0.3rem 0.8rem;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: 600;
}
.status-badge.connected { background: var(--success); color: white; }
.status-badge.disconnected { background: var(--accent); color: white; }

.btn {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
  transition: all 0.2s;
}
.btn-primary { background: var(--primary-light); color: white; }
.btn-primary:hover { background: #3498db; }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover { background: #34495e; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Tabs */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 0 1rem;
  max-width: 1400px;
  margin: 0 auto;
}

.tab {
  padding: 0.6rem 1rem;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-weight: 500;
  border-bottom: 3px solid transparent;
  transition: all 0.2s;
  font-size: 0.85rem;
  white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--primary-light);
  border-bottom-color: var(--primary-light);
}

/* Main content */
main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.5rem 2rem;
}

.panel { animation: fadeIn 0.2s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}
.card h3 { margin-bottom: 1rem; font-size: 1.1rem; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

/* Filters */
.filters {
  display: flex;
  gap: 0.8rem;
  align-items: center;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

select, .search-input {
  padding: 0.5rem 0.8rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.85rem;
}
.search-input { min-width: 200px; }
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
}

/* Tables */
.table-container { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
th, td {
  padding: 0.6rem 0.8rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
th {
  background: var(--bg);
  font-weight: 600;
  color: var(--text-muted);
  position: sticky;
  top: 0;
}
tr:hover { background: var(--bg-card-hover); }
td.positive { color: var(--trending-up); font-weight: 600; }
td.negative { color: var(--trending-down); font-weight: 600; }

/* Player list items */
.player-list { overflow-y: visible; }

.player-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0.8rem;
  border-radius: 6px;
  margin-bottom: 0.3rem;
  cursor: pointer;
  transition: background 0.2s;
}
.player-item:hover { background: var(--bg-card-hover); }
.player-item .name { font-weight: 500; }
.player-item .position { color: var(--text-muted); font-size: 0.8rem; margin-left: 0.5rem; }
.player-item .stat { font-weight: 600; }
.player-item .stat.up { color: var(--trending-up); }
.player-item .stat.down { color: var(--trending-down); }

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  margin-top: 1rem;
}

/* Setup card */
.setup-card {
  max-width: 700px;
  margin: 2rem auto;
}
.setup-card ol { padding-left: 1.5rem; line-height: 2; }
.setup-card code {
  background: var(--bg);
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-size: 0.85rem;
}
.env-example {
  background: var(--bg);
  border-radius: 6px;
  padding: 1rem;
  margin-top: 1rem;
}
.env-example pre {
  font-size: 0.8rem;
  line-height: 1.6;
  color: var(--success);
}

/* Upload section */
.upload-section {
  margin-bottom: 1rem;
}
.upload-section details {
  padding: 0.8rem;
  background: var(--bg);
  border-radius: 6px;
}
.upload-section summary { cursor: pointer; color: var(--text-muted); }

/* Modal */
.modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-content {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
  max-width: 800px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
}
.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.5rem;
  cursor: pointer;
}
.modal-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin: 1rem 0;
}

/* Trend indicators */
.trend-arrow { font-size: 1.2rem; }
.trend-arrow.up { color: var(--trending-up); }
.trend-arrow.down { color: var(--trending-down); }

/* Responsive */
@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
  .modal-grid { grid-template-columns: 1fr; }
  .filters { flex-direction: column; align-items: stretch; }
}

/* Loading state */
.loading {
  text-align: center;
  padding: 2rem;
  color: var(--text-muted);
}
.loading::after {
  content: '';
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--text-muted);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-left: 0.5rem;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Checkbox labels */
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 0.3rem;
  transition: all 0.2s;
}
.checkbox-label:has(input:checked) {
  border-color: var(--primary-light);
  background: rgba(41,128,185,0.15);
  color: var(--text);
}

/* Player list for watchlist / alerts */
.player-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  color: var(--text-muted);
  min-height: 60px;
}
.player-list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0.8rem;
  background: var(--bg);
  border-radius: 0.4rem;
  border: 1px solid var(--border);
  font-size: 0.9rem;
}
.player-list-item .name { color: var(--text); font-weight: 600; }
.player-list-item .pos { color: var(--primary-light); margin-left: 0.5rem; }
.player-list-item .remove-btn {
  background: none; border: none; color: var(--accent); cursor: pointer; font-size: 1rem; padding: 0 0.3rem;
}
.player-list-item .remove-btn:hover { opacity: 0.7; }

.alert-item {
  padding: 0.6rem 0.8rem;
  background: rgba(231,76,60,0.1);
  border: 1px solid rgba(231,76,60,0.3);
  border-radius: 0.4rem;
  font-size: 0.9rem;
}
.alert-item.dismissed { opacity: 0.4; }

/* Waiver rank badge */
.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-weight: 700;
  font-size: 0.8rem;
}
.rank-badge.top-5 { background: #27ae60; color: white; }
.rank-badge.top-10 { background: #2980b9; color: white; }
.rank-badge.top-20 { background: #8e44ad; color: white; }
.rank-badge.other { background: var(--border); color: var(--text-muted); }

/* Roster search dropdown */
.roster-search-dropdown {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 0.5rem 0.5rem;
  max-height: 300px;
  overflow-y: auto;
  z-index: 100;
  margin-top: -0.5rem;
}
.roster-search-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0.8rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}
.roster-search-item:hover { background: var(--bg-card-hover); }
.roster-search-item .player-info { display: flex; gap: 0.5rem; align-items: center; }
.roster-search-item .player-team { color: var(--text-muted); font-size: 0.8rem; }
.roster-search-item .add-btn {
  background: var(--primary); color: white; border: none; border-radius: 0.3rem;
  padding: 0.2rem 0.6rem; cursor: pointer; font-size: 0.8rem;
}
.roster-search-item .add-btn:hover { background: var(--primary-light); }
.roster-search-item.already-added { opacity: 0.4; }
.roster-search-item.already-added .add-btn { display: none; }

/* Watch toggle in waiver table */
.watch-toggle {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  border-radius: 0.3rem;
  border: 1px solid var(--border);
  transition: all 0.2s;
  user-select: none;
}
.watch-toggle input { display: none; }
.watch-toggle .watch-icon { font-size: 1rem; }
.watch-toggle.active {
  border-color: var(--primary-light);
  background: rgba(41,128,185,0.2);
}
.watch-toggle:hover { border-color: var(--primary-light); }

/* Watchlist projection line */
.watch-proj {
  width: 100%;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
  padding-top: 0.3rem;
  border-top: 1px solid var(--border);
  font-family: monospace;
}

}

/* News icon */
.news-icon { cursor: pointer; font-size: 0.85rem; margin-left: 0.3rem; opacity: 0.8; }
.news-icon:hover { opacity: 1; }

/* Clickable player name */
.player-link { color: var(--primary); cursor: pointer; text-decoration: none; border-bottom: 1px dotted var(--primary); }
.player-link:hover { color: #60a5fa; border-bottom-color: #60a5fa; }

/* Modal tabs */
.modal-tabs { display: flex; gap: 0; margin-bottom: 1rem; border-bottom: 2px solid var(--border); }
.modal-tab { background: none; border: none; color: var(--text-muted); padding: 0.6rem 1rem; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; font-size: 0.9rem; }
.modal-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* News list */
.news-list { max-height: 400px; overflow-y: auto; }
.news-item { padding: 0.8rem; border-bottom: 1px solid var(--border); }
.news-item:last-child { border-bottom: none; }
.news-item .news-title { font-weight: 600; margin-bottom: 0.3rem; }
.news-item .news-title a { color: var(--primary); text-decoration: none; }
.news-item .news-title a:hover { text-decoration: underline; }
.news-item .news-meta { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 0.3rem; }
.news-item .news-desc { font-size: 0.85rem; color: var(--text-secondary); }

/* Admin status */
.status-grid { display: grid; gap: 0.8rem; }
.status-row { display: flex; justify-content: space-between; align-items: center; padding: 0.6rem; background: var(--bg-alt); border-radius: 0.4rem; }
.status-row .source-name { font-weight: 600; }
.status-row .status-indicator { display: flex; align-items: center; gap: 0.5rem; }
.status-dot { width: 10px; height: 10px; border-radius: 50%; }
.status-dot.green { background: #22c55e; }
.status-dot.yellow { background: #eab308; }
.status-dot.red { background: #ef4444; }
.status-dot.gray { background: #6b7280; }
.status-time { font-size: 0.8rem; color: var(--text-muted); }
.status-count { font-size: 0.8rem; color: var(--text-secondary); background: var(--bg-card); padding: 0.1rem 0.5rem; border-radius: 0.3rem; }
.error-list { max-height: 200px; overflow-y: auto; }
.error-item { padding: 0.5rem; border-left: 3px solid #ef4444; margin-bottom: 0.5rem; background: rgba(239,68,68,0.05); border-radius: 0 0.3rem 0.3rem 0; font-size: 0.8rem; }
.error-item .error-source { color: #ef4444; font-weight: 600; }
.error-item .error-time { color: var(--text-muted); }

/* Pace tracker */
.pace-inputs { display: flex; gap: 1rem; flex-wrap: wrap; align-items: center; }
.pace-inputs label { font-size: 0.85rem; color: var(--text-secondary); display: flex; align-items: center; gap: 0.4rem; }
.pace-inputs input { background: var(--bg-alt); border: 1px solid var(--border); color: var(--text); border-radius: 0.3rem; padding: 0.3rem 0.5rem; }
.pace-bar { height: 24px; background: var(--bg-alt); border-radius: 0.3rem; overflow: hidden; margin-top: 0.5rem; position: relative; }
.pace-bar-fill { height: 100%; border-radius: 0.3rem; transition: width 0.3s; }
.pace-bar-label { position: absolute; top: 3px; left: 50%; transform: translateX(-50%); font-size: 0.75rem; font-weight: 600; }
.pace-stat { display: inline-block; margin-right: 1.5rem; margin-top: 0.5rem; }

/* ===== MOBILE RESPONSIVE ===== */

.trend-player { padding: 0.4rem 0; border-bottom: 1px solid var(--border); display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.trend-player:last-child { border-bottom: none; }
.trend-stat { font-size: 0.8rem; color: var(--text-muted); margin-left: auto; }

@media (max-width: 768px) {
  header { padding: 0.8rem 1rem; }
  .header-content { flex-direction: column; gap: 0.5rem; }
  .header-content h1 { font-size: 1.2rem; }

  .tabs {
    flex-wrap: wrap;
    padding: 0 0.5rem;
    gap: 0;
  }
  .tab {
    padding: 0.5rem 0.7rem;
    font-size: 0.75rem;
    flex: 0 0 auto;
  }

  main { padding: 1rem 0.8rem; }

  table { font-size: 0.75rem; }
  th, td { padding: 0.4rem 0.5rem; }

  .card { padding: 1rem; }

  /* Player modal */
  .modal-content { width: 95%; max-height: 90vh; padding: 1rem; }
  .mini-stats { font-size: 0.7rem; }
  .splits-table { font-size: 0.7rem; }

  /* Optimizer */
  .pace-inputs { flex-direction: column; align-items: flex-start; }

  /* Radar chart */
  canvas { max-width: 100%; height: auto !important; }

  /* Trend players */
  .trend-player { font-size: 0.85rem; }
  .trend-stat { font-size: 0.7rem; flex-basis: 100%; margin-left: 0; }
  .player-team { font-size: 0.7rem; }

  /* Table containers scroll */
  .table-container { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Filters row */
  .filters select, .filters input, .filters button { font-size: 0.8rem; }
}

@media (max-width: 480px) {
  .tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab {
    white-space: nowrap;
    font-size: 0.7rem;
    padding: 0.5rem 0.6rem;
  }
}
.pace-stat .label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; }
.pace-stat .value { font-size: 1.3rem; font-weight: 700; }
.pace-over { color: #ef4444; }
.pace-ok { color: #22c55e; }
.pace-warn { color: #eab308; }

/* Optimizer results */
.opt-player-row { display: flex; justify-content: space-between; align-items: center; padding: 0.6rem 0.8rem; border-bottom: 1px solid var(--border); }
.opt-player-row:last-child { border-bottom: none; }
.opt-start { border-left: 3px solid #22c55e; }
.opt-sit { border-left: 3px solid #ef4444; opacity: 0.7; }
.opt-matchup { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.2rem; }
.opt-sched { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.15rem; opacity: 0.8; }
.opt-park { font-size: 0.8rem; padding: 0.1rem 0.4rem; border-radius: 0.2rem; }
.opt-park.hot { background: rgba(34,197,94,0.15); color: #22c55e; }
.opt-park.cold { background: rgba(239,68,68,0.15); color: #ef4444; }
.opt-park.neutral { background: rgba(107,114,128,0.15); color: #9ca3af; }
.opp-sp { font-size: 0.85rem; }
.sp-bad { color: #4ade80; font-weight: 600; }
.sp-good { color: #f87171; font-weight: 600; }
.opt-sp-bonus { font-size: 0.75rem; }

/* Splits table */
.splits-table { width: 100%; border-collapse: collapse; margin-top: 0.8rem; }
.splits-table th, .splits-table td { padding: 0.5rem 0.6rem; text-align: center; border-bottom: 1px solid var(--border); font-size: 0.85rem; }
.splits-table th { color: var(--text-muted); font-weight: 600; }
.splits-table td:first-child { text-align: left; font-weight: 600; }
.split-home { background: rgba(34,197,94,0.05); }
.split-away { background: rgba(96,165,250,0.05); }
.split-better { color: #4ade80; font-weight: 700; }
.split-worse { color: #f87171; }
.split-summary { font-size: 0.9rem; }
.split-hot { color: #4ade80; font-weight: 700; }
.split-cold { color: #f87171; font-weight: 700; }

/* IL / Roster section */
.roster-section-label { font-weight: 700; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 0.4rem; text-transform: uppercase; letter-spacing: 0.5px; }
.il-btn { background: var(--warning); color: #000; border: none; border-radius: 4px; padding: 0.2rem 0.5rem; font-size: 0.7rem; cursor: pointer; font-weight: 600; }
.il-btn:hover { opacity: 0.8; }
.activate-btn { background: var(--success); color: #fff; }
.il-player { opacity: 0.7; border-left: 3px solid var(--warning); padding-left: 0.5rem; }
.bench-btn { background: var(--primary-light); color: #fff; border: none; border-radius: 4px; padding: 0.2rem 0.5rem; font-size: 0.7rem; cursor: pointer; font-weight: 600; }
.bench-btn:hover { opacity: 0.8; }
.bench-player { opacity: 0.85; border-left: 3px solid var(--primary-light); padding-left: 0.5rem; }

/* Config slots */
.config-slots { display: grid; gap: 0.5rem; }
.config-slot-row { background: var(--bg-alt); padding: 0.5rem 0.8rem; border-radius: 0.4rem; }
.slot-header { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.3rem; }
.slot-pos { font-weight: 700; font-size: 0.9rem; min-width: 2rem; }
.slot-label { color: var(--text-muted); font-size: 0.8rem; flex: 1; }
.slot-fill { font-size: 0.8rem; font-weight: 600; }
.slot-bar { height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; }
.slot-bar-fill { height: 100%; border-radius: 2px; }
.slot-players { font-size: 0.8rem; color: var(--text-secondary); margin-top: 0.3rem; }
.slot-player { margin-right: 0.5rem; }
