/* =====================================================================
   kpaper.css — dedicated stylesheet for the folder-based paper templates
   (paper_templates/*.php, rendered by lib/kfunc_paper.php).
   ---------------------------------------------------------------------
   ORGANISATION
     1. COMMON            — the A4 page shell + the shared building blocks
                            every template reuses (header, sections, tables,
                            parties, amounts, signatures, footer, watermark,
                            print rules). Templates should lean on these.
     2. PER-TEMPLATE      — one commented block per template for anything
                            extra it needs. A template picks its identity by
                            setting the --kpc-accent* tokens on its brand
                            class (e.g. .kpaper--realestate); only add rules
                            here when the common blocks aren't enough.

   NAMING SETUP (kept UNIQUE — nothing here collides with ttstyles.css /
   ttstylesmain.css / apps.js; verified zero prior use of these tokens):
     • Classes   → prefix  .kpaper-<block>[-<element>]   (e.g. .kpaper-page,
                   .kpaper-sec-hd). ALWAYS use this prefix for paper markup.
     • Template  → brand modifier  .kpaper--<template>   (double dash), e.g.
                   .kpaper--realestate, set on the .kpaper-doc root.
     • Variables → CSS custom properties prefixed  --kpc-*  (kpaper colour).
   Never reuse an app class (k116-*, kdv-*, tbl-*, mya4, …) in a paper —
   the paper must be self-contained through .kpaper-* only.

   Brand tokens (override per template on its .kpaper--<template> class):
     --kpc-accent   main brand colour (rules, headings, ref-no)
     --kpc-accent2  secondary/deep accent (footer bar, strong headings)
     --kpc-tint     very light brand tint (section header background)
   ===================================================================== */

/* =====================================================================
   1. COMMON
   ===================================================================== */

/* ---- Bundled fonts (self-hosted, downloaded to app_assets/fonts/kpaper)
   Inter → Latin, Tajawal → Arabic. Unique family names so nothing clashes
   with the app's own Google-Fonts copies. NOTE: the ../fonts URLs are
   rewritten to app_assets/fonts when this stylesheet is INLINED into the
   paper (see kpaper_cr_styles) — inline <style> resolves URLs against the
   document, not the css file. */
@font-face { font-family: 'KpaperSans'; src: url('../fonts/kpaper/inter-400.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'KpaperSans'; src: url('../fonts/kpaper/inter-600.woff2') format('woff2'); font-weight: 600; font-display: swap; }
@font-face { font-family: 'KpaperSans'; src: url('../fonts/kpaper/inter-700.woff2') format('woff2'); font-weight: 700; font-display: swap; }
@font-face { font-family: 'KpaperArabic'; src: url('../fonts/kpaper/plexar-400.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'KpaperArabic'; src: url('../fonts/kpaper/plexar-600.woff2') format('woff2'); font-weight: 600; font-display: swap; }
@font-face { font-family: 'KpaperArabic'; src: url('../fonts/kpaper/plexar-700.woff2') format('woff2'); font-weight: 700; font-display: swap; }

/* ---- Document + A4 page shell -------------------------------------- */
/* .kpaper-doc stacks one or more A4 pages (single- or multi-page). Each
   .kpaper-page is a real A4 sheet; content that needs more room simply
   adds another .kpaper-page. */
.kpaper-doc {
    --kpc-accent:  #00549a;
    --kpc-accent2: #003a6b;
    --kpc-tint:    #eef4fb;
    --kpc-ink:     #22303c;
    --kpc-muted:   #6b7683;
    --kpc-line:    #d8dee6;
    display: flex;
    flex-direction: column;
    /* "safe center": centre the sheet when the panel is wide enough, but fall
       back to start (no left-clip) when the panel is narrower than A4, so the
       logo/title are never cut. overflow-x lets the user scroll to the rest. */
    align-items: safe center;
    overflow-x: auto;
    gap: 16px;
    padding: 16px 8px 28px;
    background: #ecebe6;
    box-sizing: border-box;
    /* Inter (Latin) with Tajawal (Arabic) fallback — self-hosted, so the
       type is consistent and modern regardless of the environment. */
    font-family: 'KpaperSans', 'KpaperArabic', 'Segoe UI', Arial, sans-serif;
    color: var(--kpc-ink);
    /* Print the header background, tag/meta colours + the dashed frame. */
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
}
.kpaper-doc * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.kpaper-page {
    position: relative;
    display: flex; flex-direction: column;
    /* Preview == print: the sheet is the SAME size on screen as the PDF prints
       (200mm x 285mm — see the print block below). Using true A4 (210x297) here
       made the on-screen preview 12mm taller than the printed page, so the
       bottom-pinned footer left a phantom gap on screen that wasn't on paper —
       the source of the "there's still room / footer looks off" confusion. The
       paginator's budget already reserves the real footer band, so at this size
       the preview footer lands exactly where it prints. min-height pinned too so
       a stale cached copy of this file (old min-height:297mm) can't re-inflate
       it. */
    width: 200mm;
    height: 285mm;
    min-height: 285mm;
    /* NO max-width:100% — inside a narrow app panel it used to squeeze the A4
       box while the fixed-size logo/title stayed put, so overflow:hidden clipped
       them. The doc scrolls / fit-scales (below) when the panel is narrower. */
    box-sizing: border-box;
    /* ZERO page padding: the masthead + meta bar are full-bleed to the frame
       BY CONSTRUCTION (no fragile -7mm/+7mm cancel that Chrome's print scaler
       rounds into a thin gap). Body sections + footer carry their own inset. */
    padding: 0;
    background: #ffffff;
    box-shadow: 0 2px 14px rgba(0, 0, 0, .16);
    /* Dashed frame around each A4 sheet (browser dashed — tight, subtle),
       with softly rounded 5px corners. overflow:hidden clips content to it. */
    border: 2px dashed #cdd7e1;
    border-radius: 5px;
    overflow: hidden;
}

/* ---- Masthead / header -------------------------------------------- */
.kpaper-hd {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--kpc-accent);
}
.kpaper-hd-brand { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.kpaper-hd-name  { font-size: 19px; font-weight: 800; letter-spacing: .4px; color: var(--kpc-accent2); }
.kpaper-hd-sub   { font-size: 11px; color: var(--kpc-muted); letter-spacing: .3px; }
.kpaper-hd-meta  { text-align: right; font-size: 11.5px; color: var(--kpc-muted); line-height: 1.7; flex-shrink: 0; }
.kpaper-hd-meta b { color: var(--kpc-ink); font-weight: 700; }
.kpaper-hd-ref {
    display: inline-block;
    margin-top: 4px;
    padding: 3px 10px;
    border: 1px solid var(--kpc-accent);
    border-radius: 4px;
    color: var(--kpc-accent);
    font-weight: 800;
    letter-spacing: .5px;
    font-size: 12px;
}

/* ---- Document title ------------------------------------------------ */
.kpaper-title {
    text-align: center;
    margin: 16px 0 6px;
    font-size: 17px;
    font-weight: 800;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: var(--kpc-ink);
}
.kpaper-title-sub { text-align: center; font-size: 11.5px; color: var(--kpc-muted); margin-bottom: 14px; }

/* ---- Section ------------------------------------------------------- */
.kpaper-sec { margin: 14px 0; break-inside: avoid; }
.kpaper-sec-hd {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    background: var(--kpc-tint);
    border-left: 3px solid var(--kpc-accent);
    font-size: 12.5px;
    font-weight: 800;
    letter-spacing: .4px;
    text-transform: uppercase;
    color: var(--kpc-accent2);
}
.kpaper-sec-bd { padding: 10px 2px 2px; }

/* ---- Key/value grid ------------------------------------------------ */
.kpaper-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 26px; }
.kpaper-grid--1 { grid-template-columns: 1fr; }
.kpaper-kv { display: flex; gap: 8px; padding: 5px 0; border-bottom: 1px dashed var(--kpc-line); font-size: 12.5px; }
.kpaper-kv--full { grid-column: 1 / -1; }
.kpaper-kv-l { flex: 0 0 42%; color: var(--kpc-muted); font-weight: 600; }
.kpaper-kv-v { flex: 1; color: var(--kpc-ink); font-weight: 600; word-break: break-word; }

/* ---- Data table (units, etc.) ------------------------------------- */
.kpaper-tbl { width: 100%; border-collapse: collapse; font-size: 12px; }
.kpaper-tbl th {
    text-align: left;
    padding: 7px 9px;
    background: var(--kpc-accent);
    color: #fff;
    font-weight: 700;
    letter-spacing: .3px;
}
.kpaper-tbl td { padding: 7px 9px; border-bottom: 1px solid var(--kpc-line); color: var(--kpc-ink); }
.kpaper-tbl tr:nth-child(even) td { background: #f7f9fc; }
.kpaper-tbl .kpaper-ta-r { text-align: right; font-variant-numeric: tabular-nums; }
/* Compact bilingual UNITS table (one row per unit). Centred, small type; each
   header stacks EN over its Arabic. Rounded frame, striped rows. */
.kpaper-tbl--units { font-size: 8.6px; border: 1px solid var(--kpc-line); border-radius: 4px; overflow: hidden; }
.kpaper-tbl--units th {
    text-align: center; padding: 5px 5px; font-size: 8px; line-height: 1.25; letter-spacing: 0;
    background: #eef2f7; color: var(--kpc-accent2); border-bottom: 1.5px solid #aab7c6;
}
.kpaper-tbl--units th span {
    display: block; direction: rtl; font-weight: 600; color: var(--kpc-muted);
    font-family: 'KpaperArabic', 'KpaperSans', sans-serif;
}
.kpaper-tbl--units td { padding: 4px 6px; text-align: center; font-weight: 700; color: var(--kpc-accent2); }
.kpaper-tbl--units td:first-child { color: var(--kpc-muted); font-weight: 700; }
.kpaper-tbl--units .kpaper-u-id { color: var(--kpc-ink); word-break: break-word; }

/* ---- Payment schedule table (unit-wise charges) ------------------- */
/* No zebra here — the unit bands / subtotal / grand rows carry the tint. */
.kpaper-tbl--pay tr:nth-child(even) td { background: #fff; }
.kpaper-tbl--pay .kpaper-ta-l { text-align: left; color: var(--kpc-ink); }
.kpaper-tbl--pay .kpaper-ta-r { text-align: right; font-variant-numeric: tabular-nums; }
.kpaper-pay-code { color: var(--kpc-muted); font-weight: 600; }
/* Unit band — names the unit its charge rows belong to. */
.kpaper-tbl--pay tr.kpaper-pay-uband td {
    text-align: left; background: #eaf1fb; color: var(--kpc-accent2);
    font-weight: 800; letter-spacing: .3px; border-bottom: 1px solid #cdd9ea;
}
.kpaper-tbl--pay tr.kpaper-pay-uband td b { color: var(--kpc-accent); }
/* Per-unit subtotal. */
.kpaper-tbl--pay tr.kpaper-pay-sub td { background: #f4f7fb; color: var(--kpc-muted); }
.kpaper-tbl--pay tr.kpaper-pay-sub td b { color: var(--kpc-accent2); }
.kpaper-tbl--pay tr.kpaper-pay-sub span { direction: rtl; color: var(--kpc-muted); font-family: 'KpaperArabic', 'KpaperSans', sans-serif; }
/* Grand total — the emphasised closing line. */
.kpaper-tbl--pay tr.kpaper-pay-grand td { background: var(--kpc-accent2); color: #fff; font-weight: 800; }
.kpaper-tbl--pay tr.kpaper-pay-grand td b { color: #fff; }
.kpaper-tbl--pay tr.kpaper-pay-grand span { direction: rtl; color: #dbe6f5; font-family: 'KpaperArabic', 'KpaperSans', sans-serif; }
/* Inactive charge — de-emphasised (kept visible). */
.kpaper-tbl--pay tr.kpaper-pay-off td { color: var(--kpc-muted); opacity: .7; }
/* Highlight cells (specificity beats the no-zebra rule above):
   • Requested Amount ≠ Approved Amount → amber "adjusted" flag.
   • Discount > 0 → red "money-off" flag. */
.kpaper-tbl--pay tbody tr td.kpaper-pay-chg { background: #fad79f; color: #8a4b00; font-weight: 800; }
.kpaper-tbl--pay tbody tr td.kpaper-pay-dsc { background: #f6b8b3; color: #922b21; font-weight: 800; }
/* Discount matches a non-zero default → the standard discount, applied as
   agreed: green (reassuring, not an alert). */
.kpaper-tbl--pay tbody tr td.kpaper-pay-dscok { background: #bfe3c0; color: #1e7a34; font-weight: 800; }

/* ---- Required Documents table ------------------------------------- */
.kpaper-tbl--docs tr:nth-child(even) td { background: #fff; }   /* no zebra — bands carry the tint */
.kpaper-tbl--docs .kpaper-ta-l { text-align: left; color: var(--kpc-ink); }
/* Category band (Residential / Commercial). */
.kpaper-tbl--docs tr.kpaper-doc-cat td {
    text-align: left; background: #eaf1fb; color: var(--kpc-accent2);
    font-weight: 800; letter-spacing: .3px; border-bottom: 1px solid #cdd9ea;
}
.kpaper-tbl--docs tr.kpaper-doc-cat .kpaper-doc-catar {
    float: right; direction: rtl; color: var(--kpc-accent); font-weight: 800;
    font-family: 'KpaperArabic', 'KpaperSans', sans-serif;
}
/* Pending rows get a faint warm tint so the outstanding items read at a glance. */
.kpaper-tbl--docs tr.kpaper-doc-row-pending td { background: #fffdf6; }
.kpaper-doc-ok      { color: #1e7a34; font-weight: 800; }
.kpaper-doc-pending { color: #a15c00; font-weight: 700; }
.kpaper-doc-ico     { display: inline-block; margin-right: 4px; font-size: 11px; line-height: 1; vertical-align: -1px; }
.kpaper-doc-na      { color: var(--kpc-muted); font-weight: 600; font-style: italic; }
/* Not-selected (not required) documents are dimmed so the required set stands out. */
.kpaper-tbl--docs tr.kpaper-doc-row-off td { color: var(--kpc-muted); opacity: .6; }

/* ---- Internal note (free-text, office-use) ------------------------ */
.kpaper-note {
    padding: 8px 11px; background: #faf7f0; border: 1px dashed #e0d8c0; border-radius: 5px;
    font-size: 10px; line-height: 1.5; color: var(--kpc-ink);
    white-space: pre-wrap; word-break: break-word;
}

/* ---- Approval signatures ------------------------------------------ */
/* Two signatures per row (two columns) to save vertical space. Each card
   holds a fixed 50% basis so an odd final card stays half-width, left-aligned. */
.kpaper-sig-row {
    display: flex; gap: 8px; margin-top: 6px; break-inside: avoid;
}
.kpaper-sig-card {
    flex: 0 0 calc(50% - 4px); min-width: 0;
    display: flex; align-items: stretch;
    border: 1px solid var(--kpc-line); border-radius: 6px; overflow: hidden; break-inside: avoid;
}
.kpaper-sig-who {
    flex: 0 0 30%; box-sizing: border-box; padding: 7px 8px;
    background: #f6f8fb; border-right: 1px solid var(--kpc-line);
    display: flex; flex-direction: column; justify-content: center; gap: 2px;
}
.kpaper-sig-name { font-size: 10.5px; font-weight: 800; color: var(--kpc-accent2); }
.kpaper-sig-role { font-size: 8px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; color: var(--kpc-muted); }
.kpaper-sig-pad {
    position: relative;   /* anchor for the absolutely-placed verification QR */
    flex: 1 1 auto; display: flex; align-items: center; justify-content: center;
    padding: 5px 12px 6px; min-height: 60px;
    /* Defence: no selecting / dragging the signature out of the pad. */
    -webkit-user-select: none; user-select: none;
}
/* Signature (with its baked-in barcode) painted as a CSS background — NOT an
   <img> — so there's no image element to "Save as" / "Open in new tab";
   pointer/drag/select all disabled. Sized so the CODE-128 barcode stays
   scannable when printed. */
.kpaper-sig-img {
    width: 100%; max-width: 320px; height: 58px;
    background-repeat: no-repeat; background-position: center; background-size: contain;
    pointer-events: none; -webkit-user-select: none; user-select: none;
    -webkit-user-drag: none; -webkit-touch-callout: none;
}
/* Per-signature verification QR, bottom-right of the pad. Painted as a CSS
   background (same no-"Save image" protection as the signature) on a white
   card with padding + border — the padding is the scanner quiet-zone, so it
   reads reliably off screen and off the headless-Chrome PDF. */
.kpaper-sig-qr {
    position: absolute; right: 5px; bottom: 5px;
    width: 42px; height: 42px; padding: 3px; box-sizing: content-box;
    background-color: #ffffff; border: 1px solid var(--kpc-line);
    border-radius: 6px; box-shadow: 0 1px 2px rgba(0,0,0,.12);
    background-repeat: no-repeat; background-position: center;
    background-size: contain; background-origin: content-box; background-clip: content-box;
    pointer-events: none; -webkit-user-select: none; user-select: none;
    -webkit-user-drag: none; -webkit-touch-callout: none;
}
.kpaper-sig-stamp { color: #1e7a34; font-weight: 800; font-size: 12px; align-self: center; }
.kpaper-sig-line { width: 88%; height: 0; border-bottom: 1px dashed var(--kpc-line); }
.kpaper-sig-stat {
    flex: 0 0 19%; box-sizing: border-box; padding: 6px 8px;
    border-left: 1px solid var(--kpc-line);
    display: flex; align-items: center; justify-content: center; text-align: center;
    font-size: 9px; font-weight: 700; line-height: 1.3;
}
.kpaper-sig-stat small { font-weight: 600; opacity: .85; }
.kpaper-sig-ok      { color: #1e7a34; }
.kpaper-sig-pending { color: #a15c00; }
/* Provided / total summary. */
.kpaper-tbl--docs tr.kpaper-doc-sum td { background: #f4f7fb; color: var(--kpc-muted); }
.kpaper-tbl--docs tr.kpaper-doc-sum td b { color: var(--kpc-accent2); }
.kpaper-tbl--docs tr.kpaper-doc-sum span { direction: rtl; color: var(--kpc-muted); font-family: 'KpaperArabic', 'KpaperSans', sans-serif; }
/* Rent Amount column — a soft standing highlight so the net rent figure
   (and its header) stands out down the whole column. */
.kpaper-tbl--pay th.kpaper-pay-rentcol,
.kpaper-tbl--pay th.kpaper-pay-totcol { background: #e2edfb; }
.kpaper-tbl--pay tbody tr td.kpaper-pay-rentcol,
.kpaper-tbl--pay tbody tr td.kpaper-pay-totcol { background: #eff5fd; color: var(--kpc-accent2); font-weight: 800; }
/* Rent Amount FLAGGED — the final rent departed from the fixed rate (amount
   changed or a discount applied): bold red on a red tint so it reads as
   "check this". Placed after .kpaper-pay-rentcol to win the equal-specificity. */
.kpaper-tbl--pay tbody tr td.kpaper-pay-rentflag { background: #f6b8b3; color: #922b21; font-weight: 800; }

/* ---- Amounts summary ---------------------------------------------- */
.kpaper-amounts { margin-left: auto; width: 320px; max-width: 100%; font-size: 12.5px; }
.kpaper-amt-row { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--kpc-line); }
.kpaper-amt-row .kpaper-amt-l { color: var(--kpc-muted); }
.kpaper-amt-row .kpaper-amt-v { font-weight: 700; font-variant-numeric: tabular-nums; }
.kpaper-amt-total {
    display: flex; justify-content: space-between;
    margin-top: 4px; padding: 8px 10px;
    background: var(--kpc-accent); color: #fff; border-radius: 4px;
    font-weight: 800; font-size: 13.5px;
}
.kpaper-amt-total .kpaper-amt-v { font-variant-numeric: tabular-nums; }

/* ---- Signatures / office use -------------------------------------- */
.kpaper-signs { display: flex; flex-wrap: wrap; gap: 22px; margin-top: 10px; }
.kpaper-sign { flex: 1 1 200px; min-width: 180px; }
.kpaper-sign-line { height: 46px; border-bottom: 1px solid #9aa4b0; margin-bottom: 6px; }
.kpaper-sign-lbl { font-size: 11px; color: var(--kpc-muted); font-weight: 600; }
.kpaper-sign-img { max-height: 44px; max-width: 100%; }

/* ---- Footer (date · page · created-by) — pinned to the page bottom -- */
.kpaper-foot {
    /* auto-top pins to bottom; sides inset by 3mm to line the footer rule up
       EXACTLY with the body sections (.kpaper-sec-cr / -cont use padding:0 3mm);
       small bottom gap (replaces the old page bottom padding). */
    margin: auto 3mm 2.5mm;
    display: flex; align-items: center;
    padding-top: 6px;
    border-top: 1px solid var(--kpc-line);
    font-size: 10px; color: var(--kpc-muted);
    position: relative; z-index: 1;
}
.kpaper-foot-l { flex: 1 1 0; text-align: left; }
.kpaper-foot-c { flex: 0 0 auto; text-align: center; font-weight: 700; color: var(--kpc-accent2); }
.kpaper-foot-r { flex: 1 1 0; text-align: right; }
.kpaper-foot b { color: var(--kpc-accent2); font-weight: 700; }

/* ---- Watermark ----------------------------------------------------- */
/* Repeating diagonal watermark tiled across the whole page. The tile itself
   (an SVG data-URI sized to the text) is set inline per-page by kpaper_cr_page;
   here we just tile it and place it IN FRONT of the content. pointer-events:none
   so it never blocks clicks/selection underneath, and the SVG's low text opacity
   keeps the content readable through the mark. */
.kpaper-wm {
    position: absolute; inset: 0;
    z-index: 5;                       /* ON TOP of the page content */
    pointer-events: none;
    background-repeat: repeat;        /* auto-fill the page cross-ways */
    background-position: center;
}
.kpaper-page > *:not(.kpaper-wm) { position: relative; z-index: 1; }
/* Continuation sheets (page 2+): the first flowed row/section should not sit
   flush against the top frame — give it a little breathing room. (Page 1 is
   :first-of-type and keeps its full-bleed masthead.) The paginator reserves the
   matching height in its budget so this never pushes the last row off-sheet. */
.kpaper-page:not(:first-of-type) > .kpaper-wm + * { margin-top: 3mm; }

/* ---- Utilities ----------------------------------------------------- */
.kpaper-muted { color: var(--kpc-muted); }
.kpaper-two   { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.kpaper-party-name { font-size: 13.5px; font-weight: 800; color: var(--kpc-accent2); margin-bottom: 4px; }

/* =====================================================================
   COMMON — Contract-request building blocks (kpaper_cr_* helpers)
   ---------------------------------------------------------------------
   The dense bilingual EN/AR form: masthead, ref bar, blue unit plate,
   bilingual field cells, coloured section title bars, checkboxes,
   included-flag cells, grace-period grid and the office-use signatures.
   Every branch request paper (req_realestate, …) reuses these; a branch
   only sets its --kpc-accent* palette + masthead background.
   ===================================================================== */

/* ---- LETTERHEAD header — professional ----------------------------
   Logo (left) | centred bilingual title + chips | QR (right), over a
   faint building backdrop; then a slim brand meta bar. Full-bleed. */
.kpaper-head {
    display: flex; align-items: center; gap: 18px;
    box-sizing: border-box; padding: 16px 24px;
    width: 100%;   /* full-bleed to the frame — no negative-margin trick */
    /* Building PNG as the header backdrop — visible but subtle; the dark
       title stays legible over the light wash. */
    background:
        linear-gradient(rgba(238, 245, 252, .66), rgba(238, 245, 252, .72)),
        url(../images/building_vactor_img.png) center 38% / 112% auto no-repeat,
        #e6eff9;
    border-bottom: 3px solid var(--kpc-accent);
    color: var(--kpc-ink);
}
.kpaper-head-logo { flex: 0 0 auto; }
.kpaper-head-logo img { height: 66px; width: auto; max-width: 150px; display: block; }
.kpaper-head-center { flex: 1 1 auto; min-width: 0; text-align: center; }
.kpaper-head-title {
    font-size: 18px; font-weight: 700; letter-spacing: .6px; line-height: 1.2;
    text-transform: uppercase; color: var(--kpc-accent2); white-space: nowrap;
}
.kpaper-head-title-ar {
    font-family: 'KpaperArabic', 'KpaperSans', sans-serif; direction: rtl;
    font-size: 18px; font-weight: 700; line-height: 1.35; color: var(--kpc-accent);
    margin-top: 2px;
}

/* Bilingual chips (EN + AR in one pill), centred under the title. */
.kpaper-chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 11px; }
.kpaper-chip {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 3px 12px; border-radius: 6px; border: 1px solid transparent;
}
.kpaper-chip-en { font-size: 9.5px; font-weight: 600; letter-spacing: .3px; text-transform: uppercase; }
.kpaper-chip-ar { font-family: 'KpaperArabic', 'KpaperSans', sans-serif; direction: rtl; font-size: 11px; font-weight: 500; opacity: .92; }
.kpaper-chip--type  { background: #eef2f7; color: #3a4a5c; border-color: #dde4ec; }
.kpaper-tag--new,  .kpaper-chip--new,
.kpaper-chip.kpaper-tag--new   { }
.kpaper-chip.kpaper-tag--new   { background: #e8f5ee; color: #1a7f4b; border-color: #cbebd8; }
.kpaper-chip.kpaper-tag--renew { background: #e8f1fb; color: #1e5fa8; border-color: #cfe1f6; }
.kpaper-chip.kpaper-tag--flow  { background: #eeeffb; color: #4b52c0; border-color: #d9dbf3; }
.kpaper-chip.kpaper-tag--flowx { background: #fdecec; color: #c0392b; border-color: #f5d1d1; }

/* QR placeholder box (filled later — client-side or an <img>). */
.kpaper-head-qr {
    flex: 0 0 auto; box-sizing: border-box;
    width: 74px; height: 74px; padding: 3px;
    background: #fff; border: 1px solid var(--kpc-line); border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
}
.kpaper-head-qr .kpaper-qr { width: 66px; height: 66px; line-height: 0; }
.kpaper-qr canvas, .kpaper-qr img { display: block; margin: 0 auto; max-width: 100%; }

/* Clean LIGHT meta row (ref / date / page) — no heavy blue bar. */
.kpaper-meta {
    display: flex; align-items: center; gap: 18px;
    box-sizing: border-box; padding: 5px 24px;   /* slimmer band */
    width: 100%;   /* full-bleed to the frame — no negative-margin trick */
    background: #f6fafe; border-bottom: 1px solid var(--kpc-line);
    color: var(--kpc-ink); font-size: 9.5px;
}
.kpaper-meta-item { display: flex; align-items: center; gap: 9px; }
/* Two-line bilingual label: EN (uppercase) over its Arabic, then the value. */
.kpaper-meta-label { display: flex; flex-direction: column; line-height: 1.12; text-align: left; }
.kpaper-meta-label > span { font-size: 7px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--kpc-muted); }
.kpaper-meta-label > i {
    font-family: 'KpaperArabic', 'KpaperSans', sans-serif; direction: rtl;
    font-size: 8px; font-style: normal; font-weight: 500; color: var(--kpc-muted); opacity: .9;
}
.kpaper-meta-item b { font-size: 11px; font-weight: 700; color: var(--kpc-accent2); }
.kpaper-meta-sep { width: 1px; height: 16px; background: var(--kpc-line); }
.kpaper-meta-page {
    margin-left: auto; font-weight: 700; font-size: 9px;
    color: var(--kpc-accent); background: #fff;
    border: 1px solid var(--kpc-accent); border-radius: 12px; padding: 2px 12px;
}
.kpaper-info-page { margin-left: auto; font-weight: 800; color: var(--kpc-accent2); }

/* ---- Bilingual field cell (EN label | value | AR label) -----------
   Every cell is the SAME fixed height so the grid lines up cleanly (the
   fix for the jagged/cramped look). Labels are fixed-proportion side
   strips with tiny type; the value gets the middle and stays centred.
   Overflow is clipped so a long label can never blow the row height. */
.kpaper-fields { display: flex; flex-wrap: wrap; align-items: stretch; width: 100%; box-sizing: border-box; }
.kpaper-cell   { box-sizing: border-box; padding: 1.5px; }
.kpaper-cell-box {
    display: flex; align-items: stretch; width: 100%; height: 27px;   /* shorter, tighter rows */
    border: 1px solid var(--kpc-line); border-radius: 3px; overflow: hidden;
    background: #fff;
}
.kpaper-cell-en {
    flex: 0 0 34%; box-sizing: border-box;
    display: flex; align-items: center; padding: 2px 5px;
    font-size: 7.6px; font-weight: 700; line-height: 1.08; color: var(--kpc-muted);
    text-transform: uppercase; letter-spacing: .2px;
    /* wrap BETWEEN words only (no mid-word breaks like "ROOM S" / "ELECTRICI TY") */
    white-space: normal; word-break: normal; overflow-wrap: break-word;
    background: #f6f8fb; border-right: 1px solid var(--kpc-line); overflow: hidden;
}
.kpaper-cell-v {
    flex: 1 1 auto; min-width: 0; box-sizing: border-box;
    display: flex; align-items: center; justify-content: center;
    padding: 2px 4px; font-size: 10px; font-weight: 800; text-align: center;
    color: var(--kpc-accent2); line-height: 1.12; overflow: hidden; word-break: break-word;
}
.kpaper-cell-ar {
    flex: 0 0 27%; box-sizing: border-box;
    /* direction:rtl reverses the main axis, so flex-START is the visual RIGHT —
       this pins the Arabic label flush to the cell's right edge. */
    display: flex; align-items: center; justify-content: flex-start;
    padding: 2px 5px; direction: rtl; text-align: right;
    font-size: 8.5px; font-weight: 700; line-height: 1.45; color: var(--kpc-muted);
    white-space: normal; word-break: break-word;
    background: #f6f8fb; border-left: 1px solid var(--kpc-line); overflow: hidden;
}
.kpaper-cell-v--ar { direction: rtl; }
/* Taller cell that holds the multi-line grace grid / inclusions checkboxes,
   with NARROW label strips so the content gets most of the width. Extra
   specificity (.kpaper-cell …) so it beats the .kpaper-w100 label rule below. */
.kpaper-cell-box--tall { height: auto; min-height: 44px; }
/* Pure content-height (grows with rows) — used for the inclusions checkbox
   row so ONE line stays compact but more items push the height up. */
.kpaper-cell-box--auto { height: auto; min-height: 26px; }
.kpaper-cell .kpaper-cell-box--tall .kpaper-cell-en,
.kpaper-cell .kpaper-cell-box--tall .kpaper-cell-ar,
.kpaper-cell .kpaper-cell-box--auto .kpaper-cell-en,
.kpaper-cell .kpaper-cell-box--auto .kpaper-cell-ar { flex: 0 0 10%; font-size: 7.4px; }
.kpaper-cell-v--grace { display: block; padding: 3px 6px; }
.kpaper-flag-in  { color: #1a7f37 !important; text-transform: uppercase; }
.kpaper-flag-out { color: #c0392b !important; text-transform: uppercase; }
/* Wider cells (w50/w60/w70/w100) can afford roomier labels + left value. */
.kpaper-w50 .kpaper-cell-en, .kpaper-w60 .kpaper-cell-en,
.kpaper-w65 .kpaper-cell-en, .kpaper-w70 .kpaper-cell-en,
.kpaper-w75 .kpaper-cell-en, .kpaper-w85 .kpaper-cell-en,
.kpaper-w100 .kpaper-cell-en { flex-basis: 22%; font-size: 8.5px; }
.kpaper-w50 .kpaper-cell-ar, .kpaper-w60 .kpaper-cell-ar,
.kpaper-w65 .kpaper-cell-ar, .kpaper-w70 .kpaper-cell-ar,
.kpaper-w75 .kpaper-cell-ar, .kpaper-w85 .kpaper-cell-ar,
.kpaper-w100 .kpaper-cell-ar { flex-basis: 20%; }

/* ---- Width modifiers (flex-basis; wrap into rows) ----------------- */
.kpaper-w15  { width: 15%; }
.kpaper-w20  { width: 20%; }
.kpaper-w25  { width: 25%; }
.kpaper-w30  { width: 30%; }
.kpaper-w33  { width: 33.333%; }
.kpaper-w35  { width: 35%; }
.kpaper-w40  { width: 40%; }
.kpaper-w50  { width: 50%; }
.kpaper-w60  { width: 60%; }
.kpaper-w65  { width: 65%; }
.kpaper-w70  { width: 70%; }
.kpaper-w75  { width: 75%; }
.kpaper-w80  { width: 80%; }
.kpaper-w85  { width: 85%; }
.kpaper-w100 { width: 100%; }

/* ---- Blue unit plate — clean card: prominent unit no + 2x2 grid ---- */
.kpaper-plate {
    box-sizing: border-box; width: 100%; height: 100%;
    display: flex; flex-direction: column; gap: 7px;
    padding: 9px; background: var(--kpc-accent); border-radius: 6px;
}
/* Head grows to fill the plate height so the white unit box is tall (no blue
   dead-space under it); the caption sits on top, the box fills the rest. */
.kpaper-plate-head {
    flex: 1 1 auto; min-height: 0;
    display: flex; flex-direction: column; text-align: center;
}
.kpaper-plate-cap {
    flex: 0 0 auto; font-size: 7.5px; font-weight: 700; text-transform: uppercase;
    letter-spacing: .4px; color: rgba(255, 255, 255, .82); line-height: 1.25;
}
.kpaper-plate-cap i {
    font-style: normal; font-family: 'KpaperArabic', 'KpaperSans', sans-serif;
    margin-right: 4px; direction: rtl;
}
.kpaper-plate-unit {
    flex: 1 1 auto; margin-top: 4px; padding: 6px 4px; min-height: 0;
    display: flex; align-items: center; justify-content: center; text-align: center;
    background: #fff; color: var(--kpc-accent2); border-radius: 4px;
    font-size: 12px; font-weight: 800; line-height: 1.18; word-break: break-word;
}
.kpaper-plate-grid { flex: 0 0 auto; display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.kpaper-plate-cell {
    background: rgba(255, 255, 255, .10); border: 1px solid rgba(255, 255, 255, .38);
    border-radius: 4px; padding: 4px 3px; text-align: center;
}
.kpaper-plate-cell-lbl {
    display: block; font-size: 6.8px; font-weight: 700; text-transform: uppercase;
    letter-spacing: .3px; color: rgba(255, 255, 255, .82); line-height: 1.15;
}
.kpaper-plate-cell-lbl i {
    font-style: normal; font-family: 'KpaperArabic', 'KpaperSans', sans-serif;
    margin-right: 3px; direction: rtl;
}
.kpaper-plate-cell b {
    display: block; margin-top: 2px; font-size: 10px; font-weight: 800; color: #fff;
    word-break: break-word; line-height: 1.12;
}

/* ---- Coloured section title bar (EN | AR) ------------------------- */
/* Body sections get a small L/R inset from the frame (the masthead + meta bar
   stay full-bleed; only the content below breathes in a touch). */
.kpaper-sec-cr { width: 100%; box-sizing: border-box; padding: 0 3mm; margin: 6px 0 0; break-inside: avoid; }
/* Continuation wrapper for a flowed row that belongs to the SAME section as the
   piece above it (row-level paginator): keeps the 3mm L/R inset but no top gap,
   so rows of one section stack tightly while the bar/sub-header owns the gap. */
.kpaper-sec-cont { width: 100%; box-sizing: border-box; padding: 0 3mm; margin: 0; break-inside: avoid; }
/* Section header — a clean "folder tab": the EN title sits in a solid accent
   tab with rounded top corners, riding a full-width accent baseline; the Arabic
   title sits at the right, above the line. Distinctive but light. */
.kpaper-secbar {
    display: flex; align-items: flex-end; justify-content: space-between;
    width: 100%; box-sizing: border-box; padding: 0; margin: 8px 0 5px;
    background: none; border: 0; border-bottom: 2px solid var(--kpc-accent);
    border-radius: 0; box-shadow: none;
}
.kpaper-secbar-en {
    display: inline-flex; align-items: center;
    padding: 5px 16px 6px; border-radius: 5px 5px 0 0;
    background: var(--kpc-accent); color: #fff;
    font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .8px;
}
.kpaper-secbar-ar {
    padding: 0 3px 4px 0;
    font-size: 13px; font-weight: 800; direction: rtl; color: var(--kpc-accent2);
    font-family: 'KpaperArabic', 'KpaperSans', sans-serif;
}
/* Small in-section sub-header (e.g. "Company Information" inside the tenant
   section) — lighter than the folder-tab, an accent-tinted strip. */
.kpaper-subhd {
    /* Left margin = the .kpaper-cell left padding (1.5px) so the strip's left
       edge lines up with the data-cell boxes below it (which are inset that much
       inside .kpaper-fields); the right edge already sits flush with the cells,
       so no right margin. */
    box-sizing: border-box; margin: 7px 0 3px 1.5px;
    display: flex; align-items: center; justify-content: space-between;
    padding: 3px 9px; background: #eef4fb; border-left: 3px solid var(--kpc-accent);
    border-radius: 3px;
}
.kpaper-subhd-en {
    font-size: 9px; font-weight: 800; text-transform: uppercase; letter-spacing: .5px;
    color: var(--kpc-accent2);
}
.kpaper-subhd-ar {
    font-size: 10.5px; font-weight: 800; direction: rtl; color: var(--kpc-accent);
    font-family: 'KpaperArabic', 'KpaperSans', sans-serif;
}

/* ---- Checkbox (New / Renewal + required documents) ---------------- */
.kpaper-chk { display: inline-flex; align-items: center; gap: 5px; margin: 2px 8px 2px 0; }
.kpaper-chk-box {
    flex: 0 0 auto; width: 16px; height: 16px;
    display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid var(--kpc-ink); border-radius: 2px;
    font-size: 12px; font-weight: 800; color: var(--kpc-accent2); line-height: 1;
}
.kpaper-chk-box--on { background: #e8f5ee; border-color: #1a7f4b; color: #1a7f4b; }
.kpaper-chk-lbl { font-size: 9px; font-weight: 700; color: var(--kpc-ink); }
.kpaper-chk--on .kpaper-chk-lbl { color: var(--kpc-accent2); }
.kpaper-chk-lbl span { direction: rtl; }
.kpaper-docs { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; padding: 3px 4px; }

/* ---- Grace-period sub-grid (inside one full-width cell value) ----- */
.kpaper-grace { display: flex; width: 100%; }
/* Each segment stacks vertically + is centred: title · days · from→to. */
.kpaper-grace-col {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px; padding: 2px 4px; border-right: 1px solid var(--kpc-line); text-align: center;
}
.kpaper-grace-col:last-child { border-right: none; }
.kpaper-grace-hd { font-size: 8.5px; font-weight: 800; color: var(--kpc-accent2); }
.kpaper-grace-hd span { direction: rtl; font-weight: 700; color: var(--kpc-ink); }
.kpaper-grace-days { font-size: 9.5px; font-weight: 800; color: var(--kpc-ink); }
.kpaper-grace-dates { display: flex; align-items: center; gap: 5px; font-size: 8px; font-weight: 700; color: var(--kpc-muted); }
.kpaper-grace-dates i { font-style: normal; color: var(--kpc-accent); font-size: 9px; }
/* Grace PRESENT → maroon tint so it's obvious at a glance. */
.kpaper-grace--on { background: #fbedef; border-radius: 4px; }
.kpaper-grace--on .kpaper-grace-col { border-right-color: #eecdd2; }
.kpaper-grace--on .kpaper-grace-hd,
.kpaper-grace--on .kpaper-grace-days { color: #8a1c2b; }
.kpaper-grace--on .kpaper-grace-hd span { color: #8a1c2b; }
.kpaper-grace--on .kpaper-grace-dates { color: #a05561; }
.kpaper-grace--on .kpaper-grace-dates i { color: #8a1c2b; }

/* ---- Office-use signatures row ------------------------------------ */
.kpaper-office { display: flex; width: 100%; box-sizing: border-box; gap: 6px; margin-top: 4px; min-height: 118px; }
.kpaper-office-col {
    flex: 1; box-sizing: border-box; display: flex; flex-direction: column;
    padding: 4px 6px 6px; text-align: center; border-bottom: 2px solid var(--kpc-accent);
}
.kpaper-office-role { font-size: 12px; font-weight: 800; color: var(--kpc-accent2); }
.kpaper-office-qr { display: flex; justify-content: center; margin: 4px 0 2px; }
.kpaper-office-sig { flex: 1 1 auto; display: flex; align-items: flex-end; justify-content: center; min-height: 60px; }
.kpaper-office-sig img { max-width: 100%; max-height: 82px; }
.kpaper-office-meta { font-size: 9px; color: var(--kpc-muted); line-height: 1.25; margin-top: 3px; word-break: break-word; }
.kpaper-office-meta small { font-size: 8px; }

/* ---- Responsive (narrow stage) ------------------------------------ */
@media (max-width: 820px) {
    .kpaper-grid, .kpaper-two { grid-template-columns: 1fr; }
    /* NOTE: no `.kpaper-page { padding }` here — A4 is 794px (< 820px) so this
       query ALSO matches in print + narrow panels, and any padding would push
       the full-bleed header off the frame (the print gap bug). The page is
       padding:0 by design at every width; body sections carry their own inset. */
}

/* ---- Print: true A4, one sheet per page --------------------------- */
@media print {
    /* No margin → the frame sits right at the sheet edge, no white space
       around it (fine for Save-as-PDF; the page now fills the box so it isn't
       scaled/clipped like before). */
    /* 5mm margin = the printer's unprintable edge band. The frame MUST sit
       inside it or a physical printer clips it away (margin:0 → border gone).
       This is the smallest safe margin, so the even white gap is minimal. */
    @page { size: A4; margin: 5mm; }
    /* Neutralise the on-screen scroll container so it can't spawn extra pages. */
    .kpaper-doc { background: none; padding: 0; gap: 0; align-items: stretch; overflow: visible; }
    /* Size the page to JUST UNDER the printable area (A4 minus 2x5mm = 287mm
       tall; use 285mm so sub-pixel rounding can't tip a hair over onto a blank
       2nd sheet). Width 200mm = printable width, so NO scaling; the footer still
       pins to the bottom (the ~2mm buffer is invisible). Dashed frame darker so
       it shows on paper. */
    .kpaper-page {
        width: 200mm; height: 285mm; min-height: 0;
        padding: 0;   /* defensive: full-bleed header must hug the frame in print */
        box-shadow: none;
        border: 1.5px dashed #93a2b4;   /* browser dashed, a touch darker for paper */
        border-radius: 5px;             /* soft rounded corners on the printed frame too */
        overflow: hidden;
        page-break-after: auto; break-after: auto;   /* never force a break */
    }
    /* Multi-page: break BEFORE each subsequent sheet (not AFTER), so the last
       page never carries a trailing forced break → no phantom blank sheet. */
    .kpaper-page + .kpaper-page { page-break-before: always; break-before: page; }
}

/* =====================================================================
   2. PER-TEMPLATE
   ---------------------------------------------------------------------
   One block per template. Set the brand tokens on the template's brand
   class; add extra rules only when the common blocks don't cover it.
   ===================================================================== */

/* ---- Realestate template (.kpaper--realestate) -------------------- */
/* Kate Realestate — corporate blue. Common blocks cover the layout; this
   just sets the brand palette. Add realestate-only rules below if needed. */
.kpaper--realestate {
    --kpc-accent:  #00549a;
    --kpc-accent2: #003a6b;
    --kpc-tint:    #eef4fb;
}
/* Kate Realestate masthead — the faint building vector behind the logo +
   bilingual titles (mirrors the legacy building_vactor_img.png backdrop). */
.kpaper--realestate .kpaper-masthead {
    background-image: url(../images/building_vactor_img.png);
}
