/* MaxRepTracker AI Frontend Components Styles */
/* Contains: Headers, navigation, switches, status indicators, messages */

/* Header and Navigation */
.mrt-ai-header {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 15px;
    -webkit-tap-highlight-color: transparent; /* Remove blue highlight on mobile */
    outline: none;
}

.mrt-ai-title-section {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 15px;
    width: 100%; /* Ensure full width for right-alignment of icon */
}

.mrt-ai-title-content {
    flex: 1;
    min-width: 0;
}

.mrt-ai-nav-arrow {
    background: none;
    border: none;
    color: #667eea;
    font-size: 1.5em;
    cursor: pointer;
    padding: 0 5px;
    transition:
        color 0.3s ease,
        transform 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    opacity: 0.7;
    flex-shrink: 0;
}

.mrt-ai-nav-arrow:hover {
    color: #764ba2;
    transform: scale(1.2);
    opacity: 1;
    background: none !important;
}

/* Toggle Icon mimicking Calendar Plugin style */
.mrt-ai-toggle-icon {
    color: #667eea;
    font-size: 0.9em;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    margin-left: auto; /* Push to right */
    padding: 0 5px;
    opacity: 0.8;
    transform: rotate(-90deg); /* Default closed state (pointing right) */
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* When active (open), rotate to point down */
.mrt-ai-tip.active .mrt-ai-toggle-icon {
    transform: rotate(0deg);
    color: #764ba2;
    opacity: 1;
}

/* Dark mode adjustment */
html.maxreptracker-dark-mode-enabled .mrt-ai-toggle-icon {
    color: #a3bffa;
}

/* On hover/focus of the header */
.mrt-ai-header:hover .mrt-ai-toggle-icon {
    opacity: 1;
    transform: rotate(-90deg) scale(1.1);
}

.mrt-ai-tip.active .mrt-ai-header:hover .mrt-ai-toggle-icon {
    transform: rotate(0deg) scale(1.1);
}

.mrt-ai-nav-arrow:active {
    transform: scale(1.1);
    background: none !important;
}

.mrt-ai-nav-arrow:focus {
    color: #764ba2;
    transform: scale(1.2);
    opacity: 1;
    background: none !important;
}

.mrt-ai-nav-arrow:focus:hover {
    color: #764ba2;
    transform: scale(1.2);
    opacity: 1;
    background: none !important;
}

.mrt-ai-header h4 {
    margin: 0 0 5px 3px;
    word-wrap: break-word;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    font-size: 1.25em; /* Increased size */
    color: #667eea;
    line-height: 1.3;
}

.mrt-ai-pagination {
    font-size: 0.85em;
    color: #888;
    font-weight: 500;
    background: rgba(0, 0, 0, 0.05);
    padding: 4px 10px;
    border-radius: 12px;
    white-space: nowrap;
}

.mrt-ai-page-current {
    font-weight: 700;
    color: #667eea;
}

.mrt-ai-page-total {
    color: #888;
}

/* Mode Tabs Navigation */
.mrt-ai-mode-tabs {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 12px;
    width: 100%;
    padding: 8px 4px 16px 4px; /* Space for shadows/indicators */
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    position: relative;
    animation: mrtTabsEntrance 0.6s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
    mask-image: linear-gradient(
        to right,
        transparent,
        black 10px,
        black 90%,
        transparent
    ); /* Fade edges if scrolling needed */
    -webkit-mask-image: linear-gradient(
        to right,
        transparent,
        black 10px,
        black 90%,
        transparent
    );
}

@keyframes mrtTabsEntrance {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.mrt-ai-mode-tabs::-webkit-scrollbar {
    display: none;
}

.mrt-ai-mode-tab {
    position: relative;
    flex: 0 0 auto; /* Don't shrink */
    padding: 10px 20px;
    min-height: 44px; /* Mobile standard */
    border: 1px solid rgba(102, 126, 234, 0.2);
    border-radius: 99px; /* Pill shape */
    background: rgba(255, 255, 255, 0.6);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: #5a6b8c;
    font-size: 0.9em;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    display: flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.02);
}

/* Safe Centering: Pushes tabs to center if they fit, allows scrolling if they don't */
.mrt-ai-mode-tab:first-child {
    margin-left: auto;
}

.mrt-ai-mode-tab:last-child {
    margin-right: auto;
}

/* Modern Indicator Dot (Hidden by default) */
.mrt-ai-mode-tab::before {
    content: "";
    position: absolute;
    bottom: -8px; /* Moved below the button */
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: #667eea;
    opacity: 0;
    transform: scale(0);
    transition: all 0.3s ease;
}

.mrt-ai-mode-tab:hover {
    color: #667eea;
    background: rgba(255, 255, 255, 0.9);
    border-color: rgba(102, 126, 234, 0.4);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.1);
}

.mrt-ai-mode-tab:active {
    transform: scale(0.96);
}

/* --- States --- */

/* 1. Preselected: "Recommended" but not active */
.mrt-ai-mode-tab.preselected {
    border-color: rgba(102, 126, 234, 0.6);
    color: #667eea;
    background: rgba(102, 126, 234, 0.05);
    font-weight: 600;
}

/* 2. Selected: User tapped it, pending action */
.mrt-ai-mode-tab.selected {
    border-color: #667eea;
    color: #667eea;
    background: white;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.15);
    font-weight: 700;
}

/* 3. Open: Content is visible / Active Mode */
.mrt-ai-mode-tab.open {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-color: transparent;
    box-shadow: 0 8px 20px rgba(102, 126, 234, 0.35);
    font-weight: 700;
    padding: 10px 20px; /* Reset padding to standard */
}

/* Open Indicator */
.mrt-ai-mode-tab.open::before {
    opacity: 1;
    transform: scale(1);
    background: #667eea; /* Theme color for visibility on page bg */
}

/* Dark Mode Overrides for Indicator */
html.maxreptracker-dark-mode-enabled .mrt-ai-mode-tab::before {
    background: #a3bffa;
}

html.maxreptracker-dark-mode-enabled .mrt-ai-mode-tab.open::before {
    background: #a3bffa; /* Ensure visibility in dark mode */
}

/* Add a pseudo-border glow for .open state */
.mrt-ai-mode-tab.open::after {
    content: "";
    position: absolute;
    inset: -2px;
    border-radius: 99px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    z-index: -1;
    opacity: 0.4;
    filter: blur(4px);
    transition: opacity 0.3s;
}

/* Dark Mode Overrides */
html.maxreptracker-dark-mode-enabled .mrt-ai-mode-tabs {
    mask-image: linear-gradient(
        to right,
        transparent,
        black 10px,
        black 90%,
        transparent
    ); /* Keep mask */
}

html.maxreptracker-dark-mode-enabled .mrt-ai-mode-tab {
    background: rgba(30, 30, 35, 0.6);
    border-color: rgba(255, 255, 255, 0.1);
    color: #94a3b8;
    box-shadow: none;
}

html.maxreptracker-dark-mode-enabled .mrt-ai-mode-tab:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #e2e8f0;
    border-color: rgba(255, 255, 255, 0.2);
}

html.maxreptracker-dark-mode-enabled .mrt-ai-mode-tab.preselected {
    background: rgba(102, 126, 234, 0.1);
    border-color: rgba(102, 126, 234, 0.4);
    color: #a3bffa;
}

html.maxreptracker-dark-mode-enabled .mrt-ai-mode-tab.selected {
    background: rgba(102, 126, 234, 0.15);
    border-color: #818cf8;
    color: #fff;
    box-shadow: 0 0 15px rgba(102, 126, 234, 0.1);
}

html.maxreptracker-dark-mode-enabled .mrt-ai-mode-tab.open {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-color: transparent;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.5); /* Stronger shadow in dark mode */
}

html.maxreptracker-dark-mode-enabled .mrt-ai-mode-tab.open::after {
    opacity: 0.6; /* Stronger glow in dark mode */
}

/* AI Coach Status Indicator */
.mrtai-status-tooltip {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-right: 8px;
    vertical-align: middle;
}

.mrtai-status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    vertical-align: middle;
    background-color: #ccc; /* Default: loading/checking state */
    transition: background-color 0.3s ease;
}

.mrtai-status-indicator.ready {
    background-color: #4caf50; /* Green - AI Coach ready */
}

.mrtai-status-indicator.unavailable {
    background-color: #9e9e9e; /* Grey - AI Coach unavailable */
}

.mrtai-status-tooltip .mrtai-tooltip-text {
    visibility: hidden;
    width: 120px;
    background-color: #555;
    color: #fff;
    text-align: center;
    border-radius: 6px;
    padding: 5px;
    position: absolute;
    z-index: 1;
    bottom: 125%;
    left: 50%;
    margin-left: -60px;
    opacity: 0;
    transition: opacity 0.3s;
    font-size: 0.8em;
}

.mrtai-status-tooltip:hover .mrtai-tooltip-text {
    visibility: visible;
    opacity: 1;
}

.mrt-ai-exercise {
    opacity: 0.9;
    font-size: 0.8em;
    font-weight: 600;
    text-align: center;
    display: block;
    padding: 5px;
    margin-top: 15px;
    margin-bottom: 5px;
    background-color: rgba(249, 220, 92, 0.23);
    border-radius: 10px;
    text-transform: uppercase;
    word-wrap: break-word;
}

.mrt-ai-context-badge {
    opacity: 0.8;
    font-size: 1.2em;
    font-style: italic;
}

/* Clickable Header */
.mrt-ai-header {
    cursor: pointer;
    transition: background-color 0.2s ease;
    border-radius: 8px;
    padding: 5px;
    margin: -5px;
}

.mrt-ai-content {
    margin: 15px 0;
    font-size: 1em;
    line-height: 1.6;
}

.mrt-ai-footer {
    border-top: 1px solid rgba(255, 255, 255, 0.3);
    padding-top: 10px;
    margin-top: 15px;
    font-size: 0.8em;
    opacity: 0.7;
}

.mrt-ai-error {
    background: rgba(255, 59, 48, 0.2);
    border: 1px solid rgba(255, 59, 48, 0.3);
    padding: 12px;
    border-radius: 6px;
    margin-top: 10px;
}

/* Loading Status Indicator - Fallback System */
.mrt-ai-loading-status {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: linear-gradient(
        135deg,
        rgba(102, 126, 234, 0.1) 0%,
        rgba(118, 75, 162, 0.1) 100%
    );
    border: 1px solid rgba(102, 126, 234, 0.2);
    border-radius: 8px;
    margin-bottom: 12px;
    animation: statusFadeIn 0.3s ease;
}

@keyframes statusFadeIn {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.mrt-ai-loading-status .status-icon {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    animation: statusPulse 1.5s infinite;
    flex-shrink: 0;
}

@keyframes statusPulse {
    0%,
    100% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.2);
        opacity: 0.7;
    }
}

.mrt-ai-loading-status .status-text {
    font-size: 0.9em;
    color: #555;
    flex: 1;
}

.mrt-ai-loading-status .status-text strong {
    color: #667eea;
}

.mrt-ai-loading-status.retrying {
    background: linear-gradient(
        135deg,
        rgba(255, 193, 7, 0.15) 0%,
        rgba(255, 152, 0, 0.15) 100%
    );
    border-color: rgba(255, 193, 7, 0.3);
}

.mrt-ai-loading-status.retrying .status-icon {
    background: linear-gradient(135deg, #ffc107 0%, #ff9800 100%);
}

/* Error Content Layout */
.mrt-ai-error-content {
    text-align: center;
}

.mrt-ai-error-content p {
    margin: 0 0 12px 0;
}

.mrt-ai-error-content .mrt-ai-support-text {
    margin-top: 12px;
    font-size: 0.9em;
    opacity: 0.8;
}

/* Retry Button */
.mrt-ai-retry-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 10px 20px;
    font-size: 0.95em;
    font-weight: 600;
    cursor: pointer;
    transition:
        transform 0.2s ease,
        box-shadow 0.2s ease,
        opacity 0.2s ease;
    margin: 8px 0;
}

.mrt-ai-retry-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.mrt-ai-retry-btn:active {
    transform: translateY(0);
}

.mrt-ai-retry-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Global Switch Styles */
/* Global Switch Styles */
.mrtai-global-switch {
    display: inline-block;
    width: 100%;
    height: auto;
    margin: 10px 0;
    padding: 20px;
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    box-sizing: border-box;
    transition:
        background-color 0.3s ease,
        border-color 0.3s ease,
        box-shadow 0.3s ease;
}

.mrtai-switch-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 20px;
    position: relative;
}

.mrtai-header-left {
    flex: 1;
    min-width: 0;
}

.mrtai-header-left h4 {
    margin: 0 0 8px 0;
    color: #333;
    font-size: 1.2em; /* Standardized */
    font-weight: 600;
}

.mrtai-header-left p {
    margin: 0 !important;
    color: #666;
    font-size: 1.1em;
}

.mrtai-header-right {
    display: flex;
    justify-content: flex-end;
    flex-shrink: 0;
}

.mrtai-switch-control {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 0;
}

.mrtai-switch {
    position: relative;
    display: inline-block;
    width: 60px; /* Standardized */
    height: 34px; /* Standardized */
    flex-shrink: 0;
}

.mrtai-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.mrtai-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: background-color 0.4s;
    border-radius: 34px; /* Standardized */
}

.mrtai-slider:before {
    position: absolute;
    content: "";
    height: 26px; /* Standardized */
    width: 26px; /* Standardized */
    left: 4px; /* Standardized */
    bottom: 4px; /* Standardized */
    background-color: white;
    transition:
        transform 0.4s,
        background-color 0.4s;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.mrtai-switch input:checked + .mrtai-slider {
    background: linear-gradient(
        135deg,
        #667eea 0%,
        #764ba2 100%
    ); /* Standardized */
}

.mrtai-switch input:checked + .mrtai-slider:before {
    transform: translateX(26px); /* Standardized */
}

/* Dark mode styles */
html.maxreptracker-dark-mode-enabled .mrtai-global-switch {
    background: rgba(26, 26, 26, 0.95) !important;
    border-color: #333 !important;
}

html.maxreptracker-dark-mode-enabled .mrtai-header-left h4 {
    color: #fff !important;
}

html.maxreptracker-dark-mode-enabled .mrtai-header-left p {
    color: #aaa !important;
}

/* Tablet (481px to 768px) */
@media (max-width: 768px) and (min-width: 481px) {
    .mrtai-switch-header {
        gap: 5px;
    }
}

/* Mobile landscape and small tablets (376px to 480px) */
@media (max-width: 480px) and (min-width: 376px) {
    .mrtai-global-switch {
        padding: 14px; /* Standardized */
    }

    .mrtai-switch-header {
        gap: 5px;
    }

    .mrtai-header-left h4 {
        font-size: 1em; /* Standardized */
    }

    .mrtai-header-left p {
        font-size: 0.9em; /* Standardized */
    }

    .mrtai-switch {
        height: 28px; /* Standardized Mobile Landscape */
        width: 52px; /* Standardized Mobile Landscape */
    }

    .mrtai-slider:before {
        height: 20px; /* Standardized */
        width: 20px; /* Standardized */
        left: 4px;
        bottom: 4px;
    }

    .mrtai-switch input:checked + .mrtai-slider:before {
        transform: translateX(22px); /* Standardized */
    }
}

/* Mobile Portrait (< 375px) */
@media (max-width: 375px) {
    .mrtai-global-switch {
        padding: 14px; /* Standardized */
    }

    .mrtai-switch-header {
        gap: 5px;
    }

    .mrtai-header-left h4 {
        font-size: 1em; /* Standardized */
    }

    .mrtai-header-left p {
        font-size: 0.9em; /* Standardized */
    }

    .mrtai-switch {
        height: 26px; /* Standardized Mobile Portrait */
        width: 48px; /* Standardized Mobile Portrait */
    }

    .mrtai-slider:before {
        height: 18px; /* Standardized */
        width: 18px; /* Standardized */
        left: 4px;
        bottom: 4px;
    }

    .mrtai-switch input:checked + .mrtai-slider:before {
        transform: translateX(20px); /* Standardized */
    }
}

/* Galaxy Note and similar devices - max-width: 412px */
@media screen and (max-width: 412px) {
    .mrtai-global-switch {
        padding: 13px;
        margin: 10px 0;
    }

    .mrtai-header-left h4 {
        font-size: 0.95em;
        line-height: 1.3;
    }

    .mrtai-header-left p {
        font-size: 0.85em;
        line-height: 1.3;
    }

    .mrtai-switch {
        width: 52px;
        height: 28px;
    }

    .mrtai-slider:before {
        height: 20px;
        width: 20px;
        left: 4px;
        bottom: 4px;
    }

    .mrtai-switch input:checked + .mrtai-slider:before {
        transform: translateX(22px);
    }

    /* Ensure right alignment on 412px screens */
    .mrtai-header-right {
        flex-direction: row;
        align-items: center;
        justify-content: flex-end;
        flex-shrink: 0;
    }

    .mrtai-switch-control {
        flex: 0;
        justify-content: flex-end;
        gap: 10px;
    }
}

/* Small mobile devices - max-width: 360px */
@media screen and (max-width: 360px) {
    .mrtai-global-switch {
        padding: 12px;
        margin: 8px 0;
    }

    .mrtai-header-left h4 {
        font-size: 1em;
    }

    .mrtai-header-left p {
        font-size: 0.9em;
        line-height: 1.3;
    }

    .mrtai-switch {
        width: 48px;
        height: 26px;
    }

    .mrtai-slider:before {
        height: 18px;
        width: 18px;
        left: 4px;
        bottom: 4px;
    }

    .mrtai-switch input:checked + .mrtai-slider:before {
        transform: translateX(20px);
    }

    /* Ensure right alignment on 360px screens */
    .mrtai-header-right {
        flex-direction: row;
        align-items: center;
        justify-content: flex-end;
        flex-shrink: 0;
    }

    .mrtai-switch-control {
        flex: 0;
        justify-content: flex-end;
        gap: 10px;
    }
}

.mrtai-switch-description {
    background: white;
    padding: 15px;
    border-radius: 6px;
    border-left: 4px solid #667eea;
    margin-bottom: 0;
}

.mrtai-switch-description p {
    margin: 8px 0;
    font-size: 0.9em;
    color: #555;
}

.mrtai-feedback-message {
    padding: 10px;
    border-radius: 4px;
    font-size: 0.9em;
}

.mrtai-feedback-success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.mrtai-feedback-error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.mrtai-global-status {
    background: #fff3cd;
    border: 1px solid #ffeaa7;
    border-radius: 6px;
    padding: 15px;
    color: #856404;
    max-width: 500px;
}

/* Locked State Styles */
.mrtai-locked .mrtai-slider-locked {
    cursor: not-allowed;
    background-color: #ddd;
}

.mrtai-locked-content {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #e9ecef;
}

.mrtai-premium-msg {
    text-align: center;
    margin-bottom: 15px;
}

.mrtai-premium-msg h6 {
    margin: 0 0 10px 0;
    font-size: 0.95em;
    font-weight: 600;
    color: #333;
}

.mrtai-premium-msg p {
    margin: 5px 0;
    font-size: 0.85em;
    color: #666;
}

.mrtai-upgrade-section {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 15px;
}

.mrtai-upgrade-btn {
    display: inline-block;
    width: auto;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white !important;
    border: none;
    border-radius: 6px;
    padding: 10px 24px;
    font-size: 0.95em;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none !important;
    text-align: center;
    transition: all 0.3s ease;
    box-sizing: border-box;
}

.mrtai-upgrade-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(102, 126, 234, 0.4);
    text-decoration: none !important;
    color: white !important;
}

/* MaxRepTracker AI Message Styles */
.mrt-ai-message p {
    margin: 0 0 12px 0;
    line-height: 1.6;
    font-size: 1em;
}

.mrt-ai-message p:last-child {
    margin-bottom: 0;
}

.mrt-ai-message em {
    font-style: italic;
    opacity: 0.9;
}

.mrt-ai-message ol,
.mrt-ai-message ul {
    margin: 12px 0;
    padding-left: 20px;
}

.mrt-ai-message li {
    margin-bottom: 6px;
    line-height: 1.6;
    font-size: 1em;
}

.mrt-ai-message li:last-child {
    margin-bottom: 0;
}

.mrt-ai-message code {
    background: rgba(255, 255, 255, 0.1);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: monospace;
    font-size: 0.95em;
}

.mrt-ai-message strong em,
.mrt-ai-message em strong {
    opacity: 0.95;
}
