/* ============================================================
   One-page report tab (รายงานสรุป 1 หน้า)
   แผ่นรายงานกว้างเท่าพื้นที่พิมพ์ A4 แนวตั้ง (194mm) เพื่อให้หน้าจอ = กระดาษ
   ============================================================ */
.op-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin-bottom: 18px;
}
.op-toolbar select {
    padding: 8px 12px;
    border: 2px solid rgba(16, 185, 129, .2);
    border-radius: 10px;
    font-family: 'Sarabun', sans-serif;
    font-size: .92em;
    background: #fff;
}
.op-toolbar select:disabled { opacity: .5; }
.op-scope {
    display: flex;
    background: #e8f5f0;
    border: 1px solid #c5e8d9;
    border-radius: 22px;
    padding: 4px;
    gap: 4px;
}
.op-scope button {
    border: none;
    background: transparent;
    padding: 6px 16px;
    border-radius: 18px;
    font-family: 'Sarabun', sans-serif;
    font-size: .88rem;
    font-weight: 600;
    color: #065f46;
    cursor: pointer;
}
.op-scope button.active { background: #059669; color: #fff; }
.op-btn {
    padding: 8px 18px;
    border: none;
    border-radius: 10px;
    background: linear-gradient(135deg, #059669, #10b981);
    color: #fff;
    font-family: 'Sarabun', sans-serif;
    font-weight: 600;
    font-size: .92em;
    cursor: pointer;
}
.op-btn.secondary { background: #fff; color: #065f46; border: 2px solid #a7f3d0; }
.op-toolbar .op-spacer { flex: 1; }

/* ── Sheet (ดีไซน์ตาม template: แบบเปล่า.png → assets/onepage-template.png) ── */
.op-stage { display: flex; justify-content: center; padding: 6px 0 24px; }
#op-sheet {
    --op-navy: #0b3a7e;
    --op-blue: #1d6fd6;
    --op-teal: #0f9b8e;
    --op-mint: #d9f6ea;
    --op-line: #d6e6f8;
    width: 194mm;              /* = ความกว้างพื้นที่พิมพ์ (A4 210mm − ขอบ 8mm×2) */
    min-height: 120mm;
    box-sizing: content-box;
    background: linear-gradient(180deg, #e4f0fd 0%, #f1f7ff 35%, #eef5fe 100%);
    color: #10233f;
    padding: 6mm 7mm 7mm 9mm;
    box-shadow: 0 4px 24px rgba(15, 23, 42, .12);
    border-radius: 6px;
    font-family: 'Sarabun', sans-serif;
    font-size: 11.5px;
    line-height: 1.4;
}
.op-empty { text-align: center; color: #7b8aa3; padding: 60px 0; font-size: 14px; background: rgba(255,255,255,.7); border-radius: 12px; margin-top: 8px; }

/* hero */
.op-hero { display: flex; justify-content: space-between; gap: 8px; min-height: 150px; }
.op-hero-left { flex: 1; min-width: 0; padding-top: 2px; }
.op-kicker {
    display: inline-block;
    background: linear-gradient(90deg, #08306b, #1d6fd6);
    color: #fff; font-weight: 700; font-size: 14px;
    padding: 3px 26px 3px 14px;
    border-radius: 14px 22px 22px 4px;
    box-shadow: 0 2px 6px rgba(11, 58, 126, .25);
}
.op-title {
    font-size: 30px; font-weight: 800; line-height: 1.15; margin-top: 4px;
    background: linear-gradient(90deg, #0b3a7e, #1d6fd6);
    -webkit-background-clip: text; background-clip: text; color: transparent;
}
.op-title i { color: #0b3a7e; font-size: 24px; -webkit-text-fill-color: #0b3a7e; }
.op-title2 { font-size: 17px; font-weight: 700; color: #0b3a7e; line-height: 1.2; }
.op-scopebar {
    display: inline-flex; align-items: center; gap: 10px;
    margin-top: 6px; max-width: 100%;
    background: linear-gradient(90deg, #0b5fa8, #0f9b8e);
    color: #fff; font-weight: 700; font-size: 16px;
    padding: 5px 22px 5px 10px;
    border-radius: 10px 26px 26px 10px;
    box-shadow: 0 3px 8px rgba(15, 155, 142, .3);
}
.op-scopebar i {
    background: rgba(255,255,255,.18); border-radius: 6px; padding: 4px 5px; font-size: 14px;
}
.op-scopebar span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.op-hero-sub { font-size: 10.5px; color: #36507a; margin-top: 3px; }
.op-hero-right { position: relative; width: 290px; flex-shrink: 0; }
.op-hero-img {
    position: absolute; right: -7mm; top: -6mm;
    width: 306px; height: 150px;
    background: url('assets/onepage-template.png') no-repeat;
    background-size: 688px auto;
    background-position: -381px 0;
    -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 18%);
            mask-image: linear-gradient(90deg, transparent 0, #000 18%);
}
.op-fybadge {
    position: absolute; right: 0; bottom: 24px;
    display: flex; align-items: center; gap: 8px;
    background: linear-gradient(90deg, #0e8a5f, #16a36f);
    color: #fff; border: 2px solid #fff; border-radius: 12px;
    padding: 4px 12px 4px 8px; box-shadow: 0 3px 8px rgba(14, 138, 95, .35);
}
.op-fybadge i { font-size: 20px; }
.op-fybadge b { display: block; font-size: 15px; line-height: 1.15; }
.op-fybadge span { font-size: 10px; }
.op-coverage {
    position: absolute; right: 0; bottom: 0;
    background: #fff; border: 1px solid var(--op-line); border-radius: 12px;
    padding: 1px 10px; font-size: 10px; font-weight: 600; color: #0b3a7e; white-space: nowrap;
}
.op-basis-note {
    margin-top: 6px; padding: 3px 9px; border-radius: 8px;
    background: rgba(29, 111, 214, .08); border: 1px solid #c4dcf7; color: #0b3a7e; font-size: 10px;
}

/* cards */
.op-section { margin-top: 7px; }
.op-section:not(.op-grid-2):not(.op-chart-row),
.op-grid-2.op-section > div,
.op-chart-row > div:first-child {
    background: rgba(255, 255, 255, .88);
    border: 1px solid var(--op-line);
    border-radius: 12px;
    padding: 0 8px 7px;
    box-shadow: 0 2px 8px rgba(29, 111, 214, .07);
}
.op-section h2 {
    position: relative;
    font-size: 13px; font-weight: 700; color: var(--op-navy);
    margin: 0 -8px 6px; padding: 4px 8px 4px 40px; min-height: 26px;
    display: flex; align-items: center; gap: 6px;
    background: linear-gradient(90deg, #9cc7f3 0%, #d7e8fb 45%, rgba(234, 243, 253, 0) 100%);
    border-radius: 12px 12px 0 0;
}
.op-section h2 > i {
    position: absolute; left: 4px; top: 50%; transform: translateY(-50%);
    width: 30px; height: 30px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 13px;
    background: radial-gradient(circle at 35% 30%, #4aa3f5, #0b5fc0);
    border: 2px solid #fff; box-shadow: 0 2px 5px rgba(11, 58, 126, .3);
}
.op-section h2.ic-green > i { background: radial-gradient(circle at 35% 30%, #34c27d, #0a7d4a); }
.op-section h2.ic-red > i   { background: radial-gradient(circle at 35% 30%, #f87171, #c0262d); }
.op-section h2 .op-note { font-weight: 400; color: #5b6f90; font-size: 10px; }

/* KPI cards */
.op-kpis { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-top: 8px; }
.op-kpi {
    background: rgba(255, 255, 255, .92);
    border: 1px solid var(--op-line);
    border-radius: 12px;
    padding: 5px 7px 6px;
    text-align: center;
    box-shadow: 0 2px 8px rgba(29, 111, 214, .08);
}
.op-kpi .k-head { display: flex; align-items: center; gap: 5px; text-align: left; }
.op-ic {
    width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0;
    display: inline-flex; align-items: center; justify-content: center;
    color: #fff; font-size: 12px; border: 2px solid #fff; box-shadow: 0 2px 4px rgba(11, 58, 126, .25);
}
.op-ic.ic-blue  { background: radial-gradient(circle at 35% 30%, #4aa3f5, #0b5fc0); }
.op-ic.ic-green { background: radial-gradient(circle at 35% 30%, #34c27d, #0a7d4a); }
.op-ic.ic-navy  { background: radial-gradient(circle at 35% 30%, #3b6fc4, #0b3a7e); }
.op-ic.ic-teal  { background: radial-gradient(circle at 35% 30%, #2cc4b3, #0f7f74); }
.op-ic.ic-amber { background: radial-gradient(circle at 35% 30%, #fbbf24, #c27c0e); }
.op-kpi .k-label { font-size: 11px; font-weight: 700; color: var(--op-navy); line-height: 1.15; }
.op-kpi .k-value { font-size: 22px; font-weight: 800; color: #0b1f3f; line-height: 1.25; margin-top: 3px; }
.op-kpi .k-value small { font-size: 12px; font-weight: 600; color: #0b3a7e; }
.op-kpi .k-sub { font-size: 9.5px; color: #3f5476; line-height: 1.3; }

.op-up   { color: #dc2626; font-weight: 700; }   /* เวลานานขึ้น = แย่ลง */
.op-down { color: #0a8a4f; font-weight: 700; }   /* เวลาลดลง = ดีขึ้น */
.op-flat { color: #6b7280; }

.op-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }

/* step bars */
.op-steps { display: grid; gap: 5px; }
.op-step {
    display: grid;
    grid-template-columns: 82px 1fr 84px;
    align-items: center;
    gap: 6px;
    font-size: 10.5px;
}
.op-step .s-label { font-weight: 700; color: #10233f; white-space: nowrap; }
.op-step .s-label i { width: 16px; margin-right: 4px; color: #0b3a7e; text-align: center; }
.op-step .s-track { position: relative; height: 12px; background: #e3edf9; border-radius: 6px; }
.op-step .s-bar { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 6px; }
.op-step .s-ref { position: absolute; top: -3px; bottom: -3px; width: 0; border-left: 2px dashed #334155; }
.op-step .s-val { text-align: right; white-space: nowrap; }
.op-step .s-val b { font-size: 12px; }
.op-legend { font-size: 9.5px; color: #4b5f80; margin-top: 4px; }
.op-legend .dash { display: inline-block; width: 12px; border-top: 2px dashed #334155; vertical-align: middle; }

/* tables */
.op-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 10.5px; }
.op-table th {
    background: var(--op-mint);
    color: #0b3a4e;
    font-weight: 700;
    padding: 3px 5px;
    text-align: right;
    white-space: nowrap;
}
.op-table th:first-child { border-radius: 6px 0 0 6px; }
.op-table th:last-child  { border-radius: 0 6px 6px 0; }
.op-table td { padding: 2.5px 5px; border-bottom: 1px solid #e6eef8; text-align: right; }
.op-table th:first-child, .op-table td:first-child { text-align: left; }
.op-table tr.op-total td { font-weight: 700; background: #eef5fe; border-top: 1px solid #c4dcf7; }
.op-table tr.op-hl td { background: #fff3b0; font-weight: 700; }
.op-table .op-name { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.op-rank td:first-child, .op-rank th:first-child { text-align: center; width: 38px; }

.op-pill {
    display: inline-block;
    min-width: 40px;
    text-align: center;
    padding: 0 6px;
    border-radius: 6px;
    font-weight: 700;
}
.op-pill.good { background: #c9f2dc; color: #08663d; }
.op-pill.mid  { background: #fdeeb5; color: #8a5a00; }
.op-pill.bad  { background: #fddcdc; color: #b4161c; }

/* chart + callout */
.op-chart-row { display: grid; grid-template-columns: 1fr 168px; gap: 7px; align-items: stretch; }
.op-chart { position: relative; height: 140px; }
.op-callout {
    border-radius: 12px; border: 2px solid #34c27d;
    background: linear-gradient(160deg, #eafbf2, #ffffff);
    display: flex; flex-direction: column; justify-content: center; align-items: center;
    text-align: center; padding: 6px; box-shadow: 0 2px 8px rgba(10, 125, 74, .12);
}
.op-callout .c-title { font-size: 13px; font-weight: 800; color: var(--op-navy); }
.op-callout .c-title i { color: #0a8a4f; font-size: 18px; margin-right: 4px; }
.op-callout .c-value { font-size: 26px; font-weight: 800; color: #0a8a4f; line-height: 1.15; }
.op-callout .c-value small { font-size: 14px; }
.op-callout .c-pct { font-size: 13px; font-weight: 700; color: #10233f; }
.op-callout .c-note { font-size: 9.5px; color: #3f5476; margin-top: 3px; }
.op-callout.up { border-color: #f87171; background: linear-gradient(160deg, #fdeeee, #ffffff); }
.op-callout.up .c-title i, .op-callout.up .c-value { color: #c0262d; }
.op-callout.flat { border-color: #c4dcf7; background: #fff; }

/* distribution bar */
.op-bands { display: flex; height: 22px; border-radius: 8px; overflow: hidden; font-size: 11px; color: #fff; font-weight: 700; }
.op-bands div { display: flex; align-items: center; justify-content: center; white-space: nowrap; }

/* findings */
.op-findings-card { position: relative; padding-right: 130px !important; min-height: 120px; }
.op-findings-card::after {
    content: ''; position: absolute; right: 4px; bottom: 2px;
    width: 125px; height: 110px;
    background: url('assets/onepage-template.png') no-repeat;
    background-size: 773px auto;
    background-position: -649px -953px;
    -webkit-mask-image: radial-gradient(ellipse at 60% 60%, #000 55%, transparent 78%);
            mask-image: radial-gradient(ellipse at 60% 60%, #000 55%, transparent 78%);
}
.op-findings { margin: 0; padding: 0; list-style: none; font-size: 11px; }
.op-findings li { position: relative; padding-left: 22px; margin-bottom: 3px; }
.op-findings li::before {
    content: '\f058'; font-family: 'Font Awesome 6 Free'; font-weight: 900;
    position: absolute; left: 2px; top: 0; color: #0f9b6a; font-size: 14px;
}

.op-foot {
    margin-top: 7px;
    padding-top: 4px;
    border-top: 1px solid #c4dcf7;
    font-size: 9px;
    color: #5b6f90;
    display: flex;
    justify-content: space-between;
    gap: 10px;
}

/* หัวหน้าแนบ */
.op-apphead {
    display: flex; justify-content: space-between; align-items: flex-end; gap: 12px;
    background: linear-gradient(90deg, #0b3a7e, #1d6fd6 60%, #0f9b8e);
    color: #fff; border-radius: 12px; padding: 6px 12px; margin-bottom: 6px;
}
.op-apphead h1 { font-size: 15px; margin: 0; line-height: 1.25; }
.op-apphead .op-sub { font-size: 10px; opacity: .9; margin-top: 2px; }
.op-apphead .op-meta { text-align: right; font-size: 10px; white-space: nowrap; }
.op-apphead .op-meta strong { font-size: 12px; }

/* หน้าแนบ: ตาราง รพ. ทุกแห่ง */
.op-appendix { margin-top: 14mm; padding-top: 6mm; border-top: 2px dashed #9cc7f3; }
.op-appendix .op-table-all { background: rgba(255,255,255,.9); border-radius: 8px; }
.op-table-all { font-size: 9.5px; }
.op-table-all td, .op-table-all th { padding: 2px 4px; }
.op-table-all tbody tr:nth-child(even) td { background: #f4f8fe; }
.op-table-all tr.op-unranked td { color: #9ca3af; font-style: italic; }
.op-table-all tr.op-nodata td { color: #b91c1c; background: #fef2f2 !important; }

/* ── Print / PDF ──
   หน้าแรก: เต็มแผ่น A4 ไม่มีขอบขาว (named page "opfirst") · หน้าแนบ: ขอบ 8mm
   printOnepage() ย้าย #op-sheet ไปไว้ใน #op-print-root (ลูกของ body) แล้วซ่อนส่วนอื่นทั้งหมด */
@media print {
    @page { size: A4 portrait; margin: 8mm; }
    @page opfirst { size: A4 portrait; margin: 0; }
    html, body.op-print { background: #fff !important; margin: 0 !important; padding: 0 !important; }
    body.op-print > *:not(#op-print-root) { display: none !important; }
    body.op-print * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    #op-print-root #op-sheet {
        width: auto; min-height: 0; margin: 0; padding: 0;
        background: none; box-shadow: none; border-radius: 0;
    }
    #op-print-root .op-page1 {
        page: opfirst;
        box-sizing: border-box;
        width: 210mm; height: 297mm; overflow: hidden;
        padding: 6mm 7mm 7mm 9mm;
        background: linear-gradient(180deg, #e4f0fd 0%, #f1f7ff 35%, #eef5fe 100%);
    }
    #op-print-root .op-page1 > * { zoom: var(--op-zoom, 1); }
    #op-print-root .op-kpi, #op-print-root .op-section h2 > i, #op-print-root .op-ic { box-shadow: none; }
    #op-print-root .op-appendix { break-before: page; margin-top: 0; padding-top: 0; border-top: none; }
    #op-print-root .op-table-all thead { display: table-header-group; }
    #op-print-root .op-table-all tr { break-inside: avoid; }
}
