/* Custom Theme Styles for RRU Exam */

/* กันไม่ให้ลากเมาส์/สไลด์นิ้วเลยขอบบนหรือล่างสุดของหน้าแล้วเห็นเบราว์เซอร์ "กระเด้ง"
   (rubber-band/elastic overscroll) โผล่เป็นพื้นที่สีขาว — ใช้กับหน้าที่ scroll ทั้งหน้าเว็บตรงๆ
   แบบปกติ (take.php, exam_preview.php ฯลฯ) ต่างจาก .app-scroll-region ด้านล่างที่เป็น div
   ย่อยที่ scroll เอง (หน้า admin/manager ที่ body ปิด overflow ไว้แล้วจึงกระเด้งที่ตัว body ไม่ได้อยู่แล้ว)
   ต้องใช้ค่า none ไม่ใช่ contain — contain กันแค่ไม่ให้ scroll ไหลต่อไปยัง parent (chaining)
   แต่ตัว html เป็น element บนสุดอยู่แล้วไม่มี parent ให้ chain ต่อ contain เลยไม่มีผลใดๆ ต้องสั่ง
   none ตรงๆ ถึงจะปิดเอฟเฟกต์กระเด้ง/glow ของเบราว์เซอร์เองได้จริง */
html, body {
    overscroll-behavior-y: none;
}

/* Keep the application shell inside the visible mobile browser viewport. */
.app-viewport {
    height: 100vh !important;
}

@supports (height: 100dvh) {
    .app-viewport {
        height: 100dvh !important;
    }
}

.app-scroll-region {
    -webkit-overflow-scrolling: touch;
    /* กันไม่ให้ลากเมาส์/สไลด์นิ้วเลยขอบบนหรือล่างสุดของพื้นที่เนื้อหาแล้วเห็น "การกระเด้ง" ของ
       เบราว์เซอร์ (rubber-band/elastic overscroll) โผล่เป็นพื้นที่สีขาวแทรกระหว่าง sidebar/header
       ที่ตรึงอยู่กับเนื้อหาที่เลื่อน เดิมกันไว้แค่จอมือถือ (<=1023px) แต่เกิดเหมือนกันบนจอกว้างด้วย
       เพราะ .app-scroll-region เป็น div ที่ scroll เอง ไม่ใช่ body ทั้งหน้า — ใช้ none ไม่ใช่ contain
       เพราะ contain กันแค่ chaining ไปยัง parent ไม่ได้ปิดเอฟเฟกต์กระเด้ง/glow ของตัว element เอง */
    overscroll-behavior: none;
}

/* บางหน้า (เช่น จัดชุดข้อสอบ) ออกแบบเป็น 2 คอลัมน์ที่ต้องเลื่อนอิสระจากกันเอง + ตรึงหัวข้อบนสุดไว้
   ปกติ .app-scroll-region คือพื้นที่เลื่อนกลางของทั้งหน้า (เลื่อนทั้งก้อนเดียว) ซึ่งไม่ใช่ flex
   container เลยทำให้คลาส shrink-0/flex-1 ที่หน้าเหล่านี้ตั้งไว้กับ header/คอลัมน์ไม่มีผลอะไรเลย
   คลาสนี้เปลี่ยน .app-scroll-region ให้เป็น flex column ที่ไม่เลื่อนเอง (overflow:hidden) แทน
   ปล่อยให้ลูกๆ ข้างในที่ตั้ง overflow-y-auto ไว้เอง (เช่น รายการคำถามแต่ละคอลัมน์) เลื่อนกันเองอิสระ
   หน้าที่ใช้ต้องเพิ่ม/ลบคลาสนี้เองตอนเข้า/ออกหน้า (ดู rruexam:spa-before-swap) ไม่ใช่ค่าเริ่มต้น
   เพราะหน้าอื่นส่วนใหญ่พึ่งพา .app-scroll-region เลื่อนทั้งก้อนตามปกติ */
.app-scroll-region.is-split-workspace {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ลูกศรลง native ของ <select> (appearance เริ่มต้นของเบราว์เซอร์) ไม่ยึดตาม padding-right ที่ตั้งไว้
   เสมอไป — แต่ละเบราว์เซอร์/OS วาดลูกศรของตัวเองในตำแหน่งที่ต่างกัน บางตัวชิดขอบขวาเกือบเสมอไม่ว่า
   จะเพิ่ม padding เท่าไหร่ก็ตาม (เจอปัญหานี้จริงกับดรอปดาวน์เติมคำ/เลือกคำชี้แจงที่แคบ) ทางเดียวที่
   การันตีระยะห่างจากขอบขวาได้แน่นอนทุกเบราว์เซอร์คือปิด native arrow แล้ววาดเองด้วย background-image
   วางตำแหน่งด้วย background-position ตรงๆ (ไม่ต้องพึ่ง native chrome ของฟอร์มคอนโทรลอีกต่อไป) */
.select-arrow-fixed {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 7l5 5 5-5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    background-size: 0.85em 0.85em;
}

@media (max-width: 1023px) {
    .app-scroll-region {
        scroll-padding-bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px));
    }

    .app-scroll-region::after {
        content: "";
        display: block;
        width: 100%;
        height: calc(1.5rem + env(safe-area-inset-bottom, 0px));
        pointer-events: none;
    }
}

/* Selected image and audio previews in question forms. */
.upload-selection-preview {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.75rem;
    padding: 0.625rem;
    border: 1px solid #cbd5e1;
    border-radius: 0.5rem;
    background: #ffffff;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
}

.upload-selection-preview__media {
    width: 5rem;
    height: 4rem;
    flex: 0 0 auto;
    overflow: hidden;
    border: 1px solid #e2e8f0;
    border-radius: 0.375rem;
    background: #f8fafc;
}

.upload-selection-preview__media img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.upload-selection-preview__audio {
    width: min(18rem, 100%);
    height: 2.25rem;
    min-width: 0;
    flex: 1 1 14rem;
}

.upload-selection-preview__details {
    display: flex;
    min-width: 0;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 0.125rem;
}

.upload-selection-preview__status,
.upload-selection-preview__size {
    color: #64748b;
    font-size: 0.6875rem;
    line-height: 1.25;
}

.upload-selection-preview__name {
    overflow: hidden;
    color: #334155;
    font-size: 0.75rem;
    line-height: 1.35;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.upload-selection-preview__remove {
    display: inline-flex;
    width: 2.75rem;
    height: 2.75rem;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 0.5rem;
    color: #e11d48;
    background: #fff1f2;
    cursor: pointer;
    transition: color 150ms ease, background-color 150ms ease;
}

.upload-selection-preview__remove:hover {
    color: #be123c;
    background: #ffe4e6;
}

.upload-selection-preview__remove:focus-visible {
    outline: 3px solid rgba(244, 63, 94, 0.25);
    outline-offset: 2px;
}

.existing-attachment-preview {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.75rem;
    padding: 0.625rem;
    border: 1px solid #ccfbf1;
    border-radius: 0.5rem;
    background: #f0fdfa;
}

.existing-attachment-preview__image {
    width: 5rem;
    height: 4rem;
    flex: 0 0 auto;
    overflow: hidden;
    border: 1px solid #99f6e4;
    border-radius: 0.375rem;
    background: #ffffff;
}

.existing-attachment-preview__image img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.existing-attachment-preview__details {
    display: flex;
    min-width: 0;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 0.25rem;
    color: #475569;
    font-size: 0.75rem;
}

.existing-attachment-preview__details a {
    width: fit-content;
    color: #0f766e;
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.existing-attachment-preview__remove,
.existing-attachment-mini__remove {
    display: inline-flex;
    width: 2rem;
    height: 2rem;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 999px;
    color: #e11d48;
    background: #ffe4e6;
    cursor: pointer;
    font-size: 0.8125rem;
    transition: color 150ms ease, background-color 150ms ease, transform 150ms ease;
}

.existing-attachment-preview__remove:hover,
.existing-attachment-mini__remove:hover {
    color: #ffffff;
    background: #e11d48;
    transform: translateY(-1px);
}

.existing-attachment-mini {
    display: flex;
    min-height: 2rem;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-top: 0.375rem;
    padding: 0.3125rem 0.45rem;
    border: 1px solid #e2e8f0;
    border-radius: 0.5rem;
    background: #ffffff;
    font-size: 0.75rem;
}

.existing-attachment-mini__remove {
    width: 1.75rem;
    height: 1.75rem;
    font-size: 0.75rem;
}

.existing-attachment-mini a {
    min-width: 0;
    overflow: hidden;
    color: #0f766e;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.existing-attachment-preview--audio {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.5rem 0.75rem;
}

.existing-attachment-preview--audio .existing-attachment-preview__details {
    grid-column: 1 / -1;
}

.existing-attachment-preview--audio audio {
    min-width: 0;
    width: 100%;
    height: 2rem;
}

.existing-attachment-preview--audio .existing-attachment-preview__remove {
    grid-column: 2;
    grid-row: 2;
}

.themed-audio-source.js-themed-audio {
    display: none;
}

.themed-audio-player {
    display: grid;
    width: 100%;
    min-width: 0;
    grid-template-columns: 2rem minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.625rem;
    padding: 0.35rem 0.55rem;
    border: 1px solid #ccfbf1;
    border-radius: 999px;
    background: linear-gradient(135deg, #ffffff 0%, #f0fdfa 100%);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.85), 0 8px 18px rgba(15, 118, 110, 0.08);
}

.themed-audio-player__play {
    display: inline-flex;
    width: 2rem;
    height: 2rem;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 999px;
    color: #ffffff;
    background: linear-gradient(135deg, #0f766e, #14b8a6);
    box-shadow: 0 8px 16px rgba(20, 184, 166, 0.28);
    cursor: pointer;
    font-size: 0.75rem;
    transition: transform 150ms ease, box-shadow 150ms ease, background-color 150ms ease;
}

.themed-audio-player__play:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 20px rgba(20, 184, 166, 0.34);
}

.themed-audio-player__play:focus-visible {
    outline: 3px solid rgba(20, 184, 166, 0.25);
    outline-offset: 2px;
}

.themed-audio-player__track {
    position: relative;
    height: 0.45rem;
    min-width: 3rem;
    overflow: hidden;
    border-radius: 999px;
    background: #dbeafe;
    cursor: pointer;
}

/* เสียงที่จำกัดจำนวนครั้งหรือบังคับฟังจนจบ เลื่อนข้ามไม่ได้
   ทำให้แถบดูเป็นตัวบอกความคืบหน้าอย่างเดียว จะได้ไม่พยายามกด */
.themed-audio-player--locked .themed-audio-player__track {
    cursor: default;
    pointer-events: none;
}

.themed-audio-player__progress {
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #14b8a6, #2563eb);
    transition: width 120ms linear;
}

.themed-audio-player__time {
    min-width: 4.8rem;
    color: #64748b;
    font-size: 0.72rem;
    font-weight: 600;
    text-align: right;
    white-space: nowrap;
}

.themed-audio-player.is-playing .themed-audio-player__play {
    background: linear-gradient(135deg, #0d9488, #2563eb);
}

.preview-answers-locked {
    position: relative;
    min-height: 6rem;
    pointer-events: none;
    user-select: none;
}

.preview-answers-locked > * {
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

.preview-answers-locked::after {
    content: "\f023  ตัวเลือกจะแสดงเมื่อฟังเสียงจบ";
    position: absolute;
    inset: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    border: 1px dashed #99f6e4;
    border-radius: 0.875rem;
    color: #64748b;
    background: rgba(255, 255, 255, 0.96);
    font-family: "Font Awesome 6 Free", var(--app-font, sans-serif);
    font-size: 0.875rem;
    font-weight: 900;
    text-align: center;
    visibility: visible !important;
    opacity: 1 !important;
}

.upload-selection-preview--audio .themed-audio-player {
    flex: 1 1 16rem;
}

.existing-attachment-mini--audio .themed-audio-player {
    flex: 1 1 auto;
    padding: 0.25rem 0.45rem;
    box-shadow: none;
}

.existing-attachment-mini--audio .themed-audio-player__play {
    width: 1.75rem;
    height: 1.75rem;
    font-size: 0.68rem;
}

.existing-attachment-mini--audio .themed-audio-player__time {
    min-width: 4.4rem;
    font-size: 0.68rem;
}

@media (max-width: 479px) {
    .upload-selection-preview--audio {
        flex-wrap: wrap;
    }

    .upload-selection-preview--audio .upload-selection-preview__audio {
        width: calc(100% - 3.5rem);
        flex-basis: calc(100% - 3.5rem);
    }

    .upload-selection-preview--audio .upload-selection-preview__details {
        order: 3;
        flex-basis: 100%;
    }

    .themed-audio-player {
        grid-template-columns: 2rem minmax(0, 1fr);
        border-radius: 1rem;
    }

    .themed-audio-player__time {
        grid-column: 2;
        min-width: 0;
        text-align: left;
    }
}

/* Ensure tables fill space but allow text to wrap */
table, .table {
    width: 100% !important;
    min-width: 100% !important;
    border-collapse: separate !important;
    border-spacing: 0 !important;
}

/* Table Headers (thead th) */
table thead tr th,
.table thead tr th,
table thead th {
    font-weight: 600 !important;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-size: 0.875rem !important; /* text-sm */
    padding-top: 1rem !important;
    padding-bottom: 1rem !important;
    border: none !important;
    white-space: nowrap !important;
}

/* Theme-specific Table Headers */
body.theme-admin table thead tr th,
body.theme-admin .table thead tr th,
body.theme-admin table thead th {
    background-color: #0f172a !important; /* Slate 900 (Admin Theme) */
    color: #ffffff !important;
}

body.theme-manager table thead tr th,
body.theme-manager .table thead tr th,
body.theme-manager table thead th {
    background-color: #0f172a !important; /* Slate 900 (Admin Theme) */
    color: #ffffff !important;
}

body.theme-student table thead tr th,
body.theme-student .table thead tr th,
body.theme-student table thead th {
    background-color: #6b21a8 !important; /* Purple 800 */
    color: #ffffff !important;
}

body.theme-proctor table thead tr th,
body.theme-proctor .table thead tr th,
body.theme-proctor table thead th {
    background-color: #c2410c !important; /* Orange 700 */
    color: #ffffff !important;
}


/* Prevent Badges/Pills inside Tables from Wrapping */
table td span.inline-flex {
    white-space: nowrap !important;
}

/* Theme-specific Table Headers */
body.theme-admin table thead tr th,
body.theme-admin .table thead tr th,
body.theme-admin table thead th {
    background-color: #0f172a !important; /* Slate 900 (Admin Theme) */
    color: #ffffff !important;
}

body.theme-manager table thead tr th,
body.theme-manager .table thead tr th,
body.theme-manager table thead th {
    background-color: #0f172a !important; /* Slate 900 (Admin Theme) */
    color: #ffffff !important;
}

body.theme-student table thead tr th,
body.theme-student .table thead tr th,
body.theme-student table thead th {
    background-color: #6b21a8 !important; /* Purple 800 */
    color: #ffffff !important;
}

body.theme-proctor table thead tr th,
body.theme-proctor .table thead tr th,
body.theme-proctor table thead th {
    background-color: #c2410c !important; /* Orange 700 */
    color: #ffffff !important;
}




/* Section Headers within Content */
/*
 * :not(.text-white) สำคัญมาก อย่าเอาออก
 *
 * กฎด้านล่างที่ตั้งใจให้หัวข้อสีขาวยังขาวอยู่นั้น มี specificity ต่ำกว่ากฎนี้
 * (main h3.text-white = 0-1-2 ส่วน main h3.text-xl.font-bold = 0-2-2)
 * ทั้งคู่เป็น !important เท่ากัน ตัวที่ specificity สูงกว่าจึงชนะ
 * ผลคือหัวข้อที่เขียน text-white ไว้บนพื้นเข้มถูกบังคับเป็น indigo-950 จนอ่านไม่ออก
 *
 * แทนที่จะไปดันให้กฎสีขาวมี specificity สูงขึ้น เลือกไม่ให้กฎนี้ไปคว้า
 * หัวข้อที่ประกาศชัดแล้วว่าต้องการสีขาวตั้งแต่แรก
 */
main h1:not(.text-white),
main h2:not(.text-white),
main h3.text-xl.font-bold:not(.text-white),
main h3.text-2xl.font-bold:not(.text-white) {
    color: #1e1b4b !important; /* Indigo 950 */
    font-weight: 700 !important;
}

/* Override for text-white headings that were globally set to Indigo 950 */
main h1.text-white,
main h2.text-white,
main h3.text-white,
main h4.text-white,
main h5.text-white,
main h6.text-white,
main .text-white h1,
main .text-white h2,
main .text-white h3,
main [class*="bg-gradient-"] h1,
main [class*="bg-gradient-"] h2,
main [class*="bg-gradient-"] h3 {
    color: #ffffff !important;
}

/* Fix contrast for headings inside dark gradients */
.hero-gradient h1, .hero-gradient h2, .hero-gradient h3 {
    color: #ffffff !important;
}

/* Add a subtle accent to accordion groups headers or section headers if they are plain */
main .accordion-group > button h4 {
    color: #312e81 !important;
    font-weight: 700 !important;
}

/* Hide scrollbar for horizontal scroll areas */
.hide-scrollbar::-webkit-scrollbar {
    display: none;
}
.hide-scrollbar {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

/* Center custom overlays in the current mobile viewport, even inside SPA scroll regions. */
.rru-mobile-centered-modal {
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    min-height: 100vh !important;
    height: 100vh !important;
    align-items: center !important;
    justify-content: center !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
}

.rru-mobile-centered-modal.hidden {
    display: none !important;
}

.rru-mobile-centered-modal.flex {
    display: flex !important;
}

@supports (height: 100dvh) {
    .rru-mobile-centered-modal {
        min-height: 100dvh !important;
        height: 100dvh !important;
    }
}

/* SweetAlert Balanced Style */
body.swal2-shown:not(.swal2-toast-shown) {
    overflow: hidden !important;
}

body.swal2-shown:not(.swal2-toast-shown) div:where(.swal2-container) {
    position: fixed !important;
    inset: 0 !important;
    display: flex !important;
    width: 100vw !important;
    min-height: 100vh !important;
    height: 100vh !important;
    align-items: center !important;
    justify-content: center !important;
    padding: max(0.75rem, env(safe-area-inset-top)) max(0.75rem, env(safe-area-inset-right)) max(0.75rem, env(safe-area-inset-bottom)) max(0.75rem, env(safe-area-inset-left)) !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
}

@supports (height: 100dvh) {
    body.swal2-shown:not(.swal2-toast-shown) div:where(.swal2-container) {
        min-height: 100dvh !important;
        height: 100dvh !important;
    }
}

.swal2-popup {
    font-size: 1rem !important;
    padding: 1.5rem !important;
    border-radius: 1.25rem !important;
    width: min(28em, calc(100vw - 1.5rem)) !important;
    max-height: calc(100vh - 1.5rem) !important;
    overflow-y: auto !important;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05) !important;
}

@supports (height: 100dvh) {
    .swal2-popup {
        max-height: calc(100dvh - 1.5rem) !important;
    }
}
.swal2-title {
    font-size: 1.3rem !important;
    margin-bottom: 0.5rem !important;
    padding: 0 !important;
}
.swal2-html-container {
    font-size: 1rem !important;
    margin: 0.5rem 0 1.25rem 0 !important;
    color: #475569 !important;
}
.swal2-actions {
    margin-top: 1rem !important;
    gap: 1rem !important;
}
.swal2-styled {
    padding: 0.6rem 1.5rem !important;
    font-size: 1rem !important;
    border-radius: 0.6rem !important;
    font-weight: 500 !important;
    margin: 0 !important;
}
.swal2-icon {
    transform: scale(0.8);
    margin: -0.5rem auto 0.5rem auto !important;
}
.swal2-icon .swal2-icon-content {
    font-size: 2rem !important;
}

/* Fix SweetAlert2 Icons conflicts with Tailwind */
.swal2-icon,
.swal2-icon * {
    box-sizing: content-box !important;
}
.swal2-icon.swal2-error [class^="swal2-x-mark-line"] {
    display: block !important;
}
.swal2-icon.swal2-success [class^="swal2-success-line"] {
    display: block !important;
}

@media (max-width: 480px) {
    .swal2-popup {
        padding: 1.15rem !important;
        border-radius: 1rem !important;
    }

    .swal2-title {
        font-size: 1.125rem !important;
    }

    .swal2-html-container {
        font-size: 0.925rem !important;
    }

    .swal2-actions {
        width: 100% !important;
        gap: 0.625rem !important;
    }

    .swal2-styled {
        min-height: 2.75rem !important;
        flex: 1 1 8rem !important;
        padding: 0.625rem 0.875rem !important;
    }
}

/* Compact circular repeated action buttons for manager exam-set rows. */
.manager-exam-row-actions > a,
.manager-exam-row-actions > button,
.manager-exam-row-actions > form > button,
.admin-exam-row-actions > a,
.admin-exam-row-actions > button,
.admin-exam-row-actions > form > button {
    width: 2.25rem !important;
    height: 2.25rem !important;
    min-width: 2.25rem !important;
    min-height: 2.25rem !important;
    border-radius: 9999px !important;
    padding: 0 !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    background: #fff !important;
    border: 1px solid #e5e7eb !important;
    color: #94a3b8 !important;
    box-shadow: 0 1px 2px rgb(15 23 42 / 0.04) !important;
}

.manager-exam-row-actions > a:hover,
.manager-exam-row-actions > button:hover,
.manager-exam-row-actions > form > button:hover,
.admin-exam-row-actions > a:hover,
.admin-exam-row-actions > button:hover,
.admin-exam-row-actions > form > button:hover {
    background: #f0f9ff !important;
    border-color: #bae6fd !important;
    color: #0284c7 !important;
}

.manager-exam-row-actions > button[data-tip*="ลบ"]:hover,
.manager-exam-row-actions > form > button[data-tip*="ลบ"]:hover,
.admin-exam-row-actions > button[data-tip*="ลบ"]:hover,
.admin-exam-row-actions > form > button[data-tip*="ลบ"]:hover {
    background: #fff1f2 !important;
    border-color: #fecdd3 !important;
    color: #e11d48 !important;
}

.manager-exam-row-actions > button[data-tip*="คัดลอก"]:hover,
.admin-exam-row-actions > button[data-tip*="คัดลอก"]:hover {
    background: #fffbeb !important;
    border-color: #fde68a !important;
    color: #d97706 !important;
}

.manager-exam-row-actions > button[data-tip*="รีเซ็ต"]:hover,
.admin-exam-row-actions > button[data-tip*="รีเซ็ต"]:hover {
    background: #fffbeb !important;
    border-color: #fde68a !important;
    color: #d97706 !important;
}

.manager-exam-row-actions i,
.admin-exam-row-actions i {
    font-size: 0.75rem !important;
    line-height: 1 !important;
}

@media (max-width: 639px) {
    .manager-exam-row-actions > a,
    .manager-exam-row-actions > button,
    .manager-exam-row-actions > form > button,
    .admin-exam-row-actions > a,
    .admin-exam-row-actions > button,
    .admin-exam-row-actions > form > button {
        width: 2.75rem !important;
        height: 2.75rem !important;
        min-width: 2.75rem !important;
        min-height: 2.75rem !important;
    }
}

.manager-exam-row-actions > [data-tip*="รายงาน"],
.admin-exam-row-actions > [data-tip*="รายงาน"] {
    background: #eff6ff !important;
    border-color: #bfdbfe !important;
    color: #2563eb !important;
}

.manager-exam-row-actions > [data-tip*="แก้ไข"],
.manager-exam-row-actions > [data-tip*="ตั้งค่า"],
.admin-exam-row-actions > [data-tip*="แก้ไข"],
.admin-exam-row-actions > [data-tip*="ตั้งค่า"] {
    background: #fff7ed !important;
    border-color: #fed7aa !important;
    color: #ea580c !important;
}

.manager-exam-row-actions > form > [data-tip*="พรีวิว"],
.admin-exam-row-actions > form > [data-tip*="พรีวิว"] {
    background: #eef2ff !important;
    border-color: #c7d2fe !important;
    color: #4f46e5 !important;
}

.manager-exam-row-actions > [data-tip*="คัดลอก"],
.manager-exam-row-actions > [data-tip*="ทำสำเนา"],
.admin-exam-row-actions > [data-tip*="คัดลอก"],
.admin-exam-row-actions > [data-tip*="ทำสำเนา"] {
    background: #fffbeb !important;
    border-color: #fde68a !important;
    color: #d97706 !important;
}

.manager-exam-row-actions > [data-tip*="รีเซ็ต"],
.admin-exam-row-actions > [data-tip*="รีเซ็ต"] {
    background: #fffbeb !important;
    border-color: #fde68a !important;
    color: #d97706 !important;
}

.manager-exam-row-actions > [data-tip*="ลบ"],
.manager-exam-row-actions > form > [data-tip*="ลบ"],
.admin-exam-row-actions > [data-tip*="ลบ"],
.admin-exam-row-actions > form > [data-tip*="ลบ"] {
    background: #fff1f2 !important;
    border-color: #fecdd3 !important;
    color: #e11d48 !important;
}

.manager-exam-row-actions > [data-tip*="จัดชุด"],
.admin-exam-row-actions > [data-tip*="จัดชุด"] {
    background: #f0f9ff !important;
    border-color: #bae6fd !important;
    color: #0284c7 !important;
}

.manager-exam-row-actions > [data-tip*="กู้คืน"],
.admin-exam-row-actions > [data-tip*="กู้คืน"] {
    background: #ecfdf5 !important;
    border-color: #bbf7d0 !important;
    color: #059669 !important;
}

/* Consistent circular action colors for question-bank management. */
.question-bank-actions > a,
.question-bank-actions > button {
    border-radius: 9999px !important;
}

.question-bank-actions > [data-tip*="ทำสำเนา"] {
    background: #fffbeb !important;
    border-color: #fde68a !important;
    color: #d97706 !important;
}

.question-bank-actions > [data-tip*="แก้ไข"] {
    background: #fff7ed !important;
    border-color: #fed7aa !important;
    color: #ea580c !important;
}

.question-bank-actions > [data-tip*="ย้ายเจ้าของ"] {
    background: #f0f9ff !important;
    border-color: #bae6fd !important;
    color: #0284c7 !important;
}

.question-bank-actions > [data-tip*="รีวิว"],
.question-bank-actions > [data-tip*="ทดสอบ"] {
    background: #eef2ff !important;
    border-color: #c7d2fe !important;
    color: #4f46e5 !important;
}

.question-bank-actions > [data-tip*="ลบ"] {
    background: #fff1f2 !important;
    border-color: #fecdd3 !important;
    color: #e11d48 !important;
}

.question-bank-actions > [data-tip*="กู้คืน"] {
    background: #ecfdf5 !important;
    border-color: #bbf7d0 !important;
    color: #059669 !important;
}

.question-bank-actions > [data-tip*="จัดการ"],
.question-bank-actions > [data-tip*="เข้าจัดการ"] {
    background: #f0f9ff !important;
    border-color: #bae6fd !important;
    color: #0284c7 !important;
}

/* Circular action buttons for report management rows. */
.report-row-actions > a,
.report-row-actions > button {
    width: 2.25rem !important;
    height: 2.25rem !important;
    min-width: 2.25rem !important;
    min-height: 2.25rem !important;
    border-radius: 9999px !important;
    padding: 0 !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
}

.report-row-actions > [data-tip*="ดูรายงาน"] {
    background: #f0f9ff !important;
    border-color: #bae6fd !important;
    color: #0284c7 !important;
}

.report-row-actions > [data-tip*="กู้คืน"] {
    background: #ecfdf5 !important;
    border-color: #bbf7d0 !important;
    color: #059669 !important;
}

.report-row-actions > [data-tip*="ลบ"] {
    background: #fff1f2 !important;
    border-color: #fecdd3 !important;
    color: #e11d48 !important;
}

.report-row-actions i {
    font-size: 0.75rem !important;
    line-height: 1 !important;
}

/* Touch targets: ปุ่มคำสั่งซ้ำ ๆ ในแถวถูกล็อกไว้ที่ 2.25rem ด้วย !important ในกฎด้านบน
   ซึ่งเล็กกว่าเกณฑ์ 44x44px บนจอสัมผัส กฎนี้จึงขยายเฉพาะช่วงมือถือ
   วางไว้หลังกฎเดิมเพื่อให้ชนะด้วยลำดับ เพราะ specificity เท่ากันและใช้ !important เหมือนกัน
   ขนาดบนเดสก์ท็อปยังเท่าเดิมทุกประการ */
@media (max-width: 639.98px) {
    .manager-exam-row-actions > a,
    .manager-exam-row-actions > button,
    .manager-exam-row-actions > form > button,
    .admin-exam-row-actions > a,
    .admin-exam-row-actions > button,
    .admin-exam-row-actions > form > button,
    .report-row-actions > a,
    .report-row-actions > button,
    .question-bank-actions > a,
    .question-bank-actions > button,
    .question-bank-actions > span {
        width: 2.75rem !important;
        height: 2.75rem !important;
        min-width: 2.75rem !important;
        min-height: 2.75rem !important;
    }
}

/* Print Styles */
@media print {
    body {
        background-color: #fff !important;
        color: #000 !important;
    }
    
    /* Hide non-printable elements */
    header, nav, aside, footer, .no-print, button, .btn {
        display: none !important;
    }
    
    /* Expand main content */
    main, .main-content, #main-content {
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
    }
    
    /* Print tables clearly */
    table {
        width: 100% !important;
        border-collapse: collapse !important;
    }
    table th, table td {
        border: 1px solid #ccc !important;
        padding: 8px !important;
        color: #000 !important;
    }
    table thead th {
        background-color: #f1f5f9 !important;
        color: #000 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    
    /* Avoid breaking inside elements */
    tr, img, .avoid-page-break {
        page-break-inside: avoid;
    }
    
    /* Remove shadows and excessive backgrounds */
    * {
        box-shadow: none !important;
    }
}

/* Arrow micro-interactions: Rotate diagonally on hover */
a:hover i.fa-arrow-right,
button:hover i.fa-arrow-right,
.group:hover i.fa-arrow-right,
a:hover i.fa-arrow-right-long,
button:hover i.fa-arrow-right-long,
.group:hover i.fa-arrow-right-long {
    rotate: -45deg !important;
    transition: rotate 0.3s ease !important;
}

a:hover i.fa-arrow-left,
button:hover i.fa-arrow-left,
.group:hover i.fa-arrow-left,
a:hover i.fa-arrow-left-long,
button:hover i.fa-arrow-left-long,
.group:hover i.fa-arrow-left-long {
    rotate: 45deg !important;
    transition: rotate 0.3s ease !important;
}

@keyframes fadeOut { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(10px); } }
.animate-fade-out { animation: fadeOut 0.3s ease-in forwards !important; pointer-events: none; }

/* Auto-hide the application header after scrolling beyond one content viewport. */
header[data-auto-hide-header] {
    overflow: visible;
    transition: height 220ms ease, opacity 180ms ease, transform 220ms ease, border-width 220ms ease !important;
    will-change: height, opacity, transform;
}

header[data-auto-hide-header].app-header-collapsed {
    height: 0 !important;
    min-height: 0 !important;
    overflow: hidden;
    opacity: 0;
    transform: translateY(-100%);
    border-width: 0 !important;
    pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
    header[data-auto-hide-header] {
        transition: none !important;
    }
}
