/* Workout Builder UI Fixes - Non-header styles only */

/* Header styles removed - now handled by workout-builder-header-simple-fix.css */

.workout-mode .workout-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: #f8f9fa;
    border-radius: 8px;
    margin-bottom: 1rem;
}

.workout-mode #workoutTimerDisplay {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--primary-color);
}

@media (max-width: 768px) {
    .workout-mode .workout-header {
        flex-direction: column;
        gap: 1rem;
    }
}

/* Ensure main content starts below header */
.workout-builder-main {
    margin-top: 0 !important;
    padding-top: 70px !important;
    width: 100% !important;
    box-sizing: border-box !important;
}

/* Reset body styles specifically for workout builder */
body.workout-builder-page {
    margin: 0 !important;
    padding: 0 !important;
    padding-top: 70px !important;
    width: 100% !important;
    overflow-x: hidden !important;
}

/* Reset any weird positioning */
html, body {
    margin: 0 !important;
    padding: 0 !important;
    overflow-x: hidden !important;
    width: 100% !important;
}

/* Ensure proper page structure */
.workout-builder-page {
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    box-sizing: border-box !important;
}

/* Override any transform that might push content */
.workout-builder-page .site-header,
.workout-builder-page .site-header * {
    transform: none !important;
    position: static !important;
}

.workout-builder-page .site-header {
    position: fixed !important;
}

/* Fix container alignment */
.workout-builder-page .container {
    max-width: 1400px !important;
    width: 100% !important;
    margin: 0 auto !important;
    padding: 0 20px !important;
    box-sizing: border-box !important;
}

/* Fix rest button text color - FORCE black text for readability */
.rest-btn {
    color: #000000 !important;
    font-weight: 600 !important;
}

.rest-btn:not(.active) {
    color: #000000 !important;
}

.rest-btn.active {
    color: white !important;
}

/* Ensure rest buttons are always readable */
.rest-options .rest-btn {
    color: #000000 !important;
    background: #f1f5f9 !important;
    border: 1px solid #e2e8f0 !important;
}

.rest-options .rest-btn.active {
    color: white !important;
    background: var(--primary-color) !important;
    border-color: var(--primary-color) !important;
}

/* Ensure rest selector label spacing */
.rest-selector {
    margin-bottom: 1rem;
}

.rest-selector label {
    display: block;
    margin-bottom: 0.75rem;
    font-weight: 600;
    color: #1e293b;
}

/* Ultra-compressed exercise details for mobile */
.exercise-details {
    padding: 0.4rem !important;
    margin: 0.25rem 0 !important;
    background-color: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
}

.detail-row {
    padding: 0.15rem 0 !important;
    font-size: 0.7rem !important;
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: auto !important;
}

.detail-label {
    font-size: 0.65rem !important;
    color: #64748b;
    font-weight: 500;
}

.detail-row span:last-child {
    font-size: 0.7rem !important;
    font-weight: 600;
    color: #1e293b;
}

/* Mobile-specific ultra-compact details */
@media (max-width: 768px) {
    .exercise-details {
        padding: 0.3rem 0.5rem !important;
        margin: 0.2rem 0 !important;
    }
    
    .detail-row {
        padding: 0.1rem 0 !important;
        font-size: 0.65rem !important;
    }
    
    .detail-label {
        font-size: 0.6rem !important;
    }
    
    .detail-row span:last-child {
        font-size: 0.65rem !important;
    }
}

/* Fix weight input spacing on mobile */
@media (max-width: 768px) {
    .weight-input {
        margin-top: 1rem;
        margin-bottom: 1rem;
    }
    
    .reps-input {
        margin-bottom: 1.5rem !important;
    }
    
    /* Ensure inputs don't overlap */
    .set-configuration input {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
        margin-bottom: 0.5rem;
        font-size: 16px; /* Prevent iOS zoom */
    }
    
    /* Ultra-compact modal for perfect mobile fit */
    .modal-content {
        padding: 0.75rem !important;
        padding-top: 2.5rem !important;
        max-height: 100vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .modal-content h3 {
        font-size: 1rem !important;
        margin-bottom: 0.3rem !important;
        padding-right: 40px !important;
        line-height: 1.2 !important;
    }
    
    /* Ensure exercise modal is extra compact */
    #exerciseModal .modal-content h3 {
        margin-bottom: 0.25rem !important;
    }
    
    .exercise-details {
        margin: 0.5rem 0 !important;
        padding: 0.5rem !important;
    }
    
    .detail-row {
        padding: 0.2rem 0 !important;
        font-size: 0.75rem !important;
    }
    
    .set-configuration {
        margin: 0.75rem 0 !important;
    }
    
    .set-configuration h4 {
        font-size: 1rem !important;
        margin-bottom: 0.75rem !important;
    }
    
    /* Compact rest buttons */
    .rest-options {
        gap: 0.4rem !important;
        margin-top: 0.5rem !important;
    }
    
    .rest-btn {
        padding: 0.5rem 0.6rem !important;
        font-size: 0.8rem !important;
        min-height: 36px !important;
        font-weight: 600 !important;
    }
    
    /* Ensure modal fits on one screen */
    .modal {
        padding: 0;
    }
    
    /* Add to workout button styling */
    .modal-content .btn-primary {
        margin-top: 1rem;
        padding: 0.75rem 1.5rem;
        font-size: 1rem;
        width: 100%;
    }
}

/* Remove weight field option - uncomment if needed */
/*
.weight-input {
    display: none !important;
}
*/

/* Better modal scrolling on iOS */
.modal-content {
    -webkit-overflow-scrolling: touch;
    overflow-y: auto;
    max-height: calc(100vh - 2rem);
    max-height: calc(var(--vh, 1vh) * 100 - 2rem);
}

/* Prevent any element from pushing the page wider */
* {
    max-width: 100vw !important;
}

/* Force header to stay in viewport */
.workout-builder-page .site-header {
    max-width: 100vw !important;
    left: 0 !important;
    right: 0 !important;
}

/* Ensure modals appear above everything and centered */
.modal {
    z-index: 9999 !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    display: none;
    align-items: center !important;
    justify-content: center !important;
    background-color: rgba(0, 0, 0, 0.5) !important;
}

.modal.show {
    display: flex !important;
}

.modal-content {
    z-index: 10000 !important;
    position: relative !important;
    background-color: white !important;
    border-radius: 8px !important;
    max-width: 700px !important;
    width: 90% !important;
    max-height: 95vh !important;
    margin: 0 auto !important;
    padding: 2rem !important;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15) !important;
    transform: none !important;
    top: auto !important;
    left: auto !important;
    right: auto !important;
    bottom: auto !important;
}

/* Ensure modal header doesn't scroll */
@media (max-width: 768px) {
    .modal-content {
        display: flex;
        flex-direction: column;
    }
    
    .modal-close {
        position: fixed !important;
        top: 0.75rem !important;
        right: 0.75rem !important;
        z-index: 10001 !important;
        background: white !important;
        width: 36px !important;
        height: 36px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        border-radius: 50% !important;
        box-shadow: 0 2px 8px rgba(0,0,0,0.15) !important;
        font-size: 1.25rem !important;
        color: #64748b !important;
        border: 2px solid #e2e8f0 !important;
    }
    
    /* Ensure close button doesn't overlap with other elements */
    .modal-content {
        position: relative !important;
    }
    
    /* Add spacing for input labels */
    .sets-input label,
    .reps-input label,
    .rest-selector label {
        display: block !important;
        margin-bottom: 0.5rem !important;
        font-size: 0.9rem !important;
        font-weight: 600 !important;
        color: #1e293b !important;
    }
}

/* Template Actions Styling */
.template-actions {
    margin: 1rem 0;
    text-align: center;
}

.template-actions .btn {
    width: 100%;
}

/* Templates Modal Styling */
.templates-list {
    max-height: 400px;
    overflow-y: auto;
    padding: 1rem 0;
}

.template-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    margin-bottom: 0.75rem;
    background: #f8f9fa;
    transition: all 0.2s ease;
}

.template-item:hover {
    background: #e9ecef;
    border-color: #cbd5e0;
}

.template-info h4 {
    margin: 0 0 0.25rem 0;
    color: #1e293b;
    font-size: 1.1rem;
}

.template-info p {
    margin: 0 0 0.25rem 0;
    color: #64748b;
    font-size: 0.9rem;
}

.template-info small {
    color: #94a3b8;
}

.template-item .btn-sm {
    padding: 0.4rem 0.8rem;
}

.templates-empty {
    text-align: center;
    padding: 3rem 1rem;
    color: #64748b;
}

/* Ensure modal works properly */
#templatesModal.show {
    display: flex \!important;
}


/* Template action buttons container */
.template-actions-btns {
    display: flex;
    gap: 0.5rem;
}

.template-actions-btns .btn-sm {
    padding: 0.4rem 0.8rem;
}

.template-actions-btns .btn-danger {
    background-color: #dc3545;
    color: white;
    border-color: #dc3545;
}

.template-actions-btns .btn-danger:hover {
    background-color: #c82333;
    border-color: #bd2130;
}


/* Specific fixes for exercise modal centering */
#exerciseModal {
    position: fixed \!important;
    top: 0 \!important;
    left: 0 \!important;
    width: 100% \!important;
    height: 100% \!important;
    display: none;
    align-items: center \!important;
    justify-content: center \!important;
    background-color: rgba(0, 0, 0, 0.5) \!important;
}

#exerciseModal.show {
    display: flex \!important;
}

#exerciseModal .modal-content {
    position: relative \!important;
    transform: none \!important;
    margin: 0 auto \!important;
    top: auto \!important;
    left: auto \!important;
    right: auto \!important;
    bottom: auto \!important;
}

/* Success modal centering */
#successModal {
    position: fixed \!important;
    top: 0 \!important;
    left: 0 \!important;
    width: 100% \!important;
    height: 100% \!important;
    display: none;
    align-items: center \!important;
    justify-content: center \!important;
}

#successModal.show {
    display: flex \!important;
}


/* Mobile Layout Reordering - Exercise Library First */
@media (max-width: 1024px) {
    .workout-builder-page .builder-layout,
    .builder-section .builder-layout,
    #strengthBuilder .builder-layout {
        display: flex !important;
        flex-direction: column !important;
    }
    
    .workout-builder-page .exercise-panel,
    .builder-section .exercise-panel,
    #strengthBuilder .exercise-panel {
        order: 1 !important; /* Exercise Library first on mobile */
    }
    
    .workout-builder-page .workout-panel,
    .builder-section .workout-panel,
    #strengthBuilder .workout-panel {
        order: 2 !important; /* Your Workout second on mobile */
        margin-top: 2rem !important;
    }
}

@media (max-width: 768px) {
    .workout-builder-page .builder-layout,
    .builder-section .builder-layout,
    #strengthBuilder .builder-layout {
        display: flex !important;
        flex-direction: column !important;
    }
    
    .workout-builder-page .exercise-panel,
    .builder-section .exercise-panel,
    #strengthBuilder .exercise-panel {
        order: 1 !important; /* Exercise Library first on mobile */
    }
    
    .workout-builder-page .workout-panel,
    .builder-section .workout-panel,
    #strengthBuilder .workout-panel {
        order: 2 !important; /* Your Workout second on mobile */
        margin-top: 1.5rem !important;
    }
}

/* Rest Timer Modal Number Centering */
.rest-timer-display {
    position: relative \!important;
    display: flex \!important;
    align-items: center \!important;
    justify-content: center \!important;
}

.rest-time-remaining {
    position: absolute \!important;
    top: 50% \!important;
    left: 50% \!important;
    transform: translate(-50%, -50%) \!important;
    font-size: 2.5rem \!important;
    font-weight: 600 \!important;
    color: var(--primary-color) \!important;
    text-align: center \!important;
    width: 100% \!important;
}

/* Ensure rest timer modal is also centered */
#restTimerModal {
    position: fixed \!important;
    top: 0 \!important;
    left: 0 \!important;
    width: 100% \!important;
    height: 100% \!important;
    display: none;
    align-items: center \!important;
    justify-content: center \!important;
    background-color: rgba(0, 0, 0, 0.5) \!important;
    z-index: 9999 \!important;
}

#restTimerModal.show {
    display: flex \!important;
}

/* Fix mobile scroll arrow positioning */
.scroll-indicator {
    position: fixed !important;
    bottom: 20px !important;
    right: 20px !important;
    width: 44px !important;
    height: 44px !important;
    background-color: var(--primary-color) !important;
    color: white !important;
    border-radius: 50% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    cursor: pointer !important;
    z-index: 100 !important; /* Lower than modal z-index */
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2) !important;
    transition: all 0.3s ease !important;
}

/* Ensure scroll arrow doesn't interfere with modal close button */
.modal.show ~ .scroll-indicator,
.modal-open .scroll-indicator {
    display: none !important;
}

/* Additional mobile modal fixes */
@media (max-width: 768px) {
    /* Ensure modal takes full screen */
    .modal-content {
        width: 100% !important;
        height: 100% !important;
        min-height: 100vh !important;
        border-radius: 0 !important;
        margin: 0 !important;
    }
    
    /* Compress set configuration inputs */
    .sets-input input,
    .reps-input input {
        padding: 0.6rem 0.8rem !important;
        font-size: 0.95rem !important;
    }
    
    /* Better spacing for rest selector - prevent blending */
    .rest-selector {
        border-top: 1px solid #e2e8f0;
        padding-top: 1rem;
        margin-top: 1.5rem !important;
        margin-bottom: 1rem !important;
    }
    
    /* Ensure proper spacing between rep range and rest selector */
    .reps-input {
        margin-bottom: 2rem !important;
    }
    
    /* Make rest options more compact but clear */
    .rest-options {
        background: #f8fafc;
        padding: 0.5rem;
        border-radius: 6px;
        border: 1px solid #e2e8f0;
    }
}

/* Desktop Modal Compression - Fit everything on one screen */
@media (min-width: 769px) {
    /* Compress modal content for desktop */
    #exerciseModal .modal-content {
        padding: 1.5rem !important;
        max-height: 95vh !important;
        overflow-y: auto !important;
    }
    
    #exerciseModal .modal-content h3 {
        font-size: 1.25rem !important;
        margin-bottom: 0.5rem !important;
    }
    
    /* Ultra-compact exercise details for desktop */
    #exerciseModal .exercise-details {
        padding: 0.5rem 0.75rem !important;
        margin: 0.5rem 0 !important;
        max-height: 100px !important;
    }
    
    #exerciseModal .detail-row {
        padding: 0.2rem 0 !important;
        font-size: 0.8rem !important;
        line-height: 1.2 !important;
    }
    
    #exerciseModal .detail-label {
        font-size: 0.75rem !important;
    }
    
    #exerciseModal .detail-row span:last-child {
        font-size: 0.8rem !important;
    }
    
    /* Compress set configuration */
    #exerciseModal .set-configuration {
        margin: 1rem 0 !important;
    }
    
    #exerciseModal .set-configuration h4 {
        font-size: 1.1rem !important;
        margin-bottom: 0.75rem !important;
    }
    
    /* Smaller inputs on desktop */
    #exerciseModal .sets-input,
    #exerciseModal .reps-input {
        margin-bottom: 0.75rem !important;
    }
    
    #exerciseModal .sets-input input,
    #exerciseModal .reps-input input {
        padding: 0.5rem 0.75rem !important;
        font-size: 0.9rem !important;
    }
    
    /* Compress rest selector */
    #exerciseModal .rest-selector {
        margin-top: 1rem !important;
        margin-bottom: 0.5rem !important;
    }
    
    #exerciseModal .rest-selector label {
        font-size: 0.9rem !important;
        margin-bottom: 0.5rem !important;
    }
    
    /* Smaller rest buttons on desktop */
    #exerciseModal .rest-options {
        gap: 0.4rem !important;
        padding: 0.4rem !important;
    }
    
    #exerciseModal .rest-btn {
        padding: 0.4rem 0.75rem !important;
        font-size: 0.8rem !important;
        min-height: 32px !important;
    }
    
    /* Force black text on desktop rest buttons */
    #exerciseModal .rest-btn:not(.active) {
        color: #000000 !important;
        background-color: #f1f5f9 !important;
    }
    
    #exerciseModal .rest-btn.active {
        color: #ffffff !important;
        background: var(--primary-color) !important;
    }
    
    /* Smaller add to workout button */
    #exerciseModal .btn-primary {
        padding: 0.75rem 1.5rem !important;
        font-size: 0.95rem !important;
        margin-top: 1rem !important;
    }
}

/* Force black text on ALL rest buttons - Desktop and Mobile */
.rest-btn:not(.active) {
    color: #000000 !important;
}

.rest-options .rest-btn:not(.active) {
    color: #000000 !important;
}

#exerciseModal .rest-btn:not(.active) {
    color: #000000 !important;
}

/* FINAL OVERRIDES - Ensure these take precedence */
@media (max-width: 768px) {
    /* Ultra-compact exercise details section */
    #exerciseModal .exercise-details {
        max-height: 80px !important;
        overflow: hidden !important;
        padding: 0.3rem 0.5rem !important;
        margin: 0.2rem 0 0.5rem 0 !important;
    }
    
    #exerciseModal .detail-row {
        line-height: 1.1 !important;
        margin: 0 !important;
        padding: 0.1rem 0 !important;
    }
    
    /* Force black text on ALL rest buttons */
    #exerciseModal .rest-btn:not(.active) {
        color: #000000 !important;
        background-color: #f1f5f9 !important;
    }
    
    #exerciseModal .rest-btn.active {
        color: #ffffff !important;
    }
    
    /* Clear separation between sections */
    #exerciseModal .sets-input {
        margin-bottom: 1rem !important;
    }
    
    #exerciseModal .reps-input {
        margin-bottom: 2rem !important;
        padding-bottom: 0.5rem !important;
    }
    
    #exerciseModal .rest-selector {
        clear: both !important;
        margin-top: 2rem !important;
        padding-top: 1.5rem !important;
        border-top: 2px solid #e2e8f0 !important;
    }
}

/* Fix: Remove rectangle/box around Rep Range */
#exerciseModal .reps-input {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    outline: none !important;
}

/* Remove any padding that creates visual separation */
@media (max-width: 768px) {
    #exerciseModal .reps-input {
        padding-bottom: 0 !important;
        margin-bottom: 1.5rem !important;
    }
}

/* ABSOLUTE FINAL OVERRIDES - Maximum compression for one-screen view */
/* Desktop specific ultra-compression */
@media (min-width: 769px) {
    #exerciseModal .modal-content {
        max-width: 700px !important;
        padding: 1.25rem !important;
        padding-right: 3rem !important; /* Extra padding to prevent overflow */
    }
    
    /* Rep range positioning handled in workout-builder-modal-desktop-fix.css */
    
    /* Grid layout for desktop efficiency */
    #exerciseModal .exercise-details {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 0.25rem 1rem !important;
        padding: 0.4rem !important;
        margin: 0.25rem 0 !important;
    }
    
    #exerciseModal .detail-row {
        border: none !important;
        padding: 0.15rem 0 !important;
    }
    
    /* Grid layout for set configuration */
    #exerciseModal .set-configuration {
        display: grid !important;
        grid-template-columns: 1fr !important;
        gap: 0.5rem !important;
        margin: 0.75rem 0 !important;
    }
    
    #exerciseModal .set-configuration h4 {
        grid-column: 1 / -1 !important;
        margin-bottom: 0.5rem !important;
    }
    
    /* Inline sets and reps */
    #exerciseModal .sets-input {
        display: grid !important;
        grid-template-columns: 120px 1fr !important;
        align-items: center !important;
        gap: 0.5rem !important;
        margin-bottom: 0.5rem !important;
    }
    
    /* Apply same grid layout to reps-input as sets-input */
    #exerciseModal .reps-input {
        display: grid !important;
        grid-template-columns: 120px calc(100% - 150px) !important; /* 30px smaller than sets */
        align-items: center !important;
        gap: 0.5rem !important;
        margin-bottom: 0.5rem !important;
        position: relative !important;
    }
    
    #exerciseModal .sets-input label,
    #exerciseModal .reps-input label {
        margin: 0 !important;
        font-size: 0.85rem !important;
        display: inline !important;
    }
}

/* Mobile specific ultra-compression */
@media (max-width: 768px) {
    /* Even more compact for mobile */
    #exerciseModal .modal-content {
        padding: 0.5rem !important;
        padding-top: 2.25rem !important;
    }
    
    #exerciseModal .modal-content h3 {
        font-size: 0.95rem !important;
        margin-bottom: 0.2rem !important;
    }
    
    #exerciseModal .exercise-details {
        font-size: 0.6rem !important;
        line-height: 1 !important;
    }
    
    #exerciseModal .set-configuration h4 {
        font-size: 0.9rem !important;
        margin-bottom: 0.5rem !important;
    }
}
