
/* 1. BIẾN MÀU CHỦ ĐẠO (HERITAGE GOLD & GLASSMORPHISM) */
:root {
    --gold-primary: #b58d46;
    --gold-light: #e5c687;
    --gold-dark: #876528;
    --glass-light: rgba(255, 255, 255, 0.84);
    --glass-dark: rgba(22, 25, 31, 0.82);
    --glass-border-light: rgba(181, 141, 70, 0.25);
    --glass-border-dark: rgba(229, 198, 135, 0.20);
}

/* 2. NỀN GỐC, PHÔNG CHỮ & HỌA TIẾT TRỐNG ĐỒNG XOAY CHẬM */
html[data-bs-theme="light"] {
    background: radial-gradient(circle at top, #fffdf8 0%, #f3efe6 100%);
    min-height: 100%;
}

html[data-bs-theme="dark"] {
    background: radial-gradient(circle at top, #1a1d24 0%, #0e1014 100%);
    min-height: 100%;
}

body,
body.bg-body-tertiary {
    font-family: 'Be Vietnam Pro', system-ui, -apple-system, sans-serif;
    background-color: transparent !important;
    position: relative;
    overflow-x: hidden;
}

.font-serif {
    font-family: 'Cormorant Garamond', Georgia, serif;
}

@keyframes drumRotate {
    from { transform: translate(-50%, -50%) rotate(0deg); }
    to   { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Lớp nền(nằm dưới lớp pháo hoa) */
body::before {
    content: "";
    position: fixed;
    top: 50%;
    left: 50%;
    width: min(105vmin, 960px);
    height: min(105vmin, 960px);
    z-index: -2;
    pointer-events: none;
    background-image: url('../img/bg_1_2.jpg');
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    animation: drumRotate 160s linear infinite;
    transition: filter 0.35s ease, opacity 0.35s ease;
}

html[data-bs-theme="light"] body::before {
    filter: invert(1) brightness(2.4) invert(1);
    mix-blend-mode: multiply;
    opacity: 0.65;
}

html[data-bs-theme="dark"] body::before {
    filter: invert(1) brightness(2.6);
    mix-blend-mode: screen;
    opacity: 0.32;
}

/* Lớp pháo hoa nền (nằm trên background, trên nội dung) */
#fireworksCanvas {
    position: fixed;
    inset: 0;
    z-index: 1;
    pointer-events: none;
}

/* 3. THANH ĐIỀU HƯỚNG, THẺ KÍNH MỜ & NÚT VÀNG ĐỒNG */
.glass-nav {
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--glass-border-light);
}

html[data-bs-theme="light"] .glass-nav {
    background: rgba(255, 253, 248, 0.80) !important;
}

html[data-bs-theme="dark"] .glass-nav {
    background: rgba(16, 18, 23, 0.80) !important;
    border-color: var(--glass-border-dark);
}

.card,
.glass-card {
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    transition: transform 0.25s ease, box-shadow 0.25s ease;
}

html[data-bs-theme="light"] .card,
html[data-bs-theme="light"] .glass-card {
    background: var(--glass-light) !important;
    border: 1px solid var(--glass-border-light) !important;
    box-shadow: 0 20px 50px rgba(135, 101, 40, 0.08);
}

html[data-bs-theme="dark"] .card,
html[data-bs-theme="dark"] .glass-card {
    background: var(--glass-dark) !important;
    border: 1px solid var(--glass-border-dark) !important;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}

.text-gold {
    color: var(--gold-primary) !important;
}

html[data-bs-theme="dark"] .text-gold {
    color: var(--gold-light) !important;
}

.btn-gold {
    background: linear-gradient(135deg, #c69f59 0%, #9b7430 100%);
    border: none;
    color: #fff !important;
    font-weight: 600;
    box-shadow: 0 8px 20px rgba(155, 116, 48, 0.28);
    transition: all 0.25s ease;
}

.btn-gold:hover {
    transform: translateY(-1px);
    box-shadow: 0 12px 26px rgba(155, 116, 48, 0.4);
    filter: brightness(1.06);
}

/* 4. TRUNG TÂM TRA CỨU 3 CHẾ ĐỘ (MÃ MỜI / SĐT-EMAIL / QUÉT QR) */
.lookup-tabs {
    background: rgba(181, 141, 70, 0.10);
    border-radius: 999px;
    padding: 5px;
    display: inline-flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px;
}

.lookup-tabs .nav-link {
    border-radius: 999px;
    font-size: 0.88rem;
    font-weight: 500;
    padding: 8px 16px;
    color: inherit;
    border: none;
    transition: all 0.25s ease;
}

.lookup-tabs .nav-link.active {
    background: linear-gradient(135deg, #c69f59 0%, #9b7430 100%);
    color: #fff !important;
    box-shadow: 0 4px 12px rgba(155, 116, 48, 0.3);
}

.search-pill {
    border-radius: 999px;
    padding: 6px;
    border: 1.5px solid var(--glass-border-light);
    background: var(--bs-body-bg);
    transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

.search-pill:focus-within {
    border-color: var(--gold-primary);
    box-shadow: 0 0 0 4px rgba(181, 141, 70, 0.16);
}

.search-pill input {
    border: none !important;
    box-shadow: none !important;
    background: transparent !important;
}

#qrReader {
    max-width: 360px;
    margin: 0 auto;
    border-radius: 16px;
    overflow: hidden;
    border: 2px dashed rgba(181, 141, 70, 0.5);
}

/* 5. ĐỒNG HỒ ĐẾM NGƯỢC SỰ KIỆN */
.countdown-wrap {
    display: inline-flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
}

.countdown-box {
    min-width: 68px;
    padding: 10px 8px;
    border-radius: 14px;
    text-align: center;
    border: 1px solid var(--glass-border-light);
    background: linear-gradient(160deg, rgba(181, 141, 70, 0.14), rgba(181, 141, 70, 0.04));
    box-shadow: 0 6px 16px rgba(135, 101, 40, 0.08);
}

html[data-bs-theme="dark"] .countdown-box {
    border-color: var(--glass-border-dark);
    background: linear-gradient(160deg, rgba(229, 198, 135, 0.14), rgba(255, 255, 255, 0.03));
}

.countdown-num {
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-size: 1.85rem;
    font-weight: 700;
    line-height: 1;
    color: var(--gold-primary);
    font-variant-numeric: tabular-nums;
}

html[data-bs-theme="dark"] .countdown-num {
    color: var(--gold-light);
}

.countdown-label {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    opacity: 0.75;
    margin-top: 4px;
}

.countdown-status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 18px;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 600;
}

.countdown-live {
    background: rgba(25, 135, 84, 0.14);
    color: #198754;
    border: 1px solid rgba(25, 135, 84, 0.3);
}

.countdown-ended {
    background: rgba(108, 117, 125, 0.14);
    color: var(--bs-secondary-color);
    border: 1px solid rgba(108, 117, 125, 0.25);
}

@keyframes liveDotBlink {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%      { opacity: 0.35; transform: scale(0.8); }
}

.live-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #198754;
    animation: liveDotBlink 1.2s infinite;
}

/* 6. BAO THƯ 3D & HIỆU ỨNG MỞ NIÊM PHONG */
@keyframes unfoldReveal {
    from { opacity: 0; transform: translateY(24px) scale(0.96); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.reveal-anim {
    animation: unfoldReveal 0.6s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.envelope-wrapper {
    position: relative;
    max-width: 540px;
    margin: 0 auto;
    padding: 0 8px 16px;
}

.env-header {
    transition: opacity 0.45s ease, transform 0.45s ease;
}

.envelope-wrapper.is-opening .env-header {
    opacity: 0.15;
    transform: translateY(-10px);
}

.env-box {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 10.5;
    min-height: 270px;
    margin: 0 auto;
    perspective: 1400px;
    border-radius: 5px;
    transition: transform 0.55s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.45s ease;
}

.env-back {
    position: absolute;
    inset: 0;
    z-index: 1;
    border-radius: 16px;
    border: 1.5px solid rgba(181, 141, 70, 0.55);
    box-shadow: 0 24px 55px rgba(135, 101, 40, 0.22);
    background: linear-gradient(160deg, #efe4ce 0%, #dfd0b0 100%);
}

html[data-bs-theme="dark"] .env-back {
    background: linear-gradient(160deg, #25221c 0%, #171511 100%);
    border-color: rgba(229, 198, 135, 0.42);
    box-shadow: 0 26px 60px rgba(0, 0, 0, 0.65);
}

.env-letter {
    position: absolute;
    left: 6%;
    right: 6%;
    top: 10%;
    bottom: 8%;
    z-index: 2;
    border-radius: 10px;
    padding: 10px;
    background: #fffdf7;
    border: 1px solid rgba(181, 141, 70, 0.55);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.14);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    transform: translateY(0) scale(0.95);
    transition: transform 0.85s cubic-bezier(0.22, 1, 0.36, 1) 0.42s,
                box-shadow 0.85s ease 0.42s;
}

html[data-bs-theme="dark"] .env-letter {
    background: #1f2229;
    border-color: rgba(229, 198, 135, 0.45);
}

.env-letter-thumb {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

.env-pocket {
    position: absolute;
    inset: 0;
    z-index: 3;
    border-radius: 16px;
    overflow: hidden;
    pointer-events: none;
}

.env-pocket-left,
.env-pocket-right,
.env-pocket-bottom {
    position: absolute;
    inset: 0;
}

.env-pocket-left {
    clip-path: polygon(0 0, 52% 54%, 0 100%);
    background: linear-gradient(125deg, #f9f3e6 0%, #eadbc0 100%);
}

.env-pocket-right {
    clip-path: polygon(100% 0, 100% 100%, 48% 54%);
    background: linear-gradient(235deg, #f9f3e6 0%, #eadbc0 100%);
}

.env-pocket-bottom {
    clip-path: polygon(0 100%, 50% 48%, 100% 100%);
    background: linear-gradient(0deg, #f5ebd8 0%, #fdf9f0 100%);
    filter: drop-shadow(0 -3px 6px rgba(135, 101, 40, 0.14));
}

html[data-bs-theme="dark"] .env-pocket-left {
    background: linear-gradient(125deg, #2b2720 0%, #1e1b16 100%);
}

html[data-bs-theme="dark"] .env-pocket-right {
    background: linear-gradient(235deg, #2b2720 0%, #1e1b16 100%);
}

html[data-bs-theme="dark"] .env-pocket-bottom {
    background: linear-gradient(0deg, #23201b 0%, #302b22 100%);
    filter: drop-shadow(0 -3px 8px rgba(0, 0, 0, 0.45));
}

.env-pocket-lines {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.env-front-label {
    position: absolute;
    left: 10%;
    right: 10%;
    bottom: 9%;
    z-index: 4;
    padding: 10px 14px;
    border-radius: 12px;
    text-align: center;
    background: rgba(255, 253, 248, 0.88);
    border: 1px solid rgba(181, 141, 70, 0.35);
    backdrop-filter: blur(6px);
    pointer-events: none;
    transition: opacity 0.35s ease;
}

html[data-bs-theme="dark"] .env-front-label {
    background: rgba(22, 20, 17, 0.84);
    border-color: rgba(229, 198, 135, 0.3);
}

.env-flap {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 58%;
    z-index: 5;
    transform-origin: top center;
    transform: rotateX(0deg);
    transition: transform 0.72s cubic-bezier(0.4, 0, 0.2, 1) 0.12s,
                z-index 0s linear 0.34s;
    pointer-events: none;
}

.env-flap-shape {
    position: absolute;
    inset: 0;
    border-radius: 16px 16px 0 0;
    clip-path: polygon(0 0, 100% 0, 50% 100%);
    background: linear-gradient(180deg, #fffbf2 0%, #ecdec3 100%);
    filter: drop-shadow(0 8px 14px rgba(135, 101, 40, 0.22));
}

html[data-bs-theme="dark"] .env-flap-shape {
    background: linear-gradient(180deg, #363026 0%, #231f19 100%);
    filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.55));
}

.env-flap-line {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

@keyframes sealPulse {

    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(160, 28, 28, 0.42), 0 10px 26px rgba(135, 101, 40, 0.32);
    }

    50% {
        box-shadow: 0 0 0 14px rgba(181, 141, 70, 0), 0 12px 30px rgba(160, 28, 28, 0.36);
    }
}

.wax-seal-btn {
    position: absolute;
    top: 53%;
    left: 50%;
    z-index: 6;
    transform: translate(-50%, -50%);
    width: 88px;
    height: 88px;
    padding: 4px;
    border-radius: 18px;
    border: 2.5px solid #d4af63;
    background: #ffffff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    overflow: visible;
    animation: sealPulse 2.4s infinite;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.28s ease;
}

.wax-seal-btn:hover {
    transform: translate(-50%, -50%) scale(1.08);
}

.wax-seal-logo {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 11px;
    display: block;
    pointer-events: none;
}

.wax-seal-tag {
    position: absolute;
    bottom: -12px;
    left: 50%;
    transform: translateX(-50%);
    padding: 2px 10px;
    border-radius: 999px;
    background: linear-gradient(135deg, #c69f59 0%, #8c6626 100%);
    border: 1.5px solid #fff8e7;
    color: #ffffff;
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    white-space: nowrap;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.22);
    pointer-events: none;
}

/* Trạng thái đang mở bao thư */
.envelope-wrapper.is-opening .wax-seal-btn {
    animation: none;
    transform: translate(-50%, -50%) scale(1.32) rotate(-18deg);
    opacity: 0;
    pointer-events: none;
}

.envelope-wrapper.is-opening .env-flap {
    transform: rotateX(180deg);
    z-index: 1;
}

.envelope-wrapper.is-opening .env-letter {
    z-index: 4;
    transform: translateY(-58%) scale(1.04);
    box-shadow: 0 22px 48px rgba(181, 141, 70, 0.38);
}

.envelope-wrapper.is-opening .env-front-label {
    opacity: 0.35;
}

.envelope-wrapper.is-exiting .env-box {
    opacity: 0;
    transform: translateY(-18px) scale(1.05);
}

/* 7. KHUNG HIỂN THỊ THƯ MỜI SAU KHI MỞ (CHỐNG TRÀN MÀN HÌNH) */
#resultSection .glass-card {
    max-width: 100%;
    overflow: hidden;
}

#eventTitle,
#eventMeta {
    overflow-wrap: anywhere;
    word-break: break-word;
}

.invitation-stage {
    perspective: 1200px;
    width: 100%;
    max-width: 100%;
    padding: 8px 4px;
    overflow: hidden;
    text-align: center;
}

.invitation-canvas {
    display: block;
    max-width: 100% !important;
    max-height: 70vh !important;
    width: auto !important;
    height: auto !important;
    margin: 0 auto;
    object-fit: contain;
    border-radius: 14px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.2);
    transition: transform 0.25s ease;
    cursor: zoom-in;
}

#zoomedImg {
    display: block;
    max-width: 100%;
    max-height: 85vh;
    width: auto;
    height: auto;
    margin: 0 auto;
    object-fit: contain;
}

/* 8. QUẢN TRỊ: BẢNG CỐ ĐỊNH CỘT, PHÂN TRANG & TRÌNH THIẾT KẾ MẪU */
.table-fixed-cols {
    table-layout: fixed;
    width: 100%;
    min-width: 980px;
}

.table-fixed-cols th,
.table-fixed-cols td {
    white-space: normal !important;
    overflow-wrap: anywhere;
    word-break: break-word;
    vertical-align: middle;
}

.table-fixed-cols .badge {
    white-space: normal !important;
    text-align: left;
    line-height: 1.35;
    max-width: 100%;
    display: inline-block;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.table-fixed-cols code {
    word-break: break-all;
}

.pagination .page-item.active .page-link {
    background: linear-gradient(135deg, #c69f59 0%, #9b7430 100%);
    border-color: #9b7430;
    color: #fff;
}

.pagination .page-link {
    min-width: 32px;
    text-align: center;
}

/* Trình thiết kế kéo-thả mẫu thư mời (admin/templates.php) */
#designStage {
    position: relative;
    display: inline-block;
    user-select: none;
    border: 2px dashed var(--gold-primary);
    background: #e9ecef;
    max-width: 100%;
}

#stageImg {
    display: block;
    max-width: 100%;
    height: auto;
    pointer-events: none;
}

.drag-field {
    position: absolute;
    cursor: move;
    border: 1px dashed rgba(13, 110, 253, 0.85);
    background: rgba(255, 255, 255, 0.45);
    padding: 1px 4px;
    white-space: nowrap;
    line-height: 1.1;
}

.drag-field.active {
    border: 2px solid #dc3545;
    background: rgba(255, 255, 255, 0.75);
    z-index: 10;
}

.drag-qr {
    position: absolute;
    cursor: move;
    border: 2px dashed #198754;
    background: rgba(255, 255, 255, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: #198754;
}

/* 9. RESPONSIVE CHO ĐIỆN THOẠI & GIẢM CHUYỂN ĐỘNG */
@media (max-width: 576px) {
    .countdown-box {
        min-width: 60px;
        padding: 8px 6px;
    }

    .countdown-num {
        font-size: 1.5rem;
    }

    .env-box {
        min-height: 245px;
    }

    .wax-seal-btn {
        position: absolute;
        top: 47%;
        left: 50%;
        z-index: 6;
        transform: translate(-50%, -50%);
        width: 70px;
        height: 70px;
        padding: 4px;
        border-radius: 18px;
        border: 2.5px solid #d4af63;
        background: #ffffff;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        overflow: visible;
        animation: sealPulse 2.4s infinite;
        transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.28s ease;
    }

    .wax-seal-tag {
        font-size: 0.56rem;
        padding: 2px 8px;
        bottom: -7px;
    }

    .env-front-label {
        padding: 7px 10px;
        bottom: 7%;
    }

    .search-pill {
        flex-wrap: nowrap;
    }
}

@media (prefers-reduced-motion: reduce) {
    body::before,
    .env-flap,
    .env-letter,
    .wax-seal-btn,
    .env-box,
    .live-dot {
        transition-duration: 0.01ms !important;
        animation: none !important;
    }
}

/* ==================== DANH SÁCH KẾT QUẢ TRA CỨU & HIGHLIGHT MỚI NHẤT ==================== */
.match-item {
    border-radius: 14px;
    padding: 12px 14px;
    border: 1px solid var(--glass-border-light);
    background: var(--bs-body-bg);
    transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
    text-align: left;
    width: 100%;
}

.match-item:hover {
    transform: translateY(-1px);
    border-color: var(--gold-primary);
    box-shadow: 0 6px 18px rgba(135, 101, 40, 0.12);
}

/* Hàng đầu tiên: Thư mời mới nhất nổi bật viền vàng đồng */
.match-item-latest {
    position: relative;
    border: 1.5px solid var(--gold-primary) !important;
    background: linear-gradient(135deg, rgba(181, 141, 70, 0.15) 0%, rgba(255, 253, 248, 0.92) 100%) !important;
    box-shadow: 0 10px 26px rgba(181, 141, 70, 0.20);
}

html[data-bs-theme="dark"] .match-item-latest {
    border-color: var(--gold-light) !important;
    background: linear-gradient(135deg, rgba(229, 198, 135, 0.18) 0%, rgba(28, 32, 40, 0.92) 100%) !important;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
}

.badge-latest-pulse {
    background: linear-gradient(135deg, #c69f59 0%, #9b7430 100%);
    color: #fff !important;
    font-size: 0.68rem;
    letter-spacing: 0.05em;
    padding: 4px 9px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    box-shadow: 0 3px 10px rgba(155, 116, 48, 0.35);
}

#multiMatchPagination .page-link {
    min-width: 30px;
    padding: 4px 8px;
    font-size: 0.8rem;
}

/* 10. TỐI ƯU KHI IN / LƯU PDF */
@media print {
    body::before,
    #fireworksCanvas,
    .no-print {
        display: none !important;
    }

    .card,
    .glass-card {
        box-shadow: none !important;
        border: none !important;
        background: #fff !important;
    }

    .invitation-canvas {
        box-shadow: none !important;
        max-height: none !important;
        width: 100% !important;
        border-radius: 0;
    }
}