/* Modern Runner's Logbook Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #f4f5f7;
}

.container {
    width: 90%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 15px;
}

header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 1.1rem 0;
    box-shadow: 0 2px 10px rgba(0,0,0,0.15);
    position: sticky;
    top: 0;
    z-index: 100;
}

header .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    flex-wrap: wrap;
}

.logo {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid rgba(255,255,255,0.35);
    flex-shrink: 0;
}

h1 {
    font-size: 1.6rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    margin-right: auto;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

/* Shared look for all header buttons (Add Race / Admin Login / Logout) */
.upload-btn,
.logout-btn,
.admin-login-btn {
    background: rgba(255,255,255,0.15);
    color: white;
    border: 1.5px solid rgba(255,255,255,0.8);
    padding: 0.6rem 1.3rem;
    font-size: 0.95rem;
    border-radius: 50px;
    cursor: pointer;
    transition: background 0.2s, transform 0.2s;
    font-weight: 600;
}

.upload-btn:hover,
.logout-btn:hover,
.admin-login-btn:hover {
    background: rgba(255,255,255,0.3);
    transform: translateY(-1px);
}

/* Language switcher: small segmented control, distinct from the admin
   controls since it's available to every visitor, not just the admin. */
.lang-switch {
    display: flex;
    border: 1.5px solid rgba(255,255,255,0.8);
    border-radius: 50px;
    overflow: hidden;
}

.lang-btn {
    background: transparent;
    color: white;
    border: none;
    padding: 0.55rem 0.9rem;
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    cursor: pointer;
    transition: background 0.2s;
}

.lang-btn:hover {
    background: rgba(255,255,255,0.2);
}

.lang-btn.active {
    background: rgba(255,255,255,0.9);
    color: #667eea;
}

.gallery-section {
    margin: 2.5rem 0;
}

.gallery-section h2,
.stats-section h2,
.calendar-section h2 {
    color: #4c3a94;
    margin-bottom: 1.5rem;
    text-align: center;
    font-size: 1.5rem;
    letter-spacing: -0.01em;
}

/* 3x3 grid on desktop, tapering down to one column on small screens (see
   media queries below). Only 9 races are ever in the DOM at once - more
   than that pages via #galleryControls (JS) instead of growing the grid. */
.gallery {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.75rem;
}

.no-races {
    grid-column: 1 / -1;
    text-align: center;
    color: #6c757d;
    background: white;
    border-radius: 10px;
    padding: 3rem 1.5rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}

.gallery-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1.5rem;
    margin-top: 1.5rem;
}

.gallery-controls button {
    background: #f0f1f7;
    border: none;
    color: #4c3a94;
    font-weight: 600;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s, opacity 0.2s;
}

.gallery-controls button:hover:not(:disabled) {
    background: #e2e4f2;
}

.gallery-controls button:disabled {
    opacity: 0.4;
    cursor: default;
}

.gallery-controls span {
    font-weight: 600;
    color: #2d2a3d;
    font-size: 0.9rem;
}

.race-card {
    background: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 3px 12px rgba(0,0,0,0.06);
    transition: transform 0.25s, box-shadow 0.25s;
    position: relative;
    display: flex;
    flex-direction: column;
}

.race-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 28px rgba(0,0,0,0.12);
}

.race-image {
    width: 100%;
    height: 260px;
    object-fit: cover;
    display: block;
}

.no-image-placeholder {
    width: 100%;
    height: 260px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #eef0f6;
    color: #9aa0b0;
    font-size: 0.85rem;
}

.race-info {
    padding: 1.4rem;
}

.race-info h3 {
    color: #2d2a3d;
    margin-bottom: 0.6rem;
    font-size: 1.15rem;
}

.race-info p {
    margin-bottom: 0.4rem;
    color: #6c757d;
    font-size: 0.92rem;
}

.race-description {
    color: #6c757d;
    margin-top: 0.75rem;
    line-height: 1.6;
}

.images-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 1rem;
}

.image-thumb {
    width: 72px;
    height: 72px;
    object-fit: cover;
    border-radius: 6px;
}

/* Action buttons */
.action-buttons {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    gap: 5px;
    z-index: 1;
}

.edit-btn {
    background: #ffc107;
    color: #212529;
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-weight: bold;
    box-shadow: 0 2px 6px rgba(0,0,0,0.25);
    transition: transform 0.2s;
}

.edit-btn:hover {
    background: #e0a800;
    transform: scale(1.1);
}

/* Statistics Styles */
.stats-section {
    margin: 2.5rem 0;
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 3px 12px rgba(0,0,0,0.06);
}

/* Headline totals (races / distance / time), one gradient tile each */
.stats-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-tile {
    text-align: center;
    padding: 1.1rem 0.5rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 10px;
    color: white;
}

.stat-tile .stat-value {
    font-size: 1.5rem;
    font-weight: 700;
}

.stat-tile .stat-label {
    font-size: 0.78rem;
    opacity: 0.85;
    margin-top: 0.25rem;
}

/* Per race-type breakdown (5K, 10K, Half Marathon, Marathon, ...) */
.stats-by-type {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1rem;
}

.type-stat-card {
    background: #f4f5f7;
    border-radius: 10px;
    padding: 1rem;
}

.type-stat-card h4 {
    color: #4c3a94;
    margin-bottom: 0.5rem;
    font-size: 1rem;
}

.type-stat-card p {
    font-size: 0.85rem;
    color: #6c757d;
    margin-bottom: 0.25rem;
}

/* Personal Records: the specific best race per category, not just an
   aggregate number - so a gold-accented card, distinct from the plain
   count cards above. */
.best-races {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}

.best-race-card {
    background: #fdf8ec;
    border: 1.5px solid #f0d999;
    border-radius: 10px;
    padding: 1rem;
}

.best-race-card h4 {
    color: #4c3a94;
    margin-bottom: 0.5rem;
    font-size: 1rem;
}

.best-race-card .best-race-name {
    font-weight: 600;
    color: #2d2a3d;
    margin-bottom: 0.25rem;
}

.best-race-card p {
    font-size: 0.85rem;
    color: #6c757d;
    margin-bottom: 0.25rem;
}

/* Calendar Styles */
.calendar-section {
    margin: 2.5rem 0;
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 3px 12px rgba(0,0,0,0.06);
}

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

.calendar-controls button {
    background: #f0f1f7;
    border: none;
    color: #4c3a94;
    font-weight: 600;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
}

.calendar-controls button:hover {
    background: #e2e4f2;
}

.calendar-controls h3 {
    font-size: 1.1rem;
    color: #2d2a3d;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 6px;
}

.calendar-day-header {
    text-align: center;
    font-weight: 700;
    padding: 8px 0;
    color: #4c3a94;
    font-size: 0.8rem;
}

.calendar-day {
    background: #f4f5f7;
    border-radius: 8px;
    padding: 6px;
    text-align: center;
    min-height: 56px;
    position: relative;
    transition: background 0.2s, outline 0.2s;
    font-size: 0.75rem;
}

.calendar-day:hover {
    background: #e9ebf3;
}

.calendar-day.empty {
    background: transparent;
}

/* Only days the admin can actually click (to add or edit a race) show a
   pointer + highlight; viewers get the plain hover background above. */
.calendar-day.admin-editable {
    cursor: pointer;
}

.calendar-day.admin-editable:hover {
    outline: 2px solid #667eea;
}

.calendar-day.has-race::after {
    content: "";
    position: absolute;
    bottom: 6px;
    left: 50%;
    transform: translateX(-50%);
    width: 6px;
    height: 6px;
    background: #28a745;
    border-radius: 50%;
}

/* Distinct dot for a day that only has planned (not-yet-run) races - green
   is reserved for races that actually have logged results. */
.calendar-day.has-planned::after {
    content: "";
    position: absolute;
    bottom: 6px;
    left: 50%;
    transform: translateX(-50%);
    width: 6px;
    height: 6px;
    background: #667eea;
    border-radius: 50%;
}

.calendar-day .day-number {
    font-weight: 700;
    font-size: 0.95rem;
    margin-bottom: 3px;
    color: #2d2a3d;
}

.calendar-day .race-count {
    font-size: 0.68rem;
    color: #28a745;
    margin-top: 3px;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(20,15,40,0.55);
    animation: fadeIn 0.25s;
    overflow-y: auto;
}

.modal-content {
    background-color: #fefefe;
    margin: 6% auto;
    padding: 2rem;
    border-radius: 14px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 15px 40px rgba(0,0,0,0.3);
    position: relative;
    animation: slideIn 0.3s;
}

.modal-content h2 {
    color: #2d2a3d;
    margin-bottom: 1.25rem;
    font-size: 1.35rem;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideIn {
    from { transform: translateY(-30px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* Hide login modal by default */
#loginModal {
    display: none;
}

.close {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
}

.close:hover {
    color: #000;
}

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

.form-group label {
    display: block;
    margin-bottom: 0.4rem;
    font-weight: 600;
    font-size: 0.9rem;
    color: #495057;
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="number"],
.form-group input[type="date"],
.form-group input[type="file"],
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1.5px solid #dde0ea;
    border-radius: 8px;
    font-size: 0.95rem;
    font-family: inherit;
    background: white;
    transition: border-color 0.2s;
}

.form-group select:focus,
.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #667eea;
}

form > button[type="submit"] {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
    transition: opacity 0.2s;
}

form > button[type="submit"]:hover {
    opacity: 0.9;
}

/* Deliberately distinct from the gradient submit button above - red and
   visually separate, so it doesn't get clicked by muscle memory when
   reaching for "Update Race". */
.delete-btn {
    background: white;
    color: #dc3545;
    border: 1.5px solid #dc3545;
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
    margin-top: 0.75rem;
    transition: background 0.2s, color 0.2s;
}

.delete-btn:hover {
    background: #dc3545;
    color: white;
}

.time-input {
    display: flex;
    gap: 10px;
}

.time-input input {
    flex: 1;
    text-align: center;
}

.hint {
    color: #9aa0b0;
    font-size: 0.82rem;
    margin-top: 0.4rem;
}

.error-message {
    color: #dc3545;
    margin-top: 10px;
    font-size: 0.9rem;
}

/* Responsive Design */
@media (max-width: 900px) {
    .gallery {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    header .container {
        flex-direction: column;
        text-align: center;
        gap: 12px;
    }

    h1 {
        font-size: 1.35rem;
        margin-right: 0;
    }

    .header-controls {
        justify-content: center;
        width: 100%;
    }

    .gallery {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .calendar-day {
        min-height: 50px;
    }

    .time-input {
        flex-direction: column;
    }

    .modal-content {
        margin: 15% auto;
        padding: 1.5rem;
    }
}

@media (max-width: 480px) {
    .container {
        width: 95%;
    }

    .calendar-controls {
        flex-direction: column;
        gap: 10px;
    }

    .calendar-controls h3 {
        margin: 0;
    }
}
