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

:root {
  --bg:       #0f1923;
  --surface:  #1a2637;
  --border:   #2a3a50;
  --text:     #e8edf2;
  --muted:    #8a9ab0;
  --accent:   #2563eb;
  --danger:   #dc2626;
  --success:  #16a34a;
  --radius:   10px;
  --panel-w:  400px;
  --header-h: 56px;
}

html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; color: var(--text); background: var(--bg); overflow: hidden; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Header ────────────────────────────────────────────────────────────────── */
#header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 1000;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 1.25rem; gap: 1rem;
}
#header .logo { font-weight: 700; font-size: 1.1rem; color: var(--text); letter-spacing: -0.01em; }
#header .logo span { color: var(--accent); }
#header nav { margin-left: auto; display: flex; align-items: center; gap: 0.75rem; }
#header nav .username { color: var(--muted); font-size: 0.875rem; }
#btn-logout { background: none; border: 1px solid var(--border); color: var(--muted); padding: 0.35rem 0.75rem; border-radius: 6px; cursor: pointer; font-size: 0.8125rem; }
#btn-logout:hover { border-color: var(--text); color: var(--text); }
#visited-count { background: var(--accent); color: #fff; border-radius: 20px; padding: 0.2rem 0.65rem; font-size: 0.8rem; font-weight: 600; }

/* ── Map ───────────────────────────────────────────────────────────────────── */
#map {
  position: fixed;
  top: var(--header-h); left: 0; right: 0; bottom: 0;
  z-index: 0;
}

/* ── Side Panel ────────────────────────────────────────────────────────────── */
#panel {
  position: fixed;
  top: var(--header-h); right: 0; bottom: 0;
  width: var(--panel-w);
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 500;
  display: flex; flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  overflow: hidden;
}
#panel.open { transform: translateX(0); }

#panel-header {
  display: flex; align-items: center; padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border); gap: 0.75rem; flex-shrink: 0;
}
#panel-logo {
  width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 0.7rem; color: #fff; flex-shrink: 0;
  letter-spacing: -0.02em;
}
#panel-title { font-weight: 700; font-size: 1rem; line-height: 1.2; }
#panel-subtitle { font-size: 0.8rem; color: var(--muted); }
#panel-close {
  margin-left: auto; background: none; border: none; color: var(--muted);
  cursor: pointer; font-size: 1.25rem; line-height: 1; padding: 0.25rem;
}
#panel-close:hover { color: var(--text); }

#panel-body { flex: 1; overflow-y: auto; padding: 0; }

/* Panel tabs */
.panel-tabs {
  display: flex; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.panel-tab {
  flex: 1; padding: 0.625rem; text-align: center; font-size: 0.8125rem;
  color: var(--muted); cursor: pointer; border: none; background: none;
  border-bottom: 2px solid transparent; transition: all 0.15s;
}
.panel-tab.active { color: var(--text); border-bottom-color: var(--accent); }
.panel-tab:hover { color: var(--text); }

/* Visit card */
.visit-card {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.visit-card:last-child { border-bottom: none; }
.visit-date { font-size: 0.8rem; color: var(--muted); margin-bottom: 0.4rem; }
.visit-matchup { font-weight: 600; font-size: 0.9375rem; margin-bottom: 0.25rem; }
.visit-score { font-size: 1.25rem; font-weight: 800; margin-bottom: 0.4rem; color: var(--text); }
.visit-score .final { font-size: 0.75rem; font-weight: 400; color: var(--muted); margin-left: 0.4rem; }
.visit-details { display: flex; gap: 1rem; font-size: 0.8rem; color: var(--muted); flex-wrap: wrap; }
.visit-detail-item span { color: var(--text); font-weight: 500; }
.visit-notes { margin-top: 0.5rem; font-size: 0.8125rem; color: var(--muted); font-style: italic; }
.visit-actions { display: flex; gap: 0.5rem; margin-top: 0.75rem; }

/* Photo grid */
.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 1rem 1.25rem; }
.photo-thumb {
  aspect-ratio: 1; overflow: hidden; border-radius: 4px; cursor: pointer; background: var(--border);
}
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; transition: opacity 0.15s; }
.photo-thumb:hover img { opacity: 0.85; }

/* Video list */
.video-list { padding: 1rem 1.25rem; display: flex; flex-direction: column; gap: 0.75rem; }
.video-item {
  display: flex; gap: 0.75rem; align-items: flex-start;
  border: 1px solid var(--border); border-radius: var(--radius); padding: 0.625rem;
  cursor: pointer; transition: border-color 0.15s;
}
.video-item:hover { border-color: var(--accent); }
.video-thumb { width: 80px; height: 52px; object-fit: cover; border-radius: 4px; flex-shrink: 0; background: var(--border); }
.video-title { font-size: 0.8rem; line-height: 1.3; color: var(--text); }
.video-dur { font-size: 0.75rem; color: var(--muted); margin-top: 0.2rem; }

/* Box score */
.boxscore-wrap { padding: 1rem 1.25rem; overflow-x: auto; }
.boxscore-table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
.boxscore-table th { color: var(--muted); font-weight: 500; padding: 0.3rem 0.5rem; text-align: center; border-bottom: 1px solid var(--border); }
.boxscore-table td { padding: 0.4rem 0.5rem; text-align: center; }
.boxscore-table td:first-child { text-align: left; font-weight: 600; }
.boxscore-table tr:nth-child(even) { background: rgba(255,255,255,0.03); }

/* Unvisited panel */
.unvisited-panel { padding: 1.5rem 1.25rem; text-align: center; }
.unvisited-panel h3 { font-size: 1rem; margin-bottom: 0.5rem; }
.unvisited-panel p { font-size: 0.85rem; color: var(--muted); margin-bottom: 1.25rem; }
.stadium-meta { background: var(--bg); border-radius: var(--radius); padding: 1rem; margin-bottom: 1.25rem; text-align: left; }
.stadium-meta-row { display: flex; justify-content: space-between; padding: 0.3rem 0; font-size: 0.8125rem; border-bottom: 1px solid var(--border); }
.stadium-meta-row:last-child { border-bottom: none; }
.stadium-meta-row .label { color: var(--muted); }

/* Empty state */
.empty-state { padding: 2rem 1.25rem; text-align: center; color: var(--muted); font-size: 0.875rem; }

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  padding: 0.55rem 1.1rem; border-radius: 7px; font-size: 0.875rem; font-weight: 600;
  cursor: pointer; border: none; transition: all 0.15s; white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #1d4ed8; }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover { background: #364a64; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Modal ──────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7); z-index: 2000;
  display: flex; align-items: center; justify-content: center; padding: 1rem;
  opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto;
  transform: translateY(10px); transition: transform 0.2s;
}
.modal-overlay.open .modal { transform: translateY(0); }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 1.05rem; font-weight: 700; }
.modal-close {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: 1.25rem; line-height: 1; padding: 0.25rem;
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 1.25rem 1.5rem; display: flex; flex-direction: column; gap: 1rem; }
.modal-footer { padding: 1rem 1.5rem; border-top: 1px solid var(--border); display: flex; gap: 0.75rem; justify-content: flex-end; }

/* Steps */
.step-indicator {
  display: flex; gap: 0.5rem; align-items: center; padding: 0.75rem 1.5rem;
  border-bottom: 1px solid var(--border);
}
.step-dot {
  width: 24px; height: 24px; border-radius: 50%; display: flex; align-items: center;
  justify-content: center; font-size: 0.75rem; font-weight: 700;
  background: var(--border); color: var(--muted);
}
.step-dot.active { background: var(--accent); color: #fff; }
.step-dot.done { background: var(--success); color: #fff; }
.step-line { flex: 1; height: 1px; background: var(--border); }

/* Form fields */
.field { display: flex; flex-direction: column; gap: 0.375rem; }
.field label { font-size: 0.8125rem; font-weight: 600; color: var(--text); }
.field input, .field textarea, .field select {
  background: var(--bg); border: 1px solid var(--border); border-radius: 7px;
  color: var(--text); padding: 0.6rem 0.85rem; font-size: 0.875rem;
  transition: border-color 0.15s; width: 100%;
}
.field input:focus, .field textarea:focus, .field select:focus {
  outline: none; border-color: var(--accent);
}
.field .hint { font-size: 0.75rem; color: var(--muted); }
.field.inline { flex-direction: row; align-items: center; gap: 0.75rem; }
.field.inline label { white-space: nowrap; min-width: 60px; }
.fields-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0.75rem; }
.field .error-msg { font-size: 0.75rem; color: var(--danger); }

/* Game picker */
.game-list { display: flex; flex-direction: column; gap: 0.5rem; }
.game-option {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 0.75rem 1rem;
  cursor: pointer; transition: border-color 0.15s;
}
.game-option:hover, .game-option.selected { border-color: var(--accent); background: rgba(37,99,235,0.08); }
.game-teams { font-weight: 600; font-size: 0.9rem; }
.game-info { font-size: 0.8rem; color: var(--muted); margin-top: 0.25rem; }
.game-score { font-size: 1.1rem; font-weight: 800; }
.game-loading { text-align: center; color: var(--muted); padding: 1.5rem; font-size: 0.875rem; }

/* Photo drop zone */
.drop-zone {
  border: 2px dashed var(--border); border-radius: var(--radius); padding: 2rem;
  text-align: center; cursor: pointer; transition: border-color 0.15s;
}
.drop-zone:hover, .drop-zone.dragover { border-color: var(--accent); }
.drop-zone p { color: var(--muted); font-size: 0.875rem; }
.drop-zone p strong { color: var(--text); }
.upload-previews { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 0.75rem; }
.upload-preview { position: relative; aspect-ratio: 1; border-radius: 6px; overflow: hidden; background: var(--border); }
.upload-preview img { width: 100%; height: 100%; object-fit: cover; }
.upload-preview .remove {
  position: absolute; top: 2px; right: 2px; width: 18px; height: 18px; border-radius: 50%;
  background: rgba(0,0,0,0.75); color: #fff; border: none; cursor: pointer;
  font-size: 0.7rem; display: flex; align-items: center; justify-content: center;
}
.upload-progress { text-align: center; color: var(--muted); font-size: 0.8rem; padding: 0.5rem 0; }

/* Toast */
#toast-container { position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%); z-index: 9999; display: flex; flex-direction: column; gap: 0.5rem; align-items: center; }
.toast {
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  padding: 0.6rem 1.2rem; border-radius: 8px; font-size: 0.875rem;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4); animation: toastIn 0.2s ease;
  white-space: nowrap;
}
.toast.success { border-color: var(--success); }
.toast.error   { border-color: var(--danger); }
@keyframes toastIn { from { opacity:0; transform:translateY(8px); } to { opacity:1; transform:translateY(0); } }

/* Leaflet marker overrides */
.mlb-marker {
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; border: 3px solid rgba(255,255,255,0.2);
  font-weight: 800; color: #fff; cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.5);
  font-size: 0.55rem; letter-spacing: -0.02em;
  transition: transform 0.15s, box-shadow 0.15s;
  text-align: center; line-height: 1;
}
.mlb-marker:hover { transform: scale(1.15); box-shadow: 0 4px 16px rgba(0,0,0,0.6); }
.mlb-marker.visited { border-color: rgba(255,255,255,0.7); z-index: 1000 !important; }
.mlb-marker .badge {
  position: absolute; top: -6px; right: -6px;
  background: var(--accent); color: #fff; border-radius: 50%;
  width: 16px; height: 16px; font-size: 0.6rem; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
}

/* ── Landing / Auth page ─────────────────────────────────────────────────────*/
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); padding: 1rem; overflow: auto; }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 2.5rem; width: 100%; max-width: 420px; }
.auth-logo { font-size: 1.75rem; font-weight: 800; margin-bottom: 0.25rem; }
.auth-logo span { color: var(--accent); }
.auth-tagline { color: var(--muted); font-size: 0.9rem; margin-bottom: 2rem; }
.auth-tabs { display: flex; border-bottom: 1px solid var(--border); margin-bottom: 1.5rem; }
.auth-tab {
  flex: 1; padding: 0.6rem; text-align: center; font-size: 0.875rem; font-weight: 600;
  cursor: pointer; color: var(--muted); border: none; background: none;
  border-bottom: 2px solid transparent; transition: all 0.15s;
}
.auth-tab.active { color: var(--text); border-bottom-color: var(--accent); }
.auth-form { display: flex; flex-direction: column; gap: 0.875rem; }
.auth-form .btn { width: 100%; margin-top: 0.5rem; justify-content: center; padding: 0.7rem; }
.auth-error { background: rgba(220,38,38,0.1); border: 1px solid var(--danger); border-radius: 7px; padding: 0.6rem 0.85rem; font-size: 0.8125rem; color: #f87171; }
.auth-divider { text-align: center; color: var(--muted); font-size: 0.8rem; margin: 0.25rem 0; position: relative; }

/* ── Lightbox ────────────────────────────────────────────────────────────────*/
#lightbox { position: fixed; inset: 0; background: rgba(0,0,0,0.92); z-index: 5000; display: none; align-items: center; justify-content: center; }
#lightbox.open { display: flex; }
#lightbox img { max-width: 90vw; max-height: 90vh; border-radius: 8px; object-fit: contain; }
#lightbox-close { position: absolute; top: 1rem; right: 1.25rem; background: none; border: none; color: #fff; font-size: 2rem; cursor: pointer; line-height: 1; }

/* ── Responsive ──────────────────────────────────────────────────────────────*/
@media (max-width: 640px) {
  :root { --panel-w: 100vw; }
  #panel { border-left: none; border-top: 1px solid var(--border); top: auto; bottom: 0; height: 70vh; transform: translateY(100%); }
  #panel.open { transform: translateY(0); }
  .fields-row { grid-template-columns: 1fr 1fr; }
}
