/**
 * Master Professional Styles & Advanced Print Engine - FanaByte Certificate Pro.
 * Optimized for Dynamic Grid Layout, Customizable Borders, and Single-Page Print.
 * Version: 2.0.0
 */

/* --- 1. General Settings & Main Container --- */
.fb-cert-main-wrapper {
    max-width: 1000px;
    margin: 40px auto;
    font-family: inherit;
    line-height: 1.6;
    color: #2d3748;
}

.fb-cert-main-wrapper.rtl {
    direction: rtl;
    text-align: right;
}

.fb-cert-main-wrapper.ltr {
    direction: ltr;
    text-align: left;
}

/* --- 2. Search Form Styles --- */
.fb-cert-form-box {
    background: #ffffff;
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
    border: 1px solid #e2e8f0;
    margin-bottom: 50px;
}

.fb-cert-intro {
    margin-bottom: 25px;
    font-size: 16px;
    color: #4a5568;
    border-bottom: 1px solid #edf2f7;
    padding-bottom: 15px;
}

.fb-cert-form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
}

.fb-group {
    margin-bottom: 15px;
}

.fb-group label {
    display: block;
    font-weight: 700;
    margin-bottom: 8px;
    color: #2d3748;
}

.fb-group input {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 15px;
    transition: all 0.3s ease;
    box-sizing: border-box;
}

.fb-group input:focus {
    border-color: #2271b1;
    outline: none;
    box-shadow: 0 0 0 3px rgba(34, 113, 177, 0.1);
}

.fb-captcha {
    margin: 20px 0;
    padding: 20px;
    background: #f7fafc;
    border-radius: 8px;
    border: 1px dashed #cbd5e0;
}

.fb-captcha label {
    display: block;
    margin-bottom: 10px;
    font-weight: bold;
}

.fb-submit {
    text-align: center;
    margin-top: 25px;
}

.fb-submit button {
    padding: 15px 60px;
    border: none;
    border-radius: 8px;
    font-size: 18px;
    font-weight: 800;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.fb-submit button:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
}

/* --- 3. Professional Certificate Card Design --- */
.fb-card {
    position: relative;
    background: #ffffff;
    padding: 50px;
    margin-top: 40px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    box-sizing: border-box;
}

/* Watermark Layer */
.fb-wm {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-position: center;
    background-repeat: no-repeat;
    background-size: 65%;
    z-index: 1;
    pointer-events: none;
}

.fb-inner {
    position: relative;
    z-index: 2;
}

/* Header (Name & Photo) */
.fb-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 35px;
    border-bottom: 2px solid #edf2f7;
    padding-bottom: 25px;
}

.fb-res-t {
    font-size: 18px;
    margin: 0;
    color: #718096;
}

.fb-name {
    font-size: 36px;
    font-weight: 900;
    margin: 10px 0 0 0;
    color: #1a202c;
}

.fb-photo {
    flex-shrink: 0;
}

.fb-personal-img {
    width: 130px;
    height: 165px;
    object-fit: cover;
    border: 6px solid #fff;
    border-radius: 4px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.12);
}

/* Details Header */
.fb-details-header-wrap {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding: 12px 15px;
    background: #f8fafc;
    box-sizing: border-box;
}

.fb-details-t {
    margin: 0;
    font-size: 20px;
    font-weight: 900;
}

.fb-date-inline {
    font-size: 13px;
    color: #718096;
}

/* Content Box */
.fb-details-content-box {
    padding: 25px;
    margin-bottom: 30px;
    box-sizing: border-box;
}

/* --- 4. Smart Grid System (Rows & Columns) --- */
.fb-dynamic-grid {
    width: 100%;
}

.fb-row {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    margin-bottom: 15px;
    border-bottom: 1px solid rgba(0,0,0,0.05);
    padding-bottom: 10px;
}

.fb-row:last-child {
    border-bottom: none;
}

.fb-col {
    flex: 1;
    min-width: 0; /* Prevents breaking on long text */
}

/* Column Widths based on row class */
.fb-cols-1 .fb-col { flex: 0 0 100%; }
.fb-cols-2 .fb-col { flex: 0 0 calc(50% - 10px); }
.fb-cols-3 .fb-col { flex: 0 0 calc(33.33% - 13.5px); }
.fb-cols-4 .fb-col { flex: 0 0 calc(25% - 15px); }

.fb-l {
    color: #718096;
    font-size: 12px;
    display: block;
    margin-bottom: 3px;
    font-weight: bold;
}

.fb-v {
    font-weight: 800;
    font-size: 17px;
    word-break: break-word;
}

.fb-v img {
    max-height: 80px;
    width: auto;
    border-radius: 4px;
}

/* Verification Badge (QR) */
.fb-verification-middle {
    display: flex;
    justify-content: flex-end;
    margin: 15px 0;
}

/* LTR override for QR alignment */
.fb-cert-main-wrapper.ltr .fb-verification-middle {
    justify-content: flex-start;
}

.fb-qr img {
    width: 100px;
    height: 100px;
    border: 1px solid #e2e8f0;
    padding: 5px;
    background: #fff;
    border-radius: 4px;
}

/* Footer (Dynamic Notes) */
.fb-footer {
    margin-top: 20px;
    padding: 25px;
    line-height: 1.9;
    font-size: 15px;
    text-align: justify;
    box-sizing: border-box;
}

/* --- 5. Web Print Button Styles --- */
.fb-bottom.fb-no-print {
    margin-top: 40px;
    display: flex;
    justify-content: center;
}

.fb-btn {
    border: none;
    border-radius: 6px;
    font-weight: 800;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 10px;
}

.fb-btn:hover {
    filter: brightness(0.9);
}

.fb-error, .fb-not-found {
    background: #fff5f5;
    color: #c53030;
    padding: 20px;
    border-radius: 8px;
    border: 1px solid #feb2b2;
    text-align: center;
    font-weight: bold;
    margin-top: 20px;
}

/* --- 6. Advanced Single Page Print Engine --- */
@media print {
    /* 1. Hide all site elements */
    html, body {
        background: #fff !important;
        margin: 0 !important;
        padding: 0 !important;
        height: auto !important;
    }

    body * {
        visibility: hidden;
    }

    /* 2. Show only the certificate card */
    .fb-printable, .fb-printable * {
        visibility: visible;
    }

    .fb-printable {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        margin: 0 !important;
        padding: 40px !important;
        box-shadow: none !important;
        box-sizing: border-box;
        border-radius: 0 !important;
        overflow: hidden;
        page-break-after: avoid;
        page-break-before: avoid;
    }

    /* 3. Maintain Grid Structure in Print */
    .fb-row {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        gap: 20px !important;
        border-bottom: 1px solid #eee !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .fb-col {
        flex: 1 !important;
        visibility: visible !important;
    }

    /* Fix Column Widths for Print */
    .fb-cols-1 .fb-col { width: 100% !important; flex: 0 0 100% !important; }
    .fb-cols-2 .fb-col { width: 48% !important; flex: 0 0 48% !important; }
    .fb-cols-3 .fb-col { width: 31% !important; flex: 0 0 31% !important; }
    .fb-cols-4 .fb-col { width: 23% !important; flex: 0 0 23% !important; }

    /* 4. Handle Watermark */
    .fb-no-print-wm .fb-wm {
        display: none !important;
    }

    .fb-print-wm .fb-wm {
        display: block !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .fb-details-content-box, 
    .fb-details-header-wrap, 
    .fb-footer {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    /* 5. Hide Web Buttons in Print */
    .fb-no-print {
        display: none !important;
        height: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
    }
}

/* --- 7. Responsiveness --- */
@media (max-width: 768px) {
    .fb-card {
        padding: 30px;
    }
    .fb-head {
        flex-direction: column-reverse;
        align-items: center;
        text-align: center;
    }
    .fb-photo {
        margin-bottom: 20px;
    }
    .fb-details-header-wrap {
        flex-direction: column;
        gap: 10px;
        text-align: center;
    }
    .fb-row {
        flex-direction: column;
        gap: 10px;
    }
    .fb-col {
        flex: 0 0 100% !important;
        width: 100% !important;
    }
    .fb-verification-middle {
        justify-content: center;
    }
}