/* Run Coach - Shared Styles */

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --secondary: #64748b;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --bg: #f8fafc;
    --bg-card: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 6px rgba(0, 0, 0, 0.1);
}

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

/* The [hidden] attribute is only display:none in the UA stylesheet, so any author
   rule setting display (.form-row grid, .chat-quick flex) silently beats it and
   the element stays visible. Make hidden mean hidden. */
[hidden] {
    display: none !important;
}

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

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

.nav-brand {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
}

.nav-links {
    display: flex;
    gap: 1.5rem;
}

.nav-links a {
    color: var(--secondary);
    text-decoration: none;
    font-weight: 500;
    padding: 0.5rem 0;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}

.nav-links a:hover,
.nav-links a.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

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

/* Headings */
h1 {
    font-size: 1.875rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
}

h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text);
}

/* Sections */
.section {
    margin-bottom: 2.5rem;
}

/* Summary Cards */
.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

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

.card-title {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.card-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text);
}

/* Activities List */
.activities-list {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 1rem;
}

.activity-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.2s;
}

.activity-row:last-child {
    border-bottom: none;
}

.activity-row:hover {
    background: var(--bg);
}

.activity-info {
    flex: 1;
}

.activity-name {
    font-weight: 600;
    margin-bottom: 0.25rem;
}

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

.activity-stats {
    display: flex;
    gap: 1.5rem;
}

.stat {
    text-align: right;
    min-width: 80px;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.stat-value {
    font-weight: 600;
}

/* Data Table */
.daily-table-container {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    border-collapse: collapse;
    font-size: 0.875rem;
}

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

.data-table th {
    background: var(--bg);
    font-weight: 600;
    color: var(--text-muted);
}

.data-table tbody tr:hover {
    background: var(--bg);
}

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

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.625rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    border-radius: var(--radius);
    border: none;
    cursor: pointer;
    transition: all 0.2s;
}

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

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--border);
}

/* Loading & Error States */
.loading,
.empty {
    padding: 2rem;
    text-align: center;
    color: var(--text-muted);
}

.error {
    padding: 2rem;
    text-align: center;
    color: var(--danger);
}

/* Activity Detail Page */
.activity-header {
    margin-bottom: 2rem;
}

.activity-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.activity-subtitle {
    color: var(--text-muted);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    text-align: center;
}

.stat-card .stat-label {
    display: block;
    margin-bottom: 0.25rem;
}

.stat-card .stat-value {
    font-size: 1.25rem;
}

/* Laps Table */
.laps-section {
    margin-top: 2rem;
}

.lap-table {
    font-size: 0.8125rem;
}

/* Back link */
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--secondary);
    text-decoration: none;
    margin-bottom: 1rem;
    font-size: 0.875rem;
}

.back-link:hover {
    color: var(--primary);
}

/* Responsive */
@media (max-width: 768px) {
    .navbar {
        padding: 1rem;
    }

    .container {
        padding: 1rem;
    }

    .activity-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .activity-stats {
        width: 100%;
        justify-content: space-between;
    }

    .stat {
        text-align: center;
        min-width: auto;
    }

    .summary-cards {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ============================================================
   Coach chat (coach.html)
   ============================================================ */

/* The chat column owns the viewport below the navbar so the log scrolls
   internally and the composer stays put — the page itself never scrolls. */
.chat-body {
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-shell {
    flex: 1;
    min-height: 0;
    width: 100%;
    max-width: 820px;
    margin: 0 auto;
    padding: 1.5rem 2rem 1rem;
    display: flex;
    flex-direction: column;
}

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

.chat-header h1 {
    margin-bottom: 0;
}

.chat-log {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding-right: 0.25rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Messages */
.msg {
    max-width: 85%;
    padding: 0.875rem 1.125rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.msg p {
    margin-bottom: 0.75rem;
}

.msg p:last-child,
.msg ul:last-child {
    margin-bottom: 0;
}

.msg ul {
    margin: 0 0 0.75rem 1.25rem;
}

.msg li {
    margin-bottom: 0.25rem;
}

.msg code {
    background: var(--bg);
    padding: 0.125rem 0.375rem;
    border-radius: 4px;
    font-size: 0.875em;
}

.msg-user {
    align-self: flex-end;
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.msg-assistant {
    align-self: flex-start;
    background: var(--bg-card);
    box-shadow: var(--shadow);
}

/* Pending state */
.msg.thinking {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.dots {
    display: inline-flex;
    gap: 4px;
}

.dots i {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: dot 1.4s infinite ease-in-out both;
}

.dots i:nth-child(2) { animation-delay: 0.16s; }
.dots i:nth-child(3) { animation-delay: 0.32s; }

@keyframes dot {
    0%, 80%, 100% { opacity: 0.25; }
    40% { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
    .dots i { animation: none; opacity: 0.6; }
}

/* Empty state and notices */
.chat-empty {
    margin: auto 0;
    text-align: center;
    color: var(--text-muted);
    padding: 2rem 1rem;
}

.chat-empty h2 {
    color: var(--text);
    margin-bottom: 0.5rem;
}

.chat-notice {
    align-self: center;
    text-align: center;
    font-size: 0.875rem;
    color: var(--text-muted);
    padding: 0.625rem 1rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.chat-notice.error {
    color: var(--danger);
    border-color: var(--danger);
}

.chat-notice.warn {
    color: var(--warning);
    border-color: var(--warning);
}

/* Quick actions */
.chat-quick {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 1rem 0 0.75rem;
}

.chip {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.4rem 0.875rem;
    font-size: 0.8125rem;
    font-family: inherit;
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s;
}

.chip:hover {
    border-color: var(--primary);
    color: var(--primary);
}

/* Composer */
.chat-input {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.625rem;
    box-shadow: var(--shadow);
}

.chat-input textarea {
    flex: 1;
    border: none;
    outline: none;
    resize: none;
    font-family: inherit;
    font-size: 0.9375rem;
    line-height: 1.5;
    color: var(--text);
    background: transparent;
    max-height: 200px;
}

.chat-input textarea:disabled {
    color: var(--text-muted);
}

.chat-input .btn {
    flex-shrink: 0;
}

.btn:disabled {
    opacity: 0.6;
    cursor: default;
}

.chat-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
    padding: 0.5rem 0 0.25rem;
}

@media (max-width: 768px) {
    .chat-shell {
        padding: 1rem 1rem 0.5rem;
    }

    .msg {
        max-width: 92%;
    }

    .chat-hint {
        display: none;
    }
}

/* ============================================================
   Auth (login.html) and dashboard banners
   ============================================================ */

.auth-container {
    max-width: 420px;
    margin: 3rem auto;
}

.auth-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: var(--shadow-lg);
}

.auth-title {
    text-align: center;
    margin-bottom: 0.5rem;
}

.auth-subtitle {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9375rem;
    margin-bottom: 1.5rem;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.375rem;
    font-weight: 500;
    font-size: 0.875rem;
}

.form-group input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
    font-family: inherit;
    color: var(--text);
    background: var(--bg-card);
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* First/last name sit side by side; they stack on narrow screens. */
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.field-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.375rem;
}

.auth-btn {
    width: 100%;
    padding: 0.875rem;
    font-size: 1rem;
    margin-top: 0.5rem;
}

.auth-switch {
    text-align: center;
    margin-top: 1.25rem;
    font-size: 0.875rem;
    color: var(--text-muted);
}

.auth-switch a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}

.auth-switch a:hover {
    text-decoration: underline;
}

.status-message {
    margin-top: 1rem;
    padding: 0.875rem 1rem;
    border-radius: var(--radius);
    text-align: center;
    font-size: 0.875rem;
}

.status-message.success {
    background: #d1fae5;
    color: #065f46;
}

.status-message.error {
    background: #fee2e2;
    color: #991b1b;
}

/* Dashboard banners — Garmin link prompt and link outcomes. */
.banner {
    padding: 1rem 1.25rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-card);
    margin-bottom: 1.5rem;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
}

.banner.prompt {
    border-color: var(--primary);
    background: #eff6ff;
}

.banner.success {
    border-color: var(--success);
    background: #d1fae5;
    color: #065f46;
}

.banner.error {
    border-color: var(--danger);
    background: #fee2e2;
    color: #991b1b;
}

.banner a:not(.btn) {
    color: inherit;
    font-weight: 600;
}

.banner-btn {
    margin-left: auto;
    text-decoration: none;
    white-space: nowrap;
}

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

    .banner-btn {
        margin-left: 0;
        width: 100%;
        text-align: center;
    }
}

/* Account page */
.account-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    max-width: 480px;
}

.account-card h2 {
    margin-bottom: 0.75rem;
}

.account-email {
    font-weight: 600;
    font-size: 1.0625rem;
}

.account-garmin {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin-top: 0.25rem;
}

/* Signed-out nav: only the Sign in link is useful, so the app links stay hidden
   until nav.js confirms a session. Hidden by default rather than removed on
   check, so a signed-out visitor never sees a menu flash into view and vanish.
   If the check fails the links stay hidden, which is right — they'd only bounce
   to the login page anyway. */
.nav-links .nav-app {
    display: none;
}

.nav-links.authed .nav-app {
    display: inline-block;
}

/* Status label on the thinking indicator — "Looking that up" while the coach
   searches, so a 25-second lookup reads as work rather than a hang. */
.msg.thinking .label {
    font-style: italic;
}
