/**
 * File: assets/css/features.css
 * Theme: Astra Child - XTEINK
 * Description: CSS hệ thống Bookmark/Tủ sách, Live Search AJAX, Bài viết liên quan & Công cụ E-Reader (EPUB/Kindle).
 */

/* =======================================================
   1. HỆ THỐNG BOOKMARK & TỦ SÁCH ĐỌC SAU (READING SHELF)
   ======================================================= */

/* Nút bấm Bookmark gắn trong bài viết chi tiết */
.xteink-bookmark-wrapper {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    margin: 10px 0 22px 0;
    padding: 6px 16px;
    background: #f8fafc;
    border-radius: 30px;
    border: 1px solid #e2e8f0;
    box-sizing: border-box;
}

.btn-toggle-bookmark {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    background: transparent;
    border: none;
    color: #475569;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    padding: 0;
    touch-action: manipulation;
    transition: color 0.2s ease;
}

.btn-toggle-bookmark svg {
    stroke: #b73229;
    transition: transform 0.2s ease, fill 0.2s ease;
}

.btn-toggle-bookmark:hover {
    color: #b73229;
}

.btn-toggle-bookmark.active {
    color: #b73229;
}

.btn-toggle-bookmark.active svg {
    fill: #b73229;
    transform: scale(1.1);
}

.link-my-reading-list {
    font-size: 12.5px;
    color: #64748b !important;
    text-decoration: underline !important;
    text-underline-offset: 3px;
    font-weight: 500;
    transition: color 0.2s ease;
}

.link-my-reading-list:hover {
    color: #b73229 !important;
}

/* Giao diện trang Tủ sách (Hỗ trợ cả shortcode cũ và template mới) */
.reading-shelf-container,
.xteink-shelf-container {
    max-width: 1240px;
    margin: 20px auto 50px auto;
    padding: 0 20px;
    box-sizing: border-box;
}

.shelf-status-filter {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 25px;
}

.filter-chip {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    padding: 7px 18px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    color: #475569;
    cursor: pointer;
    transition: all 0.2s ease;
}

.filter-chip.active,
.filter-chip:hover {
    background: #b73229;
    border-color: #b73229;
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(183, 50, 41, 0.2);
}

.shelf-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 24px;
}

.shelf-item-card {
    background: #ffffff;
    border-radius: 14px;
    border: 1px solid #e2e8f0;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.03);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.shelf-item-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.06);
    border-color: #cbd5e1;
}

.shelf-card-media {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 10;
    overflow: hidden;
    background: #f1f5f9;
}

.shelf-card-media img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.35s ease;
}

.shelf-item-card:hover .shelf-card-media img {
    transform: scale(1.03);
}

.shelf-badge-cat {
    position: absolute;
    top: 10px;
    left: 10px;
    background: rgba(183, 50, 41, 0.9);
    color: #ffffff;
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    padding: 3px 8px;
    border-radius: 4px;
    letter-spacing: 0.5px;
}

.shelf-card-body {
    padding: 16px 18px;
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}

.shelf-card-title {
    margin: 0 0 10px 0;
    font-size: 15.5px;
    line-height: 1.45;
    font-weight: 700;
}

.shelf-card-title a {
    color: #0f172a !important;
    text-decoration: none !important;
    transition: color 0.2s ease;
}

.shelf-card-title a:hover {
    color: #b73229 !important;
}

.shelf-card-controls {
    margin-top: auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding-top: 12px;
    border-top: 1px solid #f1f5f9;
}

.status-select {
    padding: 5px 10px;
    font-size: 12px;
    border-radius: 8px;
    border: 1px solid #cbd5e1;
    background: #f8fafc;
    color: #334155;
    outline: none;
    font-weight: 500;
}

.btn-remove-shelf {
    background: none;
    border: none;
    font-size: 12px;
    color: #ef4444;
    cursor: pointer;
    padding: 4px 6px;
    font-weight: 600;
    transition: opacity 0.2s ease;
}

.btn-remove-shelf:hover {
    opacity: 0.75;
}

/* Khối trống (Empty State) */
.shelf-empty {
    text-align: center;
    padding: 50px 20px;
    background: #f8fafc;
    border-radius: 16px;
    border: 1px dashed #cbd5e1;
    max-width: 520px;
    margin: 30px auto;
}

.shelf-empty .empty-icon { font-size: 40px; margin-bottom: 12px; }
.shelf-empty h3 { margin: 0 0 8px 0; font-size: 18px; font-weight: 700; color: #1e293b; }
.shelf-empty p { color: #64748b; font-size: 14px; max-width: 420px; margin: 0 auto 20px auto; line-height: 1.6; }

.btn-browse-posts {
    display: inline-block;
    background: #0f172a;
    color: #ffffff !important;
    padding: 8px 22px;
    border-radius: 20px;
    font-size: 13.5px;
    font-weight: 600;
    text-decoration: none !important;
    transition: background 0.2s ease;
}

.btn-browse-posts:hover {
    background: #b73229;
}


/* =======================================================
   2. GIAO DIỆN BẢNG TÌM KIẾM TỨC THÌ (LIVE AJAX SEARCH)
   ======================================================= */
.topbar-search-form {
    position: relative !important;
}

.live-search-dropdown-box {
    display: none;
    position: absolute !important;
    top: calc(100% + 8px) !important;
    right: 0 !important;
    left: auto !important;
    width: 380px !important;
    max-width: 92vw !important;
    background: #ffffff !important;
    border-radius: 12px !important;
    border: 1px solid #e2e8f0 !important;
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.12) !important;
    z-index: 9999999 !important;
    max-height: 480px !important;
    overflow-y: auto !important;
    scrollbar-width: thin;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;
    text-align: left !important;
}

.ls-highlight {
    background-color: #fee2e2 !important;
    color: #b73229 !important;
    font-weight: 700 !important;
    padding: 0 2px !important;
    border-radius: 3px !important;
}

.ls-group {
    border-bottom: 1px solid #f1f5f9;
}
.ls-group:last-child {
    border-bottom: none;
}
.ls-group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f8fafc;
    padding: 8px 14px;
    font-size: 11px;
    font-weight: 700;
    color: #64748b;
    letter-spacing: 0.6px;
    border-bottom: 1px solid #f1f5f9;
}
.ls-badge-count {
    background: #e2e8f0;
    color: #334155;
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 8px;
    font-weight: 600;
}

.ls-item-post {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    text-decoration: none !important;
    border-bottom: 1px solid #f8fafc;
    transition: background-color 0.15s ease;
}
.ls-item-post:last-child {
    border-bottom: none;
}
.ls-item-post:hover {
    background-color: #fef2f2;
}

.ls-item-thumb {
    width: 52px;
    height: 40px;
    aspect-ratio: 16 / 10;
    object-fit: cover;
    border-radius: 6px;
    background: #f1f5f9;
    flex-shrink: 0;
}

.ls-item-info {
    flex-grow: 1;
    min-width: 0;
}

.ls-item-title {
    margin: 0 0 3px 0;
    font-size: 13.5px;
    line-height: 1.35;
    font-weight: 600;
    color: #1e293b !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ls-item-post:hover .ls-item-title {
    color: #b73229 !important;
}

.ls-item-meta {
    font-size: 11px;
    color: #94a3b8;
}
.ls-item-meta .ls-cat {
    color: #b73229;
    font-weight: 600;
}

.ls-term-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 10px 14px;
}
.ls-pill-item {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 14px;
    background: #f1f5f9;
    color: #334155 !important;
    font-size: 12px;
    font-weight: 500;
    text-decoration: none !important;
    border: 1px solid #e2e8f0;
    transition: all 0.15s ease;
}
.ls-pill-item:hover {
    background: #fee2e2;
    border-color: #b73229;
    color: #b73229 !important;
}

.ls-loading, .ls-empty {
    padding: 22px 16px;
    text-align: center;
    font-size: 13px;
    color: #64748b;
}
.ls-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid #cbd5e1;
    border-top-color: #b73229;
    border-radius: 50%;
    animation: lsSpin 0.6s linear infinite;
    vertical-align: middle;
    margin-right: 6px;
}
@keyframes lsSpin {
    to { transform: rotate(360deg); }
}

.ls-footer-all {
    padding: 10px;
    background: #fafafa;
    border-top: 1px solid #f1f5f9;
    text-align: center;
}
.ls-view-all-btn {
    background: transparent;
    border: none;
    font-size: 12.5px;
    font-weight: 600;
    color: #b73229;
    cursor: pointer;
}
.ls-view-all-btn:hover {
    text-decoration: underline;
}


/* =======================================================
   3. BÀI VIẾT LIÊN QUAN THÔNG MINH (3 CỘT CARDS)
   ======================================================= */
.xteink-related-container {
    margin-top: 45px;
    padding-top: 32px;
    border-top: 1px solid #e5e7eb;
    clear: both;
}

.related-header-wrap {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 22px;
}

.related-section-title {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;
    font-size: 20px !important;
    font-weight: 800 !important;
    color: #0f172a !important;
    margin: 0 !important;
    white-space: nowrap;
    position: relative;
    padding-left: 14px;
}

.related-section-title::before {
    content: "";
    position: absolute;
    left: 0;
    top: 3px;
    bottom: 3px;
    width: 4px;
    background-color: #b73229;
    border-radius: 2px;
}

.related-divider-line {
    flex-grow: 1;
    height: 1px;
    background-color: #f1f5f9;
}

.related-cards-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 22px;
}

.related-card-item {
    background: #ffffff;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.03);
    transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.related-card-item:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 22px rgba(0, 0, 0, 0.06);
    border-color: #cbd5e1;
}

.related-card-media {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 10;
    overflow: hidden;
    background-color: #f8fafc;
}

.related-card-media img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.35s ease;
}

.related-card-item:hover .related-card-media img {
    transform: scale(1.03);
}

.related-badge-cat {
    position: absolute;
    top: 10px;
    left: 10px;
    background: rgba(183, 50, 41, 0.9);
    color: #ffffff;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    padding: 2px 8px;
    border-radius: 4px;
    letter-spacing: 0.4px;
}

.related-card-content {
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}

.related-card-title {
    margin: 0 0 10px 0;
    font-size: 14.5px;
    line-height: 1.45;
    font-weight: 700;
    min-height: 2.9em;
}

.related-card-title a {
    color: #1e293b !important;
    text-decoration: none !important;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: color 0.2s ease;
}

.related-card-item:hover .related-card-title a {
    color: #b73229 !important;
}

.related-card-meta {
    margin-top: auto;
    font-size: 11.5px;
    color: #94a3b8;
}

.related-skeleton-card {
    height: 230px;
    border-radius: 12px;
    background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
    background-size: 200% 100%;
    animation: skeletonPulse 1.5s infinite;
}

@keyframes skeletonPulse {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}


/* ==========================================================
   4. TIỆN ÍCH XUẤT BẢN: TẢI EPUB & GỬI VÀO KINDLE
   ========================================================== */
.xteink-ereader-toolbox {
    margin: 30px 0 20px 0;
    padding: 16px 20px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 14px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.03);
}

.toolbox-header {
    display: flex;
    align-items: center;
    gap: 8px;
}
.toolbox-icon {
    font-size: 20px;
}
.toolbox-title {
    font-size: 14px;
    font-weight: 700;
    color: #1e293b;
}

.toolbox-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.btn-toolbox-action {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 16px;
    border-radius: 20px;
    font-size: 12.5px;
    font-weight: 600;
    text-decoration: none !important;
    cursor: pointer;
    border: 1px solid #cbd5e1;
    background: #f8fafc;
    color: #334155 !important;
    transition: all 0.2s ease;
    touch-action: manipulation;
}

.btn-toolbox-action svg {
    stroke: #64748b;
    transition: stroke 0.2s ease;
}

.btn-toolbox-action:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.btn-epub-dl:hover {
    background-color: #fee2e2;
    border-color: #b73229;
    color: #b73229 !important;
}
.btn-epub-dl:hover svg {
    stroke: #b73229;
}

.btn-kindle-send:hover {
    background-color: #eff6ff;
    border-color: #2563eb;
    color: #2563eb !important;
}
.btn-kindle-send:hover svg {
    stroke: #2563eb;
}

/* Modal Popup Gửi Kindle */
.kindle-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.65);
    backdrop-filter: blur(4px);
    z-index: 9999999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    box-sizing: border-box;
}

.kindle-modal-card {
    background: #ffffff;
    border-radius: 16px;
    max-width: 440px;
    width: 100%;
    padding: 26px;
    box-shadow: 0 20px 45px rgba(0, 0, 0, 0.22);
    animation: modalPop 0.2s ease;
    box-sizing: border-box;
}

@keyframes modalPop {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.kindle-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
}
.kindle-modal-header h4 {
    margin: 0;
    font-size: 17px;
    font-weight: 800;
    color: #0f172a;
}
.modal-close-btn {
    background: none;
    border: none;
    font-size: 22px;
    color: #94a3b8;
    cursor: pointer;
    line-height: 1;
}
.modal-close-btn:hover {
    color: #b73229;
}

.kindle-modal-body p {
    font-size: 13.5px;
    color: #475569;
    line-height: 1.55;
    margin: 0 0 16px 0;
}

.kindle-input-group input {
    width: 100% !important;
    padding: 11px 14px !important;
    border-radius: 8px !important;
    border: 1.5px solid #cbd5e1 !important;
    font-size: 16px !important; /* Chuẩn 16px để ngăn iOS auto-zoom */
    box-sizing: border-box !important;
    margin-bottom: 14px !important;
}
.kindle-input-group input:focus {
    border-color: #2563eb !important;
    outline: none !important;
}

.btn-confirm-kindle {
    width: 100%;
    background: #2563eb;
    color: #ffffff;
    border: none;
    padding: 11px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: background-color 0.2s;
}
.btn-confirm-kindle:hover {
    background: #1d4ed8;
}

.kindle-status-text {
    font-size: 12.5px;
    font-weight: 600;
    margin-bottom: 10px;
    min-height: 18px;
}

.kindle-hint {
    display: block;
    margin-top: 14px;
    font-size: 11.5px;
    color: #94a3b8;
    line-height: 1.45;
}


/* =======================================================
   5. RESPONSIVE CHO TABLET & MOBILE (<= 768px)
   ======================================================= */
@media screen and (max-width: 768px) {
    /* Lưới Tủ sách & Bài viết liên quan về 1 cột trên mobile */
    .shelf-grid,
    .related-cards-grid {
        grid-template-columns: 1fr !important;
        gap: 18px !important;
    }

    /* Bảng tìm kiếm Live Search trải đều theo thanh search mobile */
    .live-search-dropdown-box {
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        top: calc(100% + 6px) !important;
    }

    /* Tiện ích E-Reader hộp công cụ xuống dòng tự nhiên */
    .xteink-ereader-toolbox {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        padding: 14px 16px;
    }

    .toolbox-actions {
        width: 100%;
        justify-content: space-between;
    }

    .btn-toolbox-action {
        flex: 1;
        justify-content: center;
    }
}