/* ===== Base ===== */
:root {
    --green: #2d6a4f;
    --green-light: #40916c;
    --green-bg: #f0f7f4;
    --blue: #1d3557;
    --red: #e63946;
    --gold: #f4a261;
    --gray-50: #f8f9fa;
    --gray-100: #e9ecef;
    --gray-200: #dee2e6;
    --gray-400: #adb5bd;
    --gray-600: #6c757d;
    --gray-800: #343a40;
    --radius: 6px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: var(--gray-800);
    background: var(--gray-50);
    line-height: 1.5;
}

/* ===== Nav ===== */
.navbar {
    background: var(--green);
    color: white;
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 2rem;
}
.nav-brand {
    font-size: 1.25rem;
    font-weight: 700;
    color: white;
    text-decoration: none;
}
.nav-links { display: flex; gap: 1.25rem; align-items: center; }
.nav-links form { margin: 0; }
.nav-links a { color: rgba(255,255,255,0.85); text-decoration: none; font-size: 0.9rem; }
.nav-links a:hover { color: white; }
.nav-link-btn {
    background: none; border: none; color: rgba(255,255,255,0.85);
    font-size: 0.9rem; cursor: pointer; padding: 0; font-family: inherit;
}
.nav-link-btn:hover { color: white; }
.alert-error { background: #fee; border: 1px solid #c33; color: #900; padding: 0.75rem 1rem; border-radius: 4px; margin-bottom: 1rem; }

/* Tee assignment badge + popup */
.tee-badge {
    display: inline-block; position: relative; cursor: pointer;
    background: var(--green); color: white; padding: 0.4rem 0.9rem;
    border-radius: 6px; font-size: 0.95rem; margin-bottom: 1rem;
    user-select: none;
}
.tee-badge .tee-yardage { opacity: 0.8; margin-left: 0.3rem; font-size: 0.85rem; }
.tee-detail {
    display: none; position: absolute; left: 0; top: calc(100% + 0.5rem);
    background: white; color: var(--gray-800); border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.25); padding: 1rem 1.2rem;
    min-width: 260px; z-index: 100; text-align: left;
}
.tee-detail.open { display: block; }
.tee-detail-title { font-weight: 700; font-size: 1rem; margin-bottom: 0.5rem; color: var(--green); }
.tee-detail-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.tee-detail-table td { padding: 0.25rem 0; }
.tee-detail-table td:first-child { color: var(--gray-500); width: 40%; }
.tee-detail small { display: block; margin-top: 0.5rem; color: var(--gray-400); text-align: center; }

/* ===== Layout ===== */
.container { max-width: 1200px; margin: 0 auto; padding: 1.5rem; }
.section { margin-bottom: 2rem; }
.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }

/* ===== Cards ===== */
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; margin-top: 1.5rem; }
.card {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 1.5rem;
    text-decoration: none;
    color: inherit;
    transition: box-shadow 0.15s;
}
.card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
.card h2 { font-size: 1.1rem; color: var(--green); margin-bottom: 0.5rem; }
.card p { font-size: 0.9rem; color: var(--gray-600); }

/* ===== Stats ===== */
.stats-bar { display: flex; gap: 0.75rem; margin-bottom: 1rem; flex-wrap: wrap; }
.stat {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 0.25rem 0.75rem;
    text-align: center;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
.stat-value { font-size: 1rem; font-weight: 700; color: var(--green); }
.stat-label { font-size: 0.75rem; color: var(--gray-600); }
.inline-select {
    font-size: 1.3rem; font-weight: 700; color: var(--green);
    border: 1px solid var(--gray-200); border-radius: var(--radius);
    background: white; padding: 0.1rem 0.3rem; cursor: pointer;
}

/* ===== Tables ===== */
.table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border-radius: var(--radius);
    overflow: hidden;
    font-size: 0.9rem;
}
.table th, .table td { padding: 0.5rem 0.75rem; text-align: center; border-bottom: 1px solid var(--gray-100); }
.table th { background: var(--gray-50); font-weight: 600; color: var(--gray-600); font-size: 0.8rem; text-transform: uppercase; }
.table tbody tr:hover { background: var(--green-bg); }
.table td:first-child, .table th:first-child { text-align: left; }
.table-compact th, .table-compact td { padding: 0.3rem 0.5rem; }

/* Score table */
.score-table-wrapper { overflow-x: auto; }
.table-scores { min-width: 900px; }
.table-scores td, .table-scores th { padding: 0.3rem 0.4rem; font-size: 0.8rem; min-width: 30px; }
.sticky-col { position: sticky; left: 0; background: white; z-index: 1; min-width: 120px !important; }
.par-row td { color: var(--gray-600); font-size: 0.75rem; background: var(--gray-50); }

/* Score colors */
.birdie { color: var(--red); font-weight: 700; }
.dbl-bogey { color: var(--blue); }
.bogey { color: var(--gray-600); }
.inactive td { opacity: 0.5; }

/* ===== Buttons ===== */
.btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    background: white;
    color: var(--gray-800);
    text-decoration: none;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.15s;
}
.btn:hover { background: var(--gray-100); }
.btn-primary { background: var(--green); color: white; border-color: var(--green); }
.btn-primary:hover { background: var(--green-light); }
.btn-danger { color: var(--red); border-color: var(--red); }
.btn-danger:hover { background: #fde8ea; }
.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.8rem; }

/* ===== Forms ===== */
.form { max-width: 800px; }
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-weight: 600; font-size: 0.85rem; margin-bottom: 0.25rem; color: var(--gray-600); }
.form-row { display: flex; gap: 1rem; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 150px; }
.form-inline { display: flex; gap: 0.5rem; align-items: flex-end; }
.form-actions { margin-top: 1.5rem; display: flex; gap: 0.75rem; }

input[type="text"], input[type="email"], input[type="number"], input[type="date"],
input[type="password"], select, textarea {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    font-size: 0.9rem;
}
input:focus, select:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 2px rgba(45,106,79,0.15); }

.input-sm { width: 48px; text-align: center; padding: 0.3rem; }
.input-score { width: 52px; text-align: center; padding: 0.4rem; font-size: 1.1rem; font-weight: 600; }

/* ===== Badges ===== */
.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}
.badge-setup { background: var(--gray-100); color: var(--gray-600); }
.badge-scoring { background: #fff3cd; color: #856404; }
.badge-finalized { background: #d4edda; color: #155724; }

/* ===== Validation ===== */
.validation-box {
    margin: 1rem 0;
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    min-height: 2.5rem;
}
.validation-box.valid { background: #d4edda; color: #155724; }
.validation-box.warning { background: #fff3cd; color: #856404; }
.validation-box.info { background: #d1ecf1; color: #0c5460; }

/* ===== Validation Results (HTMX) ===== */
.validation-results { margin-bottom: 1rem; }
.val-summary {
    padding: 0.6rem 1rem;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius) var(--radius) 0 0;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}
.val-summary small { color: var(--gray-600); }
.val-summary-ok { color: #155724; font-weight: 600; }
.val-summary-error { color: var(--red); font-weight: 600; }
.val-summary-incomplete { color: #0c5460; font-weight: 600; }
.table-validation { border-radius: 0 0 var(--radius) var(--radius); font-size: 0.85rem; }
.table-validation th:first-child,
.table-validation td:first-child { width: 30px; text-align: center; }
tr.val-ok td:first-child { color: #155724; }
tr.val-error td { background: #fde8ea; }
tr.val-error td:first-child { color: var(--red); font-size: 1.1rem; }
tr.val-incomplete td { color: var(--gray-600); font-style: italic; }
tr.val-incomplete td:first-child { color: #0c5460; }

/* ===== Skins Results ===== */
.skins-results { margin: 1rem 0; }
.skins-section { margin-bottom: 1.5rem; }
.skins-section h3 { color: var(--green); margin-bottom: 0.25rem; }
.skins-info {
    font-size: 0.85rem; color: var(--gray-600);
    margin-bottom: 0.5rem;
}
.table-skins { font-size: 0.85rem; min-width: auto; }
.table-skins td, .table-skins th { padding: 0.25rem 0.5rem; }
.skins-winner { font-weight: 600; color: var(--green); }
tr.skins-push td { color: var(--gray-400); font-style: italic; }
.table-skins-summary { font-size: 0.85rem; min-width: auto; }
.table-skins-summary td, .table-skins-summary th { padding: 0.25rem 0.5rem; }

/* ===== Mobile Scoring ===== */
.mobile-scoring { max-width: 500px; margin: 0 auto; }
.hole-info { text-align: center; margin-bottom: 1rem; }
.hole-info h2 { font-size: 2rem; color: var(--green); }
.player-score-card {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
}
.player-score-card h3 { margin-bottom: 0.5rem; }
.score-buttons { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.btn-score {
    width: 48px; height: 48px;
    border: 2px solid var(--gray-200);
    border-radius: var(--radius);
    background: white;
    font-size: 1.2rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.1s;
}
.btn-score:hover { border-color: var(--green); background: var(--green-bg); }
.btn-score.btn-par { border-color: var(--green); background: var(--green-bg); }
.score-status { margin-top: 0.5rem; font-size: 0.9rem; }
.score-saved { color: var(--green); font-weight: 700; }
.hole-nav { display: flex; justify-content: space-between; margin-top: 1.5rem; }

.complete-message { text-align: center; padding: 3rem; }
.complete-message h2 { color: var(--green); margin-bottom: 0.5rem; }

/* Leaderboard */
.table-leaderboard td:nth-child(3) { font-size: 1.1rem; }
.positive { color: var(--green); font-weight: 600; }
.negative { color: var(--red); }
.note { font-style: italic; color: var(--gray-600); margin-top: 1rem; font-size: 0.85rem; }

/* ===== Type-ahead ===== */
.typeahead-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid var(--gray-200);
    border-top: none;
    border-radius: 0 0 var(--radius) var(--radius);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    z-index: 100;
    max-height: 300px;
    overflow-y: auto;
}
.typeahead-item {
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    font-size: 0.9rem;
}
.typeahead-item:hover { background: var(--green-bg); }
.typeahead-item.typeahead-active { background: var(--green); color: white; font-weight: 600; }
.form-label { display: block; font-weight: 600; font-size: 0.85rem; margin-bottom: 0.25rem; color: var(--gray-600); }

/* ===== Modal ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.modal-content {
    background: white;
    border-radius: var(--radius);
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
    display: flex;
    flex-direction: column;
    max-height: 90vh;
    height: 80vh;
    width: 100%;
}
.modal-large { max-width: 800px; }
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--gray-200);
}
.modal-header h2 { margin: 0; font-size: 1.1rem; }
.modal-header .btn-sm { font-size: 1.2rem; line-height: 1; padding: 0.2rem 0.5rem; }
.modal-footer {
    display: flex;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--gray-200);
}

/* ===== Dual List ===== */
.dual-list {
    display: flex;
    flex-direction: row;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}
.dual-list-panel {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    min-width: 0;
}
.dual-list-panel { border: 1px solid var(--gray-200); }
.dual-list-panel:first-child { border-right: 2px solid var(--green); }
.dual-list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 1rem;
    background: var(--gray-50);
}
.dual-list-header h3 { margin: 0; font-size: 0.9rem; color: var(--gray-600); }
.dual-list-items {
    flex: 1;
    overflow-y: auto;
    padding: 0.25rem 0;
}
.dual-list-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 1rem;
    cursor: pointer;
    font-size: 0.9rem;
    user-select: none;
    white-space: nowrap;
}
.dual-list-item:hover { background: var(--green-bg); }
.dual-list-item small { color: var(--gray-600); }
#selected-list .dual-list-item { color: var(--green); font-weight: 500; }
#selected-list .dual-list-item:hover { background: #fde8ea; color: var(--red); }

/* ===== Scoring Rules Toggle ===== */
.scoring-rules-toggle { margin-top: 1rem; }
.scoring-rules-toggle summary { cursor: pointer; list-style: none; }
.scoring-rules-toggle summary::-webkit-details-marker { display: none; }
.scoring-rules {
    margin-top: 0.75rem;
    padding: 1rem;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
}

.empty-state { color: var(--gray-600); font-style: italic; padding: 2rem; text-align: center; }

/* ===== Scoring Grid Page (Mobile) ===== */
.scoring-grid-page {
    width: 100%;
    max-width: 100vw;
    padding: 0.5rem;
    overflow-x: hidden;
}
.scoring-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0;
    flex-wrap: wrap;
}
.scoring-header h2 { font-size: 1.1rem; margin: 0; }
.scoring-grid-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.scoring-grid {
    width: 100%;
    border-collapse: collapse;
    background: white;
    font-size: 0.85rem;
}
.scoring-grid th,
.scoring-grid td {
    border: 2px solid #000;
    text-align: center;
    padding: 0;
    vertical-align: middle;
}
.scoring-grid thead th {
    background: #f8f9fa;
    font-weight: 700;
    padding: 0.4rem 0.25rem;
    font-size: 0.8rem;
    color: #000;
}
.sg-player-name { font-size: 0.75rem; font-weight: 700; }
.sg-player-quota { font-size: 0.65rem; color: #555; }

.sg-hole-col,
.sg-par-col {
    position: sticky;
    background: #f8f9fa;
    z-index: 2;
    width: 32px;
    min-width: 32px;
}
.sg-hole-col { left: 0; }
.sg-par-col { left: 34px; }
.sg-player-col { min-width: 54px; }

.sg-hole-num {
    font-weight: 700;
    font-size: 0.8rem;
    color: #000;
    background: #f8f9fa;
    position: sticky;
    left: 0;
    z-index: 1;
    padding: 0.2rem;
}
.sg-par {
    font-size: 0.8rem;
    color: #000;
    background: #f8f9fa;
    position: sticky;
    left: 34px;
    z-index: 1;
    padding: 0.2rem;
}

/* Tappable score cells */
.sg-cell {
    min-width: 44px;
    min-height: 44px;
    height: 44px;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    font-weight: 700;
    font-size: 1rem;
    color: #000;
    position: relative;
}
.sg-cell:active { background: #e9ecef; }

/* Empty cell hint */
.sg-cell .sg-strokes:empty::after {
    content: '';
    display: block;
    width: 100%;
    height: 100%;
}

/* Error indicator */
.sg-cell.sg-error { background: #fde8ea; }

/* Score cell styling — plain numbers, no decoration */
.sg-cell .sg-strokes { color: #000; font-weight: 700; }
.table-scores td.sc-birdie,
.table-scores td.sc-eagle,
.table-scores td.sc-dbl-eagle,
.table-scores td.sc-bogey,
.table-scores td.sc-dbl-bogey,
.table-scores td.sc-par { color: #000; font-weight: 700; }

/* Subtotal / total rows */
.sg-subtotal td,
.sg-total td {
    background: #f0f0f0;
    font-weight: 700;
    border-top: 3px solid #000;
    font-size: 0.85rem;
    color: #000;
    padding: 0.2rem;
}
.sg-total td { background: #e0e0e0; }
.sg-cell-total { font-weight: 700; font-size: 0.9rem; color: #000; }
.sg-pts { font-size: 0.85rem; }
.sg-back-nine td { border-top: 3px solid #000; }

/* ===== Numpad Overlay ===== */
.numpad-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;
}
.numpad-modal {
    background: #fff;
    border: 3px solid #000;
    border-radius: 8px;
    width: 100%;
    max-width: 340px;
    padding: 1rem;
}
.numpad-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
    gap: 0.5rem;
}
.numpad-player { font-weight: 700; font-size: 1rem; color: #000; }
.numpad-hole-info { font-size: 0.9rem; color: #333; }
.numpad-close {
    background: #fff;
    border: 2px solid #000;
    font-size: 1.5rem;
    line-height: 1;
    width: 36px;
    height: 36px;
    cursor: pointer;
    font-weight: 700;
    color: #000;
}
.numpad-display {
    text-align: center;
    font-size: 2.5rem;
    font-weight: 700;
    color: #000;
    padding: 0.5rem;
    border: 2px solid #000;
    margin-bottom: 0.75rem;
    background: #fff;
}
.numpad-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}
.numpad-btn {
    background: #fff;
    border: 3px solid #000;
    border-radius: 6px;
    font-size: 1.5rem;
    font-weight: 700;
    color: #000;
    padding: 0.75rem;
    min-height: 56px;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}
.numpad-btn:active { background: #ddd; }
.numpad-btn-clear {
    background: #fff;
    color: #000;
    border-color: #000;
    font-size: 1.1rem;
}
.numpad-btn-ace {
    grid-column: 1 / -1;
    background: #fff;
    border-color: #000;
    color: #000;
}
.numpad-btn-back {
    background: #fff;
    border-color: #000;
    color: #000;
    font-size: 1rem;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .navbar { flex-direction: column; gap: 0.5rem; padding: 0.5rem 1rem; }
    .container { padding: 1rem; }
    .stats-bar { flex-direction: row; }
    .form-row { flex-direction: column; }
    .table-score-entry { font-size: 0.8rem; }
    .input-score { width: 42px; font-size: 1rem; }

    .scoring-grid-page { padding: 0.25rem; }
    .sg-cell { min-width: 48px; min-height: 48px; height: 48px; }
    .numpad-modal { max-width: 100%; }
    .numpad-btn { min-height: 60px; font-size: 1.7rem; }
}
