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

:root {
  --bg: #0f1117;
  --surface: #1a1d26;
  --surface2: #22273a;
  --border: #2e3350;
  --accent: #4f8ef7;
  --accent2: #7c3aed;
  --text: #e8eaf0;
  --text-muted: #8892b0;
  --green: #4ade80;
  --red: #f87171;
  --yellow: #fbbf24;
  --min-tap: 44px;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

html { font-size: 16px; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100dvh;
}

/* ── App header (sticky, contains title + toggle + tab nav) ─────────────────── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: max(10px, env(safe-area-inset-top)) 16px 0;
}

.header-row1 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 8px;
}

.header-row2 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.app-title {
  font-size: 1.1rem;
  font-weight: 700;
  white-space: nowrap;
  color: var(--text);
}

.last-updated {
  font-size: 0.65rem;
  color: var(--text-muted);
  white-space: nowrap;
  padding-bottom: 4px;
}

/* ── Header tab navigation ──────────────────────────────────────────────────── */
.header-tabs {
  display: flex;
  gap: 0;
}

.nav-tab {
  padding: 10px 16px;
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
  min-height: var(--min-tap);
  display: flex;
  align-items: center;
  gap: 5px;
}

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

/* ── Pill toggle (ROS / YTD and Hitter / Pitcher) ──────────────────────────── */
.toggle-pill {
  display: flex;
  background: var(--bg);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.toggle-btn {
  min-height: 36px;
  padding: 0 14px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.toggle-btn.active {
  background: var(--accent);
  color: #fff;
}

/* ── Tab content area ───────────────────────────────────────────────────────── */
.tab-content {
  padding-bottom: 32px;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Panel controls ─────────────────────────────────────────────────────────── */
.panel-controls {
  padding: 10px 16px 8px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.team-select {
  min-height: var(--min-tap);
  padding: 0 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.95rem;
  cursor: pointer;
  flex: 1;
  min-width: 160px;
}

/* ── Min filter ─────────────────────────────────────────────────────────────── */
.min-filter {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.min-filter input {
  width: 80px;
  min-height: var(--min-tap);
  padding: 0 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.9rem;
  text-align: center;
}

/* ── Position group headers ──────────────────────────────────────────────────── */
.pos-group {
  margin: 0;
}

.pos-group-header {
  padding: 8px 16px;
  background: var(--surface2);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
}

/* ── Scrollable table wrapper ────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-bottom: 2px solid var(--border);
}

/* Fixed column widths so tables don't reflow between sections */
table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  table-layout: fixed;
}

/* Hitter table column widths */
table.hitter-table .col-pos   { width: 40px; }
table.hitter-table .col-name  { width: 150px; }
table.hitter-table .col-team  { width: 44px; }
table.hitter-table .col-sal   { width: 44px; }
table.hitter-table .col-ctrt  { width: 48px; }
table.hitter-table .col-pts   { width: 56px; }
table.hitter-table .col-ppg   { width: 52px; }
table.hitter-table .col-ab    { width: 44px; }
table.hitter-table .col-h     { width: 40px; }
table.hitter-table .col-2b    { width: 40px; }
table.hitter-table .col-3b    { width: 40px; }
table.hitter-table .col-hr    { width: 40px; }
table.hitter-table .col-r     { width: 40px; }
table.hitter-table .col-rbi   { width: 44px; }
table.hitter-table .col-bb    { width: 40px; }
table.hitter-table .col-hbp   { width: 44px; }
table.hitter-table .col-sb    { width: 40px; }
table.hitter-table .col-cs    { width: 40px; }
table.hitter-table .col-sf    { width: 40px; }

/* Pitcher table column widths */
table.pitcher-table .col-pos   { width: 40px; }
table.pitcher-table .col-name  { width: 150px; }
table.pitcher-table .col-team  { width: 44px; }
table.pitcher-table .col-sal   { width: 44px; }
table.pitcher-table .col-ctrt  { width: 48px; }
table.pitcher-table .col-pts   { width: 56px; }
table.pitcher-table .col-ppg   { width: 52px; }
table.pitcher-table .col-ip    { width: 48px; }
table.pitcher-table .col-h     { width: 40px; }
table.pitcher-table .col-er    { width: 40px; }
table.pitcher-table .col-bb    { width: 40px; }
table.pitcher-table .col-so    { width: 40px; }
table.pitcher-table .col-hbp   { width: 44px; }
table.pitcher-table .col-qs    { width: 40px; }
table.pitcher-table .col-svhld { width: 60px; }

thead th {
  position: sticky;
  top: 0;
  background: var(--surface2);
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 8px 6px;
  text-align: right;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  overflow: hidden;
  text-overflow: ellipsis;
}

thead th.col-name {
  text-align: left;
  position: sticky;
  left: 0;
  z-index: 20;
  background: var(--surface2);
}

thead th.col-pos {
  text-align: center;
  color: var(--accent);
}

thead th.sorted-asc::after { content: " ▲"; color: var(--accent); }
thead th.sorted-desc::after { content: " ▼"; color: var(--accent); }

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}

tbody tr:hover { background: var(--surface2); }

tbody td {
  padding: 9px 6px;
  text-align: right;
  color: var(--text);
  white-space: nowrap;
  font-size: 0.875rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

tbody td.col-name {
  text-align: left;
  position: sticky;
  left: 0;
  background: var(--surface);
  z-index: 5;
  font-weight: 600;
}

tbody tr:hover td.col-name { background: var(--surface2); }

tbody td.col-pos {
  text-align: center;
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 700;
}

.col-team {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.col-pts { color: var(--yellow); font-weight: 700; }
.col-ppg { color: var(--green); font-weight: 600; }

.contract-badge {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.status-badge {
  display: inline-block;
  font-size: 0.6rem;
  font-weight: 700;
  padding: 1px 4px;
  border-radius: 3px;
  vertical-align: middle;
  margin-left: 3px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.status-minors { background: #2e3350; color: #8892b0; }
.status-reserve { background: #1e2a1e; color: #4ade80; }
.status-il { background: #3a2020; color: #f87171; }

/* ── Empty / loading states ──────────────────────────────────────────────────── */
.empty-state {
  padding: 48px 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.loading-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px;
  color: var(--text-muted);
}

/* ── Utility ─────────────────────────────────────────────────────────────────── */
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ── Desktop enhancements ────────────────────────────────────────────────────── */
@media (min-width: 768px) {
  .app-title { font-size: 1.25rem; }
  .app-header { padding: max(12px, env(safe-area-inset-top)) 24px 0; }
  .panel-controls { padding: 14px 24px; }
  .tab-content { max-width: 1400px; margin: 0 auto; }
  tbody td, thead th { padding: 10px 8px; font-size: 0.9rem; }
  .nav-tab { padding: 10px 20px; font-size: 0.9rem; }
}
