/* PHC Application */
:root {
    --brand: #0b6e4f;
    --brand-dark: #08513a;
    --brand-light: #e6f3ee;
    --bg: #f4f6f5;
    --surface: #ffffff;
    --text: #1d2a25;
    --muted: #66746e;
    --border: #dde3e0;
    --blue: #2563c9;   --blue-bg: #e8f0fc;
    --green: #1a8a4a;  --green-bg: #e3f5ea;
    --orange: #b86200; --orange-bg: #fdf0e0;
    --red: #c0352b;    --red-bg: #fbe7e5;
    --gray: #5f6b66;   --gray-bg: #eef1ef;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(16, 40, 30, .06), 0 2px 8px rgba(16, 40, 30, .04);
    --topbar-h: 60px;
    --sidebar-w: 230px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font: 15px/1.55 "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--text);
    background: var(--bg);
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: .1em 0 .2em; line-height: 1.25; }
h2 { font-size: 1.15rem; margin: 0 0 .6em; }
h3 { font-size: 1rem; margin: 1em 0 .5em; }
p { margin: .4em 0 .8em; }
code { background: var(--gray-bg); padding: 1px 5px; border-radius: 4px; font-size: .88em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.spacer { flex: 1; }
.inline { display: inline; }

/* ---------------- layout */
.topbar {
    position: fixed; inset: 0 0 auto 0; height: var(--topbar-h); z-index: 30;
    display: flex; align-items: center; gap: 14px; padding: 0 20px;
    background: var(--brand); color: #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, .15);
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; }
.brand:hover { text-decoration: none; }
.brand-text { display: flex; flex-direction: column; font-weight: 600; line-height: 1.15; }
.brand-text small { font-weight: 400; opacity: .8; font-size: .75rem; }
.brand-mark {
    display: inline-flex; align-items: center; justify-content: center;
    background: #fff; color: var(--brand); font-weight: 800; letter-spacing: .5px;
    border-radius: 8px; padding: 6px 8px; font-size: .85rem;
}
.brand-mark.lg { font-size: 1.3rem; padding: 10px 14px; background: var(--brand); color: #fff; }
.topbar-user { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.user-name { display: flex; flex-direction: column; text-align: right; line-height: 1.2; font-weight: 600; }
.user-name small { font-weight: 400; opacity: .8; }
.topbar .btn-ghost { color: #fff; border-color: rgba(255, 255, 255, .4); }
.topbar .btn-ghost:hover { background: rgba(255, 255, 255, .12); }
.nav-toggle { display: none; background: none; border: 0; color: #fff; font-size: 1.4rem; cursor: pointer; }

.sidebar {
    position: fixed; top: var(--topbar-h); bottom: 0; left: 0; width: var(--sidebar-w); z-index: 20;
    background: var(--surface); border-right: 1px solid var(--border); padding: 14px 10px; overflow-y: auto;
}
.sidebar a {
    display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px;
    color: var(--text); font-weight: 500; margin-bottom: 2px;
}
.sidebar a:hover { background: var(--bg); text-decoration: none; }
.sidebar a.active { background: var(--brand-light); color: var(--brand-dark); font-weight: 600; }
.nav-icon { width: 20px; text-align: center; }

.content { padding: 24px 28px 60px; max-width: 1400px; }
.has-sidebar .content { margin-left: var(--sidebar-w); padding-top: calc(var(--topbar-h) + 24px); }

.page-head { margin-bottom: 18px; }
.page-head p { margin: 0; }
.row-between { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.grid-wide-left { grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); }

.card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 20px; margin-bottom: 18px; min-width: 0;
}
details.card > summary { cursor: pointer; list-style: none; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::before { content: '▸ '; color: var(--muted); }
details.card[open] > summary::before { content: '▾ '; }
.inline-h { display: inline; }

/* ---------------- alerts, badges */
.alert { padding: 11px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid transparent; }
.alert-success { background: var(--green-bg); color: #145c33; border-color: #bfe3cc; }
.alert-error { background: var(--red-bg); color: #8f241c; border-color: #f2c6c1; }
.alert-warning { background: var(--orange-bg); color: #7d4300; border-color: #f4d6ad; }
.alert-info { background: var(--blue-bg); color: #1b4a96; border-color: #c7d8f5; }

.badge {
    display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .75rem; font-weight: 600;
    white-space: nowrap; vertical-align: middle;
}
.badge-gray { background: var(--gray-bg); color: var(--gray); }
.badge-blue { background: var(--blue-bg); color: var(--blue); }
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-orange { background: var(--orange-bg); color: var(--orange); }
.badge-red { background: var(--red-bg); color: var(--red); }

.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; flex: none; }
.dot-gray { background: #b7c0bc; }
.dot-blue { background: var(--blue); }
.dot-green { background: var(--green); }
.dot-orange { background: var(--orange); }

.code {
    display: inline-block; font-family: Consolas, monospace; font-size: .82em; font-weight: 700;
    background: var(--brand-light); color: var(--brand-dark); padding: 1px 6px; border-radius: 5px;
}

/* ---------------- buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 8px 15px; border-radius: 8px; border: 1px solid var(--border);
    background: var(--surface); color: var(--text); font: inherit; font-weight: 500;
    cursor: pointer; text-decoration: none; white-space: nowrap; line-height: 1.3;
}
.btn:hover { background: var(--bg); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-sm { padding: 4px 10px; font-size: .85rem; }
.btn-icon { padding: 4px 8px; }
.btn-block { display: flex; width: 100%; margin-top: 8px; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-success { background: var(--green); border-color: var(--green); color: #fff; }
.btn-success:hover { background: #147339; }
.btn-warning { background: var(--orange); border-color: var(--orange); color: #fff; }
.btn-warning:hover { background: #994f00; }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-danger:hover { background: #9e2a22; }
.btn-danger-ghost { color: var(--red); }
.btn-danger-ghost:hover { background: var(--red-bg); }
.btn-ghost { background: transparent; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
td.actions { white-space: nowrap; }
.default-submit { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

/* ---------------- forms */
.form label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: .9rem; margin-bottom: 14px; }
.form label.check, label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; }
.label-plain, .form label.label-plain { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 6px; }
input[type=text], input[type=email], input[type=password], input[type=search], input[type=date],
input[type=number], select, textarea {
    width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px;
    font: inherit; font-weight: 400; color: var(--text); background: #fff;
}
input:focus, select:focus, textarea:focus, .rte-body:focus {
    outline: 2px solid rgba(11, 110, 79, .25); border-color: var(--brand);
}
input:disabled { background: var(--bg); }
textarea { resize: vertical; }
input[type=file] { font: inherit; margin: 6px 0; max-width: 100%; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.span-2 { grid-column: span 2; }
.form-actions { display: flex; gap: 8px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.filters input, .filters select { width: auto; min-width: 200px; }
.filters-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.filters-bar .filters { margin: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
    display: inline-block; padding: 4px 11px; border-radius: 999px; border: 1px solid var(--border);
    background: #fff; color: var(--text); font: inherit; font-size: .82rem; cursor: pointer;
}
.chip:hover { background: var(--brand-light); text-decoration: none; }
.chip.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.radio-row { display: flex; gap: 22px; margin: 6px 0 14px; }
.sticky-actions {
    position: sticky; bottom: 0; z-index: 5; display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
    background: rgba(255, 255, 255, .96); border-top: 1px solid var(--border);
    margin: 18px -20px -20px; padding: 12px 20px; border-radius: 0 0 var(--radius) var(--radius);
}
form > .sticky-actions { margin: 0; border: 1px solid var(--border); border-radius: var(--radius); }

/* ---------------- tables */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 10px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.table tbody tr:hover { background: #fafcfb; }
.table-compact th, .table-compact td { padding: 7px 8px; }
.table .empty, .empty { text-align: center; color: var(--muted); padding: 22px; }
.card > .table { margin-bottom: 8px; }
.card { overflow-x: auto; }

/* ---------------- progress & stats */
.progress { height: 8px; border-radius: 99px; background: var(--gray-bg); overflow: hidden; margin: 4px 0; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--brand), #23a776); border-radius: 99px; }
.progress-block { margin: 12px 0 16px; }
.stat-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; color: var(--muted); font-size: .88rem; margin-bottom: 8px; }
.stat-item { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px;
    display: flex; flex-direction: column; color: var(--muted); box-shadow: var(--shadow); border-top: 3px solid var(--brand);
}
.stat:hover { text-decoration: none; border-color: var(--brand); }
.stat-num { font-size: 1.9rem; font-weight: 700; color: var(--text); }
.stat-blue { border-top-color: var(--blue); }
.stat-green { border-top-color: var(--green); }
.head-progress { min-width: 220px; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.head-progress .progress { width: 220px; }
.steps li { margin-bottom: 8px; }
.steps li.done { color: var(--muted); text-decoration: line-through; }
.activity { list-style: none; margin: 0; padding: 0; }
.activity li { display: flex; flex-direction: column; padding: 8px 0; border-bottom: 1px solid var(--border); }
.activity li:last-child { border: 0; }
.dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0 0 12px; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; }

/* ---------------- misc lists */
.file-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px dashed var(--border); flex-wrap: wrap; }
.file-list { list-style: none; padding: 0; margin: 8px 0 0; }
.file-list li { padding: 3px 0; }
.user-row { display: flex; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.danger-zone { border-color: #f2c6c1; }
.empty-state { text-align: center; padding: 40px 20px; }
.section-card h2 { margin-bottom: 4px; }
.section-heading { margin: 22px 0 10px; color: var(--brand-dark); }

/* ---------------- facility type cards (Templates page) */
.type-search { width: 260px; max-width: 100%; }
.type-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 18px; margin-bottom: 22px; }
.type-card {
    position: relative; display: flex; flex-direction: column; gap: 8px; padding: 20px; min-height: 210px;
    background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
    box-shadow: var(--shadow); color: var(--text); overflow: hidden;
    transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.type-card::before {
    content: ''; position: absolute; inset: 0 0 auto 0; height: 4px; background: var(--brand);
    transform: scaleX(.25); transform-origin: left; transition: transform .25s ease;
}
.type-card.is-empty::before { background: #b7c0bc; }
.type-card:hover, .type-card:focus-visible {
    text-decoration: none; transform: translateY(-3px); border-color: var(--brand);
    box-shadow: 0 10px 24px rgba(16, 40, 30, .12); outline: none;
}
.type-card:hover::before, .type-card:focus-visible::before { transform: scaleX(1); background: var(--brand); }
.type-card:active { transform: translateY(-1px); }
.type-card[hidden] { display: none; }
.type-top { display: flex; justify-content: space-between; align-items: flex-start; }
.type-icon {
    display: inline-flex; align-items: center; justify-content: center; width: 48px; height: 48px;
    border-radius: 12px; background: var(--brand-light); font-size: 1.5rem; transition: transform .2s ease;
}
.type-card:hover .type-icon { transform: scale(1.08) rotate(-4deg); }
.type-name { font-size: 1.15rem; font-weight: 700; line-height: 1.25; }
.type-desc { color: var(--muted); font-size: .84rem; line-height: 1.4; }
.type-stats { display: flex; gap: 16px; color: var(--muted); font-size: .88rem; }
.type-stats strong { color: var(--text); font-size: 1.05rem; }
.type-action {
    margin-top: auto; padding-top: 10px; border-top: 1px solid var(--border);
    color: var(--brand); font-weight: 600; display: flex; justify-content: space-between; align-items: center;
}
.type-action .arrow { transition: transform .2s ease; }
.type-card:hover .type-action .arrow { transform: translateX(4px); }
.type-card-add {
    border: 2px dashed var(--border); background: transparent; box-shadow: none;
    justify-content: center; align-items: center; text-align: center;
}
.type-card-add::before { display: none; }
.type-card-add .type-icon { background: transparent; border: 2px dashed var(--border); color: var(--brand); font-weight: 700; }
.type-card-add .type-name { color: var(--brand); }
.type-card-add:hover { background: var(--brand-light); }
.group-row td { background: var(--brand-light); color: var(--brand-dark); font-weight: 700; font-size: .85rem; padding: 6px 10px; }

/* ---------------- indicator editor */
.indicator-no { max-width: 260px; }
.indicator-no input { font-size: 1.1rem; font-weight: 600; }
.autofill { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 4px 0 10px; }
.autofill-label { font-weight: 600; font-size: .85rem; color: var(--muted); margin-right: 2px; }

/* ---------------- auth */
.no-sidebar .content { margin: 0 auto; }
.auth-wrap { min-height: calc(100vh - 80px); display: flex; align-items: center; justify-content: center; }
.auth-card { width: 100%; max-width: 420px; padding: 30px; }
.auth-brand { text-align: center; margin-bottom: 18px; }
.auth-brand h1 { margin-top: 12px; }

/* ---------------- client filling */
.fill-layout { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 18px; align-items: start; }
.indicator-nav { position: sticky; top: calc(var(--topbar-h) + 16px); max-height: calc(100vh - var(--topbar-h) - 32px); overflow-y: auto; padding: 12px; }
.nav-section { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 12px 6px 4px; }
.nav-section:first-child { margin-top: 0; }
.nav-ind { display: flex; gap: 8px; align-items: baseline; padding: 6px 8px; border-radius: 6px; color: var(--text); font-size: .86rem; line-height: 1.35; }
.nav-ind:hover { background: var(--bg); text-decoration: none; }
.nav-ind.active { background: var(--brand-light); }
.indicator-title { margin: 6px 0 12px; font-size: 1.25rem; }
.instructions { background: #f7faf9; border-left: 4px solid var(--brand); padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; }
.instructions p { margin: 4px 0 0; }
.samples { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.evidence { margin-top: 18px; padding-top: 6px; border-top: 1px solid var(--border); }
.readonly-box { border: 1px solid var(--border); border-radius: 8px; padding: 14px 18px; background: #fbfcfb; }
.doc-text.reference { border: 1px dashed var(--border); border-radius: 8px; padding: 10px 14px; margin-bottom: 14px; background: #fbfcfb; }

/* ---------------- review */
.review-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 18px; align-items: start; }
.sticky { position: sticky; top: calc(var(--topbar-h) + 16px); }
.review-item { border-left: 4px solid #b7c0bc; }
.review-item h3 { margin: 0 0 4px; }
.review-item.status-completed { border-left-color: var(--blue); }
.review-item.status-approved { border-left-color: var(--green); }
.review-item.status-needs_revision { border-left-color: var(--orange); }
.answer-box { background: #fbfcfb; border: 1px solid var(--border); border-radius: 8px; padding: 12px 16px; margin: 10px 0; }
.review-form { display: flex; flex-direction: column; gap: 8px; }

/* ---------------- rich text editor */
.rte { border: 1px solid var(--border); border-radius: 8px; background: #fff; margin-bottom: 14px; }
.rte-toolbar {
    display: flex; flex-wrap: wrap; gap: 2px; padding: 6px; border-bottom: 1px solid var(--border);
    background: #f8faf9; border-radius: 8px 8px 0 0; position: sticky; top: var(--topbar-h); z-index: 4;
}
.rte-toolbar button {
    border: 1px solid transparent; background: none; border-radius: 5px; padding: 3px 8px;
    font: inherit; font-size: .85rem; cursor: pointer; color: var(--text); min-width: 30px;
}
.rte-toolbar button:hover { background: #fff; border-color: var(--border); }
.rte-sep { width: 1px; background: var(--border); margin: 2px 4px; }
.rte-toolbar .rte-size { font: inherit; font-size: .8rem; padding: 2px 4px; border: 1px solid var(--border); border-radius: 5px; background: #fff; width: auto; }
.rte-body { min-height: 260px; max-height: 70vh; overflow-y: auto; padding: 14px 18px; border-radius: 0 0 8px 8px; }

/* Shared formatting for document text (editor, answers, printed document) */
.doc-text h1, .doc-text h2, .doc-text h3 { margin: .8em 0 .4em; }
.doc-text table { border-collapse: collapse; width: 100%; margin: 10px 0; }
.doc-text td, .doc-text th { border: 1px solid #9aa8a2; padding: 6px 8px; min-width: 40px; vertical-align: top; }
.doc-text th { background: #eef3f1; }
.doc-text ol, .doc-text ul { padding-left: 26px; }
.doc-text p:first-child { margin-top: 0; }
mark.ph { background: #fff2b3; padding: 0 3px; border-radius: 3px; }

/* ---------------- printable document */
.document-page { background: #e9eeec; }
.doc-toolbar {
    position: sticky; top: 0; z-index: 10; display: flex; gap: 8px; align-items: center;
    padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.document {
    max-width: 860px; margin: 24px auto; background: #fff; padding: 56px 64px;
    box-shadow: 0 2px 16px rgba(0, 0, 0, .08); border-radius: 4px; font-size: 14.5px;
}
.doc-cover { text-align: center; padding-bottom: 28px; border-bottom: 3px double var(--brand); margin-bottom: 28px; }
.doc-cover h1 { margin-top: 18px; color: var(--brand-dark); }
.doc-cover h2 { font-weight: 500; }
.doc-meta { margin: 18px auto 0; border-collapse: collapse; text-align: left; min-width: 60%; }
.doc-meta th, .doc-meta td { padding: 5px 12px; border-bottom: 1px solid var(--border); }
.doc-meta th { color: var(--muted); font-weight: 600; width: 40%; }
.doc-toc { margin-bottom: 30px; }
.doc-section { margin-bottom: 30px; }
.doc-section-title { background: var(--brand); color: #fff; padding: 8px 14px; border-radius: 4px; font-size: 1.1rem; }
.doc-indicator { padding: 6px 0 14px; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.doc-indicator h3 { color: var(--brand-dark); }
.doc-evidence { font-size: .9rem; background: #f7faf9; padding: 8px 12px; border-radius: 6px; }

/* ---------------- letterhead / page template */
.lh-print-bg { display: none; }
.lh-doc { padding: 24px 0; }
.lh-page {
    width: 210mm; min-height: 297mm; height: 297mm; margin: 0 auto 24px; border-collapse: collapse;
    background: #fff var(--lh-img) top center / 210mm 297mm repeat-y;
    box-shadow: 0 2px 16px rgba(0, 0, 0, .12); font-size: 14px;
}
.lh-top { height: var(--lh-top); padding: 0; }
.lh-bottom { height: var(--lh-bottom); padding: 0; }
.lh-body { padding: 0 var(--lh-side); vertical-align: top; }
.lh-page .doc-cover { border-bottom: 0; padding-bottom: 8px; margin-bottom: 18px; }
.lh-page .doc-indicator { border-bottom: 0; }

/* Index page ("from – to" indicators) */
.ix-title { text-align: center; color: var(--brand-dark); font-size: 1.4rem; margin: 0 0 16px; letter-spacing: .04em; }
.ix-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.ix-table th, .ix-table td { padding: 8px 10px; border-bottom: 1px solid #cfd8d4; text-align: left; vertical-align: top; }
.ix-table thead th { background: var(--brand); color: #fff; font-weight: 600; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.ix-table tbody tr:nth-child(even) td { background: #f5f9f7; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.ix-table tfoot td { font-weight: 700; border-bottom: 0; border-top: 2px solid var(--brand); }
.ix-table a { color: inherit; }
.ix-no { width: 36px; text-align: center !important; }
.ix-code { white-space: nowrap; font-weight: 700; color: var(--brand-dark); width: 1%; }
.ix-arrow { width: 1%; color: var(--muted); padding: 8px 2px !important; }
.ix-count { text-align: center !important; width: 1%; white-space: nowrap; }
.doc-index { margin-bottom: 30px; }
.lh-sheet {
    position: relative; width: 210mm; min-height: 297mm; margin: 0 auto 24px; background: #fff;
    box-shadow: 0 2px 16px rgba(0, 0, 0, .12); overflow: hidden;
}
.lh-sheet-bg { position: absolute; top: 0; left: 0; width: 210mm; height: 297mm; z-index: 0; }
.lh-sheet-body { position: relative; z-index: 1; padding: var(--ix-top) var(--ix-side) var(--ix-bottom); font-size: 14px; }

.design-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(460px, 1fr)); gap: 0 18px; }
@media (max-width: 1100px) { .design-grid { grid-template-columns: 1fr; } }

/* Page template card on the facility type page */
.page-tpl { display: grid; grid-template-columns: 170px minmax(0, 1fr); gap: 20px; align-items: start; }
.page-thumb {
    position: relative; width: 170px; aspect-ratio: 210 / 297; border: 1px solid var(--border); border-radius: 6px;
    background: #fff center / cover no-repeat; box-shadow: var(--shadow); overflow: hidden;
}
.page-thumb .zone { position: absolute; left: 0; right: 0; background: rgba(11, 110, 79, .12); border: 1px dashed rgba(11, 110, 79, .5); }
.page-thumb .zone-text { position: absolute; background: repeating-linear-gradient(#fff0 0 7px, rgba(0,0,0,.15) 7px 8px); }
.page-thumb.empty { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: .8rem; text-align: center; padding: 10px; background: var(--bg); }
.margin-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 12px; }
@media (max-width: 600px) { .page-tpl { grid-template-columns: 1fr; } .margin-row { grid-template-columns: 1fr; } }

/* ---------------- responsive */
@media (max-width: 1100px) {
    .review-layout { grid-template-columns: 1fr; }
    .sticky { position: static; }
}
@media (max-width: 900px) {
    .nav-toggle { display: block; }
    .sidebar { transform: translateX(-100%); transition: transform .2s; box-shadow: 2px 0 12px rgba(0, 0, 0, .1); }
    .nav-open .sidebar { transform: none; }
    .has-sidebar .content { margin-left: 0; }
    .content { padding-left: 16px; padding-right: 16px; }
    .grid-2, .grid-wide-left, .fill-layout { grid-template-columns: 1fr; }
    .indicator-nav { position: static; max-height: 300px; }
    .brand-text small, .user-name small { display: none; }
    .document { padding: 28px 20px; margin: 0; }
}
@media (max-width: 600px) {
    .form-grid { grid-template-columns: 1fr; }
    .span-2 { grid-column: auto; }
    .user-name { display: none; }
    .head-progress { align-items: flex-start; }
    .filters input, .filters select { min-width: 0; width: 100%; }
}

/* ---------------- print */
@media print {
    .no-print, .topbar, .sidebar, .doc-toolbar { display: none !important; }
    body, .document-page { background: #fff; }
    .document { box-shadow: none; margin: 0; padding: 0; max-width: none; }
    .doc-section-title { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .doc-indicator { break-inside: avoid-page; }
    .doc-toc { break-after: page; }
    a { color: inherit; }
    /* Letterhead: fixed image repeats on every printed page; each block starts a new page */
    .lh-print-bg { display: block; position: fixed; top: 0; left: 0; width: 210mm; height: 297mm; z-index: -1; }
    .lh-doc { padding: 0; }
    .lh-page { width: 100%; height: auto; min-height: 0; margin: 0; box-shadow: none; background: none; }
    .lh-page { page-break-before: always; break-before: page; }
    .lh-doc > .lh-page:first-child { page-break-before: auto; break-before: auto; }
    /* Index on its own design: exactly one page, covering the indicator-page design */
    .lh-sheet { width: 210mm; height: 296mm; min-height: 0; margin: 0; box-shadow: none; page-break-before: always; break-before: page; }
    .doc-index { page-break-before: always; break-before: page; page-break-after: always; break-after: page; }
    .lh-doc .doc-toc { break-after: auto; }
    .lh-doc .doc-indicator { break-inside: auto; }
}

/* Indicator No. + Heading row */
.indicator-head { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 0 16px; }
.indicator-head .indicator-no { max-width: none; }
.indicator-heading input { font-size: 1.05rem; font-weight: 600; }
@media (max-width: 600px) { .indicator-head { grid-template-columns: 1fr; } }

.print-blank { font-size: 1.02rem; letter-spacing: .02em; margin: 10px 0 4px; }

/* ---------------- clinic layout: header, IND NO., heading box, signature, divider pages */
.lh-head { padding: 0; }
.lh-head-gap { height: var(--lh-top); }
.clinic-head {
    position: relative; display: flex; align-items: center; gap: 5mm;
    padding: 13mm var(--lh-side) 6mm; font-family: "Canva Sans", "Poppins", "Segoe UI", Arial, sans-serif; color: #000;
}
.lh-head-gap + .clinic-head { padding-top: 0; }
.clinic-logo { width: 30mm; height: 30mm; object-fit: contain; flex: none; }
.clinic-logo-ph {
    display: flex; align-items: center; justify-content: center; border: 2px dashed #b7c0bc;
    border-radius: 50%; color: #8a9690; font-weight: 700; font-size: 10pt;
}
.clinic-id { min-width: 0; }
.clinic-name { font-size: 22pt; font-weight: 700; line-height: 1.15; margin-bottom: 1.5mm; }
.clinic-line { font-size: 12pt; font-weight: 700; text-transform: uppercase; line-height: 1.3; }
.ind-no { position: absolute; top: 6mm; right: var(--lh-side); font-size: 11pt; letter-spacing: .02em; white-space: nowrap; }

.clinic-style .lh-body { font-family: "Times New Roman", Times, serif; font-size: 12pt; color: #000; }
.clinic-style .doc-text { font-size: 12pt; line-height: 1.5; text-align: justify; }
.clinic-style .doc-text p { margin: 0 0 4mm; }
.clinic-style .doc-indicator { padding: 0; margin: 0; border: 0; }
.heading-box {
    background: #000; color: #fff; text-align: center; font-family: "Times New Roman", Times, serif;
    font-weight: 700; font-size: 13.5pt; line-height: 1.45; padding: 7mm 12mm; margin: 4mm 0 9mm;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
}
.heading-box + .no-print { display: block; margin: -6mm 0 6mm; }
.sign-block { width: 62mm; margin: 14mm 0 0 auto; text-align: center; break-inside: avoid; }
.sign-img { display: block; max-width: 55mm; max-height: 28mm; margin: 0 auto -3mm; object-fit: contain; }
.sign-line { border-bottom: 1px solid #000; height: 16mm; margin: 0 6mm 2mm; }
.sign-role { font-weight: 700; font-size: 12pt; }
.sign-name { font-size: 10.5pt; }
.lh-divider .lh-body { height: 190mm; vertical-align: middle; text-align: center; }
.divider-text { font-family: "Canva Sans", "Poppins", "Segoe UI", Arial, sans-serif; font-size: 40pt; font-weight: 800; letter-spacing: .01em; }
.divider-sub { margin-top: 4mm; font-size: 14pt; color: #333; }

/* Facility form: logo / signature / standard picker */
.image-field { grid-column: span 1; margin-bottom: 14px; }
.image-row { display: flex; gap: 12px; align-items: center; }
.image-preview {
    width: 84px; height: 84px; flex: none; display: flex; align-items: center; justify-content: center;
    border: 1px dashed var(--border); border-radius: 8px; background: #fff; color: var(--muted); font-size: .75rem; text-align: center; overflow: hidden;
}
.image-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
.std-row { display: grid; grid-template-columns: minmax(220px, 1fr) 2fr; gap: 0 16px; align-items: start; }
.new-std { display: grid; grid-template-columns: 140px 1fr; gap: 0 12px; }
.new-std[hidden] { display: none; }
.auto-options { background: var(--brand-light); border-radius: 8px; padding: 12px 14px; margin-bottom: 14px; }
.auto-options label.check { margin-bottom: 6px; font-size: .9rem; }
@media (max-width: 600px) { .std-row, .new-std { grid-template-columns: 1fr; } }

/* ---------------- pop-up dialog (Add Index page) */
dialog.modal {
    width: min(520px, calc(100vw - 32px)); padding: 22px 24px; border: 0; border-radius: 14px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .25); color: var(--text);
}
dialog.modal::backdrop { background: rgba(16, 30, 24, .45); }
dialog.modal[open] { animation: modal-in .16s ease-out; }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.modal-head h2 { margin: 0; }
.modal-close { border: 0; background: none; font-size: 1.1rem; cursor: pointer; color: var(--muted); padding: 4px 8px; border-radius: 6px; }
.modal-close:hover { background: var(--bg); color: var(--text); }
.modal-grid { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 0 12px; margin-top: 10px; }
.index-preview {
    display: flex; flex-direction: column; align-items: center; gap: 2px; margin: 4px 0 16px; padding: 14px;
    border: 1px dashed var(--border); border-radius: 10px; background: #fafcfb;
}
.index-preview strong { font-size: 1.6rem; font-weight: 800; letter-spacing: .01em; }
@media (max-width: 480px) { .modal-grid { grid-template-columns: 1fr; } }

/* Index page rows in the indicator list */
.index-row td { background: #eef4fd; }
.index-label { font-size: 1.05rem; }
.doc-divider { text-align: center; padding: 120px 0; page-break-before: always; break-before: page; page-break-after: always; break-after: page; }

/* Index page printed on the uploaded Index page template */
.lh-index-sheet .ix-body { display: flex; flex-direction: column; min-height: 297mm; box-sizing: border-box; }
.lh-index-sheet .ix-center { flex: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
@media print {
    .lh-index-sheet .ix-body { min-height: 0; height: 296mm; }
}

/* ---------------- indicator / index page boxes (facility type page) */
.item-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.item-box {
    display: grid; grid-template-columns: 110px minmax(0, 1fr) auto; gap: 16px; align-items: center;
    padding: 14px 16px; border: 1px solid var(--border); border-left-width: 5px; border-radius: 10px; background: #fff;
    transition: box-shadow .15s ease, border-color .15s ease;
}
.item-box:hover { box-shadow: 0 4px 14px rgba(16, 40, 30, .08); }
.item-box:target { box-shadow: 0 0 0 3px rgba(11, 110, 79, .25); }
.item-ind { border-left-color: var(--brand); }
.item-index { border-left-color: var(--blue); background: var(--blue-bg); }
.item-tag { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.item-kind { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.item-index .item-kind { color: var(--blue); }
.item-no {
    font-family: Consolas, monospace; font-weight: 700; font-size: 1.05rem; color: var(--brand-dark);
    background: var(--brand-light); border-radius: 6px; padding: 2px 10px;
}
.item-title { display: block; font-weight: 700; font-size: 1rem; color: var(--brand-dark); line-height: 1.35; }
.item-index .item-title { font-size: 1.15rem; color: var(--text); }
.item-excerpt { margin-top: 3px; }
.item-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.item-actions { display: flex; gap: 6px; align-items: center; flex-wrap: nowrap; }
.item-group-title { margin: 10px 0 2px; font-weight: 700; color: var(--brand-dark); font-size: .9rem; text-transform: uppercase; letter-spacing: .04em; }
@media (max-width: 760px) {
    .item-box { grid-template-columns: 1fr; gap: 8px; }
    .item-tag { flex-direction: row; align-items: center; }
    .item-actions { flex-wrap: wrap; }
}

/* ---------------- page specification (from the uploaded page templates)
   Margin box: 15 mm top/sides, 17 mm bottom (set on the template cards).
   IND NO.: Canva Sans 14, top-right above the margin box.
   Facility name: Canva Sans 22 · address / PHC # / PMDC: Canva Sans 12.
   Heading: Times New Roman 16, white on a black box as wide as the text area, height follows the heading.
   Text: Times New Roman 14 · Sign & stamp: right side, straight after the text.
   Index page: header + "ROM Ind 01-10" in large Canva Sans, centred. */
.clinic-head { padding: var(--lh-top) var(--lh-side) 0; gap: 4mm; align-items: flex-start; }
.clinic-logo { width: 29mm; height: 29mm; }
.clinic-id { padding-top: 3mm; }
.clinic-name { font-size: 22pt; font-weight: 700; line-height: 1.1; margin-bottom: 1mm; }
.clinic-line { font-size: 12pt; font-weight: 700; line-height: 1.25; text-transform: uppercase; }
.ind-no {
    top: max(2mm, calc(var(--lh-top) - 7mm)); right: var(--lh-side);
    font-family: "Canva Sans", "Poppins", "Segoe UI", Arial, sans-serif; font-size: 14pt; font-weight: 400;
}
.clinic-style .lh-body, .page-text { font-family: "Times New Roman", Times, serif; font-size: 14pt; color: #000; }
.clinic-style .doc-text, .page-text { font-size: 14pt; line-height: 1.5; text-align: justify; }
.clinic-style .doc-text p, .page-text p { margin: 0 0 4mm; }
.heading-box {
    font-family: "Times New Roman", Times, serif; font-size: 16pt; font-weight: 700; line-height: 1.45;
    padding: 3.5mm 8mm; margin: 14mm 0 9mm;
}
.sign-block { margin: 8mm 0 0 auto; width: 58mm; font-family: "Times New Roman", Times, serif; }
.sign-role { font-size: 14pt; }
.sign-name { font-size: 12pt; }
.lh-divider .lh-body { height: calc(297mm - var(--lh-top) - var(--lh-bottom) - 33mm); }
.divider-text { font-size: 46pt; font-weight: 800; line-height: 1.1; }

.list-footer { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; border-top: 1px solid var(--border); padding-top: 14px; margin-top: 4px; }

/* ---------------- live A4 editor (indicator form) */
.a4-editor { margin-top: 6px; }
.a4-toolbar .rte-toolbar { border: 1px solid var(--border); border-radius: 8px; position: sticky; top: var(--topbar-h); }
.a4-meter {
    display: flex; flex-wrap: wrap; gap: 6px 18px; align-items: center; font-size: .85rem; color: var(--muted);
    padding: 8px 4px; position: sticky; top: calc(var(--topbar-h) + 44px); z-index: 3; background: var(--surface);
}
.a4-status { font-weight: 600; }
.a4-status.is-ok { color: var(--green); }
.a4-status.is-near { color: var(--orange); }
.a4-status.is-over { color: var(--red); }
.a4-scroll { overflow-x: auto; background: #e9eeec; border-radius: 10px; padding: 20px; }
.a4-page {
    position: relative; width: 210mm; min-height: 297mm; margin: 0 auto; background: #fff;
    box-shadow: 0 2px 16px rgba(0, 0, 0, .12); color: #000;
}
.a4-body { padding: 0 var(--lh-side); }
.a4-page .heading-box { white-space: pre-wrap; }
.rte-inpage { border: 0; margin: 0; background: transparent; }
.rte-page {
    min-height: 30mm; max-height: none; overflow: visible; padding: 0; border-radius: 0;
    outline: 1px dashed transparent; outline-offset: 3mm;
}
.rte-page:focus { outline-color: rgba(11, 110, 79, .35); }
.a4-end {
    position: absolute; left: 0; right: 0; top: calc(297mm - var(--lh-bottom)); border-top: 2px dashed #c0352b;
    pointer-events: none;
}
.a4-end span {
    position: absolute; right: 6px; top: -20px; font: 600 11px/1 "Segoe UI", Arial, sans-serif; color: #c0352b;
    background: #fff; padding: 3px 6px; border-radius: 4px;
}
.a4-page:not(.a4-over) .a4-end { border-top-color: #b7c0bc; }
.a4-page:not(.a4-over) .a4-end span { color: var(--muted); }
.a4-over { box-shadow: 0 0 0 3px rgba(192, 53, 43, .35), 0 2px 16px rgba(0, 0, 0, .12); }
.a4-over::after {
    content: ''; position: absolute; left: 0; right: 0; top: calc(297mm - var(--lh-bottom)); bottom: 0;
    background: rgba(192, 53, 43, .08); pointer-events: none;
}

/* mini A4 preview in the Add Index page pop-up (scaled) */
.mini-a4 { width: calc(210mm * .36); height: calc(297mm * .36); margin: 4px auto 16px; overflow: hidden; border-radius: 4px; box-shadow: 0 2px 12px rgba(0, 0, 0, .15); }
.mini-a4 .a4-page { transform: scale(.36); transform-origin: 0 0; box-shadow: none; height: 297mm; }
.a4-index-text {
    position: absolute; left: 0; right: 0; top: 50%; transform: translateY(-50%); text-align: center;
    font-family: "Canva Sans", "Poppins", "Segoe UI", Arial, sans-serif; font-size: 46pt; font-weight: 800; line-height: 1.1;
}
dialog.modal { width: min(560px, calc(100vw - 32px)); }

/* "Is the owner / in-charge a doctor?" on the client form */
.doctor-q { margin-bottom: 14px; }
.doctor-q .radio-row { margin: 4px 0 10px; }
.doctor-q label[hidden], .doctor-q p[hidden] { display: none; }

/* ---------------- page parts + image slots */
.page-parts { display: flex; flex-wrap: wrap; gap: 6px 22px; align-items: center; padding: 10px 14px; background: var(--bg); border-radius: 8px; margin-bottom: 14px; }
.page-parts .label-plain { margin: 0 6px 0 0; }
.page-parts label.check { margin: 0; }
.image-slots { border: 1px dashed var(--border); border-radius: 10px; padding: 12px 14px; margin-bottom: 16px; }
.slot-list { display: flex; flex-direction: column; gap: 8px; margin: 8px 0 10px; }
.slot-list:empty { margin: 0; }
.slot-row { display: grid; grid-template-columns: 26px minmax(0, 1fr) auto; gap: 8px; align-items: center; }
.slot-no { font-weight: 700; color: var(--muted); text-align: right; }
[data-a4-images] { display: flow-root; }
[hidden][data-part] { display: none !important; }
.no-header .heading-box { margin-top: 0; }
.a4-page.no-header .a4-body { padding-top: var(--lh-top); }

/* images printed on an indicator page (max 6, inside the margins) */
.page-images { display: grid; gap: 4mm; margin: 6mm 0 0; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.page-images.n-1 { grid-template-columns: minmax(0, 1fr); }
.page-images.n-3, .page-images.n-5, .page-images.n-6 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.page-image { margin: 0; break-inside: avoid; text-align: center; }
.page-image img, .page-image-ph { display: block; width: 100%; height: 55mm; object-fit: contain; border: 1px solid #bbb; background: #fff; }
.page-images.n-1 .page-image img, .page-images.n-1 .page-image-ph { height: 100mm; }
.page-images.n-2 .page-image img, .page-images.n-2 .page-image-ph { height: 70mm; }
.page-images.n-5 .page-image img, .page-images.n-5 .page-image-ph,
.page-images.n-6 .page-image img, .page-images.n-6 .page-image-ph { height: 45mm; }
.page-image-ph { display: flex; align-items: center; justify-content: center; border-style: dashed; color: #888; font: 11pt "Segoe UI", Arial, sans-serif; background: #fafafa; }
.page-image figcaption { font-family: "Times New Roman", Times, serif; font-size: 11pt; margin-top: 1.5mm; line-height: 1.25; }

/* client: image uploads on the indicator */
.slot-uploads { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; margin: 8px 0 4px; }
.slot-card { border: 1px solid var(--border); border-radius: 10px; padding: 10px; background: #fff; }
.slot-card.missing { border-color: #f4d6ad; background: #fffaf3; }
.slot-card .slot-thumb { height: 120px; display: flex; align-items: center; justify-content: center; background: var(--bg); border-radius: 6px; overflow: hidden; margin-bottom: 8px; color: var(--muted); font-size: .8rem; }
.slot-card .slot-thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.slot-card .slot-label { font-weight: 600; font-size: .9rem; margin-bottom: 6px; }
.slot-card input[type=file] { font-size: .8rem; width: 100%; }

/* ================================================================ pages (A4 sheets) */
@font-face {
    font-family: "PHC Nastaleeq";
    src: local("Jameel Noori Nastaleeq"), url("../fonts/JameelNooriNastaleeq.ttf") format("truetype");
    font-display: swap;
}
.pg {
    position: relative; width: 210mm; height: 297mm; box-sizing: border-box; overflow: hidden;
    padding: var(--lh-top, 15mm) var(--lh-side, 15mm) var(--lh-bottom, 17mm);
    display: flex; flex-direction: column; background: #fff; color: #000;
    font-family: "Times New Roman", Times, serif; font-size: 14pt;
}
.pg-indno {
    position: absolute; top: max(2mm, calc(var(--lh-top, 15mm) - 8mm)); right: var(--lh-side, 15mm);
    font-family: "Canva Sans", "Poppins", "Segoe UI", Arial, sans-serif; font-size: 14pt; white-space: nowrap;
}
.pg-head .clinic-head { padding: 0; }
.pg-head { flex: none; }
.pg .heading-box { flex: none; margin: 10mm 0 8mm; }
.pg-indno + .heading-box, .pg > .heading-box:first-child, .pg-head[hidden] + .heading-box { margin-top: 4mm; }
.pg-text { flex: none; }
.pg .doc-text, .pg .page-text { font-size: 14pt; line-height: 1.5; text-align: justify; }
.pg .doc-text p, .pg .page-text p { margin: 0 0 4mm; }
.pg-sign { flex: none; margin-top: 6mm; align-self: flex-end; }
.pg .sign-block { margin: 0; }

/* Urdu: Jameel Noori Nastaleeq, right-to-left; the sign & stamp moves to the left (flex-end in RTL) */
.pg-ur .pg-text, .pg-ur .page-text, .pg-ur .heading-box, .pg-ur .pg-img-h {
    font-family: "PHC Nastaleeq", "Jameel Noori Nastaleeq", "Noto Nastaliq Urdu", serif;
}
.pg-ur .doc-text, .pg-ur .page-text { font-size: 16pt; line-height: 2.1; text-align: right; }
.pg-ur .heading-box { font-size: 18pt; line-height: 1.9; }

/* Images (max 6) inside the margins:
   1 = centred · 2 = top / bottom · 3 = one column · 4 = 2 × 2 · 5 = 2 + 2 + 1 · 6 = two columns × 3 */
.pg-images-wrap { display: contents; }
.pg-images { flex: 1 1 auto; display: grid; gap: 5mm; margin-top: 6mm; grid-template-columns: 1fr; grid-template-rows: 1fr; min-height: 45mm; }
.pg-images.n-2 { grid-template-rows: 1fr 1fr; min-height: 70mm; }
.pg-images.n-3 { grid-template-rows: 1fr 1fr 1fr; min-height: 90mm; }
.pg-images.n-4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; min-height: 70mm; }
.pg-images.n-5, .pg-images.n-6 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr 1fr; min-height: 90mm; }
.pg-images.n-5 .pg-img:nth-child(5) { grid-column: 1 / -1; justify-self: center; width: calc(50% - 2.5mm); }
.pg-img { margin: 0; min-height: 0; min-width: 0; display: flex; flex-direction: column; }
.pg-img-h { flex: none; text-align: center; font-weight: 700; font-size: 12pt; margin-bottom: 1.5mm; line-height: 1.3; }
.pg-img-box { position: relative; flex: 1 1 auto; min-height: 0; }
.pg-img-box img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.pg-img-ph {
    position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 3mm;
    border: 1px dashed #9aa; background: #fafbfb; color: #778; font: 10.5pt "Segoe UI", Arial, sans-serif;
}

/* index page sheet */
.pg-index .pg-center { flex: 1; display: flex; align-items: center; justify-content: center; text-align: center; }

/* client fields */
.fld { background: #fff3c4; border-bottom: 2px solid #e0a800; padding: 0 2px; border-radius: 2px; font-weight: 700; }
.fld-img { background: #e3f0ff; border-bottom-color: #3b82f6; }
.pg-edit strong.is-field, .pg-edit b.is-field { background: #fff3c4; box-shadow: inset 0 -2px 0 #e0a800; }
.fld-val { background: #e8f0fc; border-radius: 2px; padding: 0 1px; }
.fld-val.is-empty { color: #8a94a6; font-style: italic; font-weight: 400; }
.fld-image { max-height: 40mm; max-width: 70mm; vertical-align: middle; }
.fld-blank { color: #8a94a6; }

/* page list on screen / print */
.pg-doc { padding: 24px 0; }
.pg-doc .pg { margin: 0 auto 24px; box-shadow: 0 2px 16px rgba(0, 0, 0, .12); }
.pg-mini { width: calc(210mm * .5); height: calc(297mm * .5); overflow: hidden; border: 1px solid var(--border); border-radius: 4px; background: #fff; flex: none; }
.pg-mini .pg { transform: scale(.5); transform-origin: 0 0; }
@media print {
    @page { size: A4; margin: 0; }
    .pg-doc { padding: 0; }
    .pg-doc .pg { margin: 0; box-shadow: none; page-break-after: always; break-after: page; }
    .pg-doc .pg:last-child { page-break-after: auto; break-after: auto; }
    .fld-val, .fld-val.is-empty { background: none; }
    .pg .heading-box, .pg-img-ph { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* page editor */
.pg-edit { overflow: visible; margin: 0 auto; box-shadow: 0 2px 16px rgba(0, 0, 0, .12); }
.pg-edit .a4-end { top: calc(297mm - var(--lh-bottom, 17mm)); }
.pg-edit .rte-page { min-height: 20mm; }
.page-fields-grid { display: grid; grid-template-columns: 200px 1fr; gap: 0 16px; }
.page-fields-grid .span-wide { grid-column: 2; }
.page-fields-grid label:only-child { grid-column: 1 / -1; }
.pdf-drop {
    display: grid; grid-template-columns: auto 1fr auto; gap: 6px 14px; align-items: center; margin: 4px 0 16px;
    padding: 14px 16px; border: 2px dashed #b7c9c0; border-radius: 10px; background: #f7fbf9;
}
.pdf-icon { font-size: 1.8rem; }
.pdf-status { grid-column: 1 / -1; font-size: .88rem; }
.pdf-status:empty { display: none; }
.pdf-status.is-ok { color: var(--green); }
.pdf-status.is-error { color: var(--red); }
.page-switches { display: flex; flex-wrap: wrap; gap: 10px 28px; align-items: flex-end; }
.page-switches > label { min-width: 240px; margin-bottom: 0; }
.yesno { display: flex; align-items: center; gap: 14px; padding: 8px 12px; background: var(--bg); border-radius: 8px; }
.yesno .label-plain { margin: 0; }
.yesno label.check { margin: 0; }
.slot-row2 { display: grid; grid-template-columns: 26px minmax(0, 1fr) auto; gap: 8px; align-items: start; }
.slot-row2 .slot-no { padding-top: 9px; }
.slot-fields { display: flex; flex-direction: column; gap: 6px; }
.slot-heading[hidden] { display: none; }
.slot-actions { display: flex; gap: 6px; padding-top: 3px; }
.field-list { display: flex; flex-direction: column; gap: 8px; }
.field-row { display: grid; grid-template-columns: 26px minmax(0, 1fr) 230px; gap: 10px; align-items: center; }
.field-no { color: var(--muted); font-weight: 700; text-align: right; }
@media (max-width: 700px) { .page-fields-grid, .field-row { grid-template-columns: 1fr; } .page-fields-grid .span-wide { grid-column: auto; } }

.item-order { border-left-color: #7c3aed; background: #f6f2ff; }
.item-order .item-kind { color: #6d28d9; }

/* client: fill-in form beside the live A4 page */
.fill-grid { display: grid; grid-template-columns: minmax(260px, 1fr) auto; gap: 20px; align-items: start; }
.fill-grid.is-order { grid-template-columns: 1fr; }
.fill-inputs h3 { margin-top: 4px; }
.fill-inputs .slot-card { margin-bottom: 10px; }
.fill-preview { position: sticky; top: calc(var(--topbar-h) + 12px); }
.pg-zoom { zoom: .62; }
.pg-zoom .pg { box-shadow: 0 2px 16px rgba(0, 0, 0, .15); }
.fill-grid.is-order .fill-preview { position: static; overflow-x: auto; background: #e9eeec; padding: 16px; border-radius: 10px; }
.fill-grid.is-order .pg { margin: 0 auto; }
@media (max-width: 1250px) { .fill-grid { grid-template-columns: 1fr; } .fill-preview { position: static; overflow-x: auto; } }

.review-page { margin: 8px 0 12px; }
.review-page .pg { margin: 0; box-shadow: 0 1px 8px rgba(0,0,0,.12); }

/* "Make field" suggestions (bold text that is not underlined) */
.field-suggest { margin-top: 14px; padding: 12px 14px; background: var(--bg); border-radius: 8px; }
.field-suggest[hidden] { display: none; }
.suggest-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.suggest-chip { display: inline-flex; align-items: center; gap: 8px; padding: 4px 4px 4px 10px; background: #fff; border: 1px solid var(--border); border-radius: 999px; font-size: .88rem; }
.pg-edit u.is-field, .pg-edit strong.is-field u, .pg-edit u.is-field strong { text-decoration-color: #e0a800; }

/* Black heading box inside page text (<h2>, from a PDF's white-on-black heading or the ▬ H button) */
.pg .pg-text h2, .pg .page-text h2, .pg .doc-text h2 {
    background: #000; color: #fff; text-align: center; font-family: "Times New Roman", Times, serif;
    font-weight: 700; font-size: 16pt; line-height: 1.45; padding: 3.5mm 8mm; margin: 6mm 0 8mm;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
}
.pg-ur .pg-text h2, .pg-ur .page-text h2 { font-family: "PHC Nastaleeq", "Jameel Noori Nastaleeq", serif; font-size: 18pt; line-height: 1.9; }
.pg .pg-text > h2:first-child, .pg .page-text > h2:first-child { margin-top: 10mm; }
.pg-head[hidden] ~ .pg-text > h2:first-child, .pg-head[hidden] ~ .pg-text .page-text > h2:first-child { margin-top: 4mm; }
.page-fields-grid label { max-width: 260px; }

/* Copy to other facility types */
.copy-list { display: flex; flex-direction: column; gap: 8px; margin: 12px 0 16px; padding: 12px 14px; background: var(--bg); border-radius: 8px; }
.copy-list label.check { margin: 0; flex-wrap: wrap; }

/* Line spacing of page text: --pg-lh set per page (default 1.15); small gap between paragraphs */
.pg .doc-text, .pg .page-text { line-height: var(--pg-lh, 1.15); }
.pg .doc-text p, .pg .page-text p, .pg .doc-text li, .pg .page-text li { margin: 0 0 1.5mm; }
.pg .doc-text ol, .pg .doc-text ul, .pg .page-text ol, .pg .page-text ul { margin: 0 0 1.5mm; }
.pg-ur .doc-text, .pg-ur .page-text { line-height: calc(var(--pg-lh, 1.15) + 0.75); }
.pg-ur .doc-text p, .pg-ur .page-text p { margin-bottom: 1mm; }
.spacing-select { min-width: 140px !important; }

/* Client fields panel: editable names, actions, add field */
.field-row { grid-template-columns: 26px minmax(0, 1fr) 210px auto; }
.fld-edit { border: 0; border-bottom: 2px solid #e0a800; background: #fff3c4; border-radius: 4px 4px 0 0; padding: 6px 8px; font-weight: 700; width: 100%; font-family: inherit; }
.fld-edit:focus { outline: 2px solid rgba(224, 168, 0, .45); background: #fffbe8; }
.field-actions { display: flex; gap: 4px; }
.field-add { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--border); }
.field-add input { flex: 0 1 280px; }
.fld-flash { animation: fld-flash 1.6s ease; }
@keyframes fld-flash { 0%, 60% { background: #ffd54a; box-shadow: 0 0 0 4px #ffd54a; } 100% { } }
@media (max-width: 700px) { .field-row { grid-template-columns: 1fr; } }
.form .field-row input.fld-edit { border: 0; border-bottom: 2px solid #e0a800; background: #fff3c4; border-radius: 4px 4px 0 0; padding: 7px 9px; font-weight: 700; }
.form .field-row input.fld-edit:focus { background: #fffbe8; outline: 2px solid rgba(224, 168, 0, .45); }
.field-actions .btn-icon { min-width: 34px; font-size: .95rem; }

/* Sign & stamp: compact, directly below the end of the text (client's signature/stamp image is scaled down to fit) */
.pg .pg-sign { margin-top: 3mm; }
.pg .sign-block { width: 50mm; line-height: 1.2; }
.pg .sign-img { display: block; max-width: 45mm; max-height: 18mm; width: auto; height: auto; margin: 0 auto 0.5mm; object-fit: contain; }
.pg .sign-line { height: 9mm; margin: 0 4mm 1mm; }
.pg .sign-role { font-size: 12pt; }
.pg .sign-name { font-size: 10pt; }
.pg .pg-images + .pg-sign { margin-top: 3mm; }

/* Without a header, content starts at the top margin (same as the sides); gaps only below something */
.pg .pg-text > h2:first-child, .pg .page-text > h2:first-child { margin-top: 0; }
.pg .pg-head:not([hidden]) + .pg-text > h2:first-child,
.pg .pg-head:not([hidden]) + .pg-text .page-text > h2:first-child { margin-top: 10mm; }
.pg > .pg-indno + .pg-images, .pg > .pg-images:first-child { margin-top: 0; }
.pg > .pg-head + .pg-images { margin-top: 8mm; }
.pg-edit .rte-page { min-height: 7mm; }
.pg-edit.pg-notext .pg-head[hidden] + .pg-text + .pg-images-wrap .pg-images,
.pg-edit.pg-notext .pg-head[hidden] + .pg-text + .pg-images-wrap > .pg-images { margin-top: 1mm; }

/* ================================================================ free layout (movable boxes, like Canva) */
.pg .pg-free { position: absolute; inset: 0; }
.pg-box { position: absolute; box-sizing: border-box; min-height: 5mm; }
.pg-box > :first-child, .pg .pg-text .pg-box > h2:first-child { margin-top: 0; }
.pg-box > :last-child { margin-bottom: 0; }
.pg-box-images { display: flex; }
.pg-box-images .pg-images { flex: 1; height: 100%; margin: 0 !important; min-height: 0; }
.pg-box-sign .sign-block { margin: 0 auto; }
.pg-box h2 { margin: 0; }

/* editor */
.pg-free-mode [data-pg-images], .pg-free-mode > [data-part="sign"] { display: none !important; }
.pg-free-mode .pg-text { position: absolute; inset: 0; }
.pg-free-mode .rte-inpage { position: absolute; inset: 0; }
.pg-free-mode .pg-free-canvas { position: absolute; inset: 0; min-height: 0; padding: 0; outline: none; }
.pg-free-canvas .pg-box { outline: 1px dashed rgba(11, 110, 79, .35); outline-offset: 1px; cursor: text; }
.pg-free-canvas .pg-box:hover { outline-color: rgba(11, 110, 79, .75); }
.pg-free-canvas .pg-box.is-selected { outline: 2px solid #0b6e4f; }
.pg-free-canvas .pg-box.is-dragging { opacity: .85; }
.pg-free-canvas .pg-box-images, .pg-free-canvas .pg-box-sign { cursor: default; }
.pg-free-canvas .pg-box:focus { outline: 2px solid #0b6e4f; }
.pg-box-tools {
    position: absolute; z-index: 30; display: flex; gap: 2px; padding: 2px; border-radius: 7px;
    background: #0b6e4f; box-shadow: 0 3px 10px rgba(0, 0, 0, .2); font: 13px/1 "Segoe UI", Arial, sans-serif; user-select: none;
}
.pg-box-tools[hidden] { display: none; }
.pg-box-tools .bt { color: #fff; padding: 5px 8px; border-radius: 5px; background: none; border: 0; font: inherit; touch-action: none; }
.pg-box-tools .bt:hover { background: rgba(255, 255, 255, .18); }
.pg-box-tools .bt-drag { cursor: grab; }
.pg-box-tools .bt-w { cursor: ew-resize; }
.pg-box-tools .bt-h { cursor: ns-resize; }
.pg-box-tools .bt-h[hidden] { display: none; }
.pg-box-tools .bt-del { cursor: pointer; }
.free-bar { margin: 6px 0 2px; }
.free-bar [hidden] { display: none; }

/* Flowing text: pictures start 2 lines below the header when there is no text */
.pg > .pg-head + .pg-images { margin-top: calc(28pt * var(--pg-lh, 1.15)); }

/* page number (position in the printed document) on the list boxes */
.item-pageno { font-size: .72rem; font-weight: 600; color: var(--muted); background: var(--bg); border: 1px solid var(--border); border-radius: 999px; padding: 1px 8px; white-space: nowrap; }

/* Text size of page text: --pg-fs set per page (default 14 pt) */
.pg .doc-text, .pg .page-text { font-size: var(--pg-fs, 14pt); }
.pg .doc-text td, .pg .doc-text th { text-align: left; }

/* Client "Indicators": all fields in one place, grouped by kind of page */
.cat-tabs { margin: 0 0 14px; }
.chip-count { display: inline-block; margin-left: 4px; padding: 0 6px; border-radius: 999px; font-size: .75rem; background: rgba(0, 0, 0, .06); }
.chip.active .chip-count { background: rgba(255, 255, 255, .25); }
.chip-count.all-done { background: var(--green-bg); color: var(--green); }
.ind-group { margin-bottom: 12px; }
.ind-group-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 4px; }
.ind-group-title { flex: 1; min-width: 200px; display: flex; flex-direction: column; line-height: 1.3; }
.fld-row { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 6px 18px; align-items: center; padding: 10px 0 10px 10px; border-top: 1px solid var(--border); border-left: 3px solid #f4d6ad; }
.fld-row.is-done { border-left-color: var(--green); }
.fld-label { font-weight: 600; }
.fld-ctx { font-size: .84rem; color: var(--muted); margin-top: 2px; line-height: 1.45; }
mark.fld-mark { background: #fff2b3; color: var(--text); font-weight: 600; padding: 0 3px; border-radius: 3px; }
.fld-input input[type=text] { width: 100%; }
.fld-input input[type=file] { max-width: 100%; }
.fld-thumb { display: block; max-height: 90px; max-width: 160px; border-radius: 6px; border: 1px solid var(--border); margin-bottom: 6px; }
@media (max-width: 760px) { .fld-row { grid-template-columns: 1fr; } }

/* Template list: filter by kind of page */
.cat-filter { margin-bottom: 12px; }
.item-box[hidden] { display: none; }
.basics-group { margin: 16px 0 2px; font-size: 1rem; color: var(--brand); }

/* Facility form: doctors, one row each (name + PMDC No.) */
.doctors-field { display: flex; flex-direction: column; gap: 8px; }
.doctor-row { display: grid; grid-template-columns: 150px minmax(0, 1.4fr) minmax(0, 1fr) auto; gap: 10px; align-items: end; }
.doctor-no { font-weight: 600; font-size: .85rem; color: var(--brand); padding-bottom: 10px; }
.doctors-field [data-doctor-add] { align-self: flex-start; }
@media (max-width: 760px) { .doctor-row { grid-template-columns: 1fr 1fr auto; } .doctor-no { grid-column: 1 / -1; padding: 0; } }
