/* =============================================================
   Print Stylesheet
   Shared across any page that needs consistent print output.
   Link with: <link rel="stylesheet" href="assets/css/print.css">
   ============================================================= */

/* --- Page setup -------------------------------------------- */
@page {
    size: A4;
    /* bottom 2cm: 1cm content margin + ~1cm for the footer row */
    margin: 1cm 1cm 1.1cm 1cm;
    /* ── Print footer ── right side: page number (start side in RTL) ── */
    @bottom-right {
        content: "صفحة " counter(page) " من " counter(pages);
        font-family: Lusail, sans-serif;
        font-size: 8.5pt;
        color: #555;
        border-top: 0.5pt solid #ccc;
        padding-top: 4pt;
        vertical-align: top;
    }
    /* ── Print footer ── left side: encyclopedia title (end side in RTL) ── */
    @bottom-left {
        content: "موسوعة الأحكام والمبادئ القضائية القطرية";
        font-family: Lusail, sans-serif;
        font-size: 8.5pt;
        color: #555;
        border-top: 0.5pt solid #ccc;
        padding-top: 4pt;
        vertical-align: top;
    }
}

/* --- Print header component (hidden on screen) ------------- */
#print-header {
    display: none;
    flex-direction: column;
    padding-bottom: 16px;
    margin-bottom: 20px;
    border-bottom: 1px solid #111;
}

/* Case/principle header — hidden on screen, revealed in @media print below */
#TopBar {
    display: none;
}

/* Top row: logo on the right (RTL start), doc-type badge on the left (RTL end) */
.print-header-row {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
}

#print-header img {
    height: 60px;
    width: auto;
}

/* Document-type badge  ——  نص الحكم  /  نص المبدأ */
.print-doc-type {
    display: inline-block;
    background-color: #7C003B;
    color: #ffffff;
    font-family: 'Lusail', sans-serif;
    font-weight: 600;
    font-size: 11pt;
    padding: 6px 16px;
    border-radius: 4px;
    line-height: 1.3;
}

/* Centered encyclopedia title below the top row */
.site-title {
    display: block;
    text-align: center;
    font-family: 'Lusail', sans-serif;
    font-weight: 700;
    font-size: 14pt;
    color: #1a1a1a;
    margin: 0;
    padding: 0;
    line-height: 1.4;
}

/* --- Lusail font family (for print) ------------------------ */
@font-face {
    font-family: 'Lusail';
    src: url('../../fonts/Lusail/Lusail-Light.ttf') format('truetype');
    font-weight: 300;
    font-style: normal;
}

@font-face {
    font-family: 'Lusail';
    src: url('../../fonts/Lusail/Lusail-Regular.ttf') format('truetype');
    font-weight: 400;
    font-style: normal;
}

@font-face {
    font-family: 'Lusail';
    src: url('../../fonts/Lusail/Lusail-Medium.ttf') format('truetype');
    font-weight: 500;
    font-style: normal;
}

@font-face {
    font-family: 'Lusail';
    src: url('../../fonts/Lusail/Lusail-Bold.ttf') format('truetype');
    font-weight: 700;
    font-style: normal;
}

/* --- Print media rules ------------------------------------- */
@media print {

    /* Remove all scroll containers so the full text renders */
    html, body, form, div, main, section, article {
        overflow: visible !important;
        height: auto !important;
    }

    /* Ensure the form wrapper adds no layout spacing */
    form {
        margin: 0 !important;
        padding: 0 !important;
    }

    /* Hide screen-only chrome */
    .icons   { display: none !important; }
    .header  { display: none !important; }

    /* Completely collapse icons — position:absolute can still
       influence print reflow even when display:none */
    .icons {
        position: static !important;
        width: 0 !important;
        height: 0 !important;
        padding: 0 !important;
        margin: 0 !important;
    }

    /* Remove the empty background placeholder div */
    #background {
        display: none !important;
    }

    /* Reveal print header — tighten bottom margin */
    #print-header {
        display: flex !important;
        margin-bottom: 8px !important;
    }
    /* #TopBar (DVMain) stays hidden — case header comes from p.header in Principles_Text */

    /* Principle page: hide the visual card header on print.
       Print title should come from the first promoted <p class='header'> lines in content. */
    .detail-principle-page .leg-header-wrapper,
    .detail-principle-page .detail-doc-card,
    .detail-principle-page .toolbar {
        display: none !important;
    }

    /* Judgement page: hide visual card header and show plain print title block */
    .detail-judgement-page .leg-header-wrapper,
    .detail-judgement-page .detail-doc-card,
    .detail-judgement-page .toolbar {
        display: none !important;
    }

    .detail-judgement-page #print-title-block {
        display: block !important;
        text-align: center !important;
        margin: 0 0 8px !important;
        padding: 0 !important;
    }

    .detail-judgement-page #print-title-block .print-title-line {
        display: block;
        font-family: 'Lusail', sans-serif !important;
        font-weight: 700;
        font-size: 14pt;
        text-align: center !important;
        line-height: 1.7;
        margin: 0;
        padding: 1pt 0;
    }

    /* Safety: hide any GridView-generated header row (<th>) inside content tables */
    table.GridText th { display: none !important; }

    /* Court document case header paragraphs ——————————————————————————
       HighlightKeyword() promotes the first 3 <p> tags in Principles_Text
       to <p class='header'>, which are the court name / session date / case-no lines.
       Counter the .header { display:none } rule above (which targets div.header logo),
       then style identically to how they appear on screen. */
    p.header {
        display: block !important;
        text-align: center !important;
        font-weight: 700 !important;
        font-family: 'Lusail', sans-serif !important;
        font-size: 14pt !important;
        line-height: 1.7 !important;
        margin: 0 !important;
        padding: 1pt 0 !important;
    }

    /* Badge: force background/text color — browsers suppress bg-colors by default */
    #print-header .print-doc-type {
        font-family: 'Lusail', sans-serif !important;
        background-color: #7C003B !important;
        color: #ffffff !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    /* Site title inside the print header */
    #print-header .site-title {
        font-family: 'Lusail', sans-serif !important;
        font-size: 14pt !important;
        color: #1a1a1a !important;
        font-weight: 700 !important;
    }

    body {
        font-family: 'Lusail', sans-serif !important;
        font-size: 12pt;
        color: #000 !important;
        background: #fff !important;
        width: 100% !important;
    }

    #content {
        padding: 0 !important;
        margin: 0 !important;
        overflow: visible !important;
        height: auto !important;
    }

    /* Keep the bold intro paragraph flush under the case header,
       then inset the remaining body text for detail pages */
    #content p.header ~ p:not(.header) ~ p:not(.header),
    #content p.header ~ p:not(.header) ~ ul,
    #content p.header ~ p:not(.header) ~ ol {
        margin-right: 0.5cm !important;
        margin-left: 0.5cm !important;
    }

    /* Judgement body — larger text, flows across pages */
    .GridText, .GridText * {
        font-family: 'Lusail', sans-serif !important;
        font-size: 12pt;
        text-align: justify;
        overflow: visible !important;
        height: auto !important;
        page-break-inside: auto;
    }

    /* Case header — no gap before body text */
    .HeadText, .HeadText * {
        font-family: 'Lusail', sans-serif !important;
        font-size: 14pt !important;
        margin-top: 0 !important;
        margin-bottom: 0 !important;
        padding-top: 0 !important;
        padding-bottom: 0 !important;
        overflow: visible !important;
        height: auto !important;
        line-height: 1.4;
    }

    /* Target the DetailsView-rendered table directly */
    table.HeadText {
        border-collapse: collapse !important;
        margin-bottom: 0 !important;
        border-spacing: 0 !important;
    }

    /* Override inline heading defaults inside HeadText (e.g. h1 with font-size:x-large) */
    table.HeadText h1,
    table.HeadText h2,
    table.HeadText h3 {
        font-size: 14pt !important;
        font-weight: 600;
        margin: 0 !important;
        padding: 2px 0 !important;
        line-height: 1.4;
    }

    /* Remove cell padding from HeadText — overrides DetailsView default cellpadding */
    table.HeadText td,
    table.HeadText th {
        padding: 0 !important;
        vertical-align: top !important;
    }

    /* Hide the orphan <br> that sits directly after the collapsed .icons div */
    .icons + br { display: none !important; }

    /* Close the gap between header and body */
    main, table.GridText {
        margin: 0 !important;
        padding: 0 !important;
    }

    /* table.GridText has Width="100%" + inline padding/margin — box-sizing: border-box
       ensures the padding is absorbed inside the 100% width instead of overflowing it */
    table.GridText {
        width: 100% !important;
        box-sizing: border-box !important;
    }

    /* Remove top padding from GridText cells so body text starts flush */
    table.GridText td {
        padding-top: 0 !important;
        vertical-align: top !important;
    }

    /* Remove any default top spacing from semantic containers */
    section, article {
        margin-top: 0 !important;
        padding-top: 0 !important;
    }

    /* Allow rows and paragraphs to break across pages naturally */
    tr, p, div {
        page-break-inside: auto;
    }

    /* Prevent text from being cut off at the bottom of a page */
    td, th {
        overflow: visible !important;
        max-height: none !important;
    }
    p, li {
        widows: 3;
        orphans: 3;
    }

    /* Hide PDF download button when printing */
    .pdf-download-btn { display: none !important; }
}
