:root {
  --bg-primary: #0f172a;
  --bg-surface: #1e293b;
  --bg-hover: #334155;
  --border: #334155;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --accent-green: #22c55e;
  --accent-red: #ef4444;
  --accent-blue: #3b82f6;
  --accent-yellow: #eab308;
  --input-bg: #0f172a;
}

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

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

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

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 16px;
}

.header h1 {
  font-size: 24px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 12px;
}

.header h1::before {
  content: ⛳;
  font-size: 28px;
}

.header-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

/* Badges */
.badge {
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
}

.badge-readonly {
  background: rgba(34, 197, 94, 0.15);
  color: var(--accent-green);
}

.badge-admin {
  background: rgba(59, 130, 246, 0.15);
  color: var(--accent-blue);
}

/* Buttons */
.btn {
  padding: 10px 20px;
  border-radius: 8px;
  border: none;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

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

.btn-primary:hover {
  background: #2563eb;
}

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

.btn-secondary:hover {
  background: var(--bg-hover);
}

.btn-success {
  background: var(--accent-green);
  color: white;
}

/* Admin Tabs */
.admin-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.tab {
  padding: 10px 20px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s;
}

.tab:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.tab.active {
  background: var(--accent-blue);
  color: white;
  border-color: var(--accent-blue);
}

/* Stats Bar */
.stats-bar {
  display: flex;
  gap: 24px;
  margin-bottom: 20px;
  padding: 16px 20px;
  background: var(--bg-surface);
  border-radius: 12px;
  flex-wrap: wrap;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--accent-blue);
}

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

/* Filters */
.filters {
  display: flex;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  align-items: center;
}

.search-box {
  position: relative;
  flex: 1;
  min-width: 250px;
  max-width: 400px;
}

.search-box input {
  width: 100%;
  padding: 10px 16px 10px 40px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 14px;
}

.search-box::before {
  content: 🔍;
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 14px;
}

.filter-select {
  padding: 10px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 14px;
  cursor: pointer;
}

/* Table */
.table-container {
  background: var(--bg-surface);
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

thead {
  background: var(--bg-primary);
}

th {
  padding: 16px 12px;
  text-align: left;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.5px;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

th:hover {
  color: var(--text-primary);
}

th .sort-icon {
  margin-left: 4px;
  opacity: 0.5;
}

th:hover .sort-icon {
  opacity: 1;
}

td {
  padding: 14px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

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

tbody tr:last-child td {
  border-bottom: none;
}

/* Golfer Cell */
.golfer-name {
  display: flex;
  align-items: center;
  gap: 12px;
}

.golfer-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent-blue);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 13px;
  flex-shrink: 0;
  color: white;
}

.golfer-info {
  display: flex;
  flex-direction: column;
}

.golfer-info .name {
  font-weight: 500;
  color: var(--text-primary);
}

.golfer-info .meta {
  font-size: 12px;
  color: var(--text-secondary);
}

/* Scores */
.current-avg {
  font-family: 'SF Mono', Monaco, monospace;
  font-size: 18px;
  font-weight: 700;
  color: var(--accent-blue);
}

.no-avg {
  color: var(--text-secondary);
  font-style: italic;
}

.score-history {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.score-pill {
  padding: 4px 8px;
  background: var(--bg-primary);
  border-radius: 4px;
  font-family: 'SF Mono', Monaco, monospace;
  font-size: 13px;
  min-width: 32px;
  text-align: center;
}

.score-pill.recent {
  background: rgba(59, 130, 246, 0.15);
  color: var(--accent-blue);
}

.score-pill.old {
  color: var(--text-secondary);
}

.no-scores {
  color: var(--text-secondary);
  font-style: italic;
  font-size: 13px;
}

/* Trend */
.trend {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}

.trend.up {
  color: var(--accent-green);
}

.trend.down {
  color: var(--accent-red);
}

.trend.neutral {
  color: var(--text-secondary);
}

/* Actions */
.actions {
  display: flex;
  gap: 8px;
}

.action-btn {
  padding: 6px 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.action-btn:hover {
  background: var(--accent-blue);
  color: white;
  border-color: var(--accent-blue);
}

/* Mobile Cards */
.mobile-cards {
  display: none;
}

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

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

.mobile-card .golfer-name {
  gap: 10px;
}

.mobile-card .golfer-avatar {
  width: 40px;
  height: 40px;
}

.mobile-current {
  font-family: 'SF Mono', Monaco, monospace;
  font-size: 24px;
  font-weight: 700;
  color: var(--accent-blue);
}

.mobile-scores {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.mobile-actions {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 90%;
  max-width: 400px;
  overflow: hidden;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-size: 18px;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 24px;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
}

.modal-close:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.modal form {
  padding: 20px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-group input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 14px;
}

.form-group input:focus {
  outline: none;
  border-color: var(--accent-blue);
}

.form-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 20px;
}

/* Error Page */
.error-container {
  text-align: center;
  padding: 60px 20px;
}

.error-container h2 {
  font-size: 24px;
  margin-bottom: 12px;
}

.error-container p {
  color: var(--text-secondary);
  margin-bottom: 24px;
}

/* Responsive */
@media (max-width: 900px) {
  .table-wrapper {
    display: none;
  }

  .mobile-cards {
    display: block;
  }

  .header {
    flex-direction: column;
    gap: 16px;
    align-items: flex-start;
  }

  .filters {
    flex-direction: column;
    align-items: stretch;
  }

  .search-box {
    max-width: none;
  }

  .stats-bar {
    gap: 16px;
  }
}

/* ============================================
   BATCH ENTRY - Responsive Font Sizing
   Desktop-first with clamp() for smooth scaling
   ============================================ */

/* Base responsive sizing using CSS variables on container */
.container {
  --be-text-xs: clamp(11px, 0.8vw, 13px);
  --be-text-sm: clamp(12px, 0.9vw, 15px);
  --be-text-base: clamp(14px, 1.1vw, 18px);
  --be-text-md: clamp(16px, 1.2vw, 20px);
  --be-text-lg: clamp(18px, 1.5vw, 24px);
  --be-text-xl: clamp(22px, 2vw, 30px);
}

/* Batch Entry Table - uses ID selector */
#batchTable {
  font-size: var(--be-text-base);
}

#batchTable thead th {
  font-size: var(--be-text-xs);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  padding: 16px 12px;
  white-space: nowrap;
}

#batchTable tbody td {
  padding: 14px 12px;
}

/* Golfer Name - uses actual classes from template */
#batchTable .golfer-name .name {
  font-size: var(--be-text-md);
  font-weight: 500;
}

#batchTable .golfer-info .meta {
  font-size: var(--be-text-sm);
}

#batchTable .golfer-avatar {
  width: clamp(36px, 3vw, 44px);
  height: clamp(36px, 3vw, 44px);
  font-size: var(--be-text-sm);
}

/* Current Average - uses .avg-badge class */
#batchTable .avg-badge {
  font-size: var(--be-text-md);
  font-weight: 700;
  color: var(--accent-blue);
  font-family: 'SF Mono', Monaco, monospace;
}

#batchTable .no-avg {
  font-size: var(--be-text-md);
  color: var(--text-secondary);
  font-style: italic;
}

/* Score History - .score-pill already styled but boost size */
#batchTable .score-pill {
  font-size: var(--be-text-sm);
  padding: 6px 12px;
  min-width: 42px;
}

#batchTable .no-scores {
  font-size: var(--be-text-sm);
}

/* Score Input - uses .score-input class */
#batchTable .score-input {
  font-size: var(--be-text-lg);
  font-weight: 600;
  padding: 10px 8px;
  width: 90px;
  height: 48px;
  text-align: center;
  border-radius: 6px;
}

/* New Average Preview - uses .new-avg class */
#batchTable .new-avg {
  font-size: var(--be-text-md);
  font-weight: 700;
  font-family: 'SF Mono', Monaco, monospace;
}

/* Date selector */
#batchDate {
  font-size: var(--be-text-base);
  padding: 10px 14px;
}

/* Save button */
#saveBtn {
  font-size: var(--be-text-base);
  padding: 14px 28px;
}

#statusMsg {
  font-size: var(--be-text-base);
}

/* Header */
.header h1 {
  font-size: var(--be-text-xl);
}

/* Column widths */
#batchTable th:nth-child(1),
#batchTable td:nth-child(1) { /* Golfer */
  width: 22%;
}

#batchTable th:nth-child(2),
#batchTable td:nth-child(2) { /* Prior Stableford */
  width: 12%;
  text-align: center;
}

#batchTable th:nth-child(3),
#batchTable td:nth-child(3) { /* Score History */
  width: 30%;
}

#batchTable th:nth-child(4),
#batchTable td:nth-child(4) { /* Last Stableford (input) */
  width: 13%;
  text-align: center;
}

#batchTable th:nth-child(5),
#batchTable td:nth-child(5) { /* Current Stableford */
  width: 13%;
  text-align: center;
}

#batchTable th:nth-child(6),
#batchTable td:nth-child(6) { /* Updated */
  width: 10%;
  text-align: center;
}

/* Mobile adjustments */
@media (max-width: 900px) {
  .container {
    --be-text-xs: 11px;
    --be-text-sm: 12px;
    --be-text-base: 14px;
    --be-text-md: 15px;
    --be-text-lg: 17px;
    --be-text-xl: 20px;
  }

  #batchTable .score-pill {
    font-size: 11px;
    padding: 3px 6px;
    min-width: 28px;
  }

  #batchTable .score-input {
    width: 70px;
    height: 40px;
    font-size: 16px;
  }

  #batchTable th:nth-child(3),
  #batchTable td:nth-child(3) {
    display: none; /* Hide score history on small screens */
  }
}

/* ============================================
   BATCH ENTRY - Wider Container
   Override max-width for data-dense table
   ============================================ */

/* Wider container only for batch entry page (has #batchTable) */
.container:has(#batchTable) {
  max-width: 1600px;
}

/* Also allow table to use full width of container */
#batchTable {
  width: 100%;
  table-layout: fixed;
}

/* ============================================
   SORTABLE HEADERS
   ============================================ */

#batchTable th.sortable {
  cursor: pointer;
  user-select: none;
  transition: color 0.2s;
}

#batchTable th.sortable:hover {
  color: var(--text-primary);
}

#batchTable th .sort-icon {
  margin-left: 6px;
  font-size: 0.9em;
  opacity: 0.5;
  transition: opacity 0.2s;
}

#batchTable th.sortable:hover .sort-icon {
  opacity: 1;
}

#batchTable th .sort-icon.active {
  opacity: 1;
  color: var(--accent-blue);
}

/* ============================================
   BATCH ENTRY HEADER HOVER FIX
   ============================================ */

#batchTable thead th {
  color: var(--text-secondary);
}

#batchTable thead th.sortable:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

#batchTable thead th.sortable {
  cursor: pointer;
  user-select: none;
}

/* ============================================
   BATCH ENTRY - Auto-save Status Column
   ============================================ */

/* Note: Status/Updated column is now nth-child(7) - see column widths section above */

.save-status {
  font-size: 32px;
  font-weight: 700;
}

/* ============================================
   BATCH ENTRY - Number Input (no spinners)
   ============================================ */

#batchTable .score-input {
  -moz-appearance: textfield;
  -webkit-appearance: none;
  appearance: none;
}

#batchTable .score-input::-webkit-outer-spin-button,
#batchTable .score-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* Saved state - dimmed but keeps value */
#batchTable .score-input.saved {
  color: #999;
  background: #f5f5f5;
  border-color: #ddd;
}

/* ============================================
   BATCH ENTRY - Score History (last 10, no wrap)
   ============================================ */

#batchTable td:nth-child(3) {
  white-space: nowrap;
  overflow-x: auto;
}

#batchTable .score-history {
  display: flex;
  gap: 4px;
  flex-wrap: nowrap;
  white-space: nowrap;
}

/* Older scores (not in current avg) */
#batchTable .score-pill.older {
  opacity: 0.5;
  background: #f0f0f0;
  color: #666;
}

/* Empty state for NEW STABLEFORD */
#batchTable .new-avg-empty {
  color: #666;
  font-weight: 600;
}

/* Calculated average - yellow */
#batchTable .new-avg:not(.new-avg-empty) {
  font-size: 1.4em;
  font-weight: 700;
  color: #FFC107;
}

/* Editable score pills */
#batchTable .score-pill {
  cursor: pointer;
  transition: all 0.15s ease;
  position: relative;
}

#batchTable .score-pill:hover {
  opacity: 0.8;
  text-decoration: underline;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.3);
}

#batchTable .score-pill-edit {
  display: inline-block;
  margin: 0 2px;
  width: 60px;
  padding: 6px 12px;
  font-size: 16px;
  font-weight: 600;
  text-align: center;
  border: 2px solid #3b82f6;
  border-radius: 4px;
  box-sizing: border-box;
  -moz-appearance: textfield;
  -webkit-appearance: none;
  appearance: textfield;
}

/* Remove number input spinners */
#batchTable .score-pill-edit::-webkit-outer-spin-button,
#batchTable .score-pill-edit::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* Status column header - prevent text overflow */
#batchTable th.status-header {
  white-space: nowrap;
  min-width: 60px;
}

/* Tooltip for score history header */
.tooltip-wrapper:hover .tooltip-text {
  visibility: visible !important;
}

.tooltip-wrapper .tooltip-text::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  margin-left: -5px;
  border-width: 5px;
  border-style: solid;
  border-color: #333 transparent transparent transparent;
}


/* Utility classes */
.hidden {
  display: none !important;
}

/* App Header with Version */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  margin: -20px -20px 20px -20px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
}

.app-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.version-info {
  font-size: 12px;
  color: var(--text-secondary);
  font-family: 'SF Mono', Monaco, monospace;
}

/* Favorite Star Styles */
.favorite-star {
  cursor: pointer;
  font-size: 1.2em;
  color: #ccc;
  margin-right: 8px;
  user-select: none;
  transition: color 0.2s ease;
}

.favorite-star:hover {
  color: #ffd700;
}

.favorite-star.is-favorite {
  color: #ffd700 !important;
  color: #ffd700;
}

.favorite-star:focus {
  outline: 2px solid #007bff;
  outline-offset: 2px;
  border-radius: 2px;
}
