/* Global Styles */

/* Theme colours (admin-editable; overridden at runtime via JS setting these
   custom properties on :root). Light row tints are derived with color-mix. */
:root {
    --c-primary: #4f46e5;
    --c-success: #2e9e5b;
    --c-danger:  #dc3545;
    --c-warning: #f0ad4e;
    --c-navbar:  #b7410e;  /* rusty orange banner */
    --c-link:    #b7410e;  /* content links & dashboard figures */
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: #f5f5f5;
    color: #333;
    line-height: 1.6;
    padding-top: 60px; /* space for the fixed navbar */
}

/* Content links use the link colour (more specific rules — nav links,
   buttons — override this). */
a {
    color: var(--c-link);
}
a:hover {
    text-decoration: underline;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* Auth Pages */
.auth-page {
    background: linear-gradient(135deg, var(--c-navbar) 0%, color-mix(in srgb, var(--c-navbar) 55%, #f0ad4e) 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.auth-container {
    max-width: 400px;
}

.auth-box {
    background: white;
    padding: 40px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.auth-box h1 {
    text-align: center;
    margin-bottom: 10px;
    color: var(--c-link);
}

.auth-box h2 {
    text-align: center;
    font-size: 1.5em;
    margin-bottom: 30px;
    color: #333;
}

.auth-link {
    text-align: center;
    margin-top: 20px;
    font-size: 0.9em;
}

.auth-link a {
    color: var(--c-link);
    text-decoration: none;
}

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

/* Hide the fixed navbar while a workout is active (reclaim its space). */
body.workout-active #navbar { display: none; }
body.workout-active { padding-top: 0; }

/* Layout */
.navbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 1000;
    background: var(--c-navbar);
    color: white;
    padding: 10px 0;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.15);
}

.navbar-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    justify-content: space-between;  /* nav on the left, brand on the right */
    align-items: center;
    gap: 12px;
    overflow-x: auto;
}

.navbar h1 {
    font-size: 1.5em;
}

.nav-links {
    display: flex;
    gap: 20px;
    list-style: none;
}

.nav-links a {
    color: white;
    text-decoration: none;
}

.nav-links a:hover,
.nav-links a:focus,
.nav-links a:active {
    color: white;
    font-weight: 700;
}

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

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
}

.form-control {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 1em;
}

.form-control:focus {
    outline: none;
    border-color: var(--c-primary);
    box-shadow: 0 0 5px color-mix(in srgb, var(--c-primary) 40%, transparent);
}

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

select.form-control {
    cursor: pointer;
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1em;
    transition: all 0.3s ease;
}

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

.btn-primary:hover {
    background: color-mix(in srgb, var(--c-primary) 85%, black);
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
}

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

.btn-danger:hover {
    background: color-mix(in srgb, var(--c-danger) 85%, black);
}

.btn-sm {
    padding: 5px 10px;
    font-size: 0.9em;
}

/* Alerts */
.alert {
    padding: 15px;
    border-radius: 4px;
    margin-bottom: 20px;
    position: fixed;
    top: 70px;            /* below the fixed navbar */
    right: 20px;
    z-index: 1100;        /* above the navbar (1000) */
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        transform: translateX(400px);
    }
    to {
        transform: translateX(0);
    }
}

.alert-success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.alert-error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

/* Bouldering / "passed" toggle button (amber). */
.set-fail-on {
    background: var(--c-warning);
    border-color: var(--c-warning);
    color: #fff;
}

/* Workout-detail meta chips: soft, icon-led, gently coloured. */
.wo-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}
.wo-meta-item {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 8px 13px;
    border-radius: 12px;
    background: color-mix(in srgb, var(--c-navbar) 7%, white);
    border: 1px solid color-mix(in srgb, var(--c-navbar) 14%, white);
}
.wo-meta-ic { font-size: 20px; line-height: 1; }
.wo-meta-val { font-weight: 600; color: #555; font-size: 0.95em; }
.wo-meta-lbl {
    font-size: 0.68em;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #b0a8a3;
}

/* Missed activity blocks on the workout detail — struck-through titles. */
.missed-list {
    list-style: none;
    padding: 0;
    margin: 0;
}
.missed-list li {
    color: #999;
    padding: 2px 0;
}

/* Resolved set rows: green when completed, red when passed (light tints). */
.set-row.set-complete > td { background: color-mix(in srgb, var(--c-success) 16%, white); }
.set-row.set-passed > td { background: color-mix(in srgb, var(--c-danger) 14%, white); }

/* Pinned workout action bar (Start / Finish) */
.wo-actionbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    display: flex;
    gap: 10px;
    justify-content: center;
    padding: 10px 16px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    background: #fff;
    border-top: 1px solid #e2e2e2;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.08);
}
.wo-actionbar .btn {
    flex: 1;
    max-width: 220px;
    margin: 0;
}
/* Keep the last content clear of the fixed bar. */
#workout-area:not(.hidden) {
    padding-bottom: 84px;
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1200;
    padding: 16px;
}
.modal-box {
    background: #fff;
    border-radius: 8px;
    padding: 20px;
    width: 100%;
    max-width: 360px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
}

/* Avatar */
.avatar-lg {
    width: 96px;
    height: 96px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid #e2e2e2;
}
.avatar-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 44px;
    background: #f0f0f0;
    color: #9e9e9e;
}

/* Badges */
.badge {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 600;
    line-height: 1;
    padding: 3px 8px;
    border-radius: 10px;
    vertical-align: middle;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.badge-public {
    background: #e0e7ff;
    color: #3730a3;
}
.badge-private {
    background: #eee;
    color: #555;
}

/* Cards */
.card {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    margin-bottom: 20px;
}

.card h3 {
    margin-top: 0;
    margin-bottom: 15px;
    color: #333;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 20px;
}

/* List */
.list-group {
    list-style: none;
}

.list-item {
    background: white;
    padding: 15px;
    border: 1px solid #eee;
    margin-bottom: 10px;
    border-radius: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.list-item:hover {
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.list-item-actions {
    display: flex;
    gap: 10px;
}

/* Dashboard */
.dashboard-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.stat-card {
    background: white;
    padding: 14px 10px;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    text-align: center;
}

.stat-card .number {
    font-size: 1.6em;
    font-weight: bold;
    color: var(--c-link);
    margin: 6px 0;
}

.stat-card .label {
    color: #999;
    font-size: 0.8em;
}

/* Timer */
.timer {
    font-size: 2em;
    font-weight: bold;
    text-align: center;
    padding: 20px;
    background: #f0f0f0;
    border-radius: 8px;
    font-family: monospace;
}

.timer-controls {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 15px;
}

/* Table */
table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

table th {
    background: #f0f0f0;
    padding: 12px;
    text-align: left;
    font-weight: 600;
    border-bottom: 2px solid #ddd;
}

table td {
    padding: 12px;
    border-bottom: 1px solid #eee;
}

table tr:hover {
    background: #f9f9f9;
}

/* These data tables should fill their card and spread columns evenly on
   larger screens (on mobile they switch to horizontal scroll below). */
#trend-table, #workouts-table {
    width: 100%;
    table-layout: fixed;
}
#trend-table td, #trend-table th { text-align: center; }
#trend-table td:first-child, #trend-table th:first-child { text-align: left; width: 3em; }

/* Responsive */
@media (max-width: 768px) {
    /* Navbar: fit the whole bar on screen (no horizontal scroll). Stack a
       small label under each icon, drop the "Cadence" wordmark to just the
       logo, and tighten spacing. */
    .navbar-content { padding: 0 12px; gap: 8px; overflow-x: hidden; }
    .nav-icons { gap: 10px; }
    .nav-icons a { flex-direction: column; gap: 2px; }
    .nav-lbl { font-size: 10px; line-height: 1; }
    .brand-text { display: none; }
    .navbar h1 { font-size: 1em; }

    .card-grid {
        grid-template-columns: 1fr;
    }

    /* Keep the stat pills packing ~3 across on phones (not one per row). */
    .dashboard-stats {
        grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
        gap: 10px;
    }

    .list-item {
        flex-direction: column;
        gap: 10px;
        align-items: flex-start;
    }

    .list-item-actions {
        width: 100%;
        justify-content: flex-end;
    }

    /* Tables scroll within their card instead of overrunning the screen. */
    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
        box-shadow: none;
    }
    table th, table td { padding: 8px 10px; font-size: 0.85rem; }
}

/* Utilities */
.mt-20 { margin-top: 20px; }
.mb-20 { margin-bottom: 20px; }
.text-center { text-align: center; }
.text-muted { color: #999; }
.hidden { display: none !important; }

/* Type-to-search combobox */
.combobox { position: relative; }
.cb-list {
    position: absolute;
    left: 0; right: 0; top: 100%;
    z-index: 1000;
    background: #fff;
    border: 1px solid #ccc;
    border-top: none;
    max-height: 220px;
    overflow-y: auto;
    border-radius: 0 0 6px 6px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.08);
}
.cb-item { padding: 8px 10px; cursor: pointer; }
.cb-item:hover { background: #eef; }
.cb-empty { padding: 8px 10px; color: #999; }

/* Location image thumbnails + lightbox */
.loc-thumb {
    width: 64px; height: 64px;
    object-fit: cover;
    border-radius: 6px;
    cursor: pointer;
    border: 1px solid #ddd;
}
.thumb-wrap { position: relative; display: inline-block; }
.thumb-del {
    position: absolute; top: -6px; right: -6px;
    background: #dc3545; color: #fff; border: none;
    width: 20px; height: 20px; border-radius: 50%;
    cursor: pointer; line-height: 1; font-size: 13px;
}
.lightbox {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.9);
    display: none; align-items: center; justify-content: center;
    z-index: 2000; cursor: zoom-out;
}
.lightbox.open { display: flex; }
.lightbox img { max-width: 95vw; max-height: 95vh; border-radius: 4px; }

/* Set-based workout logger */
.set-table { border-collapse: collapse; }
.set-table th, .set-table td { padding: 4px 5px; text-align: center; vertical-align: middle; }
.set-table thead th { font-size: 0.8em; color: #666; font-weight: 500; }
.set-table input.set-input { padding: 5px; text-align: center; }
.set-table .btn-sm { padding: 4px 8px; }

/* Inline sprite icons */
.ic { width: 22px; height: 22px; display: inline-block; vertical-align: middle; }

/* Icon navbar — icons + labels on one line, left-aligned */
.nav-icons { gap: 18px; flex-wrap: nowrap; }
.nav-icons a { display: inline-flex; flex-direction: row; align-items: center; gap: 6px; white-space: nowrap; }
.nav-lbl { font-size: 14px; }

/* Settings pills */
.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
    margin-top: 10px;
}
.settings-pill {
    display: flex; align-items: center; gap: 12px;
    padding: 14px 20px;
    border-radius: 999px;
    background: #fff;
    border: 1px solid #ddd;
    color: #333;
    text-decoration: none;
    font-weight: 500;
}
.settings-pill:hover { border-color: var(--c-link); color: var(--c-link); }
.settings-pill .pill-ic { font-size: 22px; }
