*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --success: #16a34a;
    --warning: #d97706;
    --danger: #dc2626;
    --info: #0891b2;
    --bg: #f8fafc;
    --surface: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --radius: 8px;
    --warmup: #f59e0b;
    --cooldown: #8b5cf6;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

/* Navigation */
nav {
    background: var(--primary);
    padding: 0.75rem 1rem;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

nav .nav-inner {
    max-width: 960px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem;
}

nav .brand {
    color: white;
    font-size: 1.25rem;
    font-weight: 700;
    text-decoration: none;
}

nav .nav-links {
    display: flex;
    gap: 0.25rem;
    flex-wrap: wrap;
}

nav a {
    color: rgba(255,255,255,0.85);
    text-decoration: none;
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    transition: background 0.15s;
}

nav a:hover, nav a.active {
    background: rgba(255,255,255,0.15);
    color: white;
}

/* Main content */
main {
    max-width: 960px;
    margin: 0 auto;
    padding: 1.5rem 1rem;
}

h1 {
    font-size: 1.75rem;
    margin-bottom: 1rem;
}

h2 {
    font-size: 1.35rem;
    margin-bottom: 0.75rem;
}

h3 {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
}

/* Cards */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

/* Flash messages */
.flash {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-weight: 500;
}

.flash.success {
    background: #dcfce7;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.flash.error {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.flash.info {
    background: #ecfeff;
    color: #155e75;
    border: 1px solid #a5f3fc;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.6rem 1.25rem;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    transition: background 0.15s, transform 0.1s;
    min-height: 44px;
    min-width: 44px;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-success {
    background: var(--success);
    color: white;
}

.btn-success:hover {
    background: #15803d;
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-secondary {
    background: #e2e8f0;
    color: var(--text);
}

.btn-delete {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.3rem;
    line-height: 1;
    padding: 0.2rem 0.5rem;
    cursor: pointer;
    border-radius: 4px;
}
.btn-delete:hover {
    background: var(--danger);
    color: white;
}

.btn-secondary:hover {
    background: #cbd5e1;
}

/* Forms */
label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.3rem;
    font-size: 0.95rem;
}

input[type="text"],
input[type="number"],
input[type="email"],
input[type="password"],
select,
textarea {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
    font-family: inherit;
    background: var(--surface);
    min-height: 44px;
}

textarea {
    resize: vertical;
    min-height: 80px;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.form-group {
    margin-bottom: 1rem;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1rem;
}

th, td {
    padding: 0.6rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

th {
    font-weight: 600;
    background: #f1f5f9;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

tr:hover {
    background: #f8fafc;
}

/* Workout logging table */
.log-table input[type="number"],
.log-table input[type="text"] {
    width: 100%;
    min-width: 60px;
    padding: 0.5rem;
}

.log-table td {
    padding: 0.4rem;
}

/* Stats grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    text-align: center;
}

.stat-card .stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
}

.stat-card .stat-label {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.streak-value {
    color: var(--warning) !important;
}

/* Feeling rating */
.feeling-group {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.feeling-group label {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-weight: normal;
    cursor: pointer;
    padding: 0.4rem 0.75rem;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    min-height: 44px;
    min-width: 44px;
    justify-content: center;
}

.feeling-group input[type="radio"] {
    display: none;
}

.feeling-group input[type="radio"]:checked + span {
    color: var(--primary);
    font-weight: 700;
}

.feeling-group label:has(input:checked) {
    border-color: var(--primary);
    background: rgba(37, 99, 235, 0.05);
}

/* Exercise block in workout view */
.exercise-block {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1.25rem;
}

.exercise-block h3 {
    color: var(--primary);
    margin-bottom: 0.25rem;
}

.exercise-meta {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

/* Links as rows */
.link-row {
    display: block;
    padding: 1rem;
    text-decoration: none;
    color: var(--text);
    border-bottom: 1px solid var(--border);
    transition: background 0.1s;
}

.link-row:hover {
    background: #f1f5f9;
}

.link-row:last-child {
    border-bottom: none;
}

/* Review sections */
.review-section {
    margin-bottom: 1.5rem;
}

.review-section h3 {
    padding-bottom: 0.3rem;
    border-bottom: 2px solid var(--primary);
    margin-bottom: 0.5rem;
}

/* ===== Loading Overlay ===== */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 2.5rem 3rem;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    max-width: 360px;
}

.loading-card h2 {
    margin-bottom: 0.25rem;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    margin: 0 auto 1rem;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-timer {
    font-family: "SF Mono", "Fira Code", "Courier New", monospace;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    margin-top: 0.75rem;
}

/* ===== Timer Card ===== */
.timer-card {
    background: var(--surface);
    border: 2px solid var(--primary);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1.5rem;
    position: sticky;
    top: 60px;
    z-index: 50;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.timer-card.timer-done {
    border-color: var(--success);
    animation: timer-pulse 0.5s ease-in-out 3;
}

@keyframes timer-pulse {
    0%, 100% { box-shadow: 0 4px 12px rgba(0,0,0,0.1); }
    50% { box-shadow: 0 4px 20px rgba(22, 163, 74, 0.4); }
}

.timer-row {
    display: flex;
    justify-content: space-around;
    margin-bottom: 0.75rem;
}

.timer-section {
    text-align: center;
}

.timer-label {
    display: block;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    font-weight: 600;
}

.timer-display {
    font-family: "SF Mono", "Fira Code", "Courier New", monospace;
    font-size: 2rem;
    font-weight: 700;
    color: var(--text);
}

.timer-buttons {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
}

.btn-timer {
    padding: 0.5rem 1rem;
    border: 2px solid var(--primary);
    background: white;
    color: var(--primary);
    border-radius: var(--radius);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    min-height: 44px;
    min-width: 44px;
    transition: background 0.15s, color 0.15s;
}

.btn-timer:hover {
    background: var(--primary);
    color: white;
}

.btn-timer-stop {
    border-color: var(--danger);
    color: var(--danger);
}

.btn-timer-stop:hover {
    background: var(--danger);
    color: white;
}

/* ===== Section Headers (Warm-Up / Main / Cool-Down) ===== */
.section-header {
    font-size: 1.1rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    margin-top: 0.5rem;
}

.warmup-header {
    background: rgba(245, 158, 11, 0.1);
    color: var(--warmup);
    border-left: 4px solid var(--warmup);
}

.main-header {
    background: rgba(37, 99, 235, 0.1);
    color: var(--primary);
    border-left: 4px solid var(--primary);
}

.cooldown-header {
    background: rgba(139, 92, 246, 0.1);
    color: var(--cooldown);
    border-left: 4px solid var(--cooldown);
}

.warmup-block {
    border-left: 3px solid var(--warmup);
}

.cooldown-block {
    border-left: 3px solid var(--cooldown);
}

/* ===== Form Cues ===== */
.form-cues {
    margin: 0.5rem 0;
    font-size: 0.9rem;
}

.form-cues summary {
    cursor: pointer;
    color: var(--info);
    font-weight: 600;
    padding: 0.3rem 0;
}

.form-cues p {
    padding: 0.5rem;
    background: #f0f9ff;
    border-radius: var(--radius);
    color: var(--text);
    margin-top: 0.25rem;
    line-height: 1.5;
}

/* ===== Last Performance Badge ===== */
.last-perf-badge {
    display: inline-block;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: var(--radius);
    padding: 0.25rem 0.75rem;
    font-size: 0.8rem;
    color: var(--primary-dark);
    font-weight: 600;
    margin-bottom: 0.5rem;
}

/* ===== Phase Card & Timeline ===== */
.phase-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
    border-left: 4px solid var(--primary);
}

.phase-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 0.5rem;
}

.phase-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.phase-badge.progressive {
    background: #dbeafe;
    color: #1e40af;
}

.phase-badge.recovery {
    background: #fef3c7;
    color: #92400e;
}

.phase-timeline {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.phase-timeline-item {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    transition: box-shadow 0.15s;
}

.phase-timeline-item.active {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
    background: #f8faff;
}

.phase-timeline-item.active.recovery {
    border-color: var(--warning);
    box-shadow: 0 0 0 2px rgba(217, 119, 6, 0.2);
}

.phase-timeline-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}

.phase-timeline-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

.phase-preview {
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0.5rem;
}

.phase-preview:last-child {
    border-bottom: none;
}

/* ===== Type Badge (warmup/main/cooldown) ===== */
.type-badge {
    display: inline-block;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
}

.type-badge.warmup {
    background: rgba(245, 158, 11, 0.15);
    color: #b45309;
}

.type-badge.main {
    background: rgba(37, 99, 235, 0.1);
    color: var(--primary-dark);
}

.type-badge.cooldown {
    background: rgba(139, 92, 246, 0.15);
    color: #6d28d9;
}

.exercise-row-warmup {
    background: rgba(245, 158, 11, 0.03);
}

.exercise-row-cooldown {
    background: rgba(139, 92, 246, 0.03);
}

/* ===== Calendar ===== */
.calendar-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.calendar-nav h2 {
    margin-bottom: 0;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.cal-header {
    text-align: center;
    padding: 0.5rem;
    font-weight: 700;
    font-size: 0.8rem;
    text-transform: uppercase;
    color: var(--text-muted);
    background: #f1f5f9;
}

.cal-day {
    text-align: center;
    padding: 0.75rem 0.25rem;
    min-height: 60px;
    position: relative;
    background: var(--surface);
    border: 1px solid transparent;
}

.cal-day.empty {
    background: #f8fafc;
}

.cal-day.today {
    border: 2px solid var(--primary);
    font-weight: 700;
}

.cal-day.completed {
    background: #dcfce7;
}

.cal-day.missed {
    background: #fef2f2;
}

.cal-day.planned {
    background: #eff6ff;
}

.cal-day-num {
    font-size: 0.95rem;
}

.cal-check {
    display: block;
    color: var(--success);
    font-size: 1.1rem;
    font-weight: 700;
}

.cal-miss {
    display: block;
    color: var(--danger);
    font-size: 0.9rem;
    opacity: 0.6;
}

.calendar-legend {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
    justify-content: center;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.legend-dot {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 3px;
}

.legend-dot.completed { background: #dcfce7; border: 1px solid #bbf7d0; }
.legend-dot.missed { background: #fef2f2; border: 1px solid #fecaca; }
.legend-dot.today { border: 2px solid var(--primary); background: white; }
.legend-dot.planned { background: #eff6ff; border: 1px solid #bfdbfe; }

/* ===== Mini Calendar (Dashboard) ===== */
.mini-calendar {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    justify-content: center;
}

.mini-day {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.5rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    min-width: 50px;
}

.mini-day.today {
    border-color: var(--primary);
    border-width: 2px;
}

.mini-day.completed {
    background: #dcfce7;
    border-color: #bbf7d0;
}

.mini-day-name {
    font-size: 0.7rem;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 600;
}

.mini-day-num {
    font-size: 1.1rem;
    font-weight: 700;
}

.mini-check {
    color: var(--success);
    font-weight: 700;
    font-size: 0.9rem;
}

/* ===== Streak Display ===== */
.streak-display {
    text-align: center;
    font-size: 1rem;
    color: var(--text-muted);
    padding: 0.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

/* ===== Nutrition Tip Box ===== */
.nutrition-tip {
    background: #fef9c3;
    border: 1px solid #fde68a;
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    margin-top: 0.75rem;
    font-size: 0.9rem;
    color: #713f12;
}

/* Utility */
.text-muted {
    color: var(--text-muted);
}

.text-center {
    text-align: center;
}

.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }

.flex-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* Responsive */
@media (max-width: 600px) {
    .form-row {
        grid-template-columns: 1fr;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }

    nav .nav-links {
        width: 100%;
        justify-content: center;
    }

    .log-table {
        font-size: 0.9rem;
    }

    .timer-display {
        font-size: 1.5rem;
    }

    .mini-calendar {
        gap: 0.25rem;
    }

    .mini-day {
        min-width: 40px;
        padding: 0.3rem;
    }

    .cal-day {
        min-height: 45px;
        padding: 0.4rem 0.1rem;
    }

    .calendar-legend {
        gap: 0.75rem;
    }

    .phase-header {
        flex-direction: column;
        align-items: flex-start;
    }
}

/* ===== Add/Remove Set Controls ===== */
.set-controls {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.25rem;
    margin-bottom: 0.5rem;
}

.btn-set-mod {
    padding: 0.35rem 0.85rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    min-height: 36px;
    transition: background 0.15s, color 0.15s;
}

.btn-set-add {
    background: rgba(22, 163, 74, 0.1);
    color: var(--success);
    border: 1px solid rgba(22, 163, 74, 0.3);
}

.btn-set-add:hover {
    background: var(--success);
    color: white;
}

.btn-set-remove {
    background: rgba(220, 38, 38, 0.08);
    color: var(--danger);
    border: 1px solid rgba(220, 38, 38, 0.25);
}

.btn-set-remove:hover {
    background: var(--danger);
    color: white;
}

/* Workout switcher on today's workout page */
.workout-switcher {
    margin-bottom: 1rem;
}
.workout-switcher select {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.95rem;
    background: var(--card);
    color: var(--text);
    cursor: pointer;
}

/* Last-time reference rows in the workout logging table */
tr.last-time-row td {
    padding-top: 0;
    padding-bottom: 0.4rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.78rem;
    font-style: italic;
    color: var(--text-muted);
    vertical-align: top;
}

td.last-time-label {
    font-weight: 600;
    white-space: nowrap;
}

td.last-time-val {
    letter-spacing: 0.01em;
}

/* -------------------------------------------------------------------------
   Auth pages
   ------------------------------------------------------------------------- */

.auth-card {
    max-width: 420px;
    margin: 2rem auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
}

.auth-card h1 {
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
}

.auth-divider {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 1.25rem 0;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.auth-divider::before,
.auth-divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--border);
}

.auth-footer {
    margin-top: 1rem;
    text-align: center;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.form-check {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.form-check input[type="checkbox"] {
    width: auto;
}

.btn-block {
    display: block;
    width: 100%;
    text-align: center;
}

.btn-google {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.625rem 1rem;
    border-radius: var(--radius);
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 500;
    transition: background 0.15s;
}

.btn-google:hover {
    background: var(--bg);
}

.btn-secondary {
    background: var(--border);
    color: var(--text);
    border: none;
    padding: 0.625rem 1.25rem;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.95rem;
    text-decoration: none;
    display: inline-block;
}

/* Nav user info */
.nav-user {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
}

.nav-email {
    color: rgba(255,255,255,0.7);
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.nav-logout {
    color: rgba(255,255,255,0.85);
    text-decoration: none;
    padding: 0.3rem 0.6rem;
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: var(--radius);
    font-size: 0.8rem;
}

.nav-logout:hover {
    background: rgba(255,255,255,0.15);
}

.link-row-danger strong { color: var(--danger); }
