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

:root {
    --primary-color: #2ecc71;
    --primary-dark: #27ae60;
    --secondary-color: #3498db;
    --danger-color: #e74c3c;
    --light-bg: #ecf0f1;
    --dark-text: #2c3e50;
    --off-day: #95a5a6;
    --border-radius: 8px;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: var(--dark-text);
    min-height: 100vh;
    padding: 10px;
}

/* Auth UI */
.auth-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.auth-container.hidden {
    display: none;
}

.auth-modal {
    background: white;
    padding: 40px;
    border-radius: var(--border-radius);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    width: 100%;
    max-width: 400px;
}

.auth-modal h1 {
    text-align: center;
    margin-bottom: 30px;
    color: var(--dark-text);
    font-size: 28px;
}

.auth-form-group {
    margin-bottom: 20px;
}

.auth-form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    font-size: 14px;
    color: var(--dark-text);
}

.auth-form-group input {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    font-family: inherit;
}

.auth-form-group input:focus {
    outline: none;
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
}

.auth-btn {
    width: 100%;
    padding: 12px;
    background: var(--secondary-color);
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: 10px;
    transition: background 0.2s;
}

.auth-btn:hover {
    background: #2980b9;
}

.auth-btn-secondary {
    background: #95a5a6;
}

.auth-btn-secondary:hover {
    background: #7f8c8d;
}

.auth-error {
    color: var(--danger-color);
    text-align: center;
    margin-top: 15px;
    font-size: 14px;
}

.auth-toggle {
    text-align: center;
    margin-top: 20px;
    font-size: 14px;
    color: #7f8c8d;
}

.auth-toggle-btn {
    background: none;
    border: none;
    color: var(--secondary-color);
    text-decoration: underline;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    padding: 0;
}

.auth-toggle-btn:hover {
    color: #2980b9;
}

#authModeTitle {
    text-align: center;
    margin-bottom: 20px;
    color: var(--dark-text);
    font-size: 20px;
}

.app-container {
    display: block;
}

.app-container.hidden {
    display: none;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    background: white;
    border-radius: var(--border-radius);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    overflow: hidden;
}

/* Header */
header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    text-align: center;
}

header h1 {
    font-size: 28px;
    margin-bottom: 15px;
    font-weight: 600;
    display: none;
}

.month-selector {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 15px;
}

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

/* Runner Selector (Coach View) */
.runner-selector {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(255, 255, 255, 0.15);
    padding: 10px 15px;
    border-radius: 6px;
    margin-top: 10px;
}

.runner-selector.hidden {
    display: none !important;
}

.runner-selector label {
    color: white;
    font-weight: 600;
    font-size: 14px;
    margin: 0;
}

.runner-dropdown {
    padding: 6px 10px;
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.95);
    color: var(--dark-text);
    font-size: 13px;
    cursor: pointer;
    min-width: 150px;
}

.logout-btn {
    padding: 6px 12px;
    background: rgba(231, 76, 60, 0.9);
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.3s;
}

.logout-btn:hover {
    background: rgba(192, 57, 43, 1);
}

.logout-btn-footer {
    padding: 6px 12px;
    background: #bdc3c7;
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.3s;
    font-weight: 500;
}

.logout-btn-footer:hover {
    background: #95a5a6;
    color: white;
}

.app-footer {
    padding: 20px;
    text-align: center;
    border-top: 1px solid #ecf0f1;
    margin-top: 30px;
}

.month-dropdown {
    padding: 8px 12px;
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.month-dropdown:hover {
    background: rgba(255, 255, 255, 0.2);
}

.month-dropdown:focus {
    outline: none;
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.6);
}

.month-dropdown option {
    background: #667eea;
    color: white;
}

.nav-buttons {
    display: flex;
    justify-content: center;
    gap: 15px;
}

.nav-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.4);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s ease;
}

.nav-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.05);
}

.month-title {
    font-size: 18px;
    font-weight: 600;
    display: none;
    margin: 10px 0;
}

/* Main Content */
main {
    padding: 20px;
}

/* Controls Section */
.controls-section {
    margin-bottom: 20px;
    display: flex;
    justify-content: center;
}

.mode-toggle {
    background: #3498db;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 20px;
    font-weight: 600;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s ease;
}

.mode-toggle:hover {
    background: #2980b9;
    transform: scale(1.05);
}

.mode-toggle.active {
    background: #e74c3c;
}

.mode-toggle.active:hover {
    background: #c0392b;
}

/* Progress Section */
.progress-section {
    background: var(--light-bg);
    padding: 15px;
    border-radius: var(--border-radius);
    margin-bottom: 20px;
    border-left: 4px solid var(--secondary-color);
}

.progress-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.progress-label {
    font-weight: 600;
    color: var(--dark-text);
    font-size: 14px;
}

.progress-stats {
    font-weight: 600;
    color: var(--secondary-color);
    font-size: 14px;
}

.progress-bar-container {
    background: #e0e0e0;
    height: 8px;
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar {
    background: linear-gradient(90deg, var(--secondary-color), var(--primary-color));
    height: 100%;
    width: 0%;
    transition: width 0.3s ease, background 0.3s ease;
    border-radius: 4px;
}

.progress-section.completed .progress-bar {
    background: linear-gradient(90deg, #ffd700, #ffed4e);
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.6);
}

.progress-section.completed {
    animation: goldGlow 0.5s ease;
}

@keyframes goldGlow {
    0%, 100% {
        box-shadow: none;
    }
    50% {
        box-shadow: 0 0 15px rgba(255, 215, 0, 0.4);
    }
}

/* Week Navigation Section */
.week-nav-section {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    padding: 12px;
    background: #f8f9fa;
    border-radius: var(--border-radius);
}

.nav-week-btn {
    background: #667eea;
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.3s ease;
}

.nav-week-btn:hover {
    background: #764ba2;
    transform: scale(1.05);
}

.month-dropdown-inline {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    background: white;
    color: var(--dark-text);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.month-dropdown-inline:hover {
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.1);
}

.month-dropdown-inline:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
}

.month-dropdown-inline option {
    background: white;
    color: var(--dark-text);
}

.week-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.week {
    background: var(--light-bg);
    border-radius: var(--border-radius);
    padding: 8px;
    border-left: 5px solid var(--primary-color);
}

.week-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--primary-dark);
    margin-bottom: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.week-total {
    font-size: 14px;
    color: #666;
    font-weight: 500;
}

.days-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 3px;
}

.day {
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: var(--border-radius);
    padding: 5px;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.day:hover {
    border-color: var(--secondary-color);
    box-shadow: var(--shadow);
    transform: translateY(-2px);
}

.day-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    margin-bottom: 4px;
}

.day-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 3px;
}

.day-date {
    font-size: 15px;
    font-weight: 600;
    color: var(--secondary-color);
    margin-bottom: 0;
}

.day-footer {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
    width: 100%;
    margin-top: 10px;
    flex-wrap: nowrap;
    min-width: 0;
}

.swap-icon {
    font-size: 16px;
    cursor: pointer;
    padding: 0;
    border-radius: 4px;
    transition: all 0.2s ease;
    user-select: none;
    text-align: center;
    flex: 0 0 18px;
    line-height: 1;
}

.swap-icon:hover {
    transform: scale(1.2);
}

.day.swapping .swap-icon {
    color: var(--secondary-color);
    font-weight: bold;
}

.edit-icon {
    font-size: 16px;
    cursor: pointer;
    padding: 0;
    border-radius: 4px;
    transition: all 0.2s ease;
    user-select: none;
    text-align: center;
    flex: 1 0 auto;
    line-height: 1;
}

.edit-icon:hover {
    transform: scale(1.2);
}

.workout-text {
    font-size: 16px;
    color: var(--dark-text);
    line-height: 1.4;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    word-break: break-word;
}

.day.completed .workout-text {
    color: #95a5a6;
    text-decoration: line-through;
    opacity: 0.7;
}

.day.today {
    border: 2px solid #667eea;
    box-shadow: 0 0 0 1px #667eea;
    background: rgba(102, 126, 234, 0.03);
}

.day-checkbox {
    width: 22px;
    height: 22px;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    border-radius: 3px;
    border: 1.5px solid #bbb;
    background: white;
    transition: all 0.2s ease;
    font-weight: 600;
    flex: 0 0 22px;
}

.day-checkbox:hover {
    border-color: var(--secondary-color);
    background: #f0f7ff;
}

.day-checkbox.unchecked {
    border-color: #ddd;
}

.day-checkbox.checked {
    color: var(--primary-color);
    border-color: var(--primary-color);
    background: #e8f5e9;
}

.day.selected {
    background: #e8f5e9;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(46, 204, 113, 0.2);
}

.day.swapping {
    border-color: var(--secondary-color);
    border-width: 2px;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
    background: rgba(52, 152, 219, 0.05);
}

/* Swap Status Message */
.swap-status {
    margin-top: 15px;
    padding: 12px 15px;
    border-radius: var(--border-radius);
    text-align: center;
    font-weight: 600;
    font-size: 14px;
    animation: slideUp 0.3s ease;
}

.swap-status.hidden {
    display: none;
}

.swap-status.info {
    background: #e3f2fd;
    color: #1976d2;
    border: 1px solid #1976d2;
}

.swap-status.success {
    background: #e8f5e9;
    color: var(--primary-dark);
    border: 1px solid var(--primary-color);
}

/* Swap Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.4);
    animation: fadeIn 0.3s ease;
}

.modal:not(.hidden) {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background-color: white;
    margin: 5% auto;
    padding: 25px;
    border-radius: var(--border-radius);
    width: 90%;
    max-width: 400px;
    box-shadow: 0 4px 25px rgba(0, 0, 0, 0.2);
    animation: slideUp 0.3s ease;
}

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

@keyframes slideUp {
    from {
        transform: translateY(50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

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

.close:hover {
    color: var(--dark-text);
}

.swap-form h2 {
    margin-bottom: 20px;
    color: var(--dark-text);
}

.distance-form h2 {
    margin-bottom: 20px;
    color: var(--dark-text);
}

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

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    font-size: 14px;
    color: var(--dark-text);
}

.form-group.info-group {
    background: #f0f4ff;
    padding: 12px;
    border-radius: 4px;
    border-left: 3px solid var(--secondary-color);
}

.form-group.info-group label {
    margin-bottom: 8px;
}

.form-group select {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    cursor: pointer;
    font-family: inherit;
}

.form-group input {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    font-family: inherit;
}

.form-group select:focus,
.form-group input:focus {
    outline: none;
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
}

#workoutTextInput {
    width: 100% !important;
    min-height: 80px;
    resize: vertical;
    padding: 10px;
    font-family: inherit;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.swap-preview {
    background: var(--light-bg);
    padding: 12px;
    border-radius: 4px;
    margin-bottom: 15px;
    font-size: 14px;
}

.preview-item {
    margin-bottom: 8px;
}

.preview-item:last-child {
    margin-bottom: 0;
}

.preview-item strong {
    display: inline-block;
    width: 50px;
    color: var(--dark-text);
}

.btn-primary,
.btn-secondary {
    width: 100%;
    padding: 12px;
    margin-bottom: 8px;
    border: none;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

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

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
}

.btn-secondary {
    background: #ecf0f1;
    color: var(--dark-text);
    border: 1px solid #ddd;
}

.btn-secondary:hover {
    background: #d5dbdf;
}

/* Info Section */
.mileage-chart-section {
    background: var(--light-bg);
    padding: 20px;
    border-radius: var(--border-radius);
    margin-top: 20px;
    border-top: 2px solid var(--secondary-color);
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.chart-header h2 {
    font-size: 16px;
    font-weight: 600;
    color: var(--primary-dark);
    margin: 0;
}

.chart-nav {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chart-nav-btn {
    background: var(--secondary-color);
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: all 0.2s ease;
}

.chart-nav-btn:hover:not(:disabled) {
    background: #2980b9;
    transform: scale(1.05);
}

.chart-nav-btn:disabled {
    background: #bdc3c7;
    cursor: not-allowed;
    opacity: 0.6;
}

.chart-date-range {
    font-size: 12px;
    color: #666;
    min-width: 120px;
    text-align: center;
}

#mileageChart {
    width: 100%;
    height: 250px;
    display: block;
}

/* Coach Panel */
.coach-toggle-btn {
    padding: 8px 16px;
    background: #f39c12;
    color: white;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: background 0.3s;
}

.coach-toggle-btn:hover {
    background: #e67e22;
}

.coach-panel {
    background: white;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    margin: 20px 0;
    padding: 20px;
    border-left: 4px solid #f39c12;
    position: relative;
    z-index: 100;
}

.coach-panel.hidden {
    display: none !important;
    pointer-events: none;
}

.coach-panel-content h2 {
    color: var(--dark-text);
    margin-bottom: 10px;
    font-size: 20px;
}

.coach-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.coach-panel-header h2 {
    margin: 0;
}

.close-panel-btn {
    background: none;
    border: none;
    font-size: 28px;
    color: #e74c3c;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-panel-btn:hover {
    color: #c0392b;
}

.coach-help-text {
    color: #7f8c8d;
    margin-bottom: 15px;
    font-size: 14px;
}

.schedule-json-input {
    width: 100%;
    min-height: 300px;
    padding: 10px;
    border: 1px solid #bdc3c7;
    border-radius: var(--border-radius);
    font-family: 'Courier New', monospace;
    font-size: 12px;
    resize: vertical;
}

.schedule-format-help {
    background: #ecf0f1;
    padding: 10px;
    border-radius: var(--border-radius);
    margin-top: 15px;
    cursor: pointer;
}

.schedule-format-help summary {
    font-weight: 600;
    color: var(--secondary-color);
    user-select: none;
}

.schedule-format-help pre {
    background: #2c3e50;
    color: #ecf0f1;
    padding: 10px;
    border-radius: 4px;
    overflow-x: auto;
    font-size: 11px;
    margin-top: 10px;
}

.upload-status {
    margin-top: 10px;
    padding: 10px;
    border-radius: 4px;
    font-weight: 600;
    display: none;
}

.upload-status.success {
    background: #d5f4e6;
    color: #27ae60;
    display: block;
}

.upload-status.error {
    background: #fadbd8;
    color: #e74c3c;
    display: block;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    body {
        padding: 5px;
    }

    .container {
        border-radius: 0;
    }

    header {
        padding: 15px;
    }

    header h1 {
        font-size: 24px;
        margin-bottom: 10px;
    }

    .month-selector {
        gap: 10px;
    }

    .nav-btn {
        padding: 6px 12px;
        font-size: 12px;
    }

    .nav-week-btn {
        padding: 6px 12px;
        font-size: 11px;
    }

    .week-nav-section {
        gap: 8px;
        padding: 10px;
    }

    .month-dropdown-inline {
        padding: 6px 10px;
        font-size: 12px;
    }

    .month-title {
        font-size: 16px;
        min-width: auto;
    }

    main {
        padding: 12px;
    }

    .week {
        padding: 8px;
    }

    .days-grid {
        grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
        gap: 3px;
    }

    .day {
        padding: 5px;
    }

    .day-date {
        font-size: 11px;
        margin-bottom: 4px;
    }

    .workout-text {
        font-size: 12px;
    }

    .modal-content {
        width: 95%;
        margin: 20% auto;
        padding: 20px;
    }

    .week-title {
        font-size: 14px;
        margin-bottom: 10px;
    }

    .week-total {
        font-size: 12px;
    }
}

@media (max-width: 480px) {
    header h1 {
        font-size: 20px;
    }

    .month-title {
        font-size: 14px;
    }

    .nav-btn {
        padding: 5px 10px;
        font-size: 11px;
    }

    .nav-week-btn {
        padding: 5px 10px;
        font-size: 10px;
    }

    .week-nav-section {
        gap: 6px;
        padding: 8px;
    }

    .month-dropdown-inline {
        padding: 5px 8px;
        font-size: 11px;
    }

    .days-grid {
        grid-template-columns: repeat(auto-fit, minmax(85px, 1fr));
        gap: 3px;
    }

    .day {
        padding: 5px;
    }

    .day-date {
        font-size: 10px;
    }

    .workout-text {
        font-size: 11px;
    }
}
