/**
 * AILMS Lesson Sidebar Styles
 * Dual sidebar layout with lessons list and timer/progress
 * Version: 1.6.0
 *
 * Changes in 1.6.0 (v3.2.7):
 * - Completed topics now have gray background (#f1f5f9)
 * - Topics are clickable to navigate to that lesson
 * - Expanded sidebar width +20% (312px → 374px)
 *
 * Changes in 1.5.0 (v3.2.6):
 * - Added topics list with completion checkmarks
 * - Expanded sidebar width by 30% (240px → 312px)
 * - Added .ailms-topics-list, .ailms-topic-item, .ailms-topic-check styles
 *
 * Changes in 1.4.0:
 * - Added active phase (pulsing) effect for current learning phase
 * - Added ailms-phase-pulse animation
 *
 * Changes in 1.3.0:
 * - Added language toggle (TH/EN)
 * - Added Learning Rules widget
 *
 * Changes in 1.2.0:
 * - Added locked state styling for sequential learning
 * - Added expandable lesson details panel
 * - Added detail sections with status badges
 * - Added go-to-phase buttons
 */

/* ============================================
   Layout Wrapper
   ============================================ */
.ailms-layout-wrapper {
    display: flex;
    min-height: auto;
    max-height: calc(100vh - 120px);
    gap: 12px;
    position: relative;
    justify-content: center;
    align-items: flex-start;
    padding: 10px 20px;
}

.ailms-main-content {
    flex: 1;
    max-width: 800px;
    margin: 0;
    padding: 10px;
    transition: margin 0.3s ease;
    position: relative;
}

/* ============================================
   Sidebar Base Styles
   ============================================ */
.ailms-sidebar {
    width: 374px; /* v3.2.7: Expanded +20% from 312px for topic names */
    max-height: calc(100vh - 140px);
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    flex-shrink: 0;
}

.ailms-sidebar-left {
    margin-left: 0;
}

.ailms-sidebar-right {
    margin-right: 0;
}

.ailms-sidebar-toggle {
    display: none;
}

.ailms-sidebar-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ============================================
   Sidebar Header
   ============================================ */
.ailms-sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 14px;
    border-bottom: 1px solid #e5e7eb;
}

.ailms-sidebar-header h3 {
    font-size: 14px;
    font-weight: 600;
    color: #1e293b;
    margin: 0;
}

.ailms-sidebar-count {
    background: #3b82f6;
    color: white;
    font-size: 11px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 10px;
}

/* ============================================
   Progress Bar
   ============================================ */
.ailms-sidebar-progress-bar {
    height: 3px;
    background: #e5e7eb;
    overflow: hidden;
}

.ailms-sidebar-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #3b82f6 0%, #2563eb 100%);
    transition: width 0.5s ease;
}

/* ============================================
   Lessons List
   ============================================ */
.ailms-sidebar-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.ailms-sidebar-loading,
.ailms-empty,
.ailms-error {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 20px 12px;
    color: #64748b;
    font-size: 13px;
}

.ailms-error {
    color: #dc2626;
}

.ailms-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid #e5e7eb;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: ailms-spin 0.8s linear infinite;
}

@keyframes ailms-spin {
    to { transform: rotate(360deg); }
}

/* ============================================
   Lesson Item
   ============================================ */
.ailms-lesson-item {
    display: flex;
    flex-direction: column;
    border-radius: 8px;
    text-decoration: none;
    color: inherit;
    transition: all 0.2s ease;
    margin-bottom: 2px;
    overflow: hidden;
}

.ailms-lesson-item:hover {
    background: #f1f5f9;
}

.ailms-lesson-item.current {
    background: #eff6ff;
    border: 2px solid #3b82f6;
}

.ailms-lesson-item.completed {
    opacity: 0.85;
}

/* Locked State */
.ailms-lesson-item.locked {
    opacity: 0.5;
    cursor: not-allowed;
}

.ailms-lesson-item.locked:hover {
    background: transparent;
}

.ailms-lesson-item.locked .ailms-lesson-main {
    cursor: not-allowed;
}

.ailms-lock-icon {
    font-size: 12px;
    flex-shrink: 0;
}

/* Lesson Main Row (clickable) */
.ailms-lesson-main {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.ailms-lesson-item.current .ailms-lesson-main {
    padding: 6px;
}

.ailms-lesson-main:hover {
    background: rgba(0, 0, 0, 0.03);
}

/* Expand Icon */
.ailms-expand-icon {
    font-size: 10px;
    color: #94a3b8;
    flex-shrink: 0;
    transition: transform 0.2s ease;
}

.ailms-lesson-item.expanded .ailms-expand-icon {
    transform: rotate(180deg);
}

/* ============================================
   Expandable Lesson Details
   ============================================ */
.ailms-lesson-details {
    padding: 6px 8px 8px 44px;
    background: #f8fafc;
    border-top: 1px solid #e5e7eb;
}

.ailms-detail-section {
    padding: 8px;
    margin-bottom: 6px;
    background: white;
    border-radius: 6px;
    border: 1px solid #e5e7eb;
}

.ailms-detail-section:last-child {
    margin-bottom: 0;
}

.ailms-detail-header {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 500;
    color: #475569;
}

.ailms-detail-icon {
    font-size: 12px;
    flex-shrink: 0;
}

.ailms-detail-status {
    margin-left: auto;
    font-size: 9px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
}

.ailms-detail-status.done {
    background: #dcfce7;
    color: #16a34a;
}

.ailms-detail-status.pending {
    background: #fef3c7;
    color: #d97706;
}

.ailms-detail-info {
    display: flex;
    gap: 10px;
    font-size: 10px;
    color: #64748b;
    margin-top: 4px;
    padding-left: 18px;
}

.ailms-go-btn {
    width: 100%;
    padding: 6px 8px;
    margin-top: 6px;
    font-size: 10px;
    font-weight: 500;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    background: white;
    color: #475569;
    cursor: pointer;
    transition: all 0.2s ease;
}

.ailms-go-btn:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
}

.ailms-go-btn.primary {
    background: #3b82f6;
    color: white;
    border-color: #3b82f6;
}

.ailms-go-btn.primary:hover {
    background: #2563eb;
    border-color: #2563eb;
}

.ailms-go-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ============================================
   Skip Introduction Button
   ============================================ */
.ailms-skip-section {
    background: linear-gradient(135deg, #fff7ed 0%, #ffedd5 100%);
    border: 1px solid #fed7aa;
    border-radius: 6px;
    padding: 10px;
    margin-bottom: 8px;
}

.ailms-skip-desc {
    font-size: 10px;
    color: #9a3412;
    margin: 4px 0 8px 0;
    line-height: 1.4;
}

.ailms-skip-btn {
    background: linear-gradient(135deg, #f97316, #ea580c) !important;
    color: white !important;
    border: none !important;
    font-weight: 600 !important;
    padding: 8px 12px !important;
}

.ailms-skip-btn:hover {
    background: linear-gradient(135deg, #ea580c, #c2410c) !important;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(249, 115, 22, 0.4);
}

/* ============================================
   Loading Overlay
   ============================================ */
.ailms-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    z-index: 100;
    border-radius: 8px;
}

.ailms-loading-overlay span {
    font-size: 13px;
    color: #64748b;
}

/* ============================================
   Language Toggle
   ============================================ */
.ailms-lang-toggle {
    display: flex;
    justify-content: center;
    gap: 4px;
    padding: 8px;
    background: #f8fafc;
    border-bottom: 1px solid #e5e7eb;
}

.ailms-lang-btn {
    padding: 4px 12px;
    font-size: 11px;
    font-weight: 600;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    background: white;
    color: #64748b;
    cursor: pointer;
    transition: all 0.2s ease;
}

.ailms-lang-btn:hover {
    border-color: #3b82f6;
    color: #3b82f6;
}

.ailms-lang-btn.active {
    background: #3b82f6;
    border-color: #3b82f6;
    color: white;
}

/* ============================================
   Learning Rules Widget
   ============================================ */
.ailms-rules-widget {
    padding: 12px;
    background: #fefce8;
    border-top: 1px solid #fef08a;
}

.ailms-rules-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 10px;
}

.ailms-rules-icon {
    font-size: 14px;
}

.ailms-rules-title {
    font-size: 12px;
    font-weight: 600;
    color: #854d0e;
}

.ailms-rules-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.ailms-rules-list li {
    position: relative;
    padding: 6px 0 6px 18px;
    font-size: 10px;
    line-height: 1.4;
    color: #713f12;
    border-bottom: 1px dashed #fde047;
}

.ailms-rules-list li:last-child {
    border-bottom: none;
}

.ailms-rules-list li::before {
    content: '✓';
    position: absolute;
    left: 0;
    top: 6px;
    font-size: 10px;
    color: #ca8a04;
}

/* ============================================
   AutoSave Widget
   ============================================ */
.ailms-autosave-widget {
    padding: 10px 12px;
    background: #f1f5f9;
    border-top: 1px solid #e5e7eb;
}

.ailms-autosave-content {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    color: #64748b;
}

.ailms-autosave-icon {
    font-size: 14px;
    flex-shrink: 0;
}

.ailms-autosave-text {
    flex: 1;
}

/* AutoSave States */
.ailms-autosave-widget.saving {
    background: #eff6ff;
}

.ailms-autosave-widget.saving .ailms-autosave-content {
    color: #3b82f6;
}

.ailms-autosave-widget.saving .ailms-autosave-icon {
    animation: ailms-pulse 1s ease-in-out infinite;
}

.ailms-autosave-widget.saved {
    background: #f0fdf4;
}

.ailms-autosave-widget.saved .ailms-autosave-content {
    color: #16a34a;
}

.ailms-autosave-widget.error {
    background: #fef2f2;
}

.ailms-autosave-widget.error .ailms-autosave-content {
    color: #dc2626;
}

@keyframes ailms-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.ailms-lesson-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
    color: white;
}

.ailms-lesson-info {
    flex: 1;
    min-width: 0;
}

.ailms-lesson-name {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: #1e293b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.ailms-lesson-phases {
    display: flex;
    gap: 3px;
}

.ailms-phase {
    width: 18px;
    height: 18px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 9px;
    font-weight: 700;
    background: #e5e7eb;
    color: #9ca3af;
    transition: all 0.2s ease;
}

.ailms-phase.done {
    background: #22c55e;
    color: white;
}

/* Active Phase - Currently Learning */
.ailms-phase.active {
    background: #3b82f6;
    color: white;
    animation: ailms-phase-pulse 1.5s ease-in-out infinite;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.3);
}

@keyframes ailms-phase-pulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.3);
    }
    50% {
        transform: scale(1.1);
        box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.2);
    }
}

.ailms-lesson-check {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #22c55e;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: bold;
    flex-shrink: 0;
}

/* ============================================
   Timer Widget
   ============================================ */
.ailms-timer-widget {
    padding: 14px;
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: white;
}

.ailms-timer-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
}

.ailms-timer-icon {
    font-size: 16px;
}

.ailms-timer-label {
    font-size: 12px;
    font-weight: 500;
    opacity: 0.9;
}

.ailms-timer-display {
    display: flex;
    align-items: baseline;
    gap: 4px;
    margin-bottom: 8px;
}

.ailms-timer-elapsed {
    font-size: 22px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.ailms-timer-separator {
    font-size: 14px;
    opacity: 0.6;
}

.ailms-timer-required {
    font-size: 13px;
    opacity: 0.8;
    font-variant-numeric: tabular-nums;
}

.ailms-timer-progress {
    height: 4px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
    overflow: hidden;
}

.ailms-timer-progress-fill {
    height: 100%;
    background: white;
    border-radius: 2px;
    transition: width 0.5s ease;
}

/* ============================================
   Responsive - Tablet
   ============================================ */
@media (max-width: 1400px) {
    .ailms-sidebar {
        width: 220px;
    }

    .ailms-layout-wrapper {
        gap: 8px;
    }
}

/* ============================================
   Responsive - Mobile (Bottom Sheet)
   ============================================ */
@media (max-width: 1200px) {
    .ailms-layout-wrapper {
        flex-direction: column;
    }

    .ailms-main-content {
        margin: 0 auto;
        max-width: 100%;
        padding-bottom: 80px;
    }

    .ailms-sidebar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: auto;
        max-height: 70vh;
        margin: 0;
        border-radius: 20px 20px 0 0;
        transform: translateY(calc(100% - 60px));
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 9999;
    }

    .ailms-sidebar.expanded {
        transform: translateY(0);
    }

    .ailms-sidebar-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        padding: 16px;
        background: #f8fafc;
        cursor: pointer;
        border-bottom: 1px solid #e5e7eb;
    }

    .ailms-sidebar-toggle::before {
        content: '';
        width: 40px;
        height: 4px;
        background: #cbd5e1;
        border-radius: 2px;
        position: absolute;
        top: 8px;
        left: 50%;
        transform: translateX(-50%);
    }

    .ailms-toggle-icon {
        font-size: 18px;
    }

    .ailms-toggle-text {
        font-size: 14px;
        font-weight: 600;
        color: #475569;
    }

    /* Show only left sidebar on mobile */
    .ailms-sidebar-right {
        display: none;
    }

    .ailms-sidebar-left {
        z-index: 10000;
    }

    .ailms-sidebar-list {
        max-height: calc(70vh - 140px);
    }
}

/* ============================================
   Scrollbar Styling
   ============================================ */
.ailms-sidebar-list::-webkit-scrollbar {
    width: 6px;
}

.ailms-sidebar-list::-webkit-scrollbar-track {
    background: transparent;
}

.ailms-sidebar-list::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.ailms-sidebar-list::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* ============================================
   Accessibility
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    .ailms-sidebar,
    .ailms-sidebar-progress-fill,
    .ailms-timer-progress-fill,
    .ailms-progress-value,
    .ailms-lesson-item,
    .ailms-lesson-main,
    .ailms-expand-icon,
    .ailms-go-btn,
    .ailms-lang-btn,
    .ailms-phase {
        transition: none;
    }

    .ailms-spinner {
        animation: none;
    }
}

/* Focus states */
.ailms-lesson-item:focus {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

.ailms-sidebar-toggle:focus {
    outline: 2px solid #3b82f6;
    outline-offset: -2px;
}

/* High contrast mode */
@media (forced-colors: active) {
    .ailms-sidebar {
        border: 2px solid currentColor;
    }

    .ailms-lesson-item.current {
        border: 2px solid currentColor;
    }
}

/* ============================================
   v3.2.6: Topics List Styles
   Shows lesson content topics with completion checkmarks
   ============================================ */
.ailms-topics-list {
    list-style: none;
    margin: 8px 0;
    padding: 0;
    font-size: 12px;
}

.ailms-topic-item {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    padding: 6px 8px;
    color: #1e293b;
    line-height: 1.3;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.ailms-topic-item:hover {
    background: #e2e8f0;
}

/* v3.2.7: Completed topics have gray background */
.ailms-topic-item.completed {
    background: #f1f5f9;
    color: #64748b;
}

.ailms-topic-check {
    flex-shrink: 0;
    width: 14px;
    height: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: bold;
    margin-top: 1px;
}

.ailms-topic-item.completed .ailms-topic-check {
    color: #16a34a;
    background: #dcfce7;
    border-radius: 50%;
}

.ailms-topic-item:not(.completed) .ailms-topic-check {
    color: #94a3b8;
}

.ailms-topic-title {
    flex: 1;
    word-break: break-word;
}

/* ============================================
   v3.2.30: Certificate Download Button
   ============================================ */
.ailms-certificate-download {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #e2e8f0;
}

.ailms-btn-download-certificate {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 12px 16px;
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: #ffffff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(16, 185, 129, 0.3);
}

.ailms-btn-download-certificate:hover {
    background: linear-gradient(135deg, #059669 0%, #047857 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(16, 185, 129, 0.4);
}

.ailms-btn-download-certificate:active {
    transform: translateY(0);
    box-shadow: 0 1px 2px rgba(16, 185, 129, 0.3);
}

.ailms-btn-download-certificate:disabled {
    opacity: 0.7;
    cursor: wait;
    transform: none;
}

/* Animation for certificate ready */
@keyframes ailms-certificate-pulse {
    0%, 100% {
        box-shadow: 0 2px 4px rgba(16, 185, 129, 0.3);
    }
    50% {
        box-shadow: 0 2px 12px rgba(16, 185, 129, 0.5);
    }
}

.ailms-certificate-download {
    animation: ailms-certificate-pulse 2s ease-in-out infinite;
}
