/**
 * RunIntensity Coach Dashboard — Dark theme matching the iOS app.
 * Colors from AppTheme.swift: backgrounds (#0a0f1e, #0f172a, #1e293b),
 * text (#f1f5f9, #e2e8f0, #94a3b8, #64748b, #475569), accent orange (#f97316).
 *
 * Copyright (c) 2026 Zero Di, LLC. All rights reserved.
 */

/* ── Reset & Globals ─────────────────────────────────────── */

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

:root {
    --bg-app: #0a0f1e;
    --bg-card: #0f172a;
    --bg-card-highlight: #1e293b;
    --bg-input: #1e293b;
    --border-card: #1e293b;
    --border-input: #334155;

    --text-heading: #f1f5f9;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-tertiary: #64748b;
    --text-muted: #475569;

    --accent: #f97316;
    --accent-hover: #ea580c;
    --green: #34d399;
    --yellow: #fbbf24;
    --red: #ef4444;
    --blue: #60a5fa;
    --pink: #f472b6;
    --teal: #2dd4bf;

    --zone-recovery: #2dd4bf;
    --zone-easy: #34d399;
    --zone-moderate: #fbbf24;
    --zone-tempo: #f97316;
    --zone-threshold: #ef4444;

    --radius: 12px;
    --radius-sm: 8px;
    --transition: 0.2s ease;

    --sidebar-width: 220px;
    --nav-height: 56px;
}

html, body {
    height: 100%;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-app);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
}

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

.hidden { display: none !important; }
.screen { display: none; }
.screen.active { display: flex; }

/* ── Sign In Screen ──────────────────────────────────────── */

#signin-screen {
    min-height: 100vh;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0a0f1e 0%, #0f172a 50%, #162544 100%);
}

.signin-container {
    text-align: center;
    max-width: 380px;
    padding: 3rem 2rem;
}

.signin-logo { margin-bottom: 2rem; }
.signin-logo .logo-icon { font-size: 3rem; display: block; margin-bottom: 0.5rem; }
.signin-logo h1 { font-size: 2rem; font-weight: 700; color: var(--text-heading); }
.signin-logo .subtitle {
    font-size: 1rem; font-weight: 400; color: var(--accent);
    margin-top: 0.25rem; letter-spacing: 0.5px;
}

.signin-desc {
    color: var(--text-secondary); font-size: 0.9rem;
    line-height: 1.6; margin-bottom: 2rem;
}

#apple-signin-btn {
    display: flex; justify-content: center; margin-bottom: 1rem;
}

.error-msg {
    color: var(--red); font-size: 0.85rem;
    margin-top: 0.75rem; padding: 0.5rem;
    background: rgba(239, 68, 68, 0.1); border-radius: var(--radius-sm);
}

.signin-note {
    color: var(--text-muted); font-size: 0.8rem; margin-top: 1.5rem;
}

/* ── Top Nav ─────────────────────────────────────────────── */

.top-nav {
    height: var(--nav-height);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-card);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-left { display: flex; align-items: center; gap: 0.75rem; }
.nav-logo { font-weight: 700; font-size: 1rem; color: var(--text-heading); }
.nav-divider { color: var(--text-muted); }
.nav-title { color: var(--accent); font-weight: 600; font-size: 0.9rem; }

.nav-right { display: flex; align-items: center; gap: 1rem; }
.nav-user { color: var(--text-secondary); font-size: 0.85rem; }

/* ── App Layout ──────────────────────────────────────────── */

#app-shell {
    flex-direction: column;
    height: 100vh;
}

.app-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────── */

.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-card);
    border-right: 1px solid var(--border-card);
    padding: 1rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    flex-shrink: 0;
}

.sidebar-btn {
    display: flex; align-items: center; gap: 0.75rem;
    width: 100%; padding: 0.65rem 1rem;
    background: transparent; border: none; border-radius: var(--radius-sm);
    color: var(--text-secondary); font-size: 0.9rem; font-weight: 500;
    cursor: pointer; transition: all var(--transition);
    font-family: inherit;
}

.sidebar-btn:hover { background: var(--bg-card-highlight); color: var(--text-primary); }
.sidebar-btn.active { background: rgba(249, 115, 22, 0.12); color: var(--accent); }
.sb-icon { font-size: 1.1rem; }

.sidebar-spacer { flex: 1; }

.sidebar-info {
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border-card);
}

.sidebar-invite .label { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; display: block; }
.sidebar-invite .value { font-size: 0.95rem; font-weight: 700; color: var(--accent); font-family: 'SF Mono', monospace; letter-spacing: 1px; }

/* ── Main Content ────────────────────────────────────────── */

.main-content {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem 2rem;
}

.view { display: none; }
.view.active { display: block; }

.view-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 1.5rem; gap: 1rem;
}

.view-header h2 {
    font-size: 1.5rem; font-weight: 700; color: var(--text-heading);
}

/* ── Buttons ─────────────────────────────────────────────── */

.btn-primary {
    background: var(--accent); color: #fff;
    border: none; border-radius: var(--radius-sm);
    padding: 0.5rem 1rem; font-size: 0.85rem; font-weight: 600;
    cursor: pointer; transition: background var(--transition);
    font-family: inherit;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { padding: 0.4rem 0.75rem; font-size: 0.8rem; }

.btn-ghost {
    background: transparent; color: var(--text-secondary);
    border: 1px solid var(--border-input); border-radius: var(--radius-sm);
    padding: 0.4rem 0.75rem; font-size: 0.8rem; font-weight: 500;
    cursor: pointer; transition: all var(--transition);
    font-family: inherit;
}
.btn-ghost:hover { background: var(--bg-card-highlight); color: var(--text-primary); border-color: var(--text-muted); }

.btn-danger {
    background: rgba(239, 68, 68, 0.15); color: var(--red);
    border: 1px solid rgba(239, 68, 68, 0.3); border-radius: var(--radius-sm);
    padding: 0.4rem 0.75rem; font-size: 0.8rem; font-weight: 500;
    cursor: pointer; font-family: inherit;
}
.btn-danger:hover { background: rgba(239, 68, 68, 0.25); }

.btn-success {
    background: rgba(52, 211, 153, 0.15); color: var(--green);
    border: 1px solid rgba(52, 211, 153, 0.3); border-radius: var(--radius-sm);
    padding: 0.4rem 0.75rem; font-size: 0.8rem; font-weight: 500;
    cursor: pointer; font-family: inherit;
}
.btn-success:hover { background: rgba(52, 211, 153, 0.25); }

/* ── Stats Row ───────────────────────────────────────────── */

.stats-row {
    display: flex; gap: 1rem; margin-bottom: 1.5rem; flex-wrap: wrap;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-card);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    flex: 1; min-width: 140px;
}

.stat-card .stat-value {
    font-size: 1.75rem; font-weight: 800; color: var(--text-heading);
    font-variant-numeric: tabular-nums;
}

.stat-card .stat-label {
    font-size: 0.75rem; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: 0.5px; margin-top: 0.25rem;
}

/* ── Athlete Grid (Dashboard) ────────────────────────────── */

.athlete-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1rem;
}

.athlete-card {
    background: var(--bg-card);
    border: 1px solid var(--border-card);
    border-radius: var(--radius);
    padding: 1.25rem;
    cursor: pointer;
    transition: all var(--transition);
}
.athlete-card:hover { border-color: var(--accent); transform: translateY(-1px); }

.athlete-card-header {
    display: flex; align-items: center; gap: 0.75rem; margin-bottom: 1rem;
}

.athlete-avatar {
    width: 40px; height: 40px; border-radius: 50%;
    background: rgba(249, 115, 22, 0.2);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 1rem; color: var(--accent);
    flex-shrink: 0;
}

.athlete-name { font-weight: 600; color: var(--text-heading); font-size: 1rem; }
.athlete-meta { font-size: 0.75rem; color: var(--text-muted); }

.athlete-stats {
    display: flex; gap: 1rem; flex-wrap: wrap;
}

.athlete-stat {
    text-align: center; min-width: 60px;
}

.athlete-stat .val {
    font-size: 1.1rem; font-weight: 700;
    font-variant-numeric: tabular-nums;
}
.athlete-stat .lbl {
    font-size: 0.65rem; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: 0.5px;
}

.sam-positive { color: var(--green); }
.sam-negative { color: var(--red); }
.sam-neutral { color: var(--yellow); }

/* ── Athlete List (Athletes tab) ─────────────────────────── */

.athlete-list { display: flex; flex-direction: column; gap: 0.5rem; }

.athlete-row {
    display: flex; align-items: center; gap: 1rem;
    padding: 0.75rem 1rem;
    background: var(--bg-card); border: 1px solid var(--border-card);
    border-radius: var(--radius-sm); cursor: pointer;
    transition: all var(--transition);
}
.athlete-row:hover { border-color: var(--accent); }

.athlete-row .row-stats { display: flex; gap: 1.5rem; margin-left: auto; }
.athlete-row .row-stat { text-align: right; }
.athlete-row .row-stat .val { font-size: 0.95rem; font-weight: 600; }
.athlete-row .row-stat .lbl { font-size: 0.65rem; color: var(--text-muted); text-transform: uppercase; }

/* ── Detail View ─────────────────────────────────────────── */

.detail-tabs {
    display: flex; gap: 0.25rem;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-card);
    padding-bottom: 0;
}

.tab-btn {
    background: transparent; border: none;
    color: var(--text-secondary); font-size: 0.85rem; font-weight: 500;
    padding: 0.65rem 1rem; cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all var(--transition);
    font-family: inherit;
}
.tab-btn:hover { color: var(--text-primary); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

.detail-content { min-height: 400px; }

/* ── Detail Cards ────────────────────────────────────────── */

.detail-section {
    margin-bottom: 1.5rem;
}

.detail-section h3 {
    font-size: 1rem; font-weight: 600; color: var(--text-heading);
    margin-bottom: 0.75rem;
    display: flex; align-items: center; gap: 0.5rem;
}

.detail-card {
    background: var(--bg-card);
    border: 1px solid var(--border-card);
    border-radius: var(--radius);
    padding: 1.25rem;
}

.detail-stats-row {
    display: flex; gap: 2rem; flex-wrap: wrap;
}

.detail-stat {
    text-align: center;
}
.detail-stat .val {
    font-size: 1.5rem; font-weight: 800;
    font-variant-numeric: tabular-nums;
}
.detail-stat .lbl {
    font-size: 0.7rem; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: 0.5px; margin-top: 0.15rem;
}

/* ── Chart Container ─────────────────────────────────────── */

.chart-container {
    background: var(--bg-card);
    border: 1px solid var(--border-card);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1.5rem;
}

.chart-container canvas {
    width: 100% !important;
    max-height: 280px;
}

/* ── Readiness Badge ─────────────────────────────────────── */

.readiness-badge {
    display: inline-flex; align-items: center; gap: 0.35rem;
    padding: 0.25rem 0.6rem; border-radius: 20px;
    font-size: 0.75rem; font-weight: 600;
}
.readiness-ready { background: rgba(52, 211, 153, 0.15); color: var(--green); }
.readiness-moderate { background: rgba(251, 191, 36, 0.15); color: var(--yellow); }
.readiness-fatigued { background: rgba(239, 68, 68, 0.15); color: var(--red); }

/* ── Workout Row ─────────────────────────────────────────── */

.workout-list { display: flex; flex-direction: column; gap: 0.5rem; }

.workout-row {
    display: flex; align-items: center; gap: 1rem;
    padding: 0.75rem 1rem;
    background: var(--bg-card-highlight);
    border-radius: var(--radius-sm);
}

.workout-date { font-size: 0.8rem; color: var(--text-muted); min-width: 75px; }
.workout-label { font-size: 0.85rem; font-weight: 500; color: var(--text-primary); flex: 1; }
.workout-stats { display: flex; gap: 1.25rem; }
.workout-stat { text-align: right; }
.workout-stat .val { font-size: 0.9rem; font-weight: 600; }
.workout-stat .lbl { font-size: 0.6rem; color: var(--text-muted); text-transform: uppercase; }

/* ── Planned Workout Row ─────────────────────────────────── */

.planned-row {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.65rem 1rem;
    background: var(--bg-card-highlight);
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--accent);
}

.planned-row .planned-day { font-size: 0.8rem; color: var(--text-muted); min-width: 35px; }
.planned-row .planned-label { font-size: 0.85rem; font-weight: 500; color: var(--text-primary); flex: 1; }
.planned-row .planned-details { font-size: 0.8rem; color: var(--text-secondary); }

/* ── Phase/Milestone Rows ────────────────────────────────── */

.phase-row {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.65rem 1rem;
    background: var(--bg-card-highlight);
    border-radius: var(--radius-sm);
}

.phase-color {
    width: 8px; height: 32px; border-radius: 4px; flex-shrink: 0;
}

.phase-name { font-size: 0.85rem; font-weight: 600; color: var(--text-primary); }
.phase-dates { font-size: 0.75rem; color: var(--text-muted); }

.milestone-row {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.65rem 1rem;
    background: var(--bg-card-highlight);
    border-radius: var(--radius-sm);
}

.milestone-icon { font-size: 1.2rem; }
.milestone-name { font-size: 0.85rem; font-weight: 600; color: var(--text-primary); }
.milestone-date { font-size: 0.75rem; color: var(--text-muted); }

/* ── Soreness / Injury ───────────────────────────────────── */

.soreness-row {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.5rem 0.75rem;
}

.soreness-dot {
    width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
}
.soreness-mild { background: var(--yellow); }
.soreness-moderate { background: var(--accent); }
.soreness-severe { background: var(--red); }

/* ── Groups ──────────────────────────────────────────────── */

.groups-list { display: flex; flex-direction: column; gap: 0.75rem; }

.group-card {
    background: var(--bg-card);
    border: 1px solid var(--border-card);
    border-radius: var(--radius);
    padding: 1.25rem;
    cursor: pointer;
    transition: all var(--transition);
}
.group-card:hover { border-color: var(--accent); }

.group-header { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 0.75rem; }
.group-type-badge {
    font-size: 0.7rem; font-weight: 700; text-transform: uppercase;
    padding: 0.2rem 0.5rem; border-radius: 4px; letter-spacing: 0.5px;
}
.group-name { font-size: 1.1rem; font-weight: 600; color: var(--text-heading); }
.group-count { font-size: 0.8rem; color: var(--text-secondary); }

.group-athletes { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.group-athlete-chip {
    font-size: 0.75rem; padding: 0.2rem 0.5rem;
    background: var(--bg-card-highlight); border-radius: 4px;
    color: var(--text-secondary);
}

/* ── Modal ────────────────────────────────────────────────── */

.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.65);
    display: flex; align-items: center; justify-content: center;
    z-index: 200; backdrop-filter: blur(4px);
}

.modal-container {
    background: var(--bg-card);
    border: 1px solid var(--border-card);
    border-radius: var(--radius);
    padding: 1.5rem;
    max-width: 500px; width: 90%;
    max-height: 85vh; overflow-y: auto;
}

.modal-title {
    font-size: 1.1rem; font-weight: 700; color: var(--text-heading);
    margin-bottom: 1rem;
}

.modal-actions {
    display: flex; gap: 0.75rem; justify-content: flex-end;
    margin-top: 1.25rem;
}

/* ── Form Elements ───────────────────────────────────────── */

.form-group { margin-bottom: 1rem; }
.form-label {
    display: block; font-size: 0.8rem; font-weight: 500;
    color: var(--text-secondary); margin-bottom: 0.35rem;
}

.form-input, .form-select, .form-textarea {
    width: 100%; padding: 0.5rem 0.75rem;
    background: var(--bg-input); border: 1px solid var(--border-input);
    border-radius: var(--radius-sm); color: var(--text-primary);
    font-size: 0.9rem; font-family: inherit;
    transition: border-color var(--transition);
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
    outline: none; border-color: var(--accent);
}
.form-textarea { resize: vertical; min-height: 80px; }
.form-select { appearance: none; cursor: pointer; }

.form-row { display: flex; gap: 0.75rem; }
.form-row .form-group { flex: 1; }

/* ── Toast ────────────────────────────────────────────────── */

.toast-container {
    position: fixed; bottom: 1.5rem; right: 1.5rem;
    display: flex; flex-direction: column; gap: 0.5rem;
    z-index: 300;
}

.toast {
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem; font-weight: 500;
    animation: slideInRight 0.3s ease;
    max-width: 350px;
}

.toast-success { background: rgba(52, 211, 153, 0.15); color: var(--green); border: 1px solid rgba(52, 211, 153, 0.3); }
.toast-error { background: rgba(239, 68, 68, 0.15); color: var(--red); border: 1px solid rgba(239, 68, 68, 0.3); }
.toast-info { background: rgba(96, 165, 250, 0.15); color: var(--blue); border: 1px solid rgba(96, 165, 250, 0.3); }

@keyframes slideInRight {
    from { transform: translateX(100px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ── Loading Spinner ─────────────────────────────────────── */

.spinner {
    display: inline-block; width: 20px; height: 20px;
    border: 2px solid var(--text-muted); border-top-color: var(--accent);
    border-radius: 50%; animation: spin 0.6s linear infinite;
}

.loading-state {
    display: flex; flex-direction: column; align-items: center;
    justify-content: center; padding: 3rem; gap: 1rem;
    color: var(--text-muted);
}

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

/* ── Empty State ─────────────────────────────────────────── */

.empty-state {
    text-align: center; padding: 3rem 2rem;
    color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 2.5rem; margin-bottom: 0.75rem; }
.empty-state .empty-text { font-size: 0.9rem; }

/* ── Budget Badge ────────────────────────────────────────── */

.budget-bar {
    height: 6px; border-radius: 3px; background: var(--bg-card-highlight);
    overflow: hidden; margin-top: 0.5rem;
}
.budget-fill { height: 100%; border-radius: 3px; transition: width 0.5s ease; }
.budget-safe { background: var(--green); }
.budget-warning { background: var(--yellow); }
.budget-over { background: var(--red); }

/* ── Join Requests ───────────────────────────────────────── */

.request-row {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.65rem 1rem;
    background: var(--bg-card-highlight);
    border-radius: var(--radius-sm);
    margin-bottom: 0.5rem;
}

.request-name { flex: 1; font-size: 0.9rem; color: var(--text-primary); }
.request-actions { display: flex; gap: 0.5rem; }

/* ── Responsive ──────────────────────────────────────────── */

@media (max-width: 768px) {
    .sidebar { display: none; }
    .main-content { padding: 1rem; }
    .athlete-grid { grid-template-columns: 1fr; }
    .detail-stats-row { gap: 1rem; }
    .stats-row { flex-direction: column; }
    .nav-title { display: none; }
    .nav-divider { display: none; }

    /* Mobile nav */
    .app-layout { flex-direction: column; }
    .mobile-nav {
        display: flex; justify-content: space-around;
        background: var(--bg-card); border-top: 1px solid var(--border-card);
        padding: 0.5rem 0;
    }
}
