/* =======================
   Book Correction Table - Frontend CSS
   v3.0.0 — CSS Custom Properties
   ======================= */

/* =======================
   Wrapper
   ======================= */
.bct-corrections-wrapper {
    /* Default theme — overridden by inline styles */
    --bct-toolbar-start: #3f136f;
    --bct-toolbar-end: #4c05e3;
    --bct-header-bg: #f3f4ff;
    --bct-header-color: #1d2ad1;
    --bct-pag-active-bg: #e8e8ff;
    --bct-pag-active-color: #1d1dff;
    --bct-row-alt: #f9fafb;

    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
}

/* =======================
   Book Grid
   ======================= */
.bct-book-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

@media (max-width: 1200px) {
    .bct-book-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (max-width: 900px) {
    .bct-book-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 600px) {
    .bct-book-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

.bct-book-card {
    background: #fff;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid #e5e7eb;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    display: flex;
    flex-direction: row;
    align-items: stretch;
    text-decoration: none;
    color: inherit;
}

.bct-book-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
}

.bct-book-card.active {
    border-color: var(--bct-toolbar-end);
    box-shadow: 0 0 0 2px var(--bct-toolbar-end), 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* Back to All Books link */
.bct-back-link {
    margin: 12px 0 4px;
}

.bct-back-link a {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 14px;
    font-weight: 500;
    color: var(--bct-toolbar-end, #4c05e3);
    text-decoration: none;
    transition: opacity 0.2s;
}

.bct-back-link a:hover {
    opacity: 0.8;
}

.bct-book-cover {
    width: 52px;
    min-height: 52px;
    overflow: hidden;
    background: #f3f4f6;
    flex-shrink: 0;
}

.bct-book-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.3s ease;
}

.bct-book-card:hover .bct-book-cover img {
    transform: scale(1.08);
}

.bct-book-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    background: linear-gradient(135deg, #f3f4f6, #e5e7eb);
}

.bct-book-info {
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 1px;
    min-width: 0;
}

.bct-book-title {
    font-size: 12px;
    font-weight: 600;
    color: #1d2327;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.bct-book-count {
    font-size: 10px;
    color: #6b7280;
}

/* =======================
   Toolbar
   ======================= */
.bct-corrections-toolbar {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 16px;
    align-items: center;
    background: linear-gradient(135deg, var(--bct-toolbar-start), var(--bct-toolbar-end));
    padding: 14px 20px;
    border-radius: 10px;
    margin-bottom: 16px;
    color: #fff;
}

.bct-toolbar-left,
.bct-toolbar-right {
    display: flex;
    align-items: center;
}

.bct-toolbar-center {
    display: flex;
    align-items: center;
}

.bct-toolbar-group {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.bct-toolbar-label {
    font-weight: 500;
    white-space: nowrap;
    font-size: 13px;
}

.bct-toolbar-static {
    padding: 8px 14px;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 8px;
    color: #fff;
    font-size: 13px;
}

.bct-corrections-toolbar select,
.bct-corrections-toolbar input[type="search"] {
    width: 100%;
    padding: 9px 14px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.25);
    background: rgba(255, 255, 255, 0.12) !important;
    color: #fff;
    font-size: 13px;
    -webkit-text-fill-color: #fff !important;
    transition: border-color 0.2s ease, background 0.2s ease;
}

.bct-corrections-toolbar select:focus,
.bct-corrections-toolbar input[type="search"]:focus {
    outline: none;
    background: rgba(255, 255, 255, 0.18) !important;
    border-color: rgba(255, 255, 255, 0.5);
}

.bct-corrections-toolbar select option {
    background-color: #3f136f !important;
    color: #fff !important;
}

.bct-corrections-toolbar input[type="search"]::placeholder {
    color: rgba(255, 255, 255, 0.6);
}

/* Mobile filter button */
.bct-mobile-filter-btn {
    display: none;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    color: #fff;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
}

@media (max-width: 768px) {
    .bct-corrections-toolbar {
        display: flex;
        justify-content: space-between;
        padding: 12px 16px;
    }

    .bct-toolbar-left,
    .bct-toolbar-center,
    .bct-toolbar-right {
        display: none !important;
    }

    .bct-mobile-filter-btn {
        display: flex;
    }
}

/* =======================
   Offcanvas Filter (Mobile)
   ======================= */
.bct-offcanvas-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999998;
    backdrop-filter: blur(2px);
}

.bct-offcanvas-overlay.open {
    display: block;
    animation: bctFadeIn 0.2s ease;
}

.bct-offcanvas {
    position: fixed;
    top: 0;
    right: -320px;
    width: 300px;
    max-width: 85vw;
    height: 100vh;
    background: #fff;
    z-index: 999999;
    display: flex;
    flex-direction: column;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
    transition: right 0.3s ease;
}

.bct-offcanvas.open {
    right: 0;
}

.bct-offcanvas-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #e5e7eb;
}

.bct-offcanvas-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: #1d2327;
}

.bct-offcanvas-close {
    width: 32px;
    height: 32px;
    border: none;
    background: #f3f4f6;
    border-radius: 8px;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6b7280;
    transition: background 0.15s;
}

.bct-offcanvas-close:hover {
    background: #e5e7eb;
}

.bct-offcanvas-body {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
}

.bct-offcanvas-group {
    margin-bottom: 20px;
}

.bct-offcanvas-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #374151;
    margin-bottom: 6px;
}

.bct-offcanvas-group select,
.bct-offcanvas-group input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 14px;
    background: #fff;
    box-sizing: border-box;
}

.bct-offcanvas-footer {
    padding: 16px 20px;
    border-top: 1px solid #e5e7eb;
    display: flex;
    gap: 10px;
}

.bct-offcanvas-apply {
    flex: 1;
    padding: 10px;
    background: linear-gradient(135deg, var(--bct-toolbar-start), var(--bct-toolbar-end));
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

.bct-offcanvas-clear {
    padding: 10px 16px;
    background: #f3f4f6;
    color: #374151;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
}

/* =======================
   DataTables Overrides
   ======================= */
.bct-topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 8px;
}

.dataTables_length {
    display: inline-flex;
    align-items: center;
    gap: 0;
    font-size: 13px;
    color: #6b7280;
}

.dataTables_length label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.dataTables_length select {
    border: 1px solid #d1d5db;
    border-radius: 6px;
    padding: 5px 8px !important;
    background: #fff !important;
    color: #374151;
    cursor: pointer;
    font-size: 13px;
    min-width: 52px;
}

.dataTables_wrapper .dataTables_info {
    padding-top: 0;
    font-size: 13px;
    color: #6b7280;
}

.dataTables_filter {
    display: none !important;
}

/* =======================
   Table
   ======================= */
.bct-table-scroll {
    overflow-x: auto;
}

@media (min-width: 1024px) {
    .bct-table-scroll {
        overflow-x: visible;
    }
}

.bct-corrections-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    table-layout: fixed;
}

.bct-corrections-table thead th {
    background: var(--bct-header-bg);
    color: var(--bct-header-color);
    padding: 12px 14px;
    font-weight: 600;
    font-size: 13px;
    border-bottom: 2px solid #e5e7eb;
    text-align: left;
}

.bct-corrections-table tbody td {
    padding: 14px;
    border-bottom: 1px solid #f0f1f3;
    vertical-align: top;
    word-wrap: break-word;
    overflow-wrap: break-word;
    color: #374151;
    line-height: 1.6;
}

.bct-corrections-table tbody tr:nth-child(odd) {
    background: #ffffff;
}

.bct-corrections-table tbody tr:nth-child(even) {
    background: var(--bct-row-alt);
}

.bct-corrections-table tbody tr:hover {
    background: #fafaff;
}

/* Column widths — Page & Chapter narrow, Error biggest, Image 2nd */
.bct-corrections-table th.bct-col-page,
.bct-corrections-table td.bct-col-page {
    width: 60px;
    white-space: nowrap;
    text-align: center;
}

.bct-corrections-table th.bct-col-chapter,
.bct-corrections-table td.bct-col-chapter {
    width: 70px;
    white-space: nowrap;
    text-align: center;
}

.bct-corrections-table th.bct-col-error,
.bct-corrections-table td.bct-col-error {
    /* Takes remaining space — largest column */
}

.bct-corrections-table th.bct-col-image,
.bct-corrections-table td.bct-col-image {
    width: 28%;
}

/* =======================
   Dual Image Display
   ======================= */
.bct-dual-images {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.bct-img-section {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.bct-img-label {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 4px;
    display: inline-block;
    width: fit-content;
}

.bct-label-wrong {
    background: #fee2e2;
    color: #dc2626;
}

.bct-label-correct {
    background: #d1fae5;
    color: #059669;
}

.bct-correction-image {
    width: 100%;
    max-width: 100%;
    height: auto;
    border-radius: 6px;
    cursor: pointer;
    display: block;
    transition: opacity 0.2s ease;
}

.bct-correction-image:hover {
    opacity: 0.9;
}

/* =======================
   Pagination
   ======================= */
.bct-bottombar {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid #f0f1f3;
    gap: 8px;
}

.dataTables_paginate {
    display: flex;
    gap: 4px;
    align-items: center;
}

.dataTables_paginate a {
    border: none;
    padding: 7px 14px;
    border-radius: 20px;
    background: #f3f4f6;
    color: #4b5563 !important;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.15s ease;
    text-decoration: none;
}

.dataTables_paginate a:hover {
    background: #e5e7eb;
    color: #1d2327 !important;
}

.dataTables_paginate a.paginate_button.current {
    background: linear-gradient(135deg, var(--bct-toolbar-start), var(--bct-toolbar-end));
    color: #fff !important;
    font-weight: 600;
    box-shadow: 0 2px 6px rgba(76, 5, 227, 0.2);
}

.dataTables_paginate a.paginate_button.disabled {
    opacity: 0.4;
    cursor: default;
}

/* =======================
   Modal
   ======================= */
.bct-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.88);
    backdrop-filter: blur(6px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 999999;
    padding: 20px;
    box-sizing: border-box;
    animation: bctFadeIn 0.2s ease;
}

.bct-modal-content {
    position: relative;
    background: #ffffff;
    padding: 48px 24px 24px;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    max-width: calc(100vw - 60px);
    max-height: calc(100vh - 60px);
    width: auto;
    height: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    overflow: hidden;
    animation: bctZoomIn 0.2s ease;
}

.bct-modal-img {
    display: block;
    max-width: 100%;
    max-height: calc(100vh - 140px);
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 6px;
}

.bct-modal-close {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
    padding: 0;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #ef4444;
    color: #fff;
    font-size: 20px;
    font-weight: 300;
    line-height: 1;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.3);
    z-index: 10;
    transition: background 0.15s ease, transform 0.15s ease;
}

.bct-modal-close:hover {
    background: #dc2626;
    transform: scale(1.1);
}

.bct-modal-close:focus {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

.bct-modal-close::before,
.bct-modal-close::after {
    display: none !important;
    content: none !important;
}

/* =======================
   Animations
   ======================= */
@keyframes bctFadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes bctZoomIn {
    from {
        transform: scale(0.95);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* =======================
   Loading Spinner
   ======================= */
.bct-corrections-table .dataTables_empty {
    text-align: center;
    padding: 48px 20px !important;
    color: #6b7280;
    font-size: 14px;
}

@keyframes bctSpin {
    to {
        transform: rotate(360deg);
    }
}

/* Spinner only during loading — not on "No corrections found" */
.bct-corrections-table.bct-loading .dataTables_empty::before {
    content: '';
    display: block;
    width: 28px;
    height: 28px;
    margin: 0 auto 12px;
    border: 3px solid #e5e7eb;
    border-top-color: var(--bct-toolbar-end);
    border-radius: 50%;
    animation: bctSpin 0.7s linear infinite;
}

/* =======================
   Tablet
   ======================= */
@media (max-width: 1024px) {
    .bct-modal-content {
        max-width: calc(100vw - 40px);
        max-height: calc(100vh - 40px);
        padding: 40px 20px 20px;
    }

    .bct-modal-img {
        max-height: calc(100vh - 120px);
    }
}

/* =======================
   Mobile Modal
   ======================= */
@media (max-width: 768px) {
    .bct-modal-overlay {
        padding: 12px;
    }

    .bct-modal-content {
        max-width: calc(100vw - 24px);
        max-height: calc(100vh - 24px);
        padding: 36px 12px 12px;
        border-radius: 10px;
    }

    .bct-modal-img {
        max-height: calc(100vh - 80px);
        max-width: 100%;
    }

    .bct-modal-close {
        top: 8px;
        right: 8px;
        width: 28px;
        height: 28px;
        min-width: 28px;
        min-height: 28px;
        font-size: 16px;
    }
}

/* =======================
   Mobile Card Layout
   ======================= */
@media screen and (max-width: 768px) {
    .bct-table-scroll {
        overflow-x: hidden !important;
        overflow-y: visible !important;
    }

    .bct-corrections-table {
        display: block !important;
        width: 100% !important;
        border: none !important;
    }

    .bct-corrections-table thead {
        display: none !important;
    }

    .bct-corrections-table tbody {
        display: block !important;
        width: 100% !important;
    }

    .bct-corrections-table tbody tr {
        display: block !important;
        width: 100% !important;
        margin-bottom: 12px !important;
        border: 1px solid #e5e7eb !important;
        border-radius: 10px !important;
        background: #ffffff !important;
        overflow: hidden !important;
        box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04) !important;
    }

    .bct-corrections-table tbody td {
        display: block !important;
        width: 100% !important;
        box-sizing: border-box !important;
        padding: 0 !important;
        border: none !important;
        border-bottom: 1px solid #f0f1f3 !important;
        text-align: left !important;
        position: relative !important;
    }

    .bct-corrections-table tbody td:last-child {
        border-bottom: none !important;
    }

    .bct-corrections-table tbody td::before {
        content: attr(data-label);
        display: block !important;
        width: 100% !important;
        padding: 10px 14px !important;
        font-size: 11px !important;
        font-weight: 700 !important;
        color: #6b7280 !important;
        background-color: #f9fafb !important;
        text-transform: uppercase !important;
        letter-spacing: 0.5px !important;
        box-sizing: border-box !important;
    }

    .bct-cell-content {
        display: block !important;
        padding: 12px 14px !important;
        background: #fff !important;
    }

    .bct-corrections-table th,
    .bct-corrections-table td {
        width: 100% !important;
    }

    .bct-correction-image {
        margin: 10px 14px !important;
        max-width: calc(100% - 28px) !important;
        width: calc(100% - 28px) !important;
    }

    .bct-dual-images {
        padding: 10px 14px;
    }

    .bct-bottombar {
        justify-content: center !important;
        flex-wrap: wrap !important;
    }

    .dataTables_paginate {
        flex-wrap: wrap !important;
        justify-content: center !important;
    }
}

/* =======================
   Extra Small
   ======================= */
@media screen and (max-width: 480px) {
    .bct-corrections-wrapper {
        padding: 0;
    }

    .bct-corrections-toolbar {
        padding: 10px 14px;
        border-radius: 8px;
    }

    .bct-book-grid {
        gap: 10px;
    }

    .bct-book-info {
        padding: 8px 10px;
    }

    .bct-book-title {
        font-size: 12px;
    }

    .bct-modal-content {
        padding: 32px 8px 8px;
    }

    .bct-modal-close {
        top: 6px;
        right: 6px;
        width: 26px;
        height: 26px;
    }

    .bct-corrections-table tbody td::before {
        padding: 8px 12px !important;
        font-size: 10px !important;
    }

    .bct-cell-content {
        padding: 10px 12px !important;
    }
}

/* =======================
   Print
   ======================= */
@media print {

    .bct-corrections-toolbar,
    .bct-book-grid,
    .bct-modal-overlay,
    .bct-offcanvas,
    .bct-offcanvas-overlay,
    .bct-mobile-filter-btn,
    .dataTables_length,
    .dataTables_paginate,
    .dataTables_info {
        display: none !important;
    }

    .bct-corrections-wrapper {
        box-shadow: none;
    }

    .bct-corrections-table {
        font-size: 12px;
    }
}