/* ============================================================
   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 ── */
.op-stage { display: flex; justify-content: center; padding: 6px 0 24px; }
#op-sheet {
    width: 194mm;              /* = ความกว้างพื้นที่พิมพ์ (A4 210mm − ขอบ 8mm×2) */
    min-height: 120mm;
    box-sizing: content-box;
    background: #fff;
    color: #1f2937;
    padding: 7mm 8mm;
    box-shadow: 0 4px 24px rgba(15, 23, 42, .12);
    border-radius: 4px;
    font-family: 'Sarabun', sans-serif;
    font-size: 11.5px;
    line-height: 1.4;
}
.op-empty { text-align: center; color: #9ca3af; padding: 60px 0; font-size: 14px; }

.op-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 12px;
    border-bottom: 3px solid #059669;
    padding-bottom: 6px;
    margin-bottom: 8px;
}
.op-head h1 { font-size: 17px; margin: 0; color: #064e3b; line-height: 1.25; }
.op-head .op-sub { font-size: 11.5px; color: #4b5563; margin-top: 2px; }
.op-head .op-meta { text-align: right; font-size: 10.5px; color: #6b7280; white-space: nowrap; }
.op-head .op-meta strong { color: #065f46; font-size: 12px; }

.op-section { margin-top: 8px; }
.op-section h2 {
    font-size: 12.5px;
    margin: 0 0 4px;
    color: #065f46;
    display: flex;
    align-items: center;
    gap: 6px;
}
.op-section h2 .op-note { font-weight: 400; color: #9ca3af; font-size: 10px; }

.op-kpis { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.op-kpi {
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 5px 7px;
    background: #f9fafb;
}
.op-kpi .k-label { font-size: 10px; color: #6b7280; }
.op-kpi .k-value { font-size: 18px; font-weight: 700; color: #111827; line-height: 1.2; }
.op-kpi .k-value small { font-size: 10.5px; font-weight: 500; color: #6b7280; }
.op-kpi .k-sub { font-size: 10px; color: #6b7280; }
.op-kpi.good  { border-left: 4px solid #10b981; }
.op-kpi.mid   { border-left: 4px solid #f59e0b; }
.op-kpi.bad   { border-left: 4px solid #ef4444; }
.op-kpi.plain { border-left: 4px solid #94a3b8; }

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

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

/* step bars */
.op-steps { display: grid; gap: 3px; }
.op-step {
    display: grid;
    grid-template-columns: 70px 1fr 92px;
    align-items: center;
    gap: 6px;
    font-size: 10.5px;
}
.op-step .s-track { position: relative; height: 11px; background: #f1f5f9; border-radius: 3px; }
.op-step .s-bar { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 3px; }
.op-step .s-ref {
    position: absolute;
    top: -2px;
    bottom: -2px;
    width: 0;
    border-left: 2px dashed #334155;
}
.op-step .s-val { text-align: right; white-space: nowrap; }
.op-step .s-val b { font-size: 11.5px; }
.op-legend { font-size: 9.5px; color: #6b7280; margin-top: 3px; }
.op-legend .dash { display: inline-block; width: 12px; border-top: 2px dashed #334155; vertical-align: middle; }

/* tables */
.op-table { width: 100%; border-collapse: collapse; font-size: 10.5px; }
.op-table th {
    background: #ecfdf5;
    color: #065f46;
    font-weight: 600;
    padding: 3px 5px;
    border-bottom: 1px solid #a7f3d0;
    text-align: right;
    white-space: nowrap;
}
.op-table td { padding: 2.5px 5px; border-bottom: 1px solid #f1f5f9; 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: #f9fafb; border-top: 1px solid #d1d5db; }
.op-table tr.op-hl td { background: #fef9c3; font-weight: 600; }
.op-table .op-name { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.op-pill {
    display: inline-block;
    min-width: 34px;
    text-align: center;
    padding: 0 5px;
    border-radius: 8px;
    font-weight: 600;
}
.op-pill.good { background: #d1fae5; color: #065f46; }
.op-pill.mid  { background: #fef3c7; color: #92400e; }
.op-pill.bad  { background: #fee2e2; color: #991b1b; }

.op-chart { position: relative; height: 150px; }

.op-bands { display: flex; height: 16px; border-radius: 4px; overflow: hidden; font-size: 10px; color: #fff; font-weight: 600; }
.op-bands div { display: flex; align-items: center; justify-content: center; white-space: nowrap; }

.op-findings { margin: 0; padding-left: 16px; font-size: 11px; }
.op-findings li { margin-bottom: 2px; }

.op-foot {
    margin-top: 8px;
    padding-top: 4px;
    border-top: 1px solid #e5e7eb;
    font-size: 9.5px;
    color: #9ca3af;
    display: flex;
    justify-content: space-between;
    gap: 10px;
}

/* หน้าแนบ: ตาราง รพ. ทุกแห่ง */
.op-appendix { margin-top: 14mm; padding-top: 6mm; border-top: 2px dashed #d1d5db; }
.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: #f9fafb; }
.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: หน้าสรุป 1 หน้า A4 (+ หน้าแนบรายโรงพยาบาล) ── */
@media print {
    @page { size: A4 portrait; margin: 8mm; }
    body.op-print { background: #fff !important; }
    body.op-print .sidebar,
    body.op-print .top-bar,
    body.op-print .page-header,
    body.op-print #morning-banner,
    body.op-print .content-footer,
    body.op-print .op-toolbar,
    body.op-print #global-loading-overlay,
    body.op-print .tab-content:not(#onepage-tab) { display: none !important; }
    body.op-print .main-content { margin: 0 !important; padding: 0 !important; width: auto !important; }
    body.op-print .content-wrapper { padding: 0 !important; margin: 0 !important; }
    body.op-print .op-stage { padding: 0; display: block; }
    body.op-print #op-sheet {
        box-shadow: none;
        border-radius: 0;
        padding: 0;
        width: 194mm;
    }
    body.op-print .op-page1 { zoom: var(--op-zoom, 1); }
    body.op-print .op-appendix { break-before: page; margin-top: 0; padding-top: 0; border-top: none; }
    body.op-print .op-table-all thead { display: table-header-group; }
    body.op-print .op-table-all tr { break-inside: avoid; }
    body.op-print * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
