/* ===== CSS Custom Properties ===== */
:root {
    --bg-primary: #f5f7f5;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-input: #ffffff;
    --text-primary: #1a1a1a;
    --text-secondary: #555;
    --text-muted: #888;
    --border-color: #ddd;
    --border-light: #eee;
    --accent: #2e7d32;
    --accent-hover: #1b5e20;
    --accent-light: #e8f5e9;
    --danger: #c62828;
    --danger-light: #ffebee;
    --warning: #e65100;
    --warning-light: #fff3e0;
    --info: #1565c0;
    --info-light: #e3f2fd;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.12);
    --radius: 10px;
    --radius-sm: 6px;
    --nav-height: 56px;
    --transition: 0.2s ease;
}

[data-theme="dark"] {
    --bg-primary: #121212;
    --bg-secondary: #1e1e1e;
    --bg-card: #252525;
    --bg-input: #333;
    --text-primary: #e0e0e0;
    --text-secondary: #aaa;
    --text-muted: #777;
    --border-color: #444;
    --border-light: #333;
    --accent: #4caf50;
    --accent-hover: #66bb6a;
    --accent-light: #1b3a1b;
    --danger: #ef5350;
    --danger-light: #3a1a1a;
    --warning: #ff9800;
    --warning-light: #3a2a10;
    --info: #42a5f5;
    --info-light: #1a2a3a;
    --shadow: 0 2px 8px rgba(0,0,0,0.3);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.4);
}

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

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

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

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

/* ===== Navbar ===== */
.navbar {
    position: fixed; top: 0; left: 0; right: 0; z-index: 100;
    height: var(--nav-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 16px;
    box-shadow: var(--shadow);
}

.nav-brand a {
    font-size: 1.15rem; font-weight: 700; color: var(--accent);
    text-decoration: none;
}

.nav-toggle {
    display: block; background: none; border: none;
    font-size: 1.5rem; cursor: pointer; color: var(--text-primary);
    padding: 4px 8px;
}

.nav-links {
    display: none;
    position: absolute; top: var(--nav-height); left: 0; right: 0;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    flex-direction: column; padding: 8px 0;
    box-shadow: var(--shadow-lg);
}

.nav-links.open { display: flex; }

.nav-icon { font-size: 1.15rem; }
.nav-label { font-size: 0.85rem; }

.nav-link {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 20px; color: var(--text-secondary);
    font-size: 0.95rem; border: none; background: none;
    text-align: left; cursor: pointer; text-decoration: none;
    transition: background var(--transition);
}

.nav-link:hover, .nav-link.active {
    background: var(--accent-light); color: var(--accent);
    text-decoration: none;
}

.theme-toggle {
    background: none; border: none; cursor: pointer;
    font-size: 1.2rem; padding: 12px 20px; text-align: left;
}

.btn-logout { color: var(--danger); }

@media (min-width: 700px) {
    .nav-toggle { display: none; }
    .nav-links {
        display: flex; position: static; flex-direction: row;
        border: none; padding: 0; box-shadow: none;
        align-items: center; gap: 0;
    }
    .nav-link {
        flex-direction: column; gap: 1px;
        padding: 4px 10px; border-radius: var(--radius-sm);
        text-align: center; justify-content: center;
    }
    .nav-icon { font-size: 1.2rem; line-height: 1; }
    .nav-label { font-size: 0.6rem; font-weight: 600; letter-spacing: 0.3px; }
    .theme-toggle { padding: 8px; }
}

/* ===== Container ===== */
.container {
    max-width: 960px; margin: 0 auto;
    padding: 16px;
}

/* ===== Cards ===== */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

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

.card-title {
    font-size: 1.15rem; font-weight: 700; color: var(--text-primary);
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 10px 20px; border: none; border-radius: var(--radius-sm);
    font-size: 0.95rem; font-weight: 600; cursor: pointer;
    transition: all var(--transition); text-decoration: none;
    min-height: 44px;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); text-decoration: none; }

.btn-secondary { background: var(--bg-input); color: var(--text-primary); border: 1px solid var(--border-color); }
.btn-secondary:hover { background: var(--border-light); text-decoration: none; }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: 0.9; text-decoration: none; }

.btn-sm { padding: 6px 14px; font-size: 0.85rem; min-height: 36px; }
.btn-block { width: 100%; }

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== Forms ===== */
.form-group { margin-bottom: 16px; }

.form-label {
    display: block; font-size: 0.85rem; font-weight: 600;
    color: var(--text-secondary); margin-bottom: 4px;
}

.form-input, .form-select, .form-textarea {
    width: 100%; padding: 10px 12px; border: 1px solid var(--border-color);
    border-radius: var(--radius-sm); font-size: 1rem;
    background: var(--bg-input); color: var(--text-primary);
    transition: border var(--transition);
    min-height: 44px;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
    outline: none; border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(46, 125, 50, 0.15);
}

.form-textarea { min-height: 80px; resize: vertical; }

.form-error { color: var(--danger); font-size: 0.8rem; margin-top: 2px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

@media (max-width: 500px) {
    .form-row { grid-template-columns: 1fr; }
}

/* ===== Checkbox / Day Selector ===== */
.day-selector {
    display: flex; flex-wrap: wrap; gap: 8px;
}

.day-chip {
    padding: 8px 14px; border: 2px solid var(--border-color);
    border-radius: 20px; cursor: pointer; font-size: 0.85rem;
    font-weight: 600; transition: all var(--transition);
    user-select: none; color: var(--text-secondary);
}

.day-chip.selected {
    background: var(--accent); color: #fff;
    border-color: var(--accent);
}

/* ===== Toast ===== */
.toast {
    position: fixed; top: 70px; right: 16px; z-index: 200;
    padding: 12px 20px; border-radius: var(--radius-sm);
    font-weight: 600; font-size: 0.9rem;
    box-shadow: var(--shadow-lg); transition: all 0.3s ease;
    max-width: 360px;
}

.toast.hidden { opacity: 0; pointer-events: none; transform: translateY(-10px); }
.toast.success { background: var(--accent); color: #fff; }
.toast.error { background: var(--danger); color: #fff; }
.toast.info { background: var(--info); color: #fff; }

/* ===== Tables ===== */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.data-table {
    width: 100%; border-collapse: collapse; font-size: 0.9rem;
}

.data-table th, .data-table td {
    padding: 10px 12px; text-align: left;
    border-bottom: 1px solid var(--border-light);
}

.data-table th {
    font-weight: 700; color: var(--text-secondary);
    font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.5px;
    background: var(--bg-primary);
    position: sticky; top: 0;
}

.data-table tr:hover { background: var(--accent-light); }

/* ===== Status Badges ===== */
.badge {
    display: inline-block; padding: 3px 10px;
    border-radius: 12px; font-size: 0.75rem;
    font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px;
}

.badge-live { background: var(--danger); color: #fff; animation: pulse 2s infinite; }
.badge-scheduled { background: var(--info); color: #fff; }
.badge-completed { background: var(--accent); color: #fff; }
.badge-cancelled { background: var(--text-muted); color: #fff; }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* ===== Scorecard ===== */
.scorecard-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 8px;
}

.hole-card {
    background: var(--bg-card); border: 1px solid var(--border-color);
    border-radius: var(--radius-sm); padding: 12px; text-align: center;
    cursor: pointer; transition: all var(--transition);
}

.hole-card:hover, .hole-card.active {
    border-color: var(--accent); box-shadow: 0 0 0 2px rgba(46, 125, 50, 0.2);
}

.hole-card.scored { border-left: 4px solid var(--accent); }

.hole-number { font-size: 0.75rem; color: var(--text-muted); font-weight: 700; }
.hole-par { font-size: 0.75rem; color: var(--text-secondary); }
.hole-score {
    font-size: 1.5rem; font-weight: 800; margin: 4px 0;
    color: var(--text-primary);
}

.score-under { color: var(--danger); }
.score-over { color: var(--info); }
.score-par { color: var(--accent); }

/* ===== Score Entry Modal ===== */
.modal-overlay {
    display: none; position: fixed; inset: 0; z-index: 300;
    background: rgba(0,0,0,0.5); align-items: flex-end; justify-content: center;
}

.modal-overlay.open { display: flex; }

.modal {
    background: var(--bg-card); border-radius: var(--radius) var(--radius) 0 0;
    padding: 24px; width: 100%; max-width: 500px; max-height: 85vh;
    overflow-y: auto;
}

@media (min-width: 700px) {
    .modal-overlay.open { align-items: center; }
    .modal { border-radius: var(--radius); }
}

.modal-title {
    font-size: 1.15rem; font-weight: 700; margin-bottom: 16px;
    display: flex; justify-content: space-between; align-items: center;
}

.modal-close {
    background: none; border: none; font-size: 1.5rem;
    cursor: pointer; color: var(--text-muted); padding: 4px;
}

/* ===== Number Stepper ===== */
.stepper {
    display: flex; align-items: center; gap: 12px;
    justify-content: center;
}

.stepper-btn {
    width: 48px; height: 48px; border-radius: 50%;
    border: 2px solid var(--border-color); background: var(--bg-input);
    font-size: 1.4rem; font-weight: 700; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-primary); transition: all var(--transition);
}

.stepper-btn:hover { border-color: var(--accent); color: var(--accent); }
.stepper-btn:active { background: var(--accent-light); }

.stepper-value {
    font-size: 2rem; font-weight: 800; min-width: 48px;
    text-align: center; color: var(--text-primary);
}

/* ===== Toggle Switch ===== */
.toggle-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 8px 0;
}

.toggle-label { font-size: 0.95rem; color: var(--text-primary); }

.toggle {
    width: 48px; height: 26px; border-radius: 13px;
    background: var(--border-color); cursor: pointer;
    position: relative; transition: background var(--transition);
    border: none;
}

.toggle.on { background: var(--accent); }

.toggle::after {
    content: ''; position: absolute; top: 3px; left: 3px;
    width: 20px; height: 20px; border-radius: 50%;
    background: #fff; transition: transform var(--transition);
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.toggle.on::after { transform: translateX(22px); }

/* ===== Empty State ===== */
.empty-state {
    text-align: center; padding: 48px 20px;
    color: var(--text-muted);
}

.empty-state-icon { font-size: 3rem; margin-bottom: 12px; }
.empty-state-text { font-size: 1rem; margin-bottom: 16px; }

/* ===== Leaderboard ===== */
.rank-1 { color: #ffd700; }
.rank-2 { color: #c0c0c0; }
.rank-3 { color: #cd7f32; }

.player-row {
    display: flex; align-items: center; gap: 12px; padding: 12px 0;
    border-bottom: 1px solid var(--border-light);
}

.player-rank {
    font-size: 1.2rem; font-weight: 800; min-width: 32px; text-align: center;
}

.player-avatar {
    width: 40px; height: 40px; border-radius: 50%;
    background: var(--accent-light); display: flex;
    align-items: center; justify-content: center;
    font-weight: 700; font-size: 1rem; color: var(--accent);
    overflow: hidden;
}

.player-avatar img { width: 100%; height: 100%; object-fit: cover; }

.player-info { flex: 1; }
.player-name { font-weight: 700; font-size: 0.95rem; }
.player-stat { font-size: 0.8rem; color: var(--text-muted); }

.player-score {
    font-size: 1.3rem; font-weight: 800; min-width: 48px; text-align: right;
}

/* ===== Utility ===== */
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 0.85rem; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.gap-8 { gap: 8px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-between { justify-content: space-between; }
.flex-center { align-items: center; }
.flex-wrap { flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

@media (max-width: 500px) { .grid-2 { grid-template-columns: 1fr; } }

/* ===== Auth Pages ===== */
.auth-page {
    display: flex; align-items: center; justify-content: center;
    min-height: calc(100vh - var(--nav-height));
    padding: 20px;
}

.auth-card {
    background: var(--bg-card); border: 1px solid var(--border-color);
    border-radius: var(--radius); padding: 32px;
    width: 100%; max-width: 420px; box-shadow: var(--shadow-lg);
}

.auth-logo {
    text-align: center; margin-bottom: 24px;
}

.auth-logo-icon { font-size: 3rem; }

.auth-logo-text {
    font-size: 1.5rem; font-weight: 800; color: var(--accent);
}

.auth-footer {
    text-align: center; margin-top: 20px;
    font-size: 0.9rem; color: var(--text-muted);
}

/* ===== Page Header ===== */
.page-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 20px; flex-wrap: wrap; gap: 12px;
}

.page-title {
    font-size: 1.4rem; font-weight: 800;
}

/* ===== Tab Nav ===== */
.tabs {
    display: flex; gap: 4px; border-bottom: 2px solid var(--border-color);
    margin-bottom: 16px; overflow-x: auto;
}

.tab {
    padding: 10px 16px; font-size: 0.9rem; font-weight: 600;
    color: var(--text-muted); background: none; border: none;
    cursor: pointer; white-space: nowrap; border-bottom: 2px solid transparent;
    margin-bottom: -2px; transition: all var(--transition);
}

.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab:hover { color: var(--text-primary); }

/* ===== Loading Spinner ===== */
.spinner {
    display: inline-block; width: 24px; height: 24px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-center {
    display: flex; justify-content: center; padding: 48px;
}
