/* ======================================= */
/* --- (D) CSS ดีไซน์ใหม่ V5 (เพิ่ม Dark Mode) --- */
/* ======================================= */

/* --- (D.1) CSS (Global Vars - Light Mode) --- */
:root {
    --primary-color: #3b82f6;
    --primary-color-light: #eff6ff;
    --text-color: #374151;
    --muted-text-color: #6b7280;
    --border-color: #e5e7eb;
    --background-color: #f9fafb; /* BG ของหน้า */
    --white-color: #ffffff; /* BG ของ Card/Sidebar */
    --black-color: #000000;
    --danger-color: #ef4444;
    --success-color: #16a34a;
    --info-color: #0ea5e9;
    
    --navbar-height: 60px;
    --playlist-sidebar-width: 400px;
}

/* --- (V5: Dark Mode Variables) --- */
body.learn-page-active.dark-mode {
    --primary-color: #3b82f6; /* (เหมือนเดิม) */
    --primary-color-light: rgba(59, 130, 246, 0.15); /* (Transparent Blue) */
    --text-color: #f3f4f6; /* (Light Gray) */
    --muted-text-color: #9ca3af; /* (Medium Gray) */
    --border-color: #374151; /* (Dark Gray Border) */
    --background-color: #111827; /* (Very Dark BG) */
    --white-color: #1f2937; /* (Dark Card BG) */
    
    /* (สีอื่นๆ เหมือนเดิม) */
}


/* --- (D.2) CSS (Body & Layout) --- */
html, body {
    height: 100%;
    /* (*** V-Mobile: แก้ไข overflow ที่นี่ ***) */
    /* overflow: hidden; (เดิม) */
}
body.learn-page-active {
    display: flex;
    flex-direction: column;
    min-height: 100vh; /* (*** V-Mobile: เปลี่ยนจาก height เป็น min-height ***) */
    /* overflow: hidden; (เดิม) */
    background-color: var(--background-color); /* (*** V5: ใช้ Variable ***) */
    transition: background-color 0.3s; /* (V5: Add transition) */
}
body.learn-page-active .modal-overlay,
body.learn-page-active .image-widget-container,
body.learn-page-active footer {
    display: none !important;
}

.learn-container-v4 {
    display: grid;
    grid-template-columns: 1fr var(--playlist-sidebar-width);
    gap: 40px;
    width: 100%;
    max-width: 1800px;
    margin: 0 auto;
    padding: 24px;
    flex-grow: 1;
    overflow: hidden;
}

.learn-main-content-v4 {
    grid-column: 1 / 2;
    overflow-y: auto;
    height: calc(100vh - var(--navbar-height) - 48px);
}

.learn-playlist-sidebar-v4 {
    grid-column: 2 / 3;
    overflow-y: auto;
    height: calc(100vh - var(--navbar-height) - 48px);
    background-color: var(--white-color); /* (V5: ใช้ Variable) */
    border: 1px solid var(--border-color); /* (V5: ใช้ Variable) */
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    transition: background-color 0.3s, border-color 0.3s; /* (V5: Add transition) */
}

/* --- (D.3) CSS (Video Player - ซ้าย) --- */
.video-player-wrapper-v4 {
    position: relative;
    width: 100%;
    padding-bottom: 56.25%;
    height: 0;
    overflow: hidden;
    background-color: #000;
    border-radius: 8px;
    border: 1px solid var(--border-color); /* (V5: ใช้ Variable) */
}
.video-player-wrapper-v4 iframe {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%; border: 0;
}
/* (Message Overlays... เหมือนเดิม) */
.message-overlay-v4 { position: absolute; top: 0; left: 0; width: 100%; height: 100%; display: flex; flex-direction: column; justify-content: center; align-items: center; color: #ccc; font-size: 1.1rem; text-align: center; background-color: rgba(0, 0, 0, 0.9); z-index: 1; padding: 20px; box-sizing: border-box; }
.message-overlay-v4 i { font-size: 3rem; margin-bottom: 15px; }
.message-overlay-v4.access-denied i { color: #ff8a80; }
.message-overlay-v4.access-denied span{ color: #ffdddd; }
.message-overlay-v4.access-denied a { color: #80d8ff; text-decoration: underline; margin-top: 15px; font-size: 1.55rem; }
.message-overlay-v4.no-video i { color: #90a4ae; }


/* --- (D.4) CSS (Lesson Details - ซ้าย) --- */
.lesson-details-wrapper-v4 {
    margin-top: 20px;
    background-color: var(--white-color); /* (V5: ใช้ Variable) */
    border: 1px solid var(--border-color); /* (V5: ใช้ Variable) */
    border-radius: 8px;
    padding: 24px;
    transition: background-color 0.3s, border-color 0.3s; /* (V5: Add transition) */
}
.lesson-title-bar-v4 {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 15px;
}
.lesson-title-bar-v4 h1 {
    font-size: 1.6rem;
    font-weight: 600;
    margin: 0;
    color: var(--text-color); /* (V5: ใช้ Variable) */
    flex-grow: 1;
    line-height: 1.3;
}
.btn-mark-complete-v4 {
    padding: 9px 18px; font-size: 0.9rem;
    background-color: var(--white-color); /* (V5: ใช้ Variable) */
    color: var(--success-color);
    border: 1px solid var(--success-color);
    border-radius: 6px; cursor: pointer; transition: all 0.2s ease;
    white-space: nowrap; display: inline-flex; align-items: center; gap: 8px;
}
.btn-mark-complete-v4 i { font-size: 1.1em; }
.btn-mark-complete-v4:hover { background-color: rgba(22, 163, 74, 0.1); } /* (V5: ปรับ hover) */
.btn-mark-complete-v4.completed { background-color: var(--success-color); color: white; border-color: var(--success-color); }
.btn-mark-complete-v4.completed i::before { content: "\f058"; font-weight: 900; }

.lesson-content-tabs-v4 { border-bottom: 1px solid var(--border-color); margin-bottom: 1.5rem; display: flex; gap: 10px; } /* (V5: ใช้ Variable) */
.tab-button-v4 { background: none; border: none; padding: 12px 18px; cursor: pointer; font-size: 1.8rem; color: var(--muted-text-color); margin-bottom: -1px; border-bottom: 3px solid transparent; transition: color 0.2s, border-color 0.2s; white-space: nowrap; } /* (V5: ใช้ Variable) */
.tab-button-v4.active { color: var(--primary-color); border-bottom-color: var(--primary-color); font-weight: 500; }
.tab-button-v4:hover:not(.active) { color: var(--text-color); } /* (V5: ใช้ Variable) */
.tab-content-v4 { display: none; line-height: 1.7; color: var(--muted-text-color); padding-top: 10px; } /* (V5: ใช้ Variable) */
.tab-content-v4.active { display: block; }
.comment-section-placeholder-v4 textarea { width: 100%; padding: 12px; border: 1px solid var(--border-color); border-radius: 6px; margin-bottom: 10px; font-family: inherit; font-size: 0.95rem; box-sizing: border-box; resize: vertical; min-height: 80px; background-color: var(--background-color); color: var(--text-color); } /* (V5: ปรับสี) */
.comment-section-placeholder-v4 button { padding: 10px 20px; background-color: var(--primary-color); color: white; border: none; border-radius: 6px; cursor: pointer; }
.file-list-placeholder-v4 { list-style: none; padding: 0; margin: 10px 0 0; }
.file-list-placeholder-v4 li { margin-bottom: 10px; background-color: var(--background-color); padding: 10px 15px; border-radius: 4px; border: 1px solid var(--border-color); } /* (V5: ปรับสี) */


/* --- (D.5) CSS (Playlist Header - ขวา) --- */
.playlist-header-v4 {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color); /* (V5: ใช้ Variable) */
    flex-shrink: 0;
    position: sticky; top: 0;
    background: var(--white-color); /* (V5: ใช้ Variable) */
    z-index: 5;
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
    transition: background-color 0.3s, border-color 0.3s; /* (V5: Add transition) */
}
/* (*** V5: CSS Wrapper ***) */
.playlist-header-top-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
    gap: 10px;
}
.playlist-course-title {
    font-size: 1.8rem;
    font-weight: 600;
    margin: 0;
    color: var(--text-color); /* (V5: ใช้ Variable) */
    flex-grow: 1;
}
.progress-bar-container-v4 { display: flex; align-items: center; width: 100%; gap: 10px; }
.progress-bar-track-v4 { height: 10px; background-color: var(--border-color); border-radius: 4px; overflow: hidden; flex-grow: 1; } /* (V5: ปรับสี BG) */
.progress-bar-fill-v4 { height: 100%; background-color: var(--success-color); width: 0%; border-radius: 4px; transition: width 0.4s ease; }
.progress-percentage-v4 { font-size: 0.85rem; font-weight: 600; color: var(--text-color); white-space: nowrap; } /* (V5: ใช้ Variable) */

/* (*** V5: CSS Dark Mode Toggle Switch ***) */
.theme-toggle-switch {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted-text-color);
    flex-shrink: 0;
}
.theme-toggle-switch .fas {
    font-size: 0.9rem;
    transition: color 0.3s;
}
body.dark-mode .theme-toggle-switch .fa-sun { color: var(--primary-color); }
body:not(.dark-mode) .theme-toggle-switch .fa-moon { color: var(--primary-color); }

.switch { position: relative; display: inline-block; width: 44px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; transition: .4s; }
.slider:before { position: absolute; content: ""; height: 16px; width: 16px; left: 4px; bottom: 4px; background-color: white; transition: .4s; }
input:checked + .slider { background-color: var(--primary-color); }
body.dark-mode .slider { background-color: var(--background-color); border: 1px solid var(--border-color); }
body.dark-mode input:checked + .slider { background-color: var(--primary-color); border: none; }

input:checked + .slider:before { transform: translateX(20px); }
.slider.round { border-radius: 24px; }
.slider.round:before { border-radius: 50%; }


/* --- (D.6) CSS (Playlist List - ขวา) --- */
.lesson-nav-list-v4 { list-style: none; padding: 0; margin: 0; flex-grow: 1; }
.no-content-message-v4 { padding: 30px 20px; color: var(--muted-text-color); text-align: center; font-style: italic;} /* (V5: ใช้ Variable) */
.module-item-v4 { border-bottom: 1px solid var(--border-color); } /* (V5: ใช้ Variable) */
.module-header-v4 { background-color: var(--background-color); padding: 15px 20px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; transition: background-color 0.2s ease; } /* (V5: ปรับสี) */
.module-header-v4:hover { background-color: rgba(107, 114, 128, 0.1); } /* (V5: ปรับ hover) */
.module-title-v4 { font-weight: 600; font-size: 1.9rem; color: var(--text-color); } /* (V5: ใช้ Variable) */
.module-toggle-icon-v4 { font-size: 0.8rem; color: var(--muted-text-color); transition: transform 0.2s ease-in-out; } /* (V5: ใช้ Variable) */
.module-header-v4.open .module-toggle-icon-v4 { transform: rotate(0deg); }
.module-header-v4.collapsed .module-toggle-icon-v4 { transform: rotate(-90deg); }
.lesson-list-v4 { display: none; background-color: var(--white-color); } /* (V5: ใช้ Variable) */
.module-header-v4.open + .lesson-list-v4 { display: block; }

.lesson-item-v4 {
    padding: 12px 20px 12px 20px;
    display: flex; align-items: flex-start; gap: 12px;
    cursor: pointer; border-bottom: 1px solid var(--background-color); /* (V5: ปรับสี) */
    transition: background-color 0.15s; font-size: 0.9rem;
    color: var(--text-color); position: relative; /* (V5: ใช้ Variable) */
}
.lesson-item-v4:last-child { border-bottom: none; }
.lesson-item-v4:hover:not(.locked):not(.active) { background-color: var(--primary-color-light); }
.lesson-item-v4.active { background-color: var(--primary-color-light); color: var(--primary-color); font-weight: 500; }
.lesson-item-v4.active::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background-color: var(--primary-color); }

.lesson-icon-v4 { width: 18px; text-align: center; color: var(--muted-text-color); flex-shrink: 0; margin-top: 2px; font-size: 1.05em; } /* (V5: ใช้ Variable) */
.lesson-item-v4.active .lesson-icon-v4 { color: var(--primary-color); }
.lesson-title-group-v4 { display: flex; flex-direction: column; flex-grow: 1; gap: 2px; }
.lesson-title-text-v4 { line-height: 1.4; }
.lesson-preview-tag-v4 {
    font-size: 1.1rem; font-weight: 600; color: var(--info-color);
    background-color: rgba(14, 165, 233, 0.1); /* (V5: ปรับสี) */
    border: 1px solid rgba(14, 165, 233, 0.3); /* (V5: ปรับสี) */
    padding: 1px 6px; border-radius: 4px; white-space: nowrap;
    margin-top: 2px; align-self: flex-start;
}
.lesson-duration-v4 { font-size: 1.45rem; color: var(--muted-text-color); white-space: nowrap; padding-left: 10px; flex-shrink: 0; margin-top: 2px; } /* (V5: ใช้ Variable) */
.lesson-item-v4.locked { cursor: not-allowed; color: var(--muted-text-color); opacity: 0.6; } /* (V5: ใช้ Variable) */
.lesson-item-v4.locked:hover { background-color: transparent; }
.lesson-item-v4.locked .lesson-icon-v4 { color: var(--muted-text-color); } /* (V5: ใช้ Variable) */
.lesson-item-v4.placeholder { cursor: default; opacity: 0.5; }

/* --- (D.7) CSS (Error Page) --- */
.learn-container-error.error-page { display: flex; justify-content: center; align-items: flex-start; padding-top: 5rem; width: 100%; box-sizing: border-box; height: calc(100vh - var(--navbar-height)); background-color: var(--background-color); }
.error-box { background-color: var(--white-color); padding: 2rem 3rem; border-radius: 8px; box-shadow: 0 4px 10px rgba(0,0,0,0.08); text-align: center; border: 1px solid var(--border-color); max-width: 600px; margin: 1rem; }
.error-box h2 { color: var(--danger-color); margin: 0 0 1rem; font-size: 1.5rem; }
.error-box h2 i { margin-right: 10px; }
.error-box p { margin-bottom: 1.5rem; color: var(--muted-text-color); }
.error-box .btn-back { display: inline-block; background-color: var(--primary-color); color: white; padding: 10px 20px; border-radius: 5px; text-decoration: none; }


/* ======================================= */
/* --- (D.8) CSS (Responsive) --- */
/* ======================================= */

@media (max-width: 1200px) {
    :root { --playlist-sidebar-width: 360px; }
    .learn-container-v4 { padding: 16px; gap: 16px; }
    .learn-main-content-v4, .learn-playlist-sidebar-v4 { height: calc(100vh - var(--navbar-height) - 32px); }
}


/* (*** V-Mobile: แก้ไข Media Query ที่ 992px ***) */
@media (max-width: 992px) {
    
    /* (*** V-Mobile: เปิด overflow ที่ body เพื่อแก้ปุ่ม Hamburger ***) */
    html, body {
        overflow: auto;
    }
    body.learn-page-active {
        overflow: auto;
        height: auto; 
    }

    .learn-container-v4 {
        /* (*** V-Mobile: เปลี่ยนจาก Grid เป็น Flex Column ***) */
        display: flex;
        flex-direction: column;
        padding: 0;
        gap: 0;
        overflow: visible; 
    }
    
    /* (*** V-Mobile: ใช้ display:contents เพื่อ "สลาย" wrapper ของ Video+Comments ***) */
    .learn-main-content-v4 {
        display: contents;
    }

    /* (*** V-Mobile: จัดลำดับใหม่ (1. วิดีโอ) ***) */
    .video-player-wrapper-v4 {
        order: 1;
        border-radius: 0;
        border-left: none;
        border-right: none;
    }

    /* (*** V-Mobile: จัดลำดับใหม่ (2. รายการบทเรียน) ***) */
    .learn-playlist-sidebar-v4 {
        order: 2; 
        height: auto;
        overflow-y: visible;
        margin: 0; 
        border-radius: 0;
        border-left: none;
        border-right: none;
        border-bottom: none;
    }

    /* (*** V-Mobile: จัดลำดับใหม่ (3. ส่วนคอมเมนต์) ***) */
    .lesson-details-wrapper-v4 {
        order: 3;
        display: block; /* (*** V-Mobile: เปิดส่วนคอมเมนต์ ***) */
        margin-top: 16px;
        padding: 16px;
        border-radius: 0;
        border-left: none;
        border-right: none;
        /* (*** V-Mobile: ทำให้ขอบเขตถูกต้อง ***) */
        width: 100%;
        box-sizing: border-box;
    }

    /* (โค้ดเดิมที่ยังใช้ได้สำหรับปรับขนาด Font) */
    .lesson-title-bar-v4 h1 { font-size: 1.3rem; }
    .btn-mark-complete-v4 { padding: 8px 12px; font-size: 0.8rem; }
    .tab-button-v4 { padding: 10px 12px; font-size: 0.9rem; }
    
    .playlist-header-v4 {
        border-top-left-radius: 0;
        border-top-right-radius: 0;
    }
}

/* (*** V-Mobile: ปรับแก้ Media Query ที่ 480px ***) */
@media (max-width: 480px) {
     /* (*** V-Mobile: 992px คุม layout หลักแล้ว ที่นี่ปรับแค่ Font/Padding เล็กน้อย ***) */
     
     .lesson-details-wrapper-v4 { 
         padding: 12px; 
     }
     .lesson-title-bar-v4 { 
         gap: 10px; 
     }
     .lesson-title-bar-v4 h1 { 
         font-size: 1.55rem; /* (*** V-Mobile: ปรับให้เล็กลงเล็กน้อย ***) */
     }
     .tab-button-v4 { 
         padding: 8px 10px; 
         font-size: 1.55rem;
         font-weight: 700; 
     }
}

/* ================================================================== */
/* --- (*** START: เพิ่ม CSS สำหรับ Comment Section ***) --- */
/* ================================================================== */
/* (ใช้ CSS เดิมจาก admin_styles.css มาปรับใช้) */
.comment-block {
    margin-bottom: 20px;
}
.comment {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 15px;
    background-color: var(--white-color);
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    transition: background-color 0.3s, border-color 0.3s;
}
.admin-reply {
    border: 1px solid var(--primary-color-light); 
    border-left: 4px solid var(--primary-color); 
    background-color: var(--primary-color-light); 
    margin-top: 10px;
    margin-left: 30px; 
    padding: 15px;
    border-radius: 0 8px 8px 0;
}

/* (Dark Mode สำหรับ Admin Reply) */
body.dark-mode .admin-reply {
     background-color: rgba(59, 130, 246, 0.15); /* (Transparent Blue) */
     border-color: var(--border-color);
     border-left-color: var(--primary-color);
}

.admin-reply .comment-author strong {
    color: var(--primary-color); 
}

.comment-author {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
}
.comment-author img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    margin-right: 12px;
    object-fit: cover;
    background-color: var(--background-color);
}
.comment-author strong {
    font-size: 1.1em;
    font-weight: 600;
    color: var(--text-color);
}
.comment-date {
    font-size: 0.85em;
    color: var(--muted-text-color);
    margin-left: auto; 
}
.comment-body p {
    margin: 0;
    line-height: 1.6;
    color: var(--text-color);
    word-wrap: break-word;
}

/* (CSS สำหรับปุ่ม Submit ใน Form) */
.comment-section-placeholder-v4 button[type="submit"] {
    padding: 10px 20px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}
.comment-section-placeholder-v4 button[type="submit"]:disabled {
    background-color: var(--muted-text-color);
    cursor: not-allowed;
}

/* ================================================================== */
/* --- (*** END: เพิ่ม CSS สำหรับ Comment Section ***) --- */
/* ================================================================== */

/* =======================================
   --- (V11.4) Resume Prompt Styles (แก้ไขปุ่ม) ---
   ======================================= */

/* (V11.4) จัดการหน้าต่าง "ดูต่อ" (เหมือนเดิม) */
.resume-prompt-v4 {
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
}

.resume-prompt-v4 i {
    font-size: 2.5rem;
    margin-bottom: 15px;
    color: var(--primary-color);
}

.resume-prompt-v4 span {
    font-size: 1.1rem;
    color: var(--text-color);
    margin-bottom: 25px; /* (เพิ่มระยะห่าง) */
}

.resume-prompt-v4 span strong {
    font-size: 1.2rem;
    color: var(--primary-color);
}

/* (V11.4) กลุ่มปุ่ม "ดูต่อ" / "เริ่มใหม่" (เหมือนเดิม) */
.resume-buttons-v4 {
    display: flex;
    gap: 15px;
}

/* (V11.4) ปุ่ม (แก้ไขใหม่ทั้งหมด) */
.btn-resume-v4,
.btn-restart-v4 {
    padding: 12px 25px; /* (เพิ่มขนาด) */
    border: none;
    border-radius: 8px;
    font-size: 1.1rem;  /* (เพิ่มขนาด) */
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    color: #ffffff; /* (สีตัวอักษรเป็นสีขาว) */
}

/* (V11.4) ปุ่ม "ดูต่อ" (สีส้ม) */
.btn-resume-v4 {
    background-color: #FF6600; /* (สีส้ม) */
}
.btn-resume-v4:hover {
    background-color: #E65C00; /* (สีส้มเข้ม) */
}

/* (V11.4) ปุ่ม "เริ่มใหม่" (สีน้ำเงิน) */
.btn-restart-v4 {
    background-color: #007BFF; /* (สีน้ำเงิน) */
}
.btn-restart-v4:hover {
    background-color: #0069D9; /* (สีน้ำเงินเข้ม) */
}