/* ==========================================================================
   AIEH SMR — Single-view / Print page styles
   Used by templates/single-view.php
   ========================================================================== */

/* GLOBAL RESET FOR ACCURATE SIZING */
*, *:before, *:after { box-sizing: border-box; }
body {
    font-family: 'Inter', 'Segoe UI', 'Noto Sans Bengali', 'Kalpurush', 'SolaimanLipi', 'Siyam Rupali', Roboto, Helvetica, Arial, sans-serif;
    line-height: 1.6;
    color: #334155;
    background: #f8fafc;
    margin: 0; padding: 0;
}

/* TABLE STRUCTURE FOR PRINT MARGINS (Header/Footer repeats) */
table.print-layout-table {
    width: 100%;
    border-collapse: collapse;
    border: none;
    border-spacing: 0;
    table-layout: fixed;
}

@media screen {
    .print-layout-table, .print-layout-table tbody, .print-layout-table tr, .print-layout-table td {
        display: block;
        width: 100%;
    }
    .print-layout-table thead, .print-layout-table tfoot { display: none; }

    .aiginex-single-container {
        max-width: 900px;
        margin: 40px auto;
        background: #fff;
        padding: 60px;
        box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
        min-height: 80vh;
        position: relative;
        border-radius: 8px;
    }

    /* CONTENT TABLE PROTECTION
       WordPress themes often override table/td display and border-collapse,
       which breaks multi-column HTML layouts (organograms, cards, etc.)
       inside the content area. These rules restore proper table behaviour. */
    .aiginex-content table:not(.print-layout-table) {
        display: table !important;
        width: 100% !important;
        table-layout: auto !important;
    }
    .aiginex-content table:not(.print-layout-table) tbody { display: table-row-group !important; }
    .aiginex-content table:not(.print-layout-table) tr     { display: table-row       !important; width: auto !important; }
    .aiginex-content table:not(.print-layout-table) td,
    .aiginex-content table:not(.print-layout-table) th {
        display: table-cell !important;
        width: auto !important;
        vertical-align: top;
    }

    .aiginex-content table[style*="border-spacing"],
    .aiginex-content table[style*="border-collapse:separate"],
    .aiginex-content table[style*="border-collapse: separate"] { border-collapse: separate !important; }

    .aiginex-content td[style*="border-radius"] { border-radius: inherit; }

    .aiginex-content div[style*="background:linear-gradient"],
    .aiginex-content div[style*="background: linear-gradient"],
    .aiginex-content td[style*="background:linear-gradient"],
    .aiginex-content td[style*="background: linear-gradient"] { background-image: unset; }

    .aiginex-content div[style*="box-shadow"] { box-shadow: unset; }
}

/* Header Content */
.aiginex-header { border-bottom: 2px solid #f1f5f9; padding-bottom: 20px; margin-bottom: 30px; position: relative; }
.aiginex-badge {
    padding: 6px 12px; border-radius: 4px; font-size: 0.85rem;
    text-transform: uppercase; letter-spacing: 0.5px; font-weight: 700;
    display: inline-block; margin-bottom: 15px;
    background: #e2e8f0; color: #475569;
}
h1 { margin: 0; font-size: 2.5rem; color: #0f172a; line-height: 1.3; }
.aiginex-meta-date { display: block; margin-top: 5px; color: #64748b; font-size: 0.9rem; }

/* Actions */
.aiginex-actions { position: absolute; top: 0; right: 0; display: flex; align-items: center; gap: 10px; }
.btn-print {
    background: #3b82f6; color: white; border: none;
    padding: 8px 16px; border-radius: 6px; cursor: pointer;
    font-weight: 600; display: flex; align-items: center; gap: 6px;
    font-family: inherit;
}
.btn-print:hover { background: #2563eb; }
.page-size-select {
    padding: 8px; border: 1px solid #cbd5e1; border-radius: 6px;
    background: white; color: #334155; font-size: 0.9rem;
    cursor: pointer; font-family: inherit;
}

/* Content Text */
.aiginex-content, .aiginex-content p, .aiginex-content span, .aiginex-content div, .aiginex-content li, .aiginex-content td {
    font-family: 'Inter', 'Segoe UI', 'Noto Sans Bengali', 'Kalpurush', 'SolaimanLipi', 'Siyam Rupali', Roboto, Helvetica, Arial, sans-serif !important;
}
.aiginex-content { font-size: 1.125rem; line-height: 1.8; margin-bottom: 50px; overflow-wrap: break-word; word-wrap: break-word; }

/* INLINE STYLE PROTECTION — higher-specificity selectors that honour inline styles */
.aiginex-content *[style*="background-color"],
.aiginex-content *[style*="background:"] { background-color: revert; background: revert; }
.aiginex-content *[style*="color:"]             { color: revert; }
.aiginex-content *[style*="border"]             { border: revert; border-left: revert; border-right: revert; border-top: revert; border-bottom: revert; }
.aiginex-content *[style*="padding"]            { padding: revert; }
.aiginex-content *[style*="margin"]             { margin: revert; }
.aiginex-content *[style*="font-size"]          { font-size: revert; }
.aiginex-content *[style*="font-weight"]        { font-weight: revert; }
.aiginex-content *[style*="text-transform"]     { text-transform: revert; }
.aiginex-content *[style*="letter-spacing"]     { letter-spacing: revert; }
.aiginex-content *[style*="border-radius"]      { border-radius: revert; }
.aiginex-content *[style*="max-width"]          { max-width: revert; }
.aiginex-content *[style*="width:"]             { width: revert; }
.aiginex-content *[style*="display:"]           { display: revert; }
.aiginex-content *[style*="text-align"]         { text-align: revert; }
.aiginex-content *[style*="line-height"]        { line-height: revert; }
.aiginex-content *[style*="overflow"]           { overflow: revert; }

/* Images */
.aiginex-content img:not(.aiginex-signature-img):not(.aiginex-auto-img) {
    max-width: 100%; height: auto; border-radius: 4px; display: block; margin: 15px auto;
}
.aiginex-auto-img {
    max-width: 100% !important; height: auto !important;
    border-radius: 4px; display: block; margin: 15px auto;
}

/* Photo-frame containers (e.g. organogram cards) */
.aiginex-content div[style*="overflow:hidden"] img:not(.aiginex-signature-img),
.aiginex-content div[style*="overflow: hidden"] img:not(.aiginex-signature-img) {
    width: 100% !important;
    height: 100% !important;
    max-width: none !important;
    object-fit: cover !important;
    object-position: 50% 20% !important;
    border-radius: 0 !important;
    display: block !important;
    margin: 0 !important;
}
.aiginex-content div[style*="overflow:hidden"][style*="border-radius"],
.aiginex-content div[style*="overflow: hidden"][style*="border-radius"] {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

.aiginex-content ul, .aiginex-content ol { margin-left: 20px; }
.aiginex-content > :first-child { margin-top: 0 !important; }
.aiginex-content > :last-child  { margin-bottom: 0 !important; }

/* Background Layer (Hidden by default, Visible on Print) */
#aiginex-print-bg { display: none; }

/* Responsive */
@media (max-width: 768px) {
    .aiginex-single-container { margin: 0; padding: 30px; box-shadow: none; border-radius: 0; }
    h1 { font-size: 2rem; }
    .aiginex-actions { position: relative; top: auto; right: auto; margin-bottom: 20px; flex-wrap: wrap; }
}

/* PRINT STYLES */
@media print {
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        color-adjust: exact !important;
    }
    [style] {
        color: revert;
        background-color: revert;
        background: revert;
        border-color: revert;
    }

    @page { margin: 0; }
    body { margin: 0; padding: 0; background: white; }

    #aiginex-print-bg {
        display: block !important;
        position: fixed;
        top: 0; left: 0; right: 0; bottom: 0;
        z-index: -1;
        overflow: hidden;
    }
    #aiginex-print-bg img { width: 100%; height: 100%; object-fit: fill; }

    .aiginex-header { display: none !important; }

    table.print-layout-table { display: table; width: 100%; }
    thead { display: table-header-group; }
    tfoot { display: table-footer-group; }
    tr, td, tbody { page-break-inside: auto !important; break-inside: auto !important; }

    .aiginex-single-container {
        box-shadow: none !important; margin: 0 !important; padding: 0 !important;
        max-width: 100% !important; width: 100% !important;
    }
    .aiginex-actions, .btn-print, .page-size-select { display: none !important; }

    .aiginex-content { color: #000; font-size: 12pt; }
    .aiginex-content a { text-decoration: none; color: #000; }

    .header-space, .footer-space { width: 100%; display: block; overflow: hidden; }

    .aiginex-content div[style*="overflow:hidden"] img:not(.aiginex-signature-img),
    .aiginex-content div[style*="overflow: hidden"] img:not(.aiginex-signature-img) {
        width: 100% !important;
        height: 100% !important;
        max-width: none !important;
        object-fit: cover !important;
        object-position: 50% 20% !important;
        border-radius: 0 !important;
        display: block !important;
        margin: 0 !important;
    }
    .aiginex-content div[style*="overflow:hidden"][style*="border-radius"],
    .aiginex-content div[style*="overflow: hidden"][style*="border-radius"] {
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }
}
