/* ============================================
   GolfStats — Eggshell / Forest / Navy / Sun
   ============================================ */

:root {
  --eggshell:    #F4EFE3;
  --eggshell-2:  #ECE5D3;
  --card:        #FBF7EC;
  --forest:      #2F5D3A;
  --forest-deep: #1F3F26;
  --forest-soft: #6B9676;
  --navy:        #1F3A5F;
  --navy-soft:   #5A7BA0;
  --sun:         #F2C94C;
  --sun-soft:    #F7DE85;
  --ink:         #1A1A1A;
  --ink-soft:    #5C5650;
  --ink-faint:   #8A8279;
  --line:        #D9D1BE;
  --line-soft:   #E8E1CE;
  --danger:      #B85450;
  --success:     #2F5D3A;

  --serif:  'Fraunces', Georgia, serif;
  --sans:   'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --script: 'Yellowtail', cursive;

  --max-width: 1280px;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 3px rgba(31, 58, 95, 0.05);
  --shadow-md: 0 4px 16px rgba(31, 58, 95, 0.08);
  --transition: 180ms ease;
}

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

html { font-size: 15px; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }

body {
  font-family: var(--sans);
  background: var(--eggshell);
  color: var(--ink);
  line-height: 1.55;
  min-width: 1280px;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    radial-gradient(circle at 15% 20%, rgba(47, 93, 58, 0.03) 0%, transparent 40%),
    radial-gradient(circle at 85% 80%, rgba(31, 58, 95, 0.03) 0%, transparent 40%);
  z-index: 0;
}

h1, h2, h3 {
  font-family: var(--serif);
  font-weight: 500;
  letter-spacing: -0.01em;
  line-height: 1.2;
  color: var(--ink);
}
h2 em, h3 em { font-style: italic; color: var(--navy); font-weight: 500; }

/* ---------- Buttons ---------- */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.85rem 2rem;
  background: var(--forest);
  color: var(--eggshell);
  border: none;
  border-radius: 999px;
  font-family: var(--sans);
  font-size: 0.92rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background var(--transition), transform 80ms ease;
}
.btn-primary:hover { background: var(--forest-deep); transform: translateY(-1px); }
.btn-primary:active { transform: scale(0.985); }

.btn-large { padding: 1rem 2.5rem; font-size: 1rem; }

.btn-text {
  background: none;
  border: none;
  color: var(--forest);
  font-family: var(--sans);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  padding: 0;
  transition: color var(--transition);
}
.btn-text:hover { color: var(--forest-deep); }

.link-accent {
  color: var(--forest);
  text-decoration: none;
  font-weight: 500;
}
.link-accent:hover { color: var(--forest-deep); text-decoration: underline; }

.btn-signout {
  background: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.45rem 1rem;
  font-family: var(--sans);
  font-size: 0.78rem;
  color: var(--ink-soft);
  cursor: pointer;
  transition: all var(--transition);
  margin-left: auto;
}
.btn-signout:hover { border-color: var(--ink); color: var(--ink); }

/* ---------- Header ---------- */
.header {
  background: rgba(244, 239, 227, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 2.5rem;
  display: flex;
  align-items: center;
  height: 72px;
  gap: 2.5rem;
}

.logo-mark {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  text-decoration: none;
  color: var(--ink);
}
.logo-mark svg { width: 42px; height: 42px; flex: 0 0 auto; }
.logo-mark .wordmark {
  font-family: var(--script);
  font-size: 1.85rem;
  font-weight: 400;
  color: var(--forest);
  line-height: 1;
  padding-top: 4px;
  white-space: nowrap;
}
.logo-mark .wordmark em { font-style: normal; color: var(--navy); }

.tab-nav { display: flex; gap: 0.25rem; }

.tab-btn {
  font-family: var(--sans);
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--ink-soft);
  background: none;
  border: none;
  padding: 0.55rem 1.1rem;
  border-radius: 999px;
  cursor: pointer;
  transition: all var(--transition);
}
.tab-btn:hover { color: var(--ink); background: var(--eggshell-2); }
.tab-btn.active {
  background: var(--forest);
  color: var(--eggshell);
}

/* ---------- Layout ---------- */
.tab-content { display: none; padding: 2.5rem 0 5rem; position: relative; z-index: 1; }
.tab-content.active { display: block; }

.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 2.5rem;
}

.section { margin-bottom: 2.5rem; }
.section h2 { font-size: 2.2rem; margin-bottom: 1.25rem; }

/* ---------- Course Select / Round Meta ---------- */
.course-search-wrapper { position: relative; max-width: 520px; }
.course-search-wrapper.hidden { display: none; }

.course-search-wrapper label,
.meta-field label {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-soft);
  margin-bottom: 0.4rem;
}

.course-select-dropdown {
  width: 100%;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: var(--sans);
  background: var(--card);
  color: var(--ink);
  transition: border-color var(--transition);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%235C5650' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}
.course-select-dropdown:focus { outline: none; border-color: var(--forest); }

.add-course-option { font-weight: 600; color: var(--forest); }

.selected-course-info {
  margin-top: 1rem;
  padding: 0.9rem 1.1rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  max-width: 520px;
}
.selected-course-info.hidden { display: none; }

.course-name-display {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
  font-size: 1.05rem;
}
.course-location { font-size: 0.85rem; color: var(--ink-faint); margin-top: 2px; }

.round-meta-row {
  display: flex;
  gap: 1.25rem;
  margin-top: 1.25rem;
  max-width: 520px;
}
.meta-field { flex: 1; }
.meta-field-small { flex: 0 0 140px; }

.meta-field input,
.meta-field select {
  width: 100%;
  padding: 0.65rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-family: var(--sans);
  font-size: 0.9rem;
  background: var(--card);
  color: var(--ink);
  transition: border-color var(--transition);
}
.meta-field input:focus,
.meta-field select:focus { outline: none; border-color: var(--forest); }

/* ---------- Add Course Form ---------- */
.add-course-form { max-width: 720px; }
.form-row { display: flex; gap: 1.25rem; align-items: flex-end; }

#course-scorecard-section h3 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 1.5rem;
}

.course-par-scorecard { margin-bottom: 1.5rem; }

.par-select {
  width: 60px;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-family: var(--sans);
  font-size: 0.9rem;
  background: var(--card);
  cursor: pointer;
  text-align: center;
}
.par-select:focus { outline: none; border-color: var(--forest); }

/* ---------- Scorecard ---------- */
#scorecard-section.hidden { display: none; }

.scorecard-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 1rem;
}
.scorecard-header h2 { margin-bottom: 0; }

.running-totals {
  display: flex;
  gap: 1.5rem;
  padding: 0.85rem 1.25rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.total-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 56px;
}
.total-label {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
}
.total-value {
  font-family: var(--serif);
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--ink);
}

.nine-section { margin-bottom: 1.75rem; }
.nine-section.hidden { display: none; }
.nine-section h3 {
  font-size: 1.1rem;
  color: var(--forest);
  margin-bottom: 0.75rem;
  font-weight: 600;
}

.scorecard-table-wrapper { overflow-x: auto; }

.scorecard-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
}

.scorecard-table th {
  background: var(--eggshell-2);
  padding: 0.65rem 0.75rem;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  text-align: center;
  border-bottom: 1px solid var(--line);
}

.scorecard-table td {
  padding: 0.4rem 0.5rem;
  text-align: center;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}

.scorecard-table tbody tr:hover { background: rgba(236, 229, 211, 0.4); }

.col-hole { width: 50px; }
.col-par { width: 50px; }
.col-score { width: 70px; }
.col-fairway { width: 200px; }
.col-green { width: 240px; }
.col-updown { width: 150px; }
.col-putts { width: 70px; }
.col-penalty { width: 80px; }

.hole-number {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.05rem;
}
.par-display { font-size: 0.9rem; color: var(--ink-soft); }

.score-input,
.putts-input {
  width: 48px;
  text-align: center;
  padding: 0.4rem 0.25rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-family: var(--sans);
  font-size: 1rem;
  font-weight: 500;
  background: var(--card);
  color: var(--ink);
  transition: border-color var(--transition), background var(--transition);
}
.score-input:focus,
.putts-input:focus { outline: none; border-color: var(--forest); }

.score-input.birdie { background: rgba(47, 93, 58, 0.12); color: var(--forest); font-weight: 600; }
.score-input.bogey { background: rgba(242, 201, 76, 0.25); color: #8a6a18; font-weight: 600; }
.score-input.double-plus { background: rgba(184, 84, 80, 0.15); color: var(--danger); font-weight: 600; }

/* Toggle / button groups */
.fairway-group,
.toggle-group {
  display: flex;
  gap: 2px;
  justify-content: center;
}

.fairway-btn,
.toggle-btn {
  font-family: var(--sans);
  font-size: 0.7rem;
  font-weight: 500;
  padding: 0.35rem 0.55rem;
  border: 1px solid var(--line);
  background: var(--card);
  cursor: pointer;
  transition: all var(--transition);
  color: var(--ink-faint);
  white-space: nowrap;
}
.fairway-btn:first-child,
.toggle-btn:first-child { border-radius: 6px 0 0 6px; }
.fairway-btn:last-child,
.toggle-btn:last-child { border-radius: 0 6px 6px 0; }

.fairway-btn.active,
.toggle-btn.active {
  background: var(--forest);
  color: var(--eggshell);
  border-color: var(--forest);
}
.toggle-btn.active-yes {
  background: var(--forest);
  color: var(--eggshell);
  border-color: var(--forest);
}
.toggle-btn.active-no {
  background: var(--danger);
  color: var(--eggshell);
  border-color: var(--danger);
}
.fairway-btn:disabled,
.toggle-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.subtotal-row td {
  font-weight: 600;
  background: var(--eggshell-2);
  border-top: 2px solid var(--line);
  font-size: 0.9rem;
}

.save-row { display: flex; justify-content: center; margin-top: 2rem; }

/* ---------- Saved Courses ---------- */
.saved-course-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1.25rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 0.6rem;
  transition: box-shadow var(--transition);
}
.saved-course-item:hover { box-shadow: var(--shadow-sm); }

.saved-course-info {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}
.saved-course-name { font-weight: 600; font-size: 1rem; min-width: 180px; }
.saved-course-location { font-size: 0.85rem; color: var(--ink-faint); min-width: 160px; }
.saved-course-detail { font-size: 0.85rem; color: var(--ink-soft); }

.saved-course-actions { display: flex; gap: 0.5rem; }

.btn-edit, .btn-delete {
  background: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.3rem 0.75rem;
  font-family: var(--sans);
  font-size: 0.75rem;
  color: var(--ink-soft);
  cursor: pointer;
  transition: all var(--transition);
}
.btn-edit:hover { border-color: var(--forest); color: var(--forest); }
.btn-delete:hover { border-color: var(--danger); color: var(--danger); }

/* ---------- Recent Rounds Table ---------- */
.rounds-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
}
.rounds-table th {
  background: var(--eggshell-2);
  padding: 0.7rem 1rem;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  text-align: left;
  border-bottom: 1px solid var(--line);
}
.rounds-table td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--line-soft);
  font-size: 0.9rem;
  vertical-align: middle;
}
.rounds-table tbody tr.rounds-row:hover { background: rgba(236, 229, 211, 0.4); }
.round-course-cell { font-weight: 500; }
.actions-cell { display: flex; gap: 0.4rem; }

.expand-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.7rem;
  color: var(--ink-faint);
  padding: 0.25rem 0.4rem;
  border-radius: 6px;
  transition: all var(--transition);
}
.expand-btn:hover { color: var(--ink); background: var(--eggshell-2); }
.expand-btn.expanded { color: var(--ink); }

.round-detail-row.hidden { display: none; }
.round-detail-row td { padding: 0; border-bottom: 2px solid var(--line); }

/* ---------- Inline Scorecard ---------- */
.inline-scorecard {
  background: var(--eggshell-2);
  padding: 1.25rem 1.5rem;
}
.inline-scorecard-content {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.inline-nine-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  font-size: 0.85rem;
  table-layout: fixed;
}
.inline-nine-table th {
  padding: 0.4rem 0.5rem;
  background: var(--eggshell-2);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  text-align: center;
  border-bottom: 1px solid var(--line);
}
.inline-nine-table th[colspan] {
  text-align: left;
  font-family: var(--serif);
  font-size: 0.95rem;
  text-transform: none;
  letter-spacing: 0;
  padding: 0.55rem 0.75rem;
  color: var(--forest);
}
.inline-nine-table td {
  padding: 0.4rem 0.5rem;
  text-align: center;
  border-bottom: 1px solid var(--line-soft);
  font-size: 0.85rem;
}
.inline-nine-table .row-label {
  text-align: left;
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  padding-left: 0.75rem;
}
/* First column (label) gets fixed width; remaining columns share space equally */
.inline-nine-table th:first-child,
.inline-nine-table td:first-child {
  width: 60px;
}

/* Nine-total column same width as hole columns */
.nine-total-header {
  min-width: auto !important;
}

.birdie-cell { color: var(--forest); font-weight: 600; }
.bogey-cell { color: #8a6a18; font-weight: 600; }
.double-cell { color: var(--danger); font-weight: 600; }

/* Inline scorecard score indicators */
.score-circle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border: 2px solid #B85450;
  border-radius: 50%;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--ink);
  line-height: 1;
}
.score-square {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border: 2px solid var(--ink);
  border-radius: 3px;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--ink);
  line-height: 1;
}

/* Nine-hole total column */
.nine-total-header {
  background: var(--eggshell-2) !important;
  font-weight: 700 !important;
  border-left: 2px solid var(--line) !important;
  min-width: 48px;
}
.nine-total-cell {
  border-left: 2px solid var(--line);
  font-weight: 600;
  font-size: 0.9rem;
  background: rgba(236, 229, 211, 0.3);
}

.inline-totals {
  font-size: 0.85rem;
  color: var(--ink-soft);
  font-weight: 500;
  padding: 0.25rem 0;
}

/* ---------- Dashboard ---------- */
.dashboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
}
.dashboard-header h2 { margin-bottom: 0; }

.filter-controls {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.filter-controls label { font-size: 0.85rem; color: var(--ink-soft); }
.filter-controls select {
  padding: 0.55rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-family: var(--sans);
  font-size: 0.85rem;
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
}
.filter-controls select:focus { outline: none; border-color: var(--forest); }

.date-range-inputs {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.date-range-inputs.hidden { display: none; }
.date-range-inputs input {
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-family: var(--sans);
  font-size: 0.85rem;
  background: var(--card);
  color: var(--ink);
}
.date-range-inputs span { font-size: 0.85rem; color: var(--ink-faint); }

/* Stat cards */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 1rem;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 1.5rem 1.4rem;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.5rem;
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 4px; height: 100%;
  background: var(--forest);
}
.stat-card:nth-child(2)::before { background: var(--navy); }
.stat-card:nth-child(3)::before { background: var(--sun); }
.stat-card:nth-child(4)::before { background: var(--forest-soft); }
.stat-card:nth-child(5)::before { background: var(--navy-soft); }

.stat-card-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-soft);
}
.stat-card-value {
  font-family: var(--serif);
  font-size: 2.2rem;
  font-weight: 600;
  color: var(--ink);
  line-height: 1;
}

/* Charts */
.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}
.chart-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 1.75rem;
}
.chart-card h3 {
  font-family: var(--serif);
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 1rem;
}
.chart-card-wide { grid-column: 1 / -1; }
.chart-card canvas { max-height: 280px; }

/* ---------- Empty State ---------- */
.empty-state {
  color: var(--ink-faint);
  font-style: italic;
  padding: 1.5rem 0;
}

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

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--ink-faint); }

.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--forest);
  color: var(--eggshell);
  padding: 0.8rem 1.75rem;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 500;
  opacity: 0;
  transition: opacity 300ms ease, transform 300ms ease;
  z-index: 999;
  pointer-events: none;
  box-shadow: var(--shadow-md);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
