/* ==========================================================================
   Body Model - Interactive SVG Body Map
   ========================================================================== */

/* ---------- Container ---------- */
.body-model-section {
    padding: 1.5rem 0;
    margin: 1.5rem 0;
}

.body-model-section h3 {
    text-align: center;
    margin-bottom: 0.5rem;
    font-size: 1.25rem;
    color: #e2e8f0;
}

.body-model-section .body-model-subtitle {
    text-align: center;
    color: #94a3b8;
    font-size: 0.85rem;
    margin-bottom: 1rem;
}

/* ---------- Flipper (display toggle) ---------- */
.body-model-flipper-container {
    max-width: 320px;
    margin: 0 auto;
}

.body-model-flipper {
    position: relative;
    width: 100%;
}

.body-model-face {
    width: 100%;
}

.body-model-face--back {
    display: none;
}

/* ---------- SVG Styling ---------- */
.body-model-svg {
    width: 100%;
    height: auto;
    display: block;
}

.body-model-svg polygon {
    stroke: rgba(255, 255, 255, 0.15);
    stroke-width: 0.3;
    cursor: pointer;
    transition: fill 0.2s ease, opacity 0.2s ease, stroke 0.2s ease;
}

.body-model-svg polygon:hover {
    stroke: rgba(255, 255, 255, 0.6);
    stroke-width: 0.6;
    filter: brightness(1.2);
}

.body-model-svg polygon.region-selected {
    stroke: #3b82f6;
    stroke-width: 0.8;
    filter: brightness(1.15);
}

.body-model-svg polygon[data-muscle="head"] {
    cursor: default;
    pointer-events: none;
}

/* ---------- Flip Button ---------- */
.body-model-flip-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    margin: 0.75rem auto 0;
    padding: 0.4rem 1rem;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 20px;
    color: #94a3b8;
    font-size: 0.8rem;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

.body-model-flip-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #e2e8f0;
}

.body-model-flip-btn .flip-icon {
    display: inline-block;
    transition: transform 0.3s;
}

.body-model-flip-btn:hover .flip-icon {
    transform: rotateY(180deg);
}

/* ---------- Color Legend ---------- */
.body-model-legend {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.6rem;
    margin-top: 0.75rem;
    padding: 0.5rem;
    font-size: 0.72rem;
    color: #94a3b8;
}

.body-model-legend-item {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.body-model-legend-swatch {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    flex-shrink: 0;
}

/* ---------- Tooltip ---------- */
.body-model-tooltip {
    position: fixed;
    padding: 0.4rem 0.7rem;
    background: rgba(15, 23, 42, 0.95);
    color: #e2e8f0;
    font-size: 0.78rem;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    pointer-events: none;
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.15s;
    white-space: nowrap;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.body-model-tooltip.visible {
    opacity: 1;
}

.body-model-tooltip .tooltip-label {
    font-weight: 600;
}

.body-model-tooltip .tooltip-detail {
    font-size: 0.7rem;
    color: #94a3b8;
    margin-top: 2px;
}

/* ---------- Exercise Modal ---------- */
.body-model-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s, visibility 0.25s;
}

.body-model-modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.body-model-modal {
    background: #1e293b;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    width: 100%;
    max-width: 480px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    transform: translateY(20px);
    transition: transform 0.25s;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

.body-model-modal-overlay.active .body-model-modal {
    transform: translateY(0);
}

.body-model-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.body-model-modal-header h4 {
    margin: 0;
    font-size: 1.1rem;
    color: #e2e8f0;
}

.body-model-modal-close {
    background: none;
    border: none;
    color: #94a3b8;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.body-model-modal-close:hover {
    color: #e2e8f0;
}

.body-model-modal-stats {
    display: flex;
    gap: 1rem;
    padding: 0.75rem 1.25rem;
    background: rgba(255, 255, 255, 0.03);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    font-size: 0.8rem;
}

.body-model-modal-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.body-model-modal-stat-value {
    font-weight: 700;
    font-size: 1rem;
    color: #e2e8f0;
}

.body-model-modal-stat-label {
    color: #94a3b8;
    font-size: 0.7rem;
    margin-top: 2px;
}

.body-model-modal-body {
    padding: 0.75rem 1.25rem;
    overflow-y: auto;
    flex: 1;
}

.body-model-exercise-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.body-model-exercise-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    font-size: 0.85rem;
    color: #e2e8f0;
}

.body-model-exercise-item:last-child {
    border-bottom: none;
}

.body-model-exercise-badge {
    display: inline-block;
    padding: 0.15rem 0.45rem;
    border-radius: 4px;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    flex-shrink: 0;
}

.body-model-exercise-badge.beginner {
    background: rgba(16, 185, 129, 0.15);
    color: #10b981;
}

.body-model-exercise-badge.intermediate {
    background: rgba(245, 158, 11, 0.15);
    color: #f59e0b;
}

.body-model-exercise-badge.advanced {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
}

/* ---------- Trained Exercises List ---------- */
.body-model-trained-header {
    font-size: 0.8rem;
    font-weight: 600;
    color: #94a3b8;
    margin-bottom: 0.5rem;
}

.body-model-trained-name {
    flex: 1;
}

.body-model-trained-count {
    font-weight: 700;
    font-size: 0.8rem;
    color: #3b82f6;
    flex-shrink: 0;
    margin-left: 0.5rem;
}

.body-model-modal-tabs {
    display: flex;
    gap: 0.25rem;
    padding: 0.5rem 1.25rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.body-model-modal-tab {
    padding: 0.4rem 0.8rem;
    font-size: 0.78rem;
    border: none;
    background: none;
    color: #94a3b8;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: color 0.2s, border-color 0.2s;
}

.body-model-modal-tab:hover {
    color: #e2e8f0;
}

.body-model-modal-tab.active {
    color: #3b82f6;
    border-bottom-color: #3b82f6;
}

.body-model-exercise-empty {
    text-align: center;
    color: #94a3b8;
    padding: 2rem 0;
    font-size: 0.85rem;
}

/* ---------- Heart & Lungs Overlay ---------- */
.organ-overlay {
    transition: opacity 0.2s, filter 0.2s;
}

.organ-overlay:hover {
    filter: brightness(1.3);
}

/* Disable organ clicks in selection mode (profile page) */
.body-model-section.mode-selection .organ-overlay {
    pointer-events: none;
}

@keyframes heartbeat {
    0%, 100% { transform: scale(1); }
    15% { transform: scale(1.12); }
    30% { transform: scale(1); }
    45% { transform: scale(1.08); }
    60% { transform: scale(1); }
}

@keyframes breathing {
    0%, 100% { transform: scaleX(1) scaleY(1); }
    50% { transform: scaleX(1.06) scaleY(1.04); }
}

.organ-heart {
    animation: heartbeat 1.2s ease-in-out infinite;
    transform-origin: 50px 56px;
}

.organ-lung {
    animation: breathing 4s ease-in-out infinite;
}

.organ-lung--left {
    transform-origin: 38px 55px;
}

.organ-lung--right {
    transform-origin: 62px 55px;
}

/* ---------- Profile Selection Mode ---------- */
.body-model-section.mode-selection .body-model-svg polygon {
    fill: #374151;
    opacity: 0.5;
}

.body-model-section.mode-selection .body-model-svg polygon.region-selected {
    fill: #3b82f6;
    opacity: 0.85;
}

.body-model-section.mode-selection .body-model-svg polygon:hover {
    opacity: 0.75;
}

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
    .body-model-flipper-container {
        max-width: 260px;
    }

    .body-model-section h3 {
        font-size: 1.1rem;
    }

    .body-model-legend {
        gap: 0.4rem;
        font-size: 0.65rem;
    }

    .body-model-modal {
        max-height: 85vh;
    }

    .body-model-modal-stats {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
}

@media (min-width: 481px) and (max-width: 768px) {
    .body-model-flipper-container {
        max-width: 280px;
    }
}

@media (min-width: 769px) {
    .body-model-flipper-container {
        max-width: 320px;
    }

}

/* ---------- Dashboard layout context ---------- */
.dashboard-grid .body-model-section {
    grid-column: 1 / -1;
    padding: 1rem;
    background: #1e293b;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.08);
}

/* ---------- Profile context ---------- */
.form-section .body-model-section {
    margin: 0.5rem 0 1rem;
    padding: 0.5rem 0;
}

/* ---------- Goal notification toast ---------- */
@keyframes goalToastSlideDown {
    from { opacity: 0; transform: translate(-50%, -20px); }
    to   { opacity: 1; transform: translate(-50%, 0); }
}

.body-model-goal-toast {
    position: fixed;
    top: max(16px, calc(16px + env(safe-area-inset-top, 0px)));
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    color: #fff;
    padding: 14px 44px 14px 18px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    z-index: 10002;
    box-shadow: 0 4px 16px rgba(245, 158, 11, 0.4);
    animation: goalToastSlideDown 0.35s ease-out;
    max-width: 90vw;
    width: max-content;
}

.body-model-goal-toast strong {
    font-weight: 700;
}

.goal-toast-close {
    position: absolute;
    top: 8px;
    right: 10px;
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.8);
    font-size: 20px;
    cursor: pointer;
    line-height: 1;
    padding: 4px;
}

.goal-toast-close:hover {
    color: #fff;
}

.goal-toast-fade-out {
    opacity: 0;
    transition: opacity 0.3s ease-out;
}

/* ---------- Homepage context ---------- */
.hero + .body-model-section,
.body-model-section.homepage-context {
    background: rgba(255, 255, 255, 0.03);
    border-radius: 12px;
    padding: 1.5rem;
    margin: 1.5rem auto;
    max-width: 600px;
}
