/* Modal Styles */

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    animation: fadeIn 0.3s ease-out;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.modal.show {
    display: block;
}

/* Prevent body scroll when modal is open */
body.modal-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
}

.modal-content {
    background-color: white;
    margin: 5% auto;
    padding: 2rem;
    border-radius: 10px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow: hidden;
    position: relative;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    animation: slideIn 0.3s ease-out;
    display: flex;
    flex-direction: column;
}

.modal-content.scrollable {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Modals with standard structure (header/body/footer) - remove padding from content */
.modal-content:has(.modal-header) {
    padding: 0;
}

/* Fallback for browsers that don't support :has() - use class-based approach */
.modal-content.has-header {
    padding: 0;
}

/* Large modal size (aliases) */
.modal-content.large,
.modal-lg .modal-content {
    max-width: 800px;
}

.modal-content.small {
    max-width: 400px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 2rem;
    border-bottom: 1px solid #e9ecef;
    background-color: white;
    position: sticky;
    top: 0;
    z-index: 10;
    flex-shrink: 0;
}

.modal-title {
    margin: 0;
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-semibold);
    color: #495057;
}

.modal-header h2,
.modal-header h3 {
    margin: 0;
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-semibold);
    color: #495057;
}

.modal-close,
.close {
    color: #aaa;
    font-size: 28px; /* Specific icon size, keep as px */
    font-weight: var(--font-weight-bold);
    cursor: pointer;
    line-height: 1;
    padding: 0;
    background: none;
    border: none;
    transition: color 0.2s;
}

.modal-close:hover,
.modal-close:focus,
.close:hover,
.close:focus {
    color: #000;
    text-decoration: none;
}

.modal-body {
    padding: 1.5rem 2rem;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
}

.modal-section:not(:first-of-type) {
    margin-top: 1.75rem;
    padding-top: 1.5rem;
    border-top: 1px solid #e9ecef;
}

.modal-section-title {
    margin: 0 0 0.9rem 0;
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-semibold);
    letter-spacing: 0.01em;
    color: #343a40;
}

.modal-section-note {
    margin: 0.35rem 0 0.5rem 0;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 1.5rem 2rem;
    border-top: 1px solid #e9ecef;
    background-color: white;
    position: sticky;
    bottom: 0;
    z-index: 10;
    flex-shrink: 0;
    margin-top: auto;
}

.modal-footer .btn {
    margin-left: 0.5rem;
}

.modal-footer .btn:first-child {
    margin-left: 0;
}

/* Modal animations */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* slideIn keyframes are defined globally in main.css to avoid duplication */

/* Modal backdrop */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 999;
}

/* Modal sizes */
.modal-sm .modal-content {
    max-width: 300px;
}

.modal-xl .modal-content {
    max-width: 1140px;
}

/* Modal fullscreen */
.modal-fullscreen {
    width: 100vw;
    height: 100vh;
    margin: 0;
    max-width: none;
    max-height: none;
    border-radius: 0;
}

/* Modal scrollable */
.modal-scrollable .modal-content {
    max-height: calc(100vh - 2rem);
}

.modal-scrollable .modal-body {
    max-height: calc(100vh - 200px);
    overflow-y: auto;
}

/* Modal centered */
.modal-centered .modal-content {
    margin: 15% auto;
}

/* Modal with form */
.modal-form .form-group {
    margin-bottom: 1rem;
}

.modal-form .form-group:last-child {
    margin-bottom: 0;
}

.modal-form .form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: var(--font-weight-medium);
    color: #495057;
}

.modal-form .form-group input,
.modal-form .form-group select,
.modal-form .form-group textarea {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid #ced4da;
    border-radius: 0.25rem;
    font-size: var(--font-size-base);
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.modal-form .form-group input:focus,
.modal-form .form-group select:focus,
.modal-form .form-group textarea:focus {
    outline: 0;
    border-color: #667eea;
    box-shadow: 0 0 0 0.2rem rgba(102, 126, 234, 0.25);
}

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

/* Modal with confirmation */
.modal-confirmation .modal-content {
    text-align: center;
}

.modal-confirmation .modal-body {
    padding: 2rem 0;
}

.modal-confirmation .modal-footer {
    justify-content: center;
}

/* Modal loading state */
.modal-loading {
    position: relative;
}

.modal-loading::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.modal-loading::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    z-index: 11;
}

/* Modal error state */
.modal-error .modal-content {
    border-left: 4px solid #dc3545;
}

.modal-error .modal-title {
    color: #dc3545;
}

/* Modal success state */
.modal-success .modal-content {
    border-left: 4px solid #28a745;
}

.modal-success .modal-title {
    color: #28a745;
}

/* Modal warning state */
.modal-warning .modal-content {
    border-left: 4px solid #ffc107;
}

.modal-warning .modal-title {
    color: #856404;
}

/* Modal info state */
.modal-info .modal-content {
    border-left: 4px solid #17a2b8;
}

.modal-info .modal-title {
    color: #0c5460;
}

/* Ensure modals without standard structure still work */
.modal-content > h2:first-child,
.modal-content > h3:first-child {
    margin-top: 0;
}

/* Modal responsive */
@media (max-width: 768px) {
    .modal-content {
        width: 85%;
        margin: 2% auto;
        max-height: 96vh;
        padding: 1.5rem;
    }

    .modal-header {
        padding: 1rem 1rem;
    }

    .modal-body {
        padding: 0 1rem;
    }

    .modal-footer {
        padding: 1rem 1rem;
    }

    .modal-content.large {
        max-width: 95%;
    }

    /* Special styling for add-runner-modal to maximize screen space on mobile */
    #add-runner-modal .modal-content {
        width: 98% !important;
        max-width: 98% !important;
        height: 96vh !important;
        max-height: 96vh !important;
        margin: 1% auto !important;
        overflow: hidden !important;
    }

    /* Ensure modal-body scrolls within the constrained height */
    #add-runner-modal .modal-body {
        overflow-y: auto !important;
        flex: 1 1 auto !important;
        min-height: 0 !important;
    }

    .modal-footer {
        flex-direction: column;
    }

    .modal-footer .btn {
        margin: 0.25rem 0;
        width: 100%;
    }

    /* Override stacking for specific modals that should keep buttons inline */
    .modal-footer.modal-footer-inline-mobile {
        flex-direction: row !important;
        gap: 0.5rem;
    }

    .modal-footer.modal-footer-inline-mobile .btn {
        margin: 0 !important;
        width: auto !important;
        flex: 1;
    }
}

/* Modal with tabs */
.modal-tabs .modal-header {
    border-bottom: none;
    padding-bottom: 0;
}

.modal-tabs .modal-tab-nav {
    display: flex;
    border-bottom: 1px solid #e9ecef;
    margin-bottom: 1.5rem;
}

.modal-tabs .modal-tab {
    padding: 0.75rem 1rem;
    border: none;
    background: none;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}

.modal-tabs .modal-tab.active {
    border-bottom-color: #667eea;
    color: #667eea;
    font-weight: var(--font-weight-semibold);
}

.modal-tabs .modal-tab:hover:not(.active) {
    background: #f8f9fa;
}

.modal-tabs .modal-tab-content {
    display: none;
}

.modal-tabs .modal-tab-content.active {
    display: block;
}

/* Wizard stepper */
.stepper {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.stepper .step {
    flex: 1;
    text-align: center;
    padding: 0.5rem 0.75rem;
    border: 1px solid #e3e7ee;
    border-radius: 999px;
    background: #f8f9fb;
    color: #6c757d;
    font-weight: var(--font-weight-medium);
    user-select: none;
}

.stepper .step.active {
    border-color: #667eea;
    background: #eef2ff;
    color: #3f51b5;
}

.stepper .step.completed {
    border-color: #28a745;
    background: #e9f7ef;
    color: #1e7e34;
}

/* .wizard-step intentionally has no base styling; styles are applied via nested elements */

/* Season Transition Modal Styles */
.transition-preview {
    max-height: 60vh;
    overflow-y: auto;
}

.transition-preview h4 {
    color: #495057;
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
    font-size: var(--font-size-md);
    font-weight: var(--font-weight-semibold);
}

.transition-preview h4:first-child {
    margin-top: 0;
}

.transition-preview p {
    margin: 0.25rem 0;
    color: #6c757d;
}

.changes-summary {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 0.375rem;
    padding: 1rem;
    margin: 1rem 0;
}

.change-item {
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid #dee2e6;
}

.change-item:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.change-item strong {
    color: #495057;
    display: block;
    margin-bottom: 0.5rem;
}

.change-item ul {
    margin: 0.5rem 0 0 1rem;
    padding: 0;
}

.change-item li {
    margin: 0.25rem 0;
    color: #6c757d;
}

.warning-box {
    background: #fff3cd;
    border: 1px solid #ffeaa7;
    border-radius: 0.375rem;
    padding: 1rem;
    margin: 1rem 0;
    color: #856404;
}

.warning-box strong {
    color: #856404;
}

.close {
    color: #aaa;
    font-size: 28px; /* Specific icon size, keep as px */
    font-weight: var(--font-weight-bold);
    cursor: pointer;
    line-height: 1;
    padding: 0;
    background: none;
    border: none;
    transition: color 0.2s;
}

.close:hover,
.close:focus {
    color: #000;
    text-decoration: none;
}

/* Status chips for promotion/demotion */
.status-chip {
    display: inline-block;
    padding: 0.125rem 0.5rem;
    border-radius: 999px;
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    line-height: 1.2;
}

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

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