/* ============================================
   Ridgetech Punters Club - Main Stylesheet
   ============================================ */

:root {
    --color-bg: #f5f5f3;
    --color-surface: #ffffff;
    --color-border: #e0e0dc;
    --color-text: #1a1a1a;
    --color-text-muted: #6b7280;
    --color-primary: #2d5a27;
    --color-primary-hover: #234820;
    --color-accent: #c8a84b;
    --color-accent-hover: #b8983b;
    --color-success: #166534;
    --color-success-bg: #dcfce7;
    --color-danger: #991b1b;
    --color-danger-bg: #fee2e2;
    --color-warning-bg: #fef9c3;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
    --radius: 8px;
    --radius-sm: 4px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
    font-size: 15px;
}

a {
    color: var(--color-primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* ---- Navbar ---- */
.navbar {
    background: var(--color-primary);
    color: #fff;
    box-shadow: var(--shadow-md);
    position: sticky;
    top: 0;
    z-index: 100;
}

.navbar-inner {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
}

.navbar-brand a {
    color: #fff;
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-decoration: none;
    white-space: nowrap;
}

.navbar-links {
    display: flex;
    align-items: center;
    gap: 1.25rem;
}

.navbar-links a {
    color: rgba(255,255,255,0.85);
    font-size: 0.9rem;
    text-decoration: none;
    transition: color 0.2s;
    white-space: nowrap;
}

.navbar-links a:hover {
    color: #fff;
    text-decoration: none;
}

.btn-logout {
    background: none;
    border: none;
    color: rgba(255,255,255,0.85);
    font-size: 0.9rem;
    cursor: pointer;
    padding: 0;
    font-family: inherit;
    white-space: nowrap;
}

.btn-logout:hover {
    color: #fff;
}

.navbar-user {
    color: rgba(255,255,255,0.7);
    font-size: 0.875rem;
    white-space: nowrap;
}

/* ---- Container ---- */
.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

/* ---- Card ---- */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

/* ---- Page Header ---- */
.page-header {
    margin-bottom: 1.5rem;
}

.page-header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--color-text);
}

.page-header .subtitle {
    color: var(--color-text-muted);
    margin-top: 0.25rem;
}

.page-header-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1.1rem;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    text-decoration: none;
    transition: background 0.2s, opacity 0.2s;
    white-space: nowrap;
}

.btn:hover { text-decoration: none; opacity: 0.9; }

.btn-primary {
    background: var(--color-primary);
    color: #fff;
}

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

.btn-secondary {
    background: transparent;
    color: var(--color-primary);
    border: 1.5px solid var(--color-primary);
}

.btn-secondary:hover { background: var(--color-primary); color: #fff; }

.btn-sm {
    padding: 0.3rem 0.7rem;
    font-size: 0.8rem;
}

.btn-tip {
    background: var(--color-accent);
    color: #1a1a1a;
}

.btn-tip:hover { background: var(--color-accent-hover); color: #1a1a1a; }

.btn-selected {
    background: var(--color-primary);
    color: #fff;
}

.btn-block {
    width: 100%;
}

/* ---- Messages ---- */
.messages {
    margin-bottom: 1rem;
}

.message {
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.message-success { background: var(--color-success-bg); color: var(--color-success); border: 1px solid #bbf7d0; }
.message-error { background: var(--color-danger-bg); color: var(--color-danger); border: 1px solid #fecaca; }
.message-warning { background: var(--color-warning-bg); color: #854d0e; border: 1px solid #fde68a; }

/* ---- Badges ---- */
.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.03em;
}

.badge-lg {
    padding: 0.3rem 0.8rem;
    font-size: 0.85rem;
}

.badge-open { background: var(--color-success-bg); color: var(--color-success); }
.badge-closed { background: #f1f5f9; color: var(--color-text-muted); }
.badge-results_in { background: var(--color-accent); color: #1a1a1a; }
.badge-results { background: var(--color-accent); color: #1a1a1a; }

/* ---- Events Grid ---- */
.events-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1.25rem;
}

.event-card {
    display: flex;
    flex-direction: column;
}

.event-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.event-card-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
}

.event-card-header h2 a {
    color: var(--color-text);
}

.event-card-body {
    flex: 1;
    margin-bottom: 1rem;
}

.event-meta {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.meta-item {
    font-size: 0.875rem;
    color: var(--color-text-muted);
}

.event-card-footer {
    display: flex;
    gap: 0.5rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--color-border);
}

/* ---- Race Cards ---- */
.races-list {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.race-card {
    padding: 0;
    overflow: hidden;
}

.race-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    background: #f8f8f7;
    border-bottom: 1px solid var(--color-border);
    gap: 1rem;
    flex-wrap: wrap;
}

.race-title h2 {
    font-size: 1rem;
    font-weight: 700;
}

.race-meta {
    display: flex;
    gap: 1rem;
    margin-top: 0.2rem;
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

.race-result-badge {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

.winner-label {
    font-size: 0.875rem;
}

.my-tip-summary {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.5rem;
    background: #f0f7ee;
    border-bottom: 1px solid var(--color-border);
    font-size: 0.875rem;
}

.tip-label {
    color: var(--color-text-muted);
}

.tip-type {
    color: var(--color-text-muted);
    font-size: 0.8rem;
}

.tip-result.win {
    color: var(--color-success);
    font-weight: 700;
    margin-left: 0.5rem;
}

.tip-result.loss {
    color: var(--color-danger);
    margin-left: 0.5rem;
}

/* ---- Horses Table ---- */
.horses-table-wrapper {
    overflow-x: auto;
}

.horses-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.horses-table th {
    text-align: left;
    padding: 0.6rem 1rem;
    background: #fafaf9;
    border-bottom: 1px solid var(--color-border);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
    font-weight: 600;
}

.horses-table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--color-border);
    vertical-align: middle;
}

.horses-table tr:last-child td {
    border-bottom: none;
}

.horses-table tr:hover td {
    background: #fafaf9;
}

.horse-winner td {
    background: #f0fdf4 !important;
}

.horse-name {
    font-weight: 600;
}

.trainer {
    display: block;
    font-size: 0.75rem;
    color: var(--color-text-muted);
    font-weight: 400;
}

.price {
    font-weight: 600;
    color: var(--color-primary);
}

.tip-cell {
    min-width: 180px;
}

.horse-tipped td {
    background: #f0f7ee !important;
}

.selected-indicator {
    color: var(--color-primary);
    font-weight: 700;
    font-size: 0.85rem;
}

.result-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 700;
}

.result-badge.win { background: var(--color-success-bg); color: var(--color-success); }
.result-badge.place { background: var(--color-warning-bg); color: #854d0e; }

/* ---- Leaderboard ---- */
.leaderboard-section {
    margin-bottom: 2rem;
}

.leaderboard-section h2,
.race-results-section h2 {
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 1rem;
}

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

.leaderboard-table th {
    text-align: left;
    padding: 0.6rem 1rem;
    border-bottom: 2px solid var(--color-border);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
}

.leaderboard-table td {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--color-border);
}

.leaderboard-table tr:last-child td { border-bottom: none; }

.rank-1 td { background: #fffbeb; }
.rank-2 td { background: #f9fafb; }
.rank-3 td { background: #fdf4ff; }

.rank { font-size: 1.25rem; width: 60px; }
.punter-name { font-weight: 600; }
.winnings { font-weight: 700; font-size: 1.05rem; }
.winnings.positive { color: var(--color-success); }

/* ---- Race Results (leaderboard page) ---- */
.race-results-section {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.race-result-card { padding: 0; overflow: hidden; }

.result-summary {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.9rem;
}

.winner-info { font-weight: 600; }
.price-info { color: var(--color-primary); font-weight: 700; }

.place-results {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    background: #f8f8f7;
    border-bottom: 1px solid var(--color-border);
}

.placing-badge {
    background: var(--color-warning-bg);
    color: #854d0e;
    padding: 0.2rem 0.6rem;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-weight: 600;
}

.tips-breakdown-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.tips-breakdown-table th {
    text-align: left;
    padding: 0.5rem 1rem;
    border-bottom: 1px solid var(--color-border);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
    background: #fafaf9;
}

.tips-breakdown-table td {
    padding: 0.65rem 1rem;
    border-bottom: 1px solid var(--color-border);
}

.tips-breakdown-table tr:last-child td { border-bottom: none; }

.positive { color: var(--color-success); font-weight: 700; }
.neutral { color: var(--color-text-muted); }

.pending { padding: 1rem 1.5rem; color: var(--color-text-muted); font-style: italic; }

/* ---- Auth Page ---- */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
}

.auth-card {
    width: 100%;
    max-width: 400px;
}

.auth-header {
    text-align: center;
    margin-bottom: 1.5rem;
}

.auth-header h1 {
    font-size: 1.4rem;
    color: var(--color-primary);
}

.auth-header p {
    color: var(--color-text-muted);
    margin-top: 0.25rem;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.form-group label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-text);
}

.form-control {
    padding: 0.6rem 0.75rem;
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    width: 100%;
    transition: border-color 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--color-primary);
}

.form-errors {
    background: var(--color-danger-bg);
    color: var(--color-danger);
    padding: 0.6rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    border: 1px solid #fecaca;
}

/* ---- Hero ---- */
.hero {
    background: linear-gradient(135deg, #1a3a15 0%, #2d5a27 55%, #3a7a32 100%);
    color: #fff;
    padding: 4rem 0 3.5rem;
    position: relative;
    overflow: hidden;
}

.hero::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        radial-gradient(ellipse at 70% 50%, rgba(200,168,75,0.12) 0%, transparent 60%),
        url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.03'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
    pointer-events: none;
}

.hero-inner {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 1.5rem;
    position: relative;
    z-index: 1;
}

.hero-eyebrow {
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--color-accent);
    margin-bottom: 1.25rem;
    opacity: 0.95;
}

.hero-heading {
    font-size: clamp(2.25rem, 5vw, 3.75rem);
    font-weight: 800;
    line-height: 1.1;
    margin-bottom: 1.25rem;
    letter-spacing: -0.02em;
}

.hero-heading-accent {
    color: var(--color-accent);
}

.hero-sub {
    font-size: 1.1rem;
    color: rgba(255,255,255,0.8);
    max-width: 560px;
    line-height: 1.65;
    margin-bottom: 2rem;
}

.hero-actions {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.hero-track-line {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, transparent, var(--color-accent), transparent);
}

.btn-accent {
    background: var(--color-accent);
    color: #1a1a1a;
    font-weight: 700;
}

.btn-accent:hover {
    background: var(--color-accent-hover);
    color: #1a1a1a;
    text-decoration: none;
    opacity: 1;
}

.btn-outline-white {
    background: transparent;
    color: #fff;
    border: 2px solid rgba(255,255,255,0.5);
    font-weight: 600;
}

.btn-outline-white:hover {
    background: rgba(255,255,255,0.1);
    border-color: #fff;
    color: #fff;
    text-decoration: none;
    opacity: 1;
}

.btn-lg {
    padding: 0.7rem 1.6rem;
    font-size: 1rem;
}

/* ---- Home Sections ---- */
.home-section {
    margin-bottom: 3rem;
}

.home-section-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 1.25rem;
    gap: 1rem;
}

.home-section-title {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--color-text);
}

.home-section-link {
    font-size: 0.875rem;
    color: var(--color-primary);
    white-space: nowrap;
}

.event-card-open {
    border-top: 3px solid var(--color-primary);
}

.event-card h3 {
    font-size: 1.05rem;
    font-weight: 600;
}

.event-card h3 a {
    color: var(--color-text);
}

/* ---- Home Empty ---- */
.home-empty {
    text-align: center;
    padding: 4rem 1.5rem;
    color: var(--color-text-muted);
}

.home-empty-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.home-empty h2 {
    font-size: 1.3rem;
    margin-bottom: 0.5rem;
    color: var(--color-text);
}

/* ---- How It Works ---- */
.how-it-works {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 2.5rem 2rem;
    margin-bottom: 2rem;
    box-shadow: var(--shadow-sm);
}

.hiw-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 2rem;
}

.hiw-step {
    text-align: center;
}

.hiw-icon {
    font-size: 2.25rem;
    margin-bottom: 0.75rem;
    line-height: 1;
}

.hiw-step h3 {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--color-text);
}

.hiw-step p {
    font-size: 0.875rem;
    color: var(--color-text-muted);
    line-height: 1.6;
}

/* ---- Misc ---- */
.empty-state {
    text-align: center;
    color: var(--color-text-muted);
    padding: 2rem;
}

.empty { color: var(--color-text-muted); text-align: center; font-style: italic; }

.auth-notice { background: var(--color-warning-bg); border-color: #fde68a; margin-bottom: 1.5rem; }
.notice { background: #f1f5f9; border-color: #cbd5e1; margin-bottom: 1rem; }

/* ---- Responsive ---- */
@media (max-width: 768px) {
    .navbar-inner { padding: 0 1rem; }
    .navbar-links { gap: 0.875rem; }
    .navbar-links a,
    .btn-logout,
    .navbar-user { font-size: 0.8rem; }

    .hero { padding: 2.75rem 0 2.5rem; }
    .hero-inner { padding: 0 1rem; }
    .hero-sub { font-size: 0.975rem; }
    .hero-actions { flex-direction: column; align-items: flex-start; }
    .btn-lg { width: 100%; text-align: center; justify-content: center; }

    .container { padding: 1.25rem 1rem; }
    .page-header-top { flex-direction: column; }
    .events-grid { grid-template-columns: 1fr; }
    .hiw-grid { grid-template-columns: 1fr; gap: 1.5rem; }
    .how-it-works { padding: 1.75rem 1.25rem; }
}

@media (max-width: 480px) {
    .navbar-brand a { font-size: 0.95rem; }
    .navbar-links { gap: 0.6rem; }

    .horses-table th:nth-child(3),
    .horses-table td:nth-child(3) { display: none; }
}
