/* =====================================================================
   KDC_Denttrack — App CSS
   ===================================================================== */

/* ── Autocomplete Dropdown (shared — symptom, service, product) ─────── */
.dt-ac-drop {
    display: none; position: fixed; z-index: 9999;
    background: #fff; border: 1px solid #dee2e6; border-radius: .375rem;
    box-shadow: 0 4px 12px rgba(0,0,0,.15); max-height: 260px; overflow-y: auto;
}
.dt-ac-item {
    display: flex; justify-content: space-between; align-items: center;
    padding: 7px 12px; cursor: pointer; border-bottom: 1px solid #f1f5f9;
    font-size: .875rem;
}
.dt-ac-item:last-child { border-bottom: none; }
.dt-ac-item:hover { background: #f0f7ff; }
.dt-ac-item span { flex: 1; }
.dt-ac-item small { margin-left: 8px; white-space: nowrap; }

/* ── Symptom Multi-Select Picker ────────────────────────────────────── */
.dt-symptom-picker { position: relative; }

.dt-symptom-box {
    display: flex; flex-wrap: wrap; gap: 4px; align-items: center;
    min-height: 38px; padding: 4px 8px;
    border: 1px solid #dee2e6; border-radius: .375rem;
    background: #fff; cursor: text;
    transition: border-color .15s, box-shadow .15s;
}
.dt-symptom-box.focused {
    border-color: #86b7fe;
    box-shadow: 0 0 0 .2rem rgba(13,110,253,.15);
    outline: 0;
}
.dt-symptom-tag {
    display: inline-flex; align-items: center; gap: 3px;
    background: #dbeafe; color: #1d4ed8;
    border-radius: 4px; padding: 1px 6px;
    font-size: .78rem; line-height: 1.6;
    white-space: nowrap;
}
.dt-symptom-tag-remove {
    background: none; border: none; padding: 0; margin: 0;
    color: #3b82f6; font-size: .9rem; line-height: 1;
    cursor: pointer; display: flex; align-items: center;
}
.dt-symptom-tag-remove:hover { color: #dc2626; }

.dt-symptom-input {
    border: none; outline: none; flex: 1; min-width: 120px;
    font-size: .875rem; padding: 2px 0; background: transparent;
}

.dt-symptom-dropdown {
    /* position/top/left/width/z-index กำหนดผ่าน Alpine :style (inline) */
    background: #fff; border: 1px solid #dee2e6; border-radius: .375rem;
    box-shadow: 0 4px 12px rgba(0,0,0,.15);
    max-height: 220px; overflow-y: auto;
}
.dt-symptom-option {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 12px; font-size: .85rem;
    cursor: pointer; user-select: none;
}
.dt-symptom-option:hover { background: #f1f5f9; }
.dt-symptom-option.selected { background: #eff6ff; }

.dt-symptom-empty {
    padding: 8px 12px; font-size: .82rem; color: #64748b;
}

:root {
    --dt-primary: #1976D2;
    --dt-primary-dark: #1565C0;
    --dt-sidebar-bg: #1e293b;
    --dt-sidebar-fg: #cbd5e1;
    --dt-sidebar-active: #38bdf8;
    --dt-sidebar-w: 248px;
}

html, body {
    font-family: 'Sarabun', system-ui, -apple-system, 'Segoe UI', sans-serif;
    background: #f6f8fb;
    min-height: 100vh;
}

/* ---- Sidebar ----
   ใช้ explicit class จาก PHP (server) → ไม่มี flicker ระหว่างรอ Alpine load
   หน้าทั่วไป layout จะ render: <aside class="dt-sidebar open">
   หน้า /queue: <aside class="dt-sidebar closed">
   Alpine จัดการ toggle ระหว่าง .open / .closed ผ่าน object syntax
*/
.dt-sidebar {
    width: var(--dt-sidebar-w);
    background: var(--dt-sidebar-bg);
    color: var(--dt-sidebar-fg);
    min-height: 100vh;
    flex: 0 0 var(--dt-sidebar-w);
    display: flex;
    flex-direction: column;
    transition: margin-left .2s ease;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    /* fallback: ถ้าทั้ง .open/.closed ไม่ได้ถูก set ด้วยเหตุผลใดก็ตาม → ปิด */
    margin-left: calc(-1 * var(--dt-sidebar-w));
}
.dt-sidebar.open   { margin-left: 0; }
.dt-sidebar.closed { margin-left: calc(-1 * var(--dt-sidebar-w)); }

/* Queue page transition tweak — เมื่อ sidebar ปิด queue ใช้พื้นที่ได้เต็ม */
body:not(:has(.dt-sidebar.open)) .dt-queue-sidebar { transition: width .15s; }

.dt-sidebar-header {
    padding: 1.1rem 1.25rem;
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.dt-brand {
    color: #fff;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: .5rem;
    font-weight: 600;
    font-size: 1.1rem;
}
.dt-brand i { color: var(--dt-sidebar-active); }

.dt-nav { padding: 1rem 0; flex-grow: 1; }
.dt-nav-group { margin-bottom: 1.25rem; }
.dt-nav-label {
    text-transform: uppercase;
    letter-spacing: .05em;
    font-size: .7rem;
    color: #64748b;
    padding: 0 1.25rem .35rem;
}
.dt-nav-link {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: .55rem 1.25rem;
    color: var(--dt-sidebar-fg);
    text-decoration: none;
    border-left: 3px solid transparent;
    transition: background .15s, color .15s, border-color .15s;
    font-size: .92rem;
}
.dt-nav-link:hover {
    background: rgba(255,255,255,.04);
    color: #fff;
}
.dt-nav-link.active {
    background: rgba(56,189,248,.1);
    color: #fff;
    border-left-color: var(--dt-sidebar-active);
}
.dt-nav-link i { width: 1.1rem; text-align: center; font-size: 1rem; }

.dt-sidebar-footer {
    border-top: 1px solid rgba(255,255,255,.08);
    padding: .9rem 1.25rem;
}

/* ---- Topbar / Main ---- */
.dt-main { display: flex; flex-direction: column; min-height: 100vh; width: 100%; }
.dt-topbar {
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
    padding: .6rem 1rem;
    display: flex;
    align-items: center;
    gap: .75rem;
    position: sticky;
    top: 0;
    z-index: 1000;
}
.dt-content { padding: 1.5rem; flex-grow: 1; }
.dt-flash-wrapper {
    padding: 1rem 1.5rem 0;
}

/* ---- Stat cards ---- */
.dt-stat .dt-stat-icon {
    width: 44px; height: 44px;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    margin-bottom: .75rem;
}
.dt-stat-label { color: #64748b; font-size: .85rem; }
.dt-stat-value { font-size: 1.6rem; font-weight: 600; line-height: 1.2; margin-top: .15rem; }

/* ---- Auth pages ---- */
.dt-auth-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1976D2 0%, #6366f1 100%);
    padding: 1rem;
}
.dt-auth-wrapper { width: 100%; max-width: 420px; }
.dt-auth-card { border-radius: 16px; }
.dt-auth-logo {
    display: inline-flex;
    width: 60px; height: 60px;
    border-radius: 16px;
    background: linear-gradient(135deg, #1976D2, #6366f1);
    color: #fff;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
}

/* ---- Mobile / Tablet ---- */
@media (max-width: 991.98px) {
    .dt-sidebar {
        position: fixed;
        z-index: 1100;
        height: 100vh;
        top: 0;
        left: 0;
        /* override margin-left ด้วย transform (margin-left ไม่มีผลบน fixed) */
        margin-left: 0 !important;
        transform: translateX(-100%);
        transition: transform .22s ease, box-shadow .22s ease;
        box-shadow: none;
    }
    .dt-sidebar.open {
        transform: translateX(0);
        box-shadow: 0 0 24px rgba(0,0,0,.22);
    }
    .dt-sidebar.closed {
        transform: translateX(-100%);
        box-shadow: none;
    }
    .dt-main { width: 100%; }
    /* ปุ่มปิดใน sidebar header — แสดงเฉพาะ mobile */
    .dt-sidebar-close-btn { display: flex !important; }
}
/* overlay backdrop สำหรับ mobile เมื่อ sidebar เปิด */
.dt-sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 1099;
}
@media (max-width: 991.98px) {
    .dt-sidebar-backdrop.show { display: block; }
}
/* ปุ่มปิด sidebar ใน header — ซ่อนบน desktop */
.dt-sidebar-close-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 32px; height: 32px;
    border-radius: 8px;
    background: rgba(255,255,255,.1);
    border: none;
    color: #fff;
    font-size: 1.1rem;
    cursor: pointer;
    margin-left: auto;
    flex-shrink: 0;
}

/* ---- Mobile bottom nav ---- */
.dt-bottomnav {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: calc(56px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: #fff;
    border-top: 1px solid #dee2e6;
    display: flex;
    align-items: stretch;
    z-index: 1050;
    box-shadow: 0 -2px 8px rgba(0,0,0,.08);
}
.dt-bnav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    font-size: .65rem;
    font-weight: 500;
    color: #6c757d;
    text-decoration: none;
    border: none;
    background: none;
    cursor: pointer;
    padding: 6px 4px 2px;
    transition: color .15s;
    -webkit-tap-highlight-color: transparent;
}
.dt-bnav-item i { font-size: 1.35rem; line-height: 1; }
.dt-bnav-item.active { color: #0d6efd; }
.dt-bnav-item:active,
.dt-bnav-item:focus { color: #0d6efd; outline: none; }

/* content padding ไม่ถูก bottom nav บัง */
@media (max-width: 991.98px) {
    .dt-main {
        padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px)) !important;
    }
}

/* ---- Helpers ---- */
.text-money { font-variant-numeric: tabular-nums; }
.cursor-pointer { cursor: pointer; }

/* =====================================================================
   Queue layout — 2 columns within page
   ===================================================================== */
:root {
    --dt-queue-sb-w: 320px;
}

.dt-queue-wrapper {
    display: flex;
    gap: 0;
    margin: -1.5rem;             /* pull to edge of .dt-content padding */
    min-height: calc(100vh - 60px);
    background: #f6f8fb;
}

/* --- Inner queue sidebar (patient list) --- */
.dt-queue-sidebar {
    flex: 0 0 var(--dt-queue-sb-w);
    background: #fff;
    border-right: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    height: calc(100vh - 60px);
    position: sticky;
    top: 60px;
    overflow: hidden;
}
.dt-queue-sidebar-header {
    padding: .85rem 1rem;
    border-bottom: 1px solid #e2e8f0;
    background: #fafbfd;
}
.dt-queue-sidebar-title {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-weight: 600;
    font-size: .95rem;
    color: #1e293b;
}
.dt-queue-sidebar-title i {
    color: var(--dt-primary);
    font-size: 1.1rem;
}

.dt-queue-sidebar-body {
    overflow-y: auto;
    flex-grow: 1;
}

/* --- Station section (group of cards per station) --- */
.dt-station-section {
    border-bottom: 1px solid #e2e8f0;
}
.dt-station-section-header {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .5rem .85rem;
    background: #f8fafc;
    font-size: .82rem;
    font-weight: 600;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: .03em;
    position: sticky;
    top: 0;
    z-index: 2;
}
.dt-station-section-header i { color: var(--dt-primary); font-size: 1rem; }
.dt-station-section-name { flex-grow: 1; }
.dt-station-section-count {
    background: #cbd5e1;
    color: #1e293b;
    border-radius: 999px;
    padding: .05rem .5rem;
    font-size: .7rem;
    font-variant-numeric: tabular-nums;
}
.dt-station-section-body {
    padding: .3rem .5rem .5rem;
    min-height: 30px;
    transition: background .12s, box-shadow .12s;
}
.dt-station-section-body.drag-over {
    background: #dbeafe;
    box-shadow: inset 0 0 0 2px var(--dt-primary);
}
.dt-station-empty {
    text-align: center;
    color: #cbd5e1;
    font-size: .78rem;
    padding: .65rem;
    font-style: italic;
}

/* --- Patient card (draggable) --- */
.dt-queue-card {
    position: relative;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    margin-bottom: .35rem;
    padding: .55rem .7rem .55rem 1.65rem;
    cursor: grab;
    transition: box-shadow .12s, border-color .12s, transform .1s;
}
.dt-queue-card:hover {
    border-color: #cbd5e1;
    box-shadow: 0 2px 6px rgba(0,0,0,.06);
}
.dt-queue-card.dragging { opacity: .35; cursor: grabbing; transform: rotate(1deg); }
.dt-queue-card.active {
    border-color: var(--dt-primary);
    background: #eff6ff;
    box-shadow: 0 2px 6px rgba(25,118,210,.15);
}
.dt-queue-card-grip {
    position: absolute;
    left: .35rem;
    top: 50%;
    transform: translateY(-50%);
    color: #cbd5e1;
    font-size: 1rem;
    cursor: grab;
    line-height: 1;
}
.dt-queue-card:hover .dt-queue-card-grip { color: #94a3b8; }
.dt-queue-card-link {
    display: block;
    color: #1e293b;
    text-decoration: none;
}
.dt-queue-card-link:hover { color: #1e293b; }
.dt-queue-card-name {
    font-weight: 700;
    font-size: 14px;
    margin-bottom: .1rem;
    line-height: 1.25;
}
.dt-queue-card-meta {
    font-size: 14px;
    color: #64748b;
}
.dt-queue-card-symp {
    font-size: 14px;
    color: #475569;
    margin-top: .2rem;
    background: #f1f5f9;
    padding: .15rem .4rem;
    border-radius: 3px;
    line-height: 1.3;
}
.dt-queue-card-allergy {
    position: absolute;
    top: .35rem;
    right: .45rem;
    font-size: .58rem;
    padding: .1rem .35rem;
}
.dt-queue-doctor {
    color: var(--dt-primary);
    font-weight: 500;
}

/* Filter button look */
.dt-filter-btn { font-size: .85rem; }

/* =====================================================================
   Cashier / Payment
   ===================================================================== */
.dt-pay-summary {
    background: linear-gradient(135deg, #f8fafc, #ffffff);
    border: 1px solid #e2e8f0 !important;
    position: sticky;
    top: 70px;
}
.dt-pay-badge {
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: .95rem;
    border-radius: 8px;
}
.dt-pay-amount {
    font-variant-numeric: tabular-nums;
}

/* =====================================================================
   Reports / Charts
   ===================================================================== */
.dt-stat-sm .small { font-size: .8rem; }

.dt-bars {
    display: flex;
    gap: 4px;
    align-items: flex-end;
    height: 170px;
    padding: 0 0 4px;
}
.dt-bar-wrap {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: default;
    min-width: 0;
}
.dt-bar {
    width: 100%;
    background: linear-gradient(180deg, #38bdf8, #1976D2);
    border-radius: 3px 3px 0 0;
    min-height: 2px;
    transition: background .15s;
}
.dt-bar-wrap:hover .dt-bar {
    background: linear-gradient(180deg, #1976D2, #1565C0);
}
.dt-bar-label {
    font-size: .65rem;
    color: #94a3b8;
    margin-top: 3px;
    font-variant-numeric: tabular-nums;
}

@media print {
    .no-print { display: none !important; }
    .dt-sidebar, .dt-topbar, .dt-bottomnav, .dt-sidebar-backdrop { display: none !important; }
    .dt-main { width: 100% !important; }
    .dt-content { padding: 0 !important; }

    /* โครงหน้าเป็น flex + min-height:100vh — ตอนพิมพ์ 100vh = 1 หน้ากระดาษ
       ทำให้ Chrome พิมพ์ออกมาว่าง/ได้หน้าเดียว (หน้ารายงานเจอปัญหานี้ เพราะเป็น
       กลุ่มเดียวที่พิมพ์จาก layout หลัก — ใบเสร็จ/ใบรับรอง/แบบฟอร์ม ไม่ใช้ layout นี้)
       → รีเซ็ตเป็น block ตอนพิมพ์ ให้เนื้อหาไหลข้ามหน้าได้ตามปกติ */
    html, body { height: auto !important; min-height: 0 !important; overflow: visible !important; }
    body { display: block !important; }
    .dt-main    { display: block !important; min-height: 0 !important; }
    .dt-content { flex-grow: 0 !important; }

    /* ตารางกว้าง ๆ อยู่ใน .table-responsive (overflow-x:auto) — ตอนพิมพ์ต้องปล่อยให้ล้นได้
       ไม่งั้นคอลัมน์ขวาถูกตัดหาย */
    .table-responsive { overflow: visible !important; }

    /* คอลัมน์ที่เป็นปุ่มควบคุมบนจอ (checkbox เลือกจ่าย, ลูกศรกาง/ยุบ) — ไม่ใช่ข้อมูล ไม่ต้องพิมพ์ */
    .dt-col-ui { display: none !important; }

    /* เอกสารทางการ: ตัดเงา/ขอบการ์ด ให้ดูเป็นกระดาษ */
    .card { box-shadow: none !important; border: 0 !important; }
    .card-header { background: transparent !important; border-bottom: 1px solid #000 !important; }

    /* ตารางยาวข้ามหน้า — ให้หัวตารางซ้ำทุกหน้า และไม่ตัดกลางแถว */
    thead { display: table-header-group; }
    tfoot { display: table-row-group; }
    tr    { page-break-inside: avoid; }

    /* หัวกระดาษคลินิก — ซ้ำหัวเรื่องเฉพาะหน้าแรก */
    .dt-print-letterhead {
        text-align: center;
        border-bottom: 2px solid #000;
        padding-bottom: 8px;
        margin-bottom: 14px;
    }
    .dt-print-letterhead .lh-clinic { font-size: 17pt; font-weight: 700; line-height: 1.3; }
    .dt-print-letterhead .lh-title  { font-size: 14pt; font-weight: 700; margin-top: 8px; }
    .dt-print-letterhead .lh-sub    { font-size: 10pt; color: #333; }
    .dt-print-letterhead .lh-meta   { margin-top: 4px; color: #666; }

    /* ----- ฉบับพิมพ์รายงาน DF (views/reports/df.php) ----- */
    .dt-df-print { font-size: 9.5pt; color: #000; }
    .dt-df-print .dfp-table { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
    .dt-df-print .dfp-table th,
    .dt-df-print .dfp-table td { border: 1px solid #999; padding: 3px 5px; vertical-align: top; }
    .dt-df-print .dfp-table thead th { background: #eee !important; font-weight: 700; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .dt-df-print .dfp-table thead th.dfp-cap { background: #fff !important; border: 0; border-bottom: 2px solid #000; font-size: 12pt; text-align: left; padding: 0 0 4px; }
    .dt-df-print .dfp-cap-sub { font-size: 9.5pt; font-weight: 400; color: #333; }
    .dt-df-print .dfp-group td { font-weight: 700; background: #f5f5f5 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .dt-df-print .dfp-sub td   { font-weight: 600; }
    .dt-df-print .dfp-total td { font-weight: 700; border-top: 2px solid #000; }
    .dt-df-print .dfp-group    { break-after: avoid; page-break-after: avoid; }
    .dt-df-print .dfp-break    { break-before: page; page-break-before: always; }
    /* เลือกฉบับพิมพ์ (ปุ่มพิมพ์ตั้ง body[data-df-print]) — ไม่ได้ตั้ง = ฉบับเต็ม */
    body:not([data-df-print="share"]) .dfp-v-share,
    body[data-df-print="share"] .dfp-v-full { display: none !important; }
    .dt-df-print .dfp-sign {
        display: flex; justify-content: space-around; text-align: center;
        margin-top: 36px; line-height: 2;
        break-inside: avoid; page-break-inside: avoid;
    }
}

/* =====================================================================
   Standalone layout (Appointments tab)
   ===================================================================== */
.dt-standalone-body {
    margin: 0;
    background: #f6f8fb;
    min-height: 100vh;
    font-family: 'Sarabun', system-ui, sans-serif;
}
.dt-standalone-top {
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
    padding: .55rem 1rem;
    display: flex;
    align-items: center;
    gap: .65rem;
    position: sticky;
    top: 0;
    z-index: 100;
}
.dt-standalone-brand {
    color: #1e293b;
    text-decoration: none;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: .5rem;
    font-size: 1.05rem;
}
.dt-standalone-brand i { color: var(--dt-primary); font-size: 1.3rem; }
.dt-standalone-main {
    padding: .75rem 1rem 2rem;
}

/* =====================================================================
   Appointments grid
   ===================================================================== */
.dt-apt-wrapper {
    font-size: .85rem;
    padding-bottom: var(--datestrip-h, 60px);   /* เว้นที่ให้ datestrip ที่ fixed ล่างจอ */
    /* CSS variables for sticky offsets */
    --top-h: 52px;
    --toolbar-h: 50px;
    --datestrip-h: 64px;
    /* datestrip ย้ายไป fixed ล่างจอ → หัวตารางไม่ต้องเผื่อความสูง datestrip */
    --grid-head-y: calc(var(--top-h) + var(--toolbar-h));
    --grid-header-h: 38px;
    --grid-doctor-h: 36px;
    --grid-subhead-h: 22px;
    --slot-h: 28px;          /* ความสูง 1 ช่องเวลา — มือถือขยายให้อ่านง่ายขึ้น */
}

.dt-apt-toolbar {
    background: #fff;
    padding: .5rem .75rem;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,.04);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: .5rem;
    position: sticky;
    top: var(--top-h);
    z-index: 99;
}

/* =====================================================================
   Date strip — horizontal scroll, Thai day colors
   ===================================================================== */
.dt-apt-datestrip-wrap {
    background: #fff;
    padding: 3px 6px;
    border-top: 1px solid #e2e8f0;
    box-shadow: 0 -3px 10px rgba(0,0,0,.08);   /* เงาด้านบน = ลอยเหนือเนื้อหา */
    display: flex;
    align-items: center;
    gap: 4px;
    /* fixed ที่ footer (ล่างจอ) — เลือกวันได้ตลอดโดยไม่ต้องเลื่อนขึ้น */
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 200;
}
/* Desktop + sidebar เปิด → เริ่ม footer หลัง sidebar ไม่ให้ทับเมนู
   (mobile: sidebar เป็น overlay ทับเนื้อหา → footer คงเต็มจอ left:0 · desktop sidebar ปิด/หน้า queue → เต็มจอเช่นกัน) */
@media (min-width: 992px) {
    body:has(.dt-sidebar.open) .dt-apt-datestrip-wrap { left: var(--dt-sidebar-w); }
}
.dt-apt-datestrip {
    flex: 1 1 auto;
    overflow: hidden;           /* เต็มจอพอดี ไม่มี scroll ซ้าย-ขวา */
    display: flex;
    align-items: center;        /* วันอื่นไม่ถูกยืดสูงตาม active */
    gap: 3px;
    padding: 4px 0;             /* เผื่อที่ให้ active (สูงขึ้น) ไม่ล้นขอบบน-ล่าง */
}

.dt-date-pill {
    flex: 1 1 0;                /* ยืดแบ่งความกว้างเท่ากัน เต็มแถบ */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 0;
    padding: 1px 4px;
    border-radius: 6px;
    text-decoration: none;
    line-height: 1.0;
    transition: transform .12s, box-shadow .12s;
    border: 2px solid transparent;
}
.dt-date-pill-day { font-size: .46rem; opacity: .85; }
.dt-date-pill-num { font-size: .76rem; line-height: 1.0; }
.dt-date-pill-mo  { font-size: .43rem; opacity: .65; }
/* หรี่วันอื่นให้จาง เน้นเฉพาะวันที่เลือก */
.dt-date-pill:not(.active) { opacity: .5; }
.dt-date-pill:not(.active):hover { opacity: 1; }
.dt-date-pill.today {
    border-color: rgba(0,0,0,.25);
}
/* วันที่เลือกอยู่ — พื้นทึบน้ำเงิน ตัวอักษรขาว + ใหญ่กว่าจริงด้วย padding (ไม่ scale กันล้นขอบ) */
.dt-date-pill.active {
    background: var(--dt-primary) !important;
    color: #fff !important;
    border-color: var(--dt-primary);
    box-shadow: 0 3px 11px rgba(25,118,210,.5);
    padding: 4px 3px;
    margin: 0 5px;
    flex-grow: 1.6;            /* วันที่เลือกกว้างกว่าวันอื่น */
    z-index: 2;
}
.dt-date-pill.active:hover { transform: none; }
.dt-date-pill.active .dt-date-pill-day { color: #fff !important; opacity: 1; font-size: .52rem; }
.dt-date-pill.active .dt-date-pill-num { color: #fff !important; font-size: 1.05rem; font-weight: 800; }
.dt-date-pill.active .dt-date-pill-mo  { color: #fff !important; opacity: 1; font-size: .48rem; }

/* Weekday = neutral, เน้นเฉพาะ อา + ส */
.day-sun { background: #FEE2E2; color: #991B1B; }   /* อา. แดง */
.day-sat { background: #F3E8FF; color: #6B21A8; }   /* ส.  ม่วง */
.day-mon, .day-tue, .day-wed, .day-thu, .day-fri {
    background: #f8fafc;
    color: #475569;
    border-color: #e2e8f0;
}

.dt-date-nav {
    flex: 0 0 auto;
    padding: 6px 8px;
    color: #475569;
    text-decoration: none;
    border-radius: 6px;
}
.dt-date-nav:hover { background: #f1f5f9; color: #1e293b; }

/* =====================================================================
   Schedule (month view of doctor assignments)
   ===================================================================== */
.dt-sched-wrapper { font-size: .85rem; }
.dt-sched-table th,
.dt-sched-table td {
    padding: .4rem .55rem;
    vertical-align: top;
}
.dt-sched-datecell {
    text-align: center;
    width: 90px;
    background: #fff;
}
.dt-sched-datecell.day-sun { background: #FEF2F2; }
.dt-sched-datecell.day-sat { background: #FAF5FF; }
.dt-sched-datecell.today {
    background: #FEF3C7 !important;
    border-left: 3px solid #f59e0b;
}
.dt-sched-cell { min-width: 180px; }
.dt-sched-pill {
    display: inline-flex;
    align-items: center;
    margin: 1px 2px;
    max-width: 100%;
}
.dt-sched-addbtn {
    color: #94a3b8;
    border-style: dashed !important;
    border-color: #cbd5e1 !important;
    background: transparent !important;
    padding: 0 !important;
    height: 22px;
    width: 100%;
    margin-top: 2px;
}
.dt-sched-addbtn:hover {
    background: #f1f5f9 !important;
    color: #475569;
}

.dt-doc-hour-pill {
    background: #f1f5f9;
    border-radius: 999px;
    padding: 3px 12px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: .82rem;
}
.dt-doc-hour-name { font-weight: 600; color: #1e293b; }
.dt-doc-hour-val  { font-variant-numeric: tabular-nums; color: #1976D2; }

/* =====================================================================
   Patient info card (on queue / visit detail) — pinned via flex layout
   (no sticky — the parent .dt-queue-content is flex-column and the
   scrollable region is .dt-vd-scrollable below it, so the card stays put
   regardless of inner scroll)
   ===================================================================== */
.dt-patient-card {
    background: linear-gradient(135deg, #f8fafc 0%, #fff 100%);
    border-left: 4px solid var(--dt-primary) !important;
    z-index: 5;
    box-shadow: 0 2px 10px rgba(0,0,0,.06) !important;
}
.dt-patient-card .card-body { padding: .5rem .7rem !important; }
.dt-pat-name {
    font-size: .98rem;
    font-weight: 600;
    color: #0f172a;
}
.dt-pat-ids { font-size: .72rem; line-height: 1.3; }

/* Profile photo avatar in patient info card */
.dt-pat-photo {
    flex: 0 0 40px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    overflow: hidden;
    border: 2px solid #e2e8f0;
    background: #f8fafc;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform .12s, border-color .12s;
    text-decoration: none;
}
.dt-pat-photo:hover {
    transform: scale(1.05);
    border-color: var(--dt-primary);
}
.dt-pat-photo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.dt-pat-photo-empty {
    color: #94a3b8;
    font-size: 1.5rem;
    line-height: 1;
}
.dt-pat-photo-empty:hover { color: var(--dt-primary); }

/* SOAP auto-save status indicator */
.dt-soap-status {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 9px;
    border-radius: 999px;
    background: rgba(0,0,0,.04);
    font-size: .72rem;
    font-weight: 500;
    transition: opacity .15s;
}
@keyframes dt-spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

/* Inline-editable price/qty cells in items + products tables */
.dt-cell-edit {
    background: #fefce8;
    border: 1px solid #fde68a !important;
    font-weight: 600;
    transition: background .15s;
}
.dt-cell-edit:focus {
    background: #fff !important;
    border-color: #f59e0b !important;
    box-shadow: 0 0 0 .15rem rgba(245,158,11,.2) !important;
}

/* Field locked by another user — RED warning (ห้ามแก้!) */
[data-locked-by-other] {
    background-color: #fee2e2 !important;          /* แดงอ่อน */
    cursor: not-allowed;
    border-color: #dc2626 !important;              /* แดงเข้ม */
    border-width: 2px !important;
    box-shadow: 0 0 0 .15rem rgba(220,38,38,.18) !important;
    color: #991b1b !important;
}
/* Field locked by me — GREEN (เป็นช่องที่ฉันกำลังพิม) */
[data-locked-by-me] {
    border-color: #16a34a !important;
    box-shadow: 0 0 0 .15rem rgba(22,163,74,.18) !important;
}
.dt-lock-badge {
    display: inline-block;
    margin-top: 2px;
    padding: 2px 10px;
    background: #dc2626;
    color: #fff;
    border-radius: 999px;
    font-size: .72rem;
    font-weight: 700;
    line-height: 1.4;
    box-shadow: 0 1px 4px rgba(220,38,38,.3);
}
.dt-lock-badge i { margin-right: 2px; }

/* ===== Queue live-update badges ===== */
.dt-live-badge {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    background: #16a34a;
    color: #fff;
    padding: 6px 12px;
    border-radius: 999px;
    font-size: .78rem;
    font-weight: 600;
    box-shadow: 0 4px 14px rgba(22,163,74,.35);
    opacity: 0;
    transform: translateY(8px);
    transition: opacity .22s, transform .22s;
    z-index: 1050;
    pointer-events: none;
}
.dt-live-badge.show {
    opacity: 1;
    transform: translateY(0);
}
.dt-pending-badge {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    background: #f59e0b;
    color: #fff;
    padding: 8px 14px;
    border-radius: 8px;
    font-size: .8rem;
    font-weight: 600;
    box-shadow: 0 4px 14px rgba(245,158,11,.35);
    cursor: pointer;
    z-index: 1050;
}
.dt-pending-badge:hover { background: #d97706; }

/* Frozen top row (patient info + master plan, 50/50) */
.dt-vd-frozen {
    flex: 0 0 auto;                /* don't grow/shrink in flex-column parent */
    max-height: 30vh;              /* cap height so working area below stays usable */
    min-height: 0;
}
.dt-vd-frozen > [class*="col-"] {
    display: flex;
    min-height: 0;
}
.dt-vd-frozen .card {
    width: 100%;
    max-height: 30vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;              /* let inner list scroll, not the card */
}
.dt-vd-frozen .card-body {
    overflow-y: auto;              /* inner content scrolls within the card */
}
.dt-patient-card::-webkit-scrollbar       { width: 6px; }
.dt-patient-card::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 6px; }
.dt-patient-card::-webkit-scrollbar-track { background: transparent; }

/* Scrollable lower region — wraps SOAP form, items, products, summary */
.dt-vd-scrollable {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    /* breathing room so the bottom card isn't flush against the scrollbar */
    padding-right: .25rem;
}
.dt-vd-scrollable::-webkit-scrollbar       { width: 8px; }
.dt-vd-scrollable::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 8px; }
.dt-vd-scrollable::-webkit-scrollbar-track { background: transparent; }

/* Inline-edit save status (qty/ราคา ในตารางหัตถการ/ยา) — saving / saved / error */
.dt-row-status {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: .72rem;
    font-weight: 500;
    white-space: nowrap;
    margin-right: .4rem;
    vertical-align: middle;
    transition: opacity .3s;
}
.dt-rs-saving   { color: #94a3b8; }
.dt-rs-saving i { display: inline-block; animation: dt-spin 1s linear infinite; }
.dt-rs-saved    { color: #16a34a; }
.dt-rs-error    { color: #dc2626; }

/* Sticky action bar — pinned below the scroll region; total + primary action
   always visible (no scroll-to-bottom). Sibling of .dt-vd-scrollable inside
   the flex-column .dt-queue-content, so it sits at the bottom and the scroll
   area shrinks to fit — never overlaps content. */
.dt-vd-actionbar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-top: .5rem;
    padding: .55rem .9rem;
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: .65rem;
    box-shadow: 0 -3px 10px rgba(0,0,0,.05);
}
.dt-vd-actionbar--cashier {
    background: #fffbeb;
    border-color: #fde68a;
}
.dt-vd-actionbar-total { display: flex; flex-direction: column; line-height: 1.12; min-width: 0; }
.dt-vd-actionbar-lbl   { font-size: .72rem; color: #15803d; }
.dt-vd-actionbar--cashier .dt-vd-actionbar-lbl { color: #b45309; }
.dt-vd-actionbar-amt   { font-size: 1.35rem; font-weight: 600; color: #15803d; white-space: nowrap; }
.dt-vd-actionbar--cashier .dt-vd-actionbar-amt { color: #b45309; }
.dt-vd-actionbar-side  { display: flex; align-items: center; gap: .5rem; flex-shrink: 0; }
.dt-vd-actionbar-side .btn { white-space: nowrap; }

/* On mobile the page itself scrolls, so pin the bar to the viewport bottom */
@media (max-width: 991.98px) {
    .dt-vd-actionbar {
        position: sticky;
        bottom: 0;
        z-index: 20;
        margin-top: 0;
        border-radius: .65rem .65rem 0 0;
    }
}
.dt-pat-demo {
    color: #475569;
    line-height: 1.5;
}
.dt-pat-demo i { color: #94a3b8; }
.dt-pat-stats { line-height: 1.4; }
.dt-pat-stats i { color: #94a3b8; }

.dt-pat-history { padding-top: 0; }
.dt-history-list { }
.dt-history-item {
    padding: 6px 8px;
    border-bottom: 1px dotted #e2e8f0;
    line-height: 1.4;
    background: #f8fafc;
    border-radius: 4px;
    margin-bottom: 4px;
    border-left: 3px solid #cbd5e1;
}
.dt-history-item:last-child { border-bottom: none; margin-bottom: 0; }

.dt-history-head {
    display: flex;
    align-items: center;
    gap: .35rem;
    margin-bottom: 2px;
}
.dt-history-date {
    font-weight: 600;
    color: #1e293b;
    font-variant-numeric: tabular-nums;
}
.dt-history-doc   { color: var(--dt-primary); }
.dt-history-doc i { font-size: .8rem; }
.dt-history-amount {
    margin-left: auto;
    color: #16a34a;
    font-weight: 600;
}

.dt-history-field {
    font-size: .76rem;
    color: #475569;
    margin-top: 1px;
    padding-left: .25rem;
    overflow-wrap: anywhere;
}
.dt-history-lbl {
    color: #64748b;
    font-weight: 600;
    margin-right: 3px;
}
.dt-history-next { color: #1e40af; }

/* =====================================================================
   Patient photo gallery + lightbox
   ===================================================================== */
.dt-photo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: .75rem;
}
.dt-photo-tile {
    position: relative;
    border-radius: 10px;
    overflow: hidden;
    background: #f1f5f9;
    aspect-ratio: 1 / 1;
    cursor: zoom-in;
    border: 1px solid #e2e8f0;
    transition: transform .12s, box-shadow .12s;
}
.dt-photo-tile:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 14px rgba(0,0,0,.10);
}
.dt-photo-tile img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.dt-photo-tile-overlay {
    position: absolute;
    top: 0; left: 0; right: 0;
    padding: 4px 6px;
    background: linear-gradient(rgba(0,0,0,.55), transparent);
    color: #fff;
    font-size: .7rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
}
.dt-photo-tile-cat {
    background: rgba(255,255,255,.92);
    padding: 1px 6px;
    border-radius: 999px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 3px;
}
.dt-photo-tile-overlay .btn {
    background: rgba(255,255,255,.92);
    border-radius: 4px;
    padding: 1px 6px !important;
    line-height: 1;
}
.dt-photo-tile-cap {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    padding: 3px 6px;
    background: linear-gradient(transparent, rgba(0,0,0,.7));
    color: #fff;
    font-size: .72rem;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Lightbox */
.dt-lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.88);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    overflow: auto;
}
.dt-lightbox-content {
    max-width: min(1100px, 96vw);
    max-height: 96vh;
    display: flex;
    flex-direction: column;
    gap: .5rem;
}
.dt-lightbox-content img {
    max-width: 100%;
    max-height: 78vh;
    object-fit: contain;
    background: #000;
    border-radius: 8px;
}
.dt-lightbox-meta {
    color: #f8fafc;
    background: rgba(15,23,42,.85);
    padding: .65rem .85rem;
    border-radius: 8px;
}
.dt-lightbox-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .3rem;
    font-size: .85rem;
}
.dt-lightbox-cat {
    color: #fff;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: .72rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.dt-lightbox-close {
    position: fixed;
    top: 1rem;
    right: 1rem;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 0;
    background: rgba(255,255,255,.18);
    color: #fff;
    z-index: 2001;
    font-size: 1.2rem;
}
.dt-lightbox-close:hover { background: rgba(255,255,255,.32); }

/* Lightbox prev/next nav buttons */
.dt-lightbox-nav {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 0;
    background: rgba(255,255,255,.18);
    color: #fff;
    z-index: 2001;
    font-size: 1.4rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s;
}
.dt-lightbox-nav:hover { background: rgba(255,255,255,.35); }
.dt-lightbox-prev { left: 1rem; }
.dt-lightbox-next { right: 1rem; }

/* === Expandable visit-history row on /patients/{cn} page === */
.dt-history-cards .dt-history-row {
    cursor: pointer;
    transition: background .12s;
}
.dt-history-cards .dt-history-row:hover { background: #f8fafc; }
.dt-history-cards .dt-history-row .dt-history-date-col {
    flex: 0 0 100px;
    line-height: 1.25;
}
.dt-history-cards .dt-history-row .dt-history-date {
    font-weight: 600;
    color: #0f172a;
    font-size: .82rem;
}
.dt-history-cards .dt-history-row .dt-history-treat-line {
    font-size: .85rem;
    color: #1e293b;
}
.dt-history-cards .dt-history-row .dt-history-expand-icon {
    width: 22px;
    text-align: center;
    color: #94a3b8;
}
.dt-history-cards .dt-history-full {
    background: #f8fafc;
    border-left: 3px solid #cbd5e1;
    padding: .65rem .75rem;
    border-radius: 6px;
    font-size: .85rem;
    line-height: 1.5;
}

/* =====================================================================
   Master Plan card (right column of top row in queue/visit detail)
   ===================================================================== */
.dt-mp-card { border-left: 4px solid #f59e0b !important; }
.dt-mp-card .card-body { padding: .55rem .75rem !important; }
.dt-mp-list { }
.dt-mp-item {
    padding: .4rem .6rem;
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-radius: 6px;
    margin-bottom: .35rem;
    line-height: 1.35;
    position: relative;
}
.dt-mp-item:last-child { margin-bottom: 0; }
.dt-mp-item.dt-mp-completed {
    background: #f0fdf4;
    border-color: #bbf7d0;
}
.dt-mp-item.dt-mp-completed .dt-mp-content {
    color: #15803d;
    text-decoration: line-through;
    text-decoration-color: #86efac;
}
.dt-mp-item.dt-mp-cancelled {
    background: #f8fafc;
    border-color: #e2e8f0;
}
.dt-mp-item.dt-mp-cancelled .dt-mp-content {
    color: #94a3b8;
    text-decoration: line-through;
}
.dt-mp-content {
    font-size: .8rem;
    color: #1e293b;
    margin-bottom: .25rem;
    overflow-wrap: anywhere;
}
.dt-mp-meta {
    font-size: .7rem;
    color: #64748b;
    display: flex;
    flex-wrap: wrap;
    gap: .3rem;
    align-items: center;
    margin-bottom: .25rem;
}
.dt-mp-meta i { font-size: .7rem; }
.dt-mp-author    { color: var(--dt-primary); font-weight: 600; }
.dt-mp-date      { font-variant-numeric: tabular-nums; }
.dt-mp-edited    { color: #94a3b8; font-style: italic; }
.dt-mp-status {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 1px 6px;
    border-radius: 9999px;
    font-size: .68rem;
    font-weight: 600;
}
.dt-mp-status-active    { background: #fef3c7; color: #b45309; }
.dt-mp-status-completed { background: #dcfce7; color: #15803d; }
.dt-mp-status-cancelled { background: #f1f5f9; color: #64748b; }

.dt-mp-actions {
    display: flex;
    flex-wrap: wrap;
    gap: .35rem;
    font-size: .75rem;
}
.dt-mp-actions .btn { font-size: .72rem; }

.dt-mp-addform textarea {
    background: #fffef5;
    border-color: #fde68a;
}

/* Master plan list scrollable container (inside frozen card) */
.dt-mp-listwrap {
    overflow-y: auto;
    min-height: 0;
    margin-top: .15rem;
}
.dt-mp-listwrap::-webkit-scrollbar       { width: 6px; }
.dt-mp-listwrap::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 6px; }
.dt-mp-listwrap::-webkit-scrollbar-track { background: transparent; }

[x-cloak] { display: none !important; }

/* Alpine x-show ซ่อน element ด้วย inline style="display:none" ซึ่ง "แพ้" utility ของ
   Bootstrap ที่ประกาศ !important (.d-flex{display:flex!important} ฯลฯ)
   → element ที่มีทั้ง x-show และ class d-* จะไม่ถูกซ่อน แสดงค้างพร้อมข้อความว่าง
   บรรทัดนี้ทำให้ x-show ชนะกลับ ครอบคลุมทุกหน้าโดยไม่ต้องแก้ markup ทีละจุด */
[x-show][style*="display: none"] { display: none !important; }

/* =====================================================================
   หัวหมวดในฟอร์มลงนัด — สีอยู่ที่หัวหมวดเท่านั้น ไม่ลงไปที่ช่องกรอก
   เพื่อให้สีทำหน้าที่บอกขอบเขตกลุ่ม ไม่ใช่ตกแต่ง
   ===================================================================== */
.dt-sec-head {
    border-bottom: 1px solid rgba(0, 0, 0, .06);
    line-height: 1.4;
}
.dt-sec-num {
    width: 1.3rem; height: 1.3rem;
    border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: .72rem; font-weight: 600;
    color: #fff; flex-shrink: 0;
}
/* หัวหมวดโทนเทาเดียว — ลดกล่องสีให้หน้าเป็นระเบียบ ไม่รก */
.dt-sec-when, .dt-sec-who, .dt-sec-what { background: #f8fafc; color: #475569; }
.dt-sec-when .dt-sec-num,
.dt-sec-who  .dt-sec-num,
.dt-sec-what .dt-sec-num { background: #94a3b8; }
/* หัวหมวดที่กดยุบได้ — ให้ปุ่มกลืนกับพื้นหัวหมวด */
button.dt-sec-head { border: 0; width: 100%; text-align: left; }
button.dt-sec-head:hover { filter: brightness(.97); }

/* =====================================================================
   Auto-sync — fade out before reload to hide flicker
   ===================================================================== */
/* แถบโหลดบางๆ ด้านบน ตอน auto-sync รีโหลด — นุ่ม ไม่วูบหน้าจอ */
.dt-sync-progress {
    position: fixed; top: 0; left: 0; height: 3px; width: 0;
    background: var(--dt-primary, #1976d2);
    box-shadow: 0 0 6px rgba(25,118,210,.5);
    z-index: 100000;
    transition: width .3s ease-out;
    pointer-events: none;
}
.dt-syncing-out {
    opacity: 0;
    transition: opacity .15s ease-out;
}

/* Hide all open dropdowns / modals immediately when syncing out, just in case */
.dt-syncing-out .dropdown-menu.show,
.dt-syncing-out .modal.show {
    display: none !important;
}

/* =====================================================================
   Auto-sync notification banner (when user is busy + data updated)
   ===================================================================== */
.dt-sync-banner {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #f59e0b;
    border-radius: 8px;
    padding: 8px 14px;
    box-shadow: 0 4px 12px rgba(0,0,0,.12);
    z-index: 10000;
    font-size: .88rem;
    display: flex;
    align-items: center;
    gap: 6px;
    animation: slideInRight .25s ease-out;
}
@keyframes slideInRight {
    from { transform: translateX(100%); opacity: 0; }
    to   { transform: translateX(0);    opacity: 1; }
}

/* =====================================================================
   Master data pages (services / products / users) — sticky headers
   ===================================================================== */
:root {
    --dt-topbar-h: 56px;
}

/* Sticky page title + Add button row */
.dt-master-page > .d-flex:first-of-type {
    position: sticky;
    top: var(--dt-topbar-h);
    z-index: 20;
    background: #f6f8fb;
    margin-left: -1.5rem;
    margin-right: -1.5rem;
    padding: .65rem 1.5rem;
    border-bottom: 1px solid #e2e8f0;
}

/* Sticky filter card */
.dt-master-page > form.card {
    position: sticky;
    top: calc(var(--dt-topbar-h) + 56px);
    z-index: 19;
}

/* Sticky table thead */
.dt-master-page .table-responsive {
    overflow: visible;
}
.dt-master-page .table thead th {
    position: sticky;
    top: calc(var(--dt-topbar-h) + 56px + 56px);
    z-index: 10;
    background: #f1f5f9 !important;
    box-shadow: inset 0 -2px 0 #cbd5e1;
}

.dt-room-toggle {
    display: inline-flex;
    align-items: center;
    gap: .25rem;
    padding: .3rem .65rem;
    background: #f1f5f9;
    border-radius: 999px;
    font-size: .82rem;
    cursor: pointer;
    user-select: none;
}
.dt-room-toggle input[type=checkbox] { margin: 0; }

/* ── Freenote chips (compact, single line) — full detail on hover (title) ── */
.dt-freenote-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.dt-freenote-chip {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    max-width: 360px;
    height: 24px;
    padding: 0 3px 0 9px;
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-radius: 999px;
    font-size: .75rem;
    line-height: 1;
    color: #78350f;
    white-space: nowrap;
}
.dt-fn-main {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    overflow: hidden;
    cursor: pointer;
}
.dt-fn-caret { color: #b45309; font-size: .7rem; flex-shrink: 0; }
.dt-fn-ico  { color: #d97706; font-size: .8rem; flex-shrink: 0; }
.dt-fn-time { color: #92400e; font-weight: 700; flex-shrink: 0; }
.dt-fn-desc { overflow: hidden; text-overflow: ellipsis; max-width: 180px; }
.dt-fn-tech {
    display: inline-flex; align-items: center; gap: 3px;
    color: #a16207;
    padding-left: 5px; border-left: 1px solid #fde68a;
    overflow: hidden; text-overflow: ellipsis; max-width: 120px;
}
.dt-fn-tech i { font-size: .72rem; }
.dt-fn-del-form { display: inline-flex; margin: 0; }
.dt-fn-del {
    background: transparent; border: none; padding: 0;
    width: 18px; height: 18px; border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    color: #b45309; cursor: pointer; flex-shrink: 0;
}
.dt-fn-del:hover { background: #fee2e2; color: #dc2626; }

/* detail popover — tap chip to view full info incl. phone */
.dt-fn-pop {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 200;
    min-width: 220px;
    max-width: 300px;
    background: #fff;
    border: 1px solid #fde68a;
    border-radius: 10px;
    box-shadow: 0 6px 20px rgba(0,0,0,.15);
    padding: 10px 12px;
    white-space: normal;
    font-size: .8rem;
    color: #1e293b;
}
.dt-fn-pop-head { font-size: .72rem; font-weight: 700; color: #92400e; display: flex; align-items: center; gap: 4px; }
.dt-fn-pop-time { color: #b45309; font-weight: 600; }
.dt-fn-pop-desc { font-weight: 600; margin: 6px 0; line-height: 1.35; }
.dt-fn-pop-row { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; color: #475569; margin-top: 4px; }
.dt-fn-pop-row > i { color: #94a3b8; }
.dt-fn-pop-tel {
    display: inline-flex; align-items: center; gap: 4px;
    background: #ecfdf5; color: #047857;
    padding: 2px 8px; border-radius: 999px;
    font-weight: 600; text-decoration: none;
}
.dt-fn-pop-tel:hover { background: #d1fae5; color: #065f46; }

/* =====================================================================
   ตารางนัด — มือถือ/แท็บเล็ต: ดูทีละห้อง ปัดซ้าย-ขวา (snap) + แถวสูงขึ้น
   ===================================================================== */
@media (max-width: 991.98px) {
    .dt-apt-wrapper { --slot-h: 40px; }              /* แถวสูงขึ้น อ่านชื่อ/เวลาชัด */

    /* กริดเลื่อนแนวนอนได้ + snap ทีละห้อง */
    .dt-apt-grid {
        overflow-x: auto;
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 64px;                         /* เผื่อ bottom nav ไม่ให้ทับแถวล่าง */
    }
    /* คอลัมน์เวลา ค้างซ้ายตอนปัด */
    .dt-apt-timecol {
        position: sticky;
        left: 0;
        z-index: 30;
        flex: 0 0 52px;
    }
    /* แต่ละห้อง = เกือบเต็มจอ (เผยขอบห้องถัดไปนิดให้รู้ว่าปัดได้) */
    .dt-apt-roomcol {
        flex: 0 0 calc(100vw - 84px);
        min-width: 0;
        scroll-snap-align: start;
    }

    /* toolbar แน่นขึ้น — เห็นกริดมากขึ้น */
    .dt-apt-toolbar { padding: .35rem .5rem; gap: .4rem; }
    .dt-room-toggle { font-size: .72rem; padding: .2rem .5rem; }
    .dt-apt-toolbar .btn { font-size: .78rem; padding: .3rem .55rem; }

    /* การ์ดนัด: ตัวอักษรโตขึ้นนิดให้อ่านง่ายบนจอเล็ก */
    .dt-apt-card { font-size: .82rem; }
    .dt-apt-card-time { font-size: .78rem; }
}

.dt-apt-grid {
    display: flex;
    background: #fff;
    border-radius: 8px;
    /* no overflow:hidden — dropdowns need to escape */
    box-shadow: 0 1px 3px rgba(0,0,0,.04);
}
.dt-apt-timecol {
    flex: 0 0 70px;
    background: #f8fafc;
    border-right: 1px solid #e2e8f0;
}
.dt-apt-roomcol {
    flex: 1 1 0;
    border-right: 1px solid #e2e8f0;
    min-width: 320px;       /* wider — has 2 sub-columns inside */
}
.dt-apt-roomcol:last-child { border-right: none; }
.dt-apt-roomcol.is-hidden { display: none; }

/* ── กรอบห้อง: ปกติเป็นแค่ทางผ่าน (กว้างเท่าผลรวมห้อง เหมือนตอนห้องเป็นลูกตรงของ .dt-apt-grid) ── */
.dt-apt-rooms,
.dt-apt-track { display: flex; flex: 1 0 auto; min-width: 0; }

/* ── โหมดห้องละจอ (.dt-apt-grid--pan) — ห้องละเต็มกริด เลื่อนทีละห้องด้วย margin-left ของ track
   overflow-x: clip ไม่ใช่ scroll container → หัวตาราง sticky ยังค้างกับหน้า + dropdown ยังโผล่ลงล่างได้ ── */
.dt-apt-grid--pan .dt-apt-rooms { flex: 1 1 0; overflow-x: clip; }
@supports not (overflow-x: clip) {
    .dt-apt-grid--pan .dt-apt-rooms { overflow: hidden; }   /* Safari < 16 — ตัดขอบได้ แต่หัวตารางจะไม่ค้าง */
}
.dt-apt-grid--pan .dt-apt-track {
    flex: 0 0 100%;
    transition: margin-left .25s ease;
}
.dt-apt-grid--pan .dt-apt-track.dt-pan-noanim { transition: none; }
.dt-apt-grid--pan .dt-apt-roomcol { flex: 0 0 100%; min-width: 0; border-right: none; }

/* ลูกศร + จุด บนหัวห้อง — ซ่อนไว้ โผล่เฉพาะโหมดห้องละจอ */
.dt-pan-btn, .dt-pan-dots { display: none; }
.dt-apt-grid--pan .dt-apt-roomcol .dt-apt-header { gap: .6rem; }
.dt-apt-grid--pan .dt-pan-dots { display: inline-flex; align-items: center; gap: 5px; }
.dt-apt-grid--pan .dt-pan-btn {
    display: inline-flex; align-items: center; justify-content: center;
    position: absolute; top: 50%; transform: translateY(-50%);
    width: 30px; height: 26px; padding: 0;
    border: 1px solid rgba(255,255,255,.25); border-radius: 6px;
    background: rgba(255,255,255,.08); color: #fff; font-size: .9rem; line-height: 1;
    cursor: pointer;
}
.dt-apt-grid--pan .dt-pan-btn:hover:not(:disabled) { background: rgba(255,255,255,.22); }
.dt-apt-grid--pan .dt-pan-btn:disabled { opacity: .25; cursor: default; }
.dt-apt-grid--pan .dt-pan-prev { left: 6px; }
.dt-apt-grid--pan .dt-pan-next { right: 6px; }
.dt-pan-dot {
    width: 8px; height: 8px; padding: 0;
    border: none; border-radius: 50%;
    background: rgba(255,255,255,.35);
    cursor: pointer;
}
.dt-pan-dot.is-on { background: #fff; transform: scale(1.2); }

/* ปุ่มเปิดโหมด + ชิปห้องที่กำลังดู */
.dt-pan-toggle.active { background: #334155; border-color: #334155; color: #fff; }
.dt-room-toggle.is-pan-current { box-shadow: 0 0 0 2px #334155; font-weight: 600; }

@media (max-width: 991.98px) {
    /* มือถือปกติปัดด้วย overflow-x scroll — โหมดห้องละจอเลื่อนด้วย JS แทน ไม่ต้อง scroll/snap
       และหัวตารางกลับมายึดกับหน้า (ไม่ใช่กริด) → offset ต้องเผื่อ topbar+toolbar เหมือนเดสก์ท็อป */
    .dt-apt-grid.dt-apt-grid--pan {
        overflow: visible;
        scroll-snap-type: none;
        --grid-head-y: calc(var(--top-h) + var(--toolbar-h));
    }
    .dt-apt-grid--pan .dt-apt-roomcol { flex: 0 0 100%; }
}

/* ── โหมดภาพ (.dt-apt-canvas บน .dt-apt-wrapper) — จอเล็กเห็นตารางหน้าตาเดียวกับจอคอม ลาก/ถ่างนิ้วดูเหมือนดูรูป
   แต่ละห้องกว้างคงที่ --room-w (การ์ดแบบเปิดห้องเดียว) เรียงต่อกันทางขวา อยู่ในกล่อง .dt-apt-panbox ที่สูงพอดีจอ
   ซูม = CSS zoom ของ .dt-apt-grid (JS ตั้ง --cz) · หัวตาราง sticky ยึดกับกล่อง (top 0) · คอลัมน์เวลา/ชื่อห้องค้างซ้าย
   กฎจอแคบ (<992px) และ iPad แนวนอนของการ์ด ถูกเขียนทับกลับเป็นค่าจอคอม ≥1200px ทั้งหมดในโหมดนี้
   (เปิดโหมดนี้ = ห้องละจอพักไว้ — การปัดเปลี่ยนห้องชนกับการลากดูภาพ) ── */
.dt-apt-panbox { display: contents; }               /* ปกติ = ไม่มีตัวตน กริดเป็นลูกของ wrapper เหมือนเดิม */

.dt-apt-wrapper.dt-apt-canvas {
    --slot-h: 28px;
    --grid-head-y: 0px;                              /* sticky ยึดกับกล่อง pan ไม่ใช่หน้า */
    --room-w: 1500px;
    padding-bottom: 0;
}
.dt-apt-canvas .dt-apt-panbox {
    display: block;
    overflow: auto;
    height: var(--panbox-h, 70vh);                   /* JS วัดให้พอดีจอ (ถึงขอบบนแถบวัน) */
    touch-action: pan-x pan-y;                       /* ลากนิ้ว = เลื่อน · สองนิ้ว = ซูมของเรา (JS) */
    overscroll-behavior: contain;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.dt-apt-canvas .dt-apt-grid {
    width: max-content;
    zoom: var(--cz, 1);
    overflow: visible;
    scroll-snap-type: none;
    padding-bottom: 0;
    border-radius: 0;
    box-shadow: none;
}
.dt-apt-canvas .dt-apt-timecol {
    position: sticky; left: 0; z-index: 90;          /* แถวนัดมี z-index สูงสุดเท่าจำนวนช่อง — ต้องอยู่เหนือ แต่ใต้หัวตาราง (95–97) */
    flex: 0 0 70px;
    box-shadow: 2px 0 4px rgba(0,0,0,.06);
}
.dt-apt-canvas .dt-apt-timecol .dt-apt-time { background: #f8fafc; }
.dt-apt-canvas .dt-apt-rooms,
.dt-apt-canvas .dt-apt-track { flex: 0 0 auto; }
.dt-apt-canvas .dt-apt-roomcol { flex: 0 0 var(--room-w); min-width: 0; scroll-snap-align: none; }
.dt-apt-canvas .dt-apt-roomcol + .dt-apt-roomcol { border-left: 3px solid #cbd5e1; }   /* รอยต่อห้องเห็นชัดตอนซูมออก */

/* ห้องกว้างเกินจอ → ชื่อห้อง + เวรหมอ ค้างชิดซ้าย (ถัดคอลัมน์เวลา) */
.dt-apt-canvas .dt-apt-roomcol .dt-apt-header { justify-content: flex-start; }
.dt-apt-canvas .dt-room-name,
.dt-apt-canvas .dt-apt-roomcol .dt-apt-doctor-row > * { position: sticky; left: 82px; flex: 0 0 auto; width: auto !important; }

/* การ์ด: คืนค่าจอคอม ≥1200px */
.dt-apt-canvas .dt-apt-card { font-size: .78rem; }
.dt-apt-canvas .dt-apt-card-time { flex: 0 0 44px; font-size: .78rem; }
.dt-apt-canvas .dt-apt-primary .dt-apt-name { font-size: .9rem; }
.dt-apt-canvas .dt-apt-secondary .dt-apt-treat { font-size: .875rem; }
.dt-apt-canvas .dt-apt-doc-chip { font-size: .6rem; padding: 0 5px; }
.dt-apt-canvas .dt-apt-grid--single .dt-apt-card-main,
.dt-apt-canvas .dt-apt-grid--single .apt-slots-1 .dt-apt-card-main { flex-direction: row; align-items: center; gap: 0; }
.dt-apt-canvas .dt-apt-grid--single .dt-apt-primary,
.dt-apt-canvas .dt-apt-grid--single .apt-slots-1 .dt-apt-primary { flex: 0 0 200px; padding-right: 8px; }
.dt-apt-canvas .dt-apt-grid--single .dt-apt-secondary { flex: 1 1 0; min-width: 0; }
.dt-apt-canvas .dt-apt-grid--single .dt-apt-cn { display: inline-block; }
.dt-apt-canvas .dt-apt-grid--single .dt-apt-icons { flex: 0 0 122px; }
.dt-apt-canvas .dt-apt-grid--single .dt-apt-islot { flex: 0 0 22px; }
.dt-apt-canvas .dt-apt-grid--single .dt-apt-islot-nc { flex: 0 0 34px; }
.dt-apt-canvas .dt-apt-grid--single .dt-apt-islot:empty { display: flex; }

/* ป้ายแนะนำครั้งแรก */
.dt-canvas-hint {
    position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 2000;
    width: min(300px, calc(100vw - 48px));
    background: rgba(15,23,42,.86); color: #fff; border-radius: 14px; padding: 14px 18px;
    font-size: .95rem; line-height: 1.6; text-align: center; pointer-events: none; transition: opacity .35s;
}
.dt-canvas-hint.is-gone { opacity: 0; }
.dt-canvas-toggle.active { background: #334155; border-color: #334155; color: #fff; }

/* Sub-column header (หลัก / สำรอง labels) — fixed height for grid alignment */
.dt-apt-subcol-header {
    display: flex;
    background: #e2e8f0;
    border-bottom: 1px solid #cbd5e1;
    height: var(--grid-subhead-h);
    box-sizing: border-box;
    flex-shrink: 0;
}
.dt-apt-subcol-label {
    flex: 1 1 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .68rem;
    font-weight: 600;
    color: #475569;
    padding: 0 4px;
    letter-spacing: .04em;
    text-transform: uppercase;
}
.dt-apt-subcol-label.backup {
    border-left: 1px dashed #94a3b8;
    color: #92400e;
    background: rgba(254, 243, 199, .35);
}

/* Shift start label inside slot — shows which doctor is on duty */
.dt-apt-shift-label {
    position: absolute;
    top: 1px;
    left: 8px;
    font-size: .72rem;
    color: #1e293b;
    background: rgba(255,255,255,.95);
    padding: 1px 6px;
    border-radius: 3px;
    line-height: 1.3;
    pointer-events: none;
    z-index: 6;
    white-space: nowrap;
    border: 1px solid rgba(0,0,0,.15);
    box-shadow: 0 1px 2px rgba(0,0,0,.08);
    font-weight: 500;
}
.dt-apt-shift-label i { font-size: .7rem; }
.dt-apt-shift-label small { color: #64748b; margin-left: 2px; }

/* =====================================================================
   พักเที่ยง — แถบคลุม slot ช่วงพัก + การ์ดป้ายที่ slot แรก
   "แสดงอย่างเดียว" — ไม่กันการลงนัด (pointer-events: none ทุกชิ้น)
   ===================================================================== */
.dt-apt-row.is-break::after {
    content: '';
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        -45deg,
        rgba(100,116,139,.16) 0,
        rgba(100,116,139,.16) 5px,
        rgba(255,255,255,0)   5px,
        rgba(255,255,255,0)   11px
    );
    pointer-events: none;
    z-index: 2;
}
.dt-apt-break-card {
    position: absolute;
    top: 2px;
    left: 50%;
    transform: translateX(-50%);
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 1px 10px;
    border-radius: 999px;
    background: rgba(255, 251, 235, .97);
    border: 1px solid #fcd34d;
    color: #92400e;
    font-size: .72rem;
    line-height: 1.4;
    white-space: nowrap;
    box-shadow: 0 1px 3px rgba(0,0,0,.12);
    pointer-events: none;
    z-index: 3;                 /* ต่ำกว่าการ์ดนัด (4) — นัดจริงต้องอ่านได้ก่อน */
}
.dt-apt-break-card small { color: #b45309; }
.dt-apt-break-doc { opacity: .75; }
.dt-apt-break-doc::before { content: '·'; margin-right: 4px; }

/* ชิปเวลาพักบน pill หมอ (ตารางนัด + ตารางหมอรายเดือน) */
.dt-break-chip {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    margin-left: 3px;
    padding: 0 5px;
    border-radius: 999px;
    background: #fef3c7;
    color: #92400e !important;
    font-size: .62rem !important;
    white-space: nowrap;
}

/* กล่องฟิลด์เวลาพักใน modal เพิ่มหมอ */
.dt-break-fieldset {
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-radius: 8px;
    padding: 8px 10px;
}
.dt-break-quick { cursor: pointer; font-weight: 500; }

/* Slot row (contains main + backup sub-cells) */
.dt-apt-row {
    display: flex;
    position: relative;
    background-color: #f1f5f9;   /* darker gray when NO doctor on duty — clear contrast */
}
.dt-apt-row.has-duty {
    /* bg set inline by PHP from doctor palette */
}
.dt-apt-row.has-duty .dt-apt-slot { background: transparent !important; }
.dt-apt-row.has-duty .dt-apt-slot.backup {
    background: rgba(255,255,255,.35) !important;   /* slightly lighter for backup col */
}
.dt-apt-row > .dt-apt-slot {
    flex: 1 1 0;
    min-width: 0;
}
.dt-apt-row > .dt-apt-slot.backup {
    border-left: 1px dashed #cbd5e1;
    background: rgba(254, 243, 199, .12);
}
.dt-apt-row > .dt-apt-slot.backup.is-empty:hover {
    background: rgba(254, 243, 199, .45);
}

.dt-apt-cell {
    border-bottom: 1px solid #f1f5f9;
    padding: 0 .35rem;
}
.dt-apt-header {
    height: var(--grid-header-h);
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #1e293b;
    color: #fff;
    font-weight: 600;
    border-bottom: 2px solid #0f172a;
    position: sticky;
    top: var(--grid-head-y);
    z-index: 97;
    flex-shrink: 0;
}
.dt-apt-doctor-row {
    background: #f0f9ff;
    height: var(--grid-doctor-h);
    box-sizing: border-box;
    overflow: hidden;
    display: flex;
    align-items: center;
    border-bottom: 1px solid #cbd5e1;
    padding: .25rem .5rem;
    position: sticky;
    top: calc(var(--grid-head-y) + var(--grid-header-h));
    z-index: 96;
    flex-shrink: 0;
}
/* Sub-column header (หลัก / สำรอง) — bottom row of the frozen header block */
.dt-apt-subcol-header {
    position: sticky;
    top: calc(var(--grid-head-y) + var(--grid-header-h) + var(--grid-doctor-h));
    z-index: 95;
    box-shadow: 0 3px 5px -1px rgba(0,0,0,.12);   /* unify head rows into one solid block */
}

.dt-apt-time {
    height: var(--slot-h);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #64748b;
    font-size: .75rem;
    font-variant-numeric: tabular-nums;
    background: #f8fafc;
    transition: background .1s, color .1s;
}
/* ไฮไลต์ช่องเวลาเมื่อชี้เมาส์เหนือ cell แถวเดียวกัน — ช่วยเล็งเวลาตอนลงนัด */
.dt-apt-time.dt-time-hl {
    background: var(--dt-primary, #1976d2);
    color: #fff;
    font-weight: 700;
}

.dt-apt-slot {
    min-height: var(--slot-h);
    padding: 1px 2px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    cursor: pointer;
    transition: background .12s;
    position: relative;
}
.dt-apt-slot.is-empty:hover {
    background: rgba(25,118,210,.05);
}
.dt-apt-slot.drag-over {
    background: rgba(25,118,210,.18);
    box-shadow: inset 0 0 0 2px var(--dt-primary);
}

/* ── ช่องนอกช่วงเวลาที่หมอลงเวร — ลงนัด/ลากการ์ดมาไม่ได้ ──────────────
   ลายทางจาง ๆ + เคอร์เซอร์ห้าม · ปุ่ม + และ double-click ถูกตัดที่ PHP
   (ไม่ใช้ pointer-events:none เพราะการ์ดที่ค้างอยู่ในช่องนี้ต้องยังกดใช้งานได้) */
.dt-apt-row > .dt-apt-slot.is-offduty {
    background: repeating-linear-gradient(
        135deg,
        rgba(100,116,139,.10) 0px,
        rgba(100,116,139,.10) 5px,
        rgba(255,255,255,0)   5px,
        rgba(255,255,255,0)   12px
    );
    cursor: not-allowed;
}
.dt-apt-row.has-duty .dt-apt-slot.is-offduty { background: transparent !important; }
.dt-apt-row > .dt-apt-slot.is-offduty.is-empty:hover { background: rgba(100,116,139,.16); }
/* ลากการ์ดมาวางไม่ได้ — ขอบแดงบอกเหตุผลตอนลากผ่าน */
.dt-apt-row > .dt-apt-slot.is-offduty.drag-blocked {
    background: rgba(220,38,38,.10);
    box-shadow: inset 0 0 0 2px rgba(220,38,38,.55);
}

/* ปุ่มเพิ่มนัดในช่อง — โผล่ตอน hover ลอยเหนือการ์ด (z-index > .dt-apt-cards) */
.dt-apt-add-btn {
    position: absolute;
    top: 1px;
    right: 1px;
    z-index: 7;
    width: 18px;
    height: 18px;
    padding: 0;
    display: none;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 4px;
    background: var(--dt-primary, #1976d2);
    color: #fff;
    font-size: .7rem;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0,0,0,.3);
    pointer-events: auto;
}
.dt-apt-slot:hover > .dt-apt-add-btn { display: inline-flex; }
.dt-apt-add-btn:hover { background: #145ca8; }

/* Badge เตือนว่ามีนัดซ้อนจมอยู่ (เกินความสูงช่อง ต้องเลื่อนดู) */
.dt-apt-more-badge {
    position: absolute;
    bottom: 2px;
    right: 3px;
    z-index: 8;
    display: inline-flex;
    align-items: center;
    gap: 1px;
    background: #dc2626;
    color: #fff;
    font-size: .6rem;
    font-weight: 700;
    line-height: 1.4;
    padding: 0 5px;
    border-radius: 9px;
    box-shadow: 0 1px 3px rgba(0,0,0,.35);
    pointer-events: none;
    white-space: nowrap;
}
.dt-apt-more-badge i { font-size: .62rem; }

.dt-doctor-pill {
    background: #fff;
    border: 1px solid #cbd5e1;
    padding: 1px 6px;
    border-radius: 999px;
    font-size: .72rem;
    color: #1e293b;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.dt-doctor-pill small { color: #64748b; font-size: .65rem; }

/* =====================================================================
   Appointment card — horizontal layout, dropdown-safe (no overflow clip)
   ===================================================================== */
/* Card overlay container — cards float over the slots beneath instead of
   pushing rows down, so every room column ends at the same height. */
.dt-apt-cards {
    position: absolute;
    top: 0;
    left: 2px;
    right: 2px;
    display: flex;
    flex-direction: column;          /* stack แนวตั้ง — การ์ดเต็มความกว้าง อ่านครบทุกใบ */
    align-items: stretch;
    gap: 2px;
    z-index: 4;
    pointer-events: none;   /* empty area below cards stays clickable */
    max-height: calc(var(--slot-h) * 5 + 8px); /* โชว์ ~5 ใบ เกินกว่านั้น scroll ในช่อง (ไม่ดันแถวเวลาให้เพี้ยน) */
    overflow-y: auto;
    overflow-x: hidden;
}
.dt-apt-cards > .dt-apt-card {
    width: 100%;
    min-width: 0;
    flex: 0 0 auto;
    pointer-events: auto;
}
.dt-apt-card {
    background: #fff;
    border-left: 3px solid #94a3b8;
    border-radius: 4px;
    padding: 0;
    font-size: .78rem;
    cursor: grab;
    box-shadow: 0 1px 2px rgba(0,0,0,.06);
    height: calc(var(--slot-h) * var(--span, 1) - 2px);
    transition: box-shadow .12s;
    position: relative;
    display: flex;
    align-items: stretch;
    gap: 2px;
    /* IMPORTANT: don't clip — dropdowns need to escape */
    overflow: visible;
}
.dt-apt-card:hover { box-shadow: 0 3px 8px rgba(0,0,0,.12); z-index: 5; }
.dt-apt-card.dragging { opacity: .4; cursor: grabbing; }

.apt-blue   { border-left-color: #3b82f6; background: linear-gradient(90deg, #eff6ff 0%, #fff 30%); }
.apt-green  { border-left-color: #10b981; background: linear-gradient(90deg, #ecfdf5 0%, #fff 30%); }
.apt-orange { border-left-color: #f59e0b; background: linear-gradient(90deg, #fffbeb 0%, #fff 30%); }
.apt-purple { border-left-color: #8b5cf6; background: linear-gradient(90deg, #faf5ff 0%, #fff 30%); }
.apt-gray   { border-left-color: #94a3b8; background: linear-gradient(90deg, #f1f5f9 0%, #fff 30%); }
.apt-red    { border-left-color: #ef4444; background: linear-gradient(90deg, #fef2f2 0%, #fff 30%); }
.apt-cancel {
    border-left-color: #cbd5e1;
    background: repeating-linear-gradient(45deg, transparent 0 4px, #f1f5f9 4px 8px);
    color: #64748b;
}
.apt-cancel .dt-apt-name { text-decoration: line-through; }
.apt-no-contact { border-left-color: #dc2626; background: linear-gradient(90deg, #fff1f2 0%, #fff 30%); }

/* ===== คนไข้ใหม่ (ยังไม่มี CN) =====
   จองด้วยชื่อ/เบอร์ ยังไม่ได้เปิดแฟ้ม → cn_id = NULL
   ขอบซ้ายหนา 6px สีชมพูม่วง (ไม่ซ้ำกับสีสถานะใดๆ) + แถบเวลาซ้ายพื้นชมพูอ่อน
   สถานะยังอ่านได้จากพื้นหลัง gradient + ชิปสถานะด้านขวาเหมือนเดิม */
.dt-apt-card.dt-apt-new { border-left: 6px solid #db2777 !important; }

/* การ์ดที่กำลังเลือกอยู่ (คลิกเดียว) — ขอบชมพูรอบทั้งใบ + เรืองแสง
   ไม่แตะพื้นหลัง เพราะพื้นหลังการ์ดใช้บอกสถานะนัด (จอง/ยืนยัน/ผิดนัด)
   ต่างจาก .dt-apt-new ที่เป็นขีดซ้ายอย่างเดียว — คนละรูปทรง แยกออกจากกันได้
   วางไว้ก่อน .dt-apt-focus เพื่อให้ไฮไลต์ผลค้นหา (สีส้ม) ยังชนะ */
.dt-apt-card.dt-apt-selected {
    outline: 5px solid #ec4899;
    outline-offset: -2px;
    box-shadow: 0 0 0 4px rgba(236, 72, 153, .55),
                0 4px 16px rgba(219, 39, 119, .6);
    z-index: 55;
}
/* กันดับเบิลคลิกไปลากเลือกข้อความบนการ์ดจนดูรก */
.dt-apt-card-main { user-select: none; -webkit-user-select: none; }
.dt-apt-card.dt-apt-new .dt-apt-card-time {
    background: #fdf2f8;
    color: #9d174d;
    border-right-color: #fbcfe8;
}

/* contact attempt badge on card — วางเป็น flex item ต่อจากปุ่มโทร */
.dt-apt-nocontact-badge {
    flex: 0 0 auto;
    align-self: center;        /* กึ่งกลางแนวตั้งเสมอกับไอคอนโทร */
    display: inline-block;
    font-size: .68rem;
    font-weight: 600;
    background: #fee2e2;        /* แดงอ่อน — ซอฟต์ลง ไม่จ้า */
    color: #c0392b;            /* ตัวอักษรแดงเข้ม อ่านออก */
    border: 1px solid #fecaca;
    border-radius: 9px;
    padding: 1px 5px;
    white-space: nowrap;
    line-height: 1.4;
}
/* queue status pill */
.dt-appt-status-no_contact .dt-appt-status-pill {
    background: #fef2f2;
    color: #dc2626;
    font-weight: 600;
}

/* ===== LINE confirmation indicator (per-card) =====
   แสดงผลคนไข้ตอบกลับมาจาก LINE: ยืนยัน / ขอเลื่อน / ปฏิเสธ
*/
.apt-conf-confirmed {
    box-shadow: inset 3px 0 0 #06C755;   /* แถบเขียว LINE ซ้าย — ต่างจากเขียว "ยืนยัน" ปกติ (#16a34a) เจตนา */
}
.apt-conf-reschedule {
    box-shadow: inset 3px 0 0 #d97706;   /* แถบส้มซ้าย */
    background-image: repeating-linear-gradient(45deg,
        transparent 0 6px, rgba(217,119,6,.12) 6px 12px);
}
.apt-conf-declined {
    box-shadow: inset 3px 0 0 #dc2626;
    opacity: .85;
}
/* badge ไอคอน LINE ข้างชื่อคนไข้ — เห็นชัดกว่าแถบ 3px (คนไข้กดตอบเองใน LINE) */
.dt-apt-line-badge {
    display: inline-flex;
    align-items: center;
    margin-left: 3px;
    font-size: .78rem;
    line-height: 1;
    vertical-align: -1px;
}

/* Card columns: left (status), main (content), right (menu) */
.dt-apt-card-left,
.dt-apt-card-right {
    flex: 0 0 22px;
    display: flex;
    align-items: center;
    justify-content: center;
}
/* เวลาเริ่ม (ซ้ายการ์ด) — ให้อ่านเวลาได้ทันทีทุกใบ ไม่ต้องไล่แกนเวลาซ้ายสุด */
/* ชิปหมอเวร (ท้ายสุดของการ์ด นัดใบแรกของเวร) — เห็นหมอง่ายโดยไม่บังชื่อ */
.dt-apt-card-doc {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    padding-right: 5px;
}
.dt-apt-doc-chip {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    font-size: .6rem;
    font-weight: 700;
    color: #1e293b;
    padding: 0 5px;
    border: 1px solid #8b5cf6;
    border-radius: 6px;
    white-space: nowrap;
    line-height: 1.5;
}
.dt-apt-doc-chip i { font-size: .62rem; }

/* ปุ่ม LINE บนการ์ด — คนไข้ผูกไลน์แล้ว กดเพื่อเปิดแชท DentTrack */
.dt-apt-line-btn {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #06C755;              /* LINE green */
    opacity: .5;                 /* หรี่ลง ไม่จ้า — hover ค่อยเต็ม */
    font-size: 1rem;
    text-decoration: none;
    padding: 0 3px;
    transition: transform .1s, opacity .1s;
}
.dt-apt-line-btn:hover { color: #05a548; opacity: 1; transform: scale(1.18); }
.dt-apt-line-btn.is-static { color: #86efac; cursor: default; }
button.dt-apt-line-btn { background: transparent; border: none; cursor: pointer; }

/* ปุ่ม FB Messenger บนการ์ด — โชว์เฉพาะห้องที่ยังตอบได้ (คนไข้ทักมาไม่เกิน 24 ชม.) */
.dt-apt-fb-btn {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #0866FF;              /* Messenger blue */
    opacity: .5;
    font-size: .95rem;
    padding: 0 3px;
    background: transparent;
    border: none;
    cursor: pointer;
    transition: transform .1s, opacity .1s;
}
.dt-apt-fb-btn:hover { opacity: 1; transform: scale(1.18); }

/* ปุ่มโทร — เข้าชุดกับปุ่ม LINE แต่สีน้ำเงินโทรศัพท์ ให้แยกออกจากกัน */
.dt-apt-call-btn {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #2563eb;
    opacity: .5;                 /* หรี่ลง ไม่จ้า — hover ค่อยเต็ม */
    font-size: .95rem;
    text-decoration: none;
    padding: 0 3px;
    transition: transform .1s, opacity .1s;
}
.dt-apt-call-btn:hover { color: #1d4ed8; opacity: 1; transform: scale(1.18); }

/* Popover พิมพ์ส่งข้อความ LINE จากการ์ด */
.dt-line-pop {
    position: fixed;
    z-index: 2100;
    width: 262px;
    background: #fff;
    border: 1px solid #06C755;
    border-radius: 10px;
    box-shadow: 0 8px 22px rgba(0,0,0,.22);
    padding: 8px;
}
.dt-line-pop-head { font-size: .74rem; font-weight: 600; color: #05a548; margin-bottom: 5px; display: flex; align-items: center; gap: 4px; }
.dt-line-tpl { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.dt-line-tpl-btn { font-size: .7rem; border: 1px solid #a7f3c9; background: #f0fdf4; color: #05a548; border-radius: 999px; padding: 2px 9px; cursor: pointer; display: inline-flex; align-items: center; gap: 3px; }
.dt-line-tpl-btn:hover { background: #dcfce7; border-color: #06C755; }
.dt-line-pop-inp {
    width: 100%;
    box-sizing: border-box;
    font-size: .82rem;
    padding: 6px 8px;
    border: 1px solid #a7f3c9;
    border-radius: 6px;
    resize: none;
    outline: none;
}
.dt-line-pop-inp:focus { border-color: #06C755; box-shadow: 0 0 0 2px rgba(6,199,85,.2); }
.dt-line-pop-actions { display: flex; justify-content: flex-end; gap: 6px; margin-top: 6px; }
.dt-line-pop-actions button { font-size: .74rem; border-radius: 6px; padding: 3px 10px; border: 1px solid transparent; cursor: pointer; }
.dt-line-cancel { background: #f1f5f9; color: #475569; }
.dt-line-cancel:hover { background: #e2e8f0; }
.dt-line-send { background: #06C755; color: #fff; }
.dt-line-send:hover { background: #05a548; }
.dt-line-send-chat { background: #fff; color: #05a548; border: 1px solid #06C755 !important; }
.dt-line-send-chat:hover { background: #f0fdf4; }
.dt-line-pop-actions button:disabled { opacity: .6; cursor: default; }

.dt-apt-card-time {
    flex: 0 0 44px;              /* ขยายจาก 38px ให้พอกับตัวเลขที่โตขึ้น */
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .78rem;           /* ~12.5px — เดิม .66rem ขยาย 2026-08-22 */
    font-weight: 600;
    color: #64748b;
    font-variant-numeric: tabular-nums;
    letter-spacing: -.2px;
    background: #f1f5f9;
    border-right: 1px solid #e2e8f0;
    border-radius: 3px 0 0 3px;
    user-select: none;
}
/* ป้ายตรงเวลา/สาย ต่อจากช่องเวลา — ซ่อนเป็น default
   โผล่เฉพาะโหมดเปิดห้องเดียว (.dt-apt-grid--single) เพราะเปิดหลายห้องพร้อมกันจะรก */
.dt-apt-punct {
    display: none;
    flex: 0 0 auto;
    align-self: center;
    min-width: 24px;
    padding: 0 3px;
    margin-left: 1px;
    border-radius: 3px;
    font-size: .6rem;
    font-weight: 700;
    line-height: 1.35;
    text-align: center;
    font-variant-numeric: tabular-nums;
    letter-spacing: -.2px;
    user-select: none;
}
.dt-apt-grid--single .dt-apt-punct { display: block; }
/* รหัสคนไข้จัดฟันบนการ์ด — ซ่อนเป็น default โผล่เฉพาะโหมดเปิดห้องเดียว (เหตุผลเดียวกับ .dt-apt-punct) */
.dt-apt-ortho-code {
    display: none;
    flex: 0 0 auto;
    padding: 0 5px;
    border-radius: 3px;
    background: #ede9fe;
    color: #5b21b6;
    font-size: .7rem;
    font-weight: 600;
    line-height: 1.5;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}
.dt-apt-grid--single .dt-apt-ortho-code { display: inline-block; }
.dt-apt-punct.punct-early     { background: #dbeafe; color: #1d4ed8; }   /* มาก่อน */
.dt-apt-punct.punct-ontime    { background: #dcfce7; color: #15803d; }   /* ตรงเวลา ±5 น. */
.dt-apt-punct.punct-late-mild { background: #fef3c7; color: #b45309; }   /* สาย 6–15 น. */
.dt-apt-punct.punct-late      { background: #fee2e2; color: #b91c1c; }   /* สาย >15 น. */

.dt-apt-card-main {
    flex: 1 1 0;
    min-width: 0;            /* allow flex shrink for ellipsis */
    display: flex;
    flex-direction: column;  /* ชื่อบรรทัดบน / หัตถการบรรทัดล่าง */
    justify-content: center; /* จัดกลางแนวตั้งในการ์ด */
    gap: 1px;
    padding: 1px 4px;
    overflow: hidden;        /* ellipsis on long text */
    line-height: 1.2;
    cursor: pointer;
}
/* บรรทัดชื่อ (เด่น) */
.dt-apt-primary {
    display: flex;
    align-items: center;
    gap: 3px;
    min-width: 0;
    overflow: hidden;
}
.dt-apt-primary .dt-apt-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 600;
    font-size: .9rem;            /* ~14.4px — เดิม .78rem ขยาย 2026-08-22 */
    color: #1e293b;
}
.dt-apt-primary small { flex-shrink: 0; }

/* ── เปิดห้องเดียว (การ์ดกว้าง): ชื่อ + งานที่ทำ อยู่บรรทัดเดียว ──
   คอลัมน์ชื่อกว้างคงที่ 150px → ขอบซ้ายของงานที่ทำเรียงตรงเป็นแนวเดียวกันทุกแถว
   (เดิม 100px แคบไป ชื่อ+ชื่อเล่นโดนตัด … ทั้งที่ด้านหลังว่าง — ขยายเมื่อ 2026-08-22)
   (หลายห้อง = การ์ดแคบ ไม่มี class นี้ → คงเดิม ชื่อ/งานคนละบรรทัด) */
.dt-apt-grid--single .dt-apt-card-main {
    flex-direction: row;
    align-items: center;
    gap: 0;
}
.dt-apt-grid--single .dt-apt-primary {
    flex: 0 0 150px;         /* คอลัมน์ชื่อคงที่ — ชื่อยาวเกินตัด … */
    padding-right: 8px;
}
.dt-apt-grid--single .dt-apt-primary .dt-apt-name { min-width: 0; }   /* ให้ ellipsis ทำงานใน flex */
.dt-apt-grid--single .dt-apt-secondary {
    flex: 1 1 0;
    min-width: 0;
}

/* บรรทัดหัตถการ + ป้ายเสริม (จาง เล็ก) */
.dt-apt-secondary {
    display: flex;
    align-items: center;
    gap: 4px;
    min-width: 0;
    overflow: hidden;
    font-size: .68rem;
    color: #64748b;
    white-space: nowrap;
}
.dt-apt-secondary .dt-apt-treat {
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: .875rem;          /* 14px — ชื่องานที่คนไข้จะทำ (เดิม 12px ขยาย 2026-08-22) */
    color: #475569;
}
/* การ์ดสั้น (นัด 10 นาที = 26px) — ชื่อ+หัตถการอยู่บรรทัดเดียว */
.apt-slots-1 .dt-apt-card-main { flex-direction: row; align-items: center; gap: 5px; }
.apt-slots-1 .dt-apt-primary   { flex: 0 1 auto; }
.apt-slots-1 .dt-apt-secondary { flex: 1 1 auto; }
/* โหมดห้องเดียว: การ์ด 10 นาทีก็ใช้คอลัมน์ชื่อคงที่เท่าการ์ดอื่น → งานที่ทำเรียงตรงกันทุกแถว
   (กฎ apt-slots-1 ด้านบนอยู่หลัง .dt-apt-grid--single เลยชนะ ต้องเพิ่ม specificity ทับกลับ) */
.dt-apt-grid--single .apt-slots-1 .dt-apt-primary { flex: 0 0 150px; }
/* ── เลข CN หน้าชื่อ — เฉพาะเปิดห้องเดียวบนจอ ≥1200px ──
   (iPad แนวนอน/จอแคบ คอลัมน์ชื่อแคบอยู่แล้ว ใส่ CN แล้วชื่อโดนตัดหมด → ไม่แสดง)
   ช่องกว้างขั้นต่ำเท่ากันทุกแถว ตัวเลขความกว้างเท่ากัน (tabular-nums) → CN และชื่อเรียงตรงแนว
   walk-in ไม่มี CN = ช่องเปล่าโปร่งใส แต่ยังกันที่ไว้ ชื่อจะได้ไม่เยื้อง */
.dt-apt-cn {
    display: none;
    flex: 0 0 auto;
    min-width: 52px;             /* CN 7 หลัก (YY×100000+seq) ที่ .7rem ≈ 46px + padding */
    padding: 0 3px;
    margin-right: 4px;
    border-radius: 3px;
    background: #f1f5f9;
    color: #475569;
    font-size: .7rem;
    font-weight: 600;
    line-height: 1.5;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}
.dt-apt-cn:empty { background: transparent; }
@media (min-width: 1200px) {
    .dt-apt-grid--single .dt-apt-cn { display: inline-block; }
    /* ขยายคอลัมน์ชื่อ 150 → 200px ให้ชื่อได้ที่เท่าเดิม (CN กินไป ~56px) — "งานที่ทำ" (flex) หดแทน */
    .dt-apt-grid--single .dt-apt-primary,
    .dt-apt-grid--single .apt-slots-1 .dt-apt-primary { flex: 0 0 200px; }
}
/* ── ราง icon ท้ายการ์ด (โทร / โทรไม่ติด / LINE / กระดิ่ง / ขอเลื่อน) ──
   ปกติ (เปิดหลายห้อง = การ์ดแคบ): ช่องยุบตามเนื้อหา ช่องว่างกว้าง 0 → หน้าตาเหมือนเดิมทุกอย่าง
   โหมดเปิดห้องเดียว: แต่ละช่องกว้างคงที่ ไม่มีไอคอนก็เว้นว่างไว้
   → ไอคอนแต่ละชนิดอยู่คอลัมน์เดียวกันทุกแถว และชิปสถานะ/ชิปหมอเรียงตรงตามไปด้วย */
.dt-apt-icons {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 2px;            /* เดิมไอคอนเป็นลูกตรงของการ์ดที่ gap:2px — คงระยะเดิมไว้ */
}
.dt-apt-islot {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
}
/* ช่องว่างต้องไม่กินที่ตอนการ์ดแคบ — ปุ่มข้างในมี padding ของตัวเองอยู่แล้ว */
.dt-apt-islot:empty { display: none; }

/* เปิดห้องเดียว: ล็อกความกว้างทุกช่อง (22 + 34 + 22 + 22 + 22 = 122px) */
.dt-apt-grid--single .dt-apt-icons  { flex: 0 0 122px; gap: 0; }   /* ช่องคงที่จัดระยะเองแล้ว */
.dt-apt-grid--single .dt-apt-islot  { flex: 0 0 22px; }
.dt-apt-grid--single .dt-apt-islot-nc {
    flex: 0 0 34px;
    order: 9;            /* ป้าย 📵 โผล่ไม่บ่อย — ดันไปท้ายราง ไอคอนที่ใช้ประจำ (โทร/LINE/กระดิ่ง)
                            จะได้ติดกัน ช่องที่กันไว้ไปอยู่ขอบติดชิปสถานะแทน ไม่เป็นรูตรงกลาง */
}
.dt-apt-grid--single .dt-apt-islot:empty { display: flex; }   /* ต้องกันช่องไว้ ไม่ซ่อน */
/* คนไข้มีทั้ง LINE + FB → ช่องแชทกว้างขึ้นเฉพาะการ์ดนั้น (FB โผล่แค่ช่วง 24 ชม. ไม่บ่อย ไม่คุ้มกันที่ทุกการ์ด) */
.dt-apt-grid--single .dt-apt-islot.dt-apt-islot-chat2 { flex: 0 0 auto; }

/* ── iPad แนวนอน (992–1199px): 2 คิวต่อห้อง แต่ละคิว ~480px — คอลัมน์ชื่อ 150px กิน "งานที่ทำ" จนอ่านไม่ได้
   → ย่อคอลัมน์ชื่อเหลือ 110px + ชิปหมอ/ไอคอนเล็กลง (desktop ≥1200 คงเดิม) ── */
@media (min-width: 992px) and (max-width: 1199.98px) {
    .dt-apt-grid--single .dt-apt-primary,
    .dt-apt-grid--single .apt-slots-1 .dt-apt-primary { flex: 0 0 110px; padding-right: 6px; }
    .dt-apt-primary .dt-apt-name { font-size: .82rem; }
    .dt-apt-secondary .dt-apt-treat { font-size: .8rem; }
    .dt-apt-doc-chip { font-size: .62rem; padding: 0 4px; }
    .dt-apt-card-time { flex: 0 0 40px; font-size: .72rem; }
    /* รางไอคอนย่อลง ไม่งั้นกิน "งานที่ทำ" จนอ่านไม่ออก (18+26+18+18+18 = 98px) */
    .dt-apt-grid--single .dt-apt-icons    { flex: 0 0 98px; }
    .dt-apt-grid--single .dt-apt-islot    { flex: 0 0 18px; }
    .dt-apt-grid--single .dt-apt-islot-nc { flex: 0 0 26px; }
}
/* ── จอแคบ <992px (iPad แนวตั้ง/มือถือ): ยกเลิกคอลัมน์ชื่อคงที่ ให้ยืดตามชื่อแล้วตัด … ท้ายตามปกติ
   (150px คงที่บนจอแคบทำให้ชื่อโดน clip จากด้านซ้าย เช่น "ะ สนิ") ── */
@media (max-width: 991.98px) {
    /* กริดบนมือถือเป็น overflow-x:auto → sticky ข้างในยึดกับกริด ไม่ใช่ viewport
       ถ้าคง offset = topbar+toolbar จะถูกดันลงเป็นแถบว่าง ~126px แล้วทับแถวแรก → ต้องเริ่มที่ 0 */
    .dt-apt-wrapper { --grid-head-y: 0px; }
    /* การ์ดกว้างแค่ ~340px (2 คิว) ใส่ชื่อ+งานบรรทัดเดียวไม่พอ → กลับไป 2 บรรทัด ชื่อบน งานล่าง (แถวสูง 40px พอดี) */
    .dt-apt-grid--single .dt-apt-card-main,
    .dt-apt-grid--single .apt-slots-1 .dt-apt-card-main { flex-direction: column; align-items: stretch; gap: 0; }
    .dt-apt-grid--single .dt-apt-primary,
    .dt-apt-grid--single .apt-slots-1 .dt-apt-primary { flex: 0 0 auto; min-width: 0; padding-right: 0; }
    .dt-apt-grid--single .dt-apt-secondary { flex: 0 0 auto; min-width: 0; }
    .dt-apt-primary .dt-apt-name { font-size: .82rem; }
    .dt-apt-secondary .dt-apt-treat { font-size: .74rem; }
    /* การ์ด 2 บรรทัดบนจอแคบ — ล็อกความกว้างรางไม่มีประโยชน์ ปล่อยยุบตามเนื้อหา */
    .dt-apt-grid--single .dt-apt-icons    { flex: 0 0 auto; }
    .dt-apt-grid--single .dt-apt-islot,
    .dt-apt-grid--single .dt-apt-islot-nc { flex: 0 0 auto; }
    .dt-apt-grid--single .dt-apt-islot:empty { display: none; }
}
/* Status chip (ชิดขวาการ์ด) */
.dt-apt-card-chip {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    padding-right: 5px;
}
.dt-apt-chip {
    font-size: .75rem;           /* 12px — เท่าชื่องาน */
    font-weight: 600;
    padding: 0 8px;
    border-radius: 8px;
    white-space: nowrap;
    line-height: 1.55;
    background: #e2e8f0;
    color: #475569;
    /* ทุกสถานะกว้างเท่ากัน + จัดกึ่งกลาง ให้ดูเป็นระเบียบ (ยาวสุด = "ไม่รับสาย") */
    min-width: 82px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
/* ชิปกดได้ — เปลี่ยนสถานะจากการ์ด */
button.dt-apt-chip-btn { border: none; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 2px; }
button.dt-apt-chip-btn:hover { filter: brightness(.94); }
.dt-apt-chip-caret { font-size: .5rem; opacity: .65; }

/* เมนูเปลี่ยนสถานะ (ลอย) */
.dt-status-menu {
    position: fixed;
    z-index: 2200;
    background: #fff;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    box-shadow: 0 8px 22px rgba(0,0,0,.22);
    padding: 4px;
    min-width: 150px;
}
.dt-status-item {
    display: flex; align-items: center; gap: 8px;
    width: 100%;
    background: transparent; border: none;
    padding: 7px 10px; border-radius: 7px;
    font-size: .85rem; color: #1e293b; text-align: left;
    cursor: pointer;
}
.dt-status-item:hover { background: #f1f5f9; }
.dt-status-item i { font-size: .95rem; }
.apt-blue       .dt-apt-chip { background: #dbeafe; color: #1e40af; }
/* ยืนยันแล้ว — เขียวเข้มนวล (จ้าน้อยลง) ตัวหนังสือขาว ยังเด่นแม้พื้นแถวมีสีหมอทับ */
.apt-green      .dt-apt-chip { background: #dcfce7; color: #166534; }
.apt-purple     .dt-apt-chip { background: #ddd6fe; color: #5b21b6; }
.apt-gray       .dt-apt-chip { background: #e2e8f0; color: #475569; }
.apt-orange     .dt-apt-chip { background: #ffedd5; color: #9a3412; }
.apt-red        .dt-apt-chip { background: #fee2e2; color: #991b1b; }
.apt-cancel     .dt-apt-chip { background: #e5e7eb; color: #6b7280; }
.apt-no-contact .dt-apt-chip { background: #fee2e2; color: #b91c1c; }
/* ยืนยันเองทาง LINE — เขียว LINE นวลลง (จ้าน้อยลง) แยกจาก "ยืนยัน" กดเองด้วยไอคอน LINE */
/* ยืนยันผ่าน LINE — สี badge เหมือนยืนยันกดเอง (เขียวอ่อนจาก .apt-green) ต่างกันแค่มีไอคอน LINE นำหน้า */
.dt-apt-chip-line { display: inline-flex; align-items: center; gap: 2px; }
.dt-apt-chip-line i { font-size: .85em; }
.dt-apt-chip-line .bi-line { color: #06C755; }  /* คงสีเขียว LINE ไว้ที่ตัวไอคอน (ไม่แตะ caret) */

/* คนไข้กด "ขอเลื่อน" ทาง LINE — ยังไม่ใช่การเลื่อนจริง การ์ดค้างในตารางรอเจ้าหน้าที่ลงช่องใหม่
   ชิปส้มทับสีตามสถานะเดิม (จอง/ยืนยัน) เพราะเรื่องที่ต้องรีบรู้คือ "ขอเลื่อน" */
button.dt-apt-chip.dt-apt-chip-resched { background: #fef3c7; color: #b45309; }
button.dt-apt-chip.dt-apt-chip-resched .bi-line { color: #06C755; }

/* ปุ่มเลื่อนบนการ์ด — โผล่เฉพาะใบที่คนไข้ขอเลื่อน (เมนู "เลื่อนนัด" ในชิปยังมีครบทุกใบเหมือนเดิม) */
.dt-apt-resched-btn {
    flex: 0 0 auto;
    align-self: center;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    cursor: pointer;
    color: #d97706;
    font-size: 1rem;
    padding: 0 3px;
    transition: transform .1s, color .1s;
}
.dt-apt-resched-btn:hover { color: #b45309; transform: rotate(-45deg) scale(1.15); }

/* Popup ประวัติคนไข้ (หน้าตารางนัด) — overlay ล้วน ไม่ใช่ Bootstrap modal
   เพราะเปิดจากใน #apptModal ซึ่งเป็น modal อยู่แล้ว z-index ต้องสูงกว่า modal ของ Bootstrap (1055) */
.dt-pt-pop { position: fixed; inset: 0; z-index: 2400; }
.dt-pt-pop-backdrop { position: absolute; inset: 0; background: rgba(15,23,42,.55); }
.dt-pt-pop-box {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: min(1050px, 94vw);
    height: 88vh;
    display: flex;
    flex-direction: column;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 18px 50px rgba(0,0,0,.35);
    overflow: hidden;
}
.dt-pt-pop-head {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    padding: .5rem .75rem;
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
}
.dt-pt-pop-box iframe { flex: 1 1 auto; width: 100%; border: none; }

/* ortho dashboard — ตารางเคสหัวติด (freeze header) เวลาสกรอลล์ในกล่อง */
.dt-ortho-scroll thead th {
    position: sticky;
    top: 0;
    z-index: 3;
    background: #f1f3f5;
    box-shadow: inset 0 -1px 0 #dee2e6;
}

/* Single-line card content */
.dt-apt-line {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: .78rem;
    width: 100%;
}
.dt-apt-line .dt-apt-name  { color: #1e293b; font-weight: 600; }
.dt-apt-line .dt-apt-treat { color: #475569; }

/* Content lines */
.dt-apt-name-line,
.dt-apt-meta-line,
.dt-apt-treat-line {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.dt-apt-name-line { font-weight: 600; color: #1e293b; font-size: .78rem; }
.dt-apt-meta-line { color: #64748b; font-size: .7rem; }
.dt-apt-treat-line { color: #475569; font-size: .7rem; }

/* Compact 1-line mode: ทุกอย่างยัดอยู่บรรทัดเดียว */
.dt-apt-1line {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: .72rem;
    line-height: 1.2;
    color: #64748b;
}
.dt-apt-1line .dt-apt-cn   { color: #1e293b; font-weight: 500; }
.dt-apt-1line .dt-apt-name { color: #1e293b; font-weight: 600; }

.dt-apt-name { color: #1e293b; }
.dt-apt-cn   { font-family: ui-monospace, monospace; }
.dt-apt-stack-badge {
    background: #fef3c7;
    color: #92400e;
    font-size: .6rem;
    padding: 0 4px;
    border-radius: 4px;
    margin-left: 3px;
    vertical-align: middle;
}

/* Lab badge — บอกว่านัดนี้ต้องใช้ Lab + สถานะการรับ Lab */
.dt-apt-lab-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: .6rem;
    font-weight: 600;
    line-height: 1.3;
    padding: 1px 6px;
    border-radius: 10px;
    margin-left: 3px;
    vertical-align: middle;
    white-space: nowrap;
}
.dt-apt-lab-badge i { font-size: .65rem; }
.dt-apt-lab-badge.lab-pending { background: #fef3c7; color: #92400e; }   /* เหลือง — รอรับ */
.dt-apt-lab-badge.lab-ready   { background: #d1fae5; color: #065f46; }   /* เขียว — รับแล้ว */
.dt-apt-lab-badge.lab-danger  {                                          /* แดง — ยืนยันแล้วแต่ Lab ยังไม่มา */
    background: #fee2e2;
    color: #991b1b;
    animation: dtLabPulse 1.6s ease-in-out infinite;
}
@keyframes dtLabPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, .45); }
    50%      { box-shadow: 0 0 0 3px rgba(220, 38, 38, 0); }
}
@media (prefers-reduced-motion: reduce) {
    .dt-apt-lab-badge.lab-danger { animation: none; }
}

/* Hide rows for small cards */
.apt-slots-1 .dt-apt-meta-line,
.apt-slots-1 .dt-apt-treat-line { display: none; }
.apt-slots-2 .dt-apt-treat-line { display: none; }

/* Hidden hour rows (collapse — outside doctor duty range) */
.dt-apt-time.dt-hour-hidden,
.dt-apt-row.dt-hour-hidden { display: none !important; }

/* Toggle button — กดอยู่ (active) จะ highlight ชัด */
.dt-hours-toggle {
    font-weight: 600;
    border: 1px solid #d97706;
    font-size: 1rem;           /* icon ใหญ่เท่าไอคอนอื่นในแถบ */
    padding: 3px 9px;
    line-height: 1;
}
.dt-hours-toggle:not(.active) {
    background: #fff;
    color: #d97706;
}
.dt-hours-toggle.active {
    background: #f59e0b;
    color: #fff;
}
.dt-hours-toggle.active::after {
    content: ' ✓';
    margin-left: 2px;
}

/* หมายเหตุในการ์ด — แท็ก highlight สีเหลืองอำพัน ให้เห็นชัดว่าเป็นหมายเหตุ */
.dt-apt-note-tag {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    font-size: .75rem;           /* 12px */
    color: #854d0e;              /* amber-800 */
    background: #fef3c7;         /* amber-100 */
    padding: 0 5px 0 4px;
    border-radius: 4px;
    border-left: 2px solid #f59e0b;
    line-height: 1.5;
    cursor: help;
}
.dt-apt-note-tag i { font-size: .62rem; flex-shrink: 0; color: #d97706; }
.dt-apt-note-txt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.dt-apt-note-tag:hover { background: #fde68a; }

/* ปุ่มไอคอนรับทราบ (ซ้ายสุดของป้าย) — คลิกเพื่อ "รับ" */
.dt-apt-note-ackbtn {
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
    padding: 0;
    margin: 0;
    background: transparent;
    border: 0;
    cursor: pointer;
    line-height: 1;
}
.dt-apt-note-ackbtn i { font-size: .68rem; }

/* โน้ตใหม่ — ยังไม่รับ: แดง + ไอคอนเตือนกะพริบ */
.dt-apt-note-new {
    color: #991b1b;             /* red-800 */
    background: #fee2e2;        /* red-100 */
    border-left-color: #ef4444; /* red-500 */
}
.dt-apt-note-new:hover { background: #fecaca; }
.dt-apt-note-new .dt-apt-note-ackbtn i { color: #dc2626; animation: dtNotePulse 1.4s ease-in-out infinite; }

/* โน้ตที่ฉันเขียนเอง ยังไม่ถูกรับ: "ส่งแล้ว" — เทาอ่อน ไอคอนเครื่องบิน ไม่แดง ไม่กะพริบ */
.dt-apt-note-sent {
    color: #475569;             /* slate-600 */
    background: #f8fafc;        /* slate-50 */
    border-left-color: #cbd5e1; /* slate-300 */
}
.dt-apt-note-sent:hover { background: #f1f5f9; }
.dt-apt-note-sent .dt-apt-note-ackbtn { cursor: default; }
.dt-apt-note-sent .dt-apt-note-ackbtn i { color: #94a3b8; }  /* slate-400 */

/* โน้ตรับแล้ว: เทา + ติ๊กเขียว */
.dt-apt-note-ack {
    color: #475569;             /* slate-600 */
    background: #f1f5f9;        /* slate-100 */
    border-left-color: #94a3b8; /* slate-400 */
}
.dt-apt-note-ack:hover { background: #e2e8f0; }
.dt-apt-note-ack .dt-apt-note-ackbtn i { color: #16a34a; }  /* green-600 */

@keyframes dtNotePulse { 0%, 100% { opacity: 1; } 50% { opacity: .4; } }
@media (prefers-reduced-motion: reduce) {
    .dt-apt-note-new .dt-apt-note-ackbtn i { animation: none; }
}

/* ปุ่มเพิ่มหมายเหตุ (การ์ดที่ยังไม่มีโน้ต) — โผล่ตอน hover การ์ด */
.dt-apt-note-add {
    display: inline-flex;
    align-items: center;
    gap: 1px;
    flex-shrink: 0;
    font-size: .58rem;
    color: #b45309;
    background: transparent;
    border: 1px dashed #fbbf24;
    border-radius: 4px;
    padding: 0 5px 0 3px;
    line-height: 1.5;
    cursor: pointer;
    opacity: 0;
    transition: opacity .12s, background .12s;
}
.dt-apt-note-add i { font-size: .6rem; }
.dt-apt-card:hover .dt-apt-note-add { opacity: .6; }
.dt-apt-note-add:hover { opacity: 1; background: #fef3c7; }

/* Popover พิมพ์หมายเหตุเร็ว */
.dt-note-pop {
    position: fixed;
    z-index: 2000;
    width: 232px;
    background: #fffbeb;
    border: 1px solid #f59e0b;
    border-radius: 8px;
    box-shadow: 0 6px 18px rgba(0,0,0,.2);
    padding: 7px;
}
.dt-note-pop-inp {
    width: 100%;
    box-sizing: border-box;
    font-size: .82rem;
    padding: 5px 7px;
    border: 1px solid #fbbf24;
    border-radius: 5px;
    background: #fff;
    color: #78350f;
    outline: none;
}
.dt-note-pop-inp:focus { border-color: #f59e0b; box-shadow: 0 0 0 2px rgba(245,158,11,.25); }
.dt-note-pop-hint { font-size: .62rem; color: #b45309; margin-top: 4px; display: flex; align-items: center; gap: 3px; }
.dt-note-pop-saving { opacity: .6; pointer-events: none; }

/* Note (remark) — chat-bubble indicator + optional inline line on bigger cards */
.dt-apt-note-ind {
    color: #f59e0b;
    font-size: .78rem;
    margin-left: 4px;
    vertical-align: -1px;
    cursor: help;
}
.dt-apt-note-line {
    font-size: .7rem;
    color: #b45309;
    background: #fffbeb;
    padding: 1px 6px;
    margin: 1px 4px 1px 22px;
    border-radius: 4px;
    line-height: 1.25;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: help;
}
.dt-apt-note-line i { font-size: .7rem; margin-right: 2px; color: #d97706; }
/* Hide note-line on small cards — บรรทัดชื่อ/หัตถการใช้พื้นที่แล้ว โน้ตดูจากไอคอน (hover) */
.apt-slots-1 .dt-apt-note-line,
.apt-slots-2 .dt-apt-note-line { display: none; }

/* Status & menu buttons */
.dt-apt-status-btn,
.dt-apt-menu-btn {
    background: transparent;
    border: none;
    padding: 0;
    width: 100%;
    height: 100%;
    line-height: 1;
    color: #475569;
    cursor: pointer;
    font-size: .9rem;
}
.dt-apt-status-btn { font-size: 1rem; }
.dt-apt-menu-btn   { font-size: 1.05rem; }
.dt-apt-status-btn:hover,
.dt-apt-menu-btn:hover { color: #1e293b; background: rgba(0,0,0,.04); }

/* Dropdown z-index so it's above other cards */
.dt-apt-card .dropdown-menu { z-index: 1080; }

/* =====================================================================
   Receipt (print-friendly)
   ===================================================================== */
.dt-receipt-wrapper {
    max-width: 800px;
    margin: 0 auto;
    padding: 1.5rem;
}
.dt-receipt-actions {
    text-align: right;
    margin-bottom: 1rem;
    display: flex;
    gap: .5rem;
    justify-content: flex-end;
}
.dt-receipt-paper {
    background: #fff;
    border: 1px solid #e2e8f0;
    box-shadow: 0 4px 14px rgba(0,0,0,.06);
    padding: 2rem;
    font-family: 'Sarabun', sans-serif;
}
.dt-receipt-head {
    text-align: center;
    border-bottom: 2px solid #1e293b;
    padding-bottom: 1rem;
    margin-bottom: 1rem;
}
.dt-clinic-name {
    font-size: 1.6rem;
    font-weight: 700;
    margin: 0;
}
.dt-clinic-sub {
    color: #64748b;
    font-size: .92rem;
}
.dt-company-name {
    margin-top: .5rem;
    font-size: .95rem;
    font-weight: 600;
    color: #1e293b;
}
.dt-company-sub {
    font-size: .82rem;
    color: #64748b;
}
.dt-receipt-meta {
    margin-bottom: 1rem;
    font-size: .92rem;
}
.dt-receipt-customer {
    background: #f1f5f9;
    padding: .65rem .9rem;
    border-radius: 6px;
    margin-bottom: 1rem;
    font-size: .92rem;
}
.dt-receipt-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1rem;
}
.dt-receipt-table th,
.dt-receipt-table td {
    padding: .45rem .55rem;
    border-bottom: 1px solid #e2e8f0;
    font-size: .9rem;
}
.dt-receipt-table th {
    background: #f8fafc;
    font-weight: 600;
    text-align: left;
}
.dt-receipt-table .text-end { text-align: right; }
.dt-receipt-table tfoot td {
    border-top: 2px solid #1e293b;
    border-bottom: none;
    padding-top: .65rem;
    font-size: 1rem;
}
.dt-receipt-pay {
    margin: 1rem 0;
    font-size: .92rem;
}
.dt-receipt-pay-table {
    width: 100%;
    margin-top: .4rem;
    border-collapse: collapse;
}
.dt-receipt-pay-table td {
    padding: .25rem .45rem;
    border-bottom: 1px dashed #e2e8f0;
}
.dt-receipt-pay-table .text-end { text-align: right; }
.dt-receipt-sign {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    margin: 2.5rem 0 1.5rem;
}
.dt-sign-line {
    border-bottom: 1px dotted #94a3b8;
    margin-bottom: .35rem;
    height: 2rem;
}
.dt-receipt-foot {
    text-align: center;
    color: #94a3b8;
    border-top: 1px dashed #e2e8f0;
    padding-top: .85rem;
    margin-top: 1.5rem;
}

@media print {
    body { background: #fff !important; }
    .no-print { display: none !important; }
    .dt-receipt-wrapper { padding: 0; max-width: 100%; }
    .dt-receipt-paper {
        border: none;
        box-shadow: none;
        padding: 0;
    }
}

/* ===== Right column: appointment schedule for selected exam room ===== */
.dt-queue-appts {
    flex: 0 0 280px;
    background: #fff;
    border-left: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    height: calc(100vh - 60px);
    position: sticky;
    top: 60px;
    overflow: hidden;
}
.dt-queue-appts-header {
    padding: .75rem .9rem;
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
}
.dt-queue-appts-title {
    font-weight: 600;
    color: #0f172a;
    font-size: .92rem;
    display: flex;
    align-items: center;
    gap: .4rem;
}
.dt-queue-appts-title i { color: var(--dt-primary); }
.dt-queue-appts-body {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: .5rem;
}
.dt-appt-item {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-left: 3px solid #94a3b8;
    border-radius: 8px;
    padding: .5rem .65rem;
    margin-bottom: .45rem;
    display: flex;
    gap: .55rem;
    transition: box-shadow .12s;
}
.dt-appt-item:hover { box-shadow: 0 2px 8px rgba(0,0,0,.06); }
.dt-appt-item.dt-appt-status-booked        { border-left-color: #0ea5e9; background: #fff; }
.dt-appt-item.dt-appt-status-confirmed     { border-left-color: #16a34a; background: #f0fdf4; }
.dt-appt-item.dt-appt-status-checked_in    { border-left-color: #8b5cf6; background: #faf5ff; }
.dt-appt-item.dt-appt-status-rescheduled   { border-left-color: #d97706; background: #fffbeb; }
.dt-appt-item.dt-appt-status-cancelled     { border-left-color: #dc2626; background: #fef2f2; opacity: .7; }
.dt-appt-item.dt-appt-status-no_show       { border-left-color: #dc2626; background: #fef2f2; }
.dt-appt-item.dt-appt-status-done          { border-left-color: #64748b; background: #f8fafc; opacity: .65; }
.dt-appt-time {
    flex: 0 0 38px;
    text-align: center;
    font-weight: 700;
    color: #0284c7;
    font-size: .82rem;
    font-variant-numeric: tabular-nums;
    padding-top: 2px;
}
.dt-appt-body { flex: 1 1 0; min-width: 0; }
.dt-appt-name {
    font-weight: 600;
    color: #0f172a;
    font-size: .82rem;
    line-height: 1.25;
    word-break: break-word;
}
.dt-appt-meta {
    font-size: .7rem;
    color: #64748b;
    line-height: 1.3;
    margin-top: 1px;
}
.dt-appt-meta i { color: #94a3b8; font-size: .72rem; }
.dt-appt-status-pill {
    display: inline-block;
    font-size: .68rem;
    font-weight: 600;
    padding: 1px 7px;
    border-radius: 999px;
    background: rgba(0,0,0,.06);
    color: #475569;
    margin-top: 3px;
}
.dt-appt-status-booked      .dt-appt-status-pill { background: #dbeafe; color: #1e40af; }
.dt-appt-status-confirmed   .dt-appt-status-pill { background: #dcfce7; color: #15803d; }
.dt-appt-status-checked_in  .dt-appt-status-pill { background: #ede9fe; color: #5b21b6; }
.dt-appt-status-rescheduled .dt-appt-status-pill { background: #fef3c7; color: #b45309; }
.dt-appt-status-cancelled   .dt-appt-status-pill { background: #fee2e2; color: #b91c1c; }
.dt-appt-status-no_show     .dt-appt-status-pill { background: #fee2e2; color: #991b1b; }
.dt-appt-status-done        .dt-appt-status-pill { background: #e2e8f0; color: #475569; }

/* Note (remark) display + edit form */
.dt-appt-note {
    font-size: .72rem;
    color: #475569;
    background: rgba(255,255,255,.7);
    padding: 3px 6px;
    border-radius: 4px;
    margin-top: 4px;
    line-height: 1.3;
    overflow-wrap: anywhere;
}
.dt-appt-note i { color: #94a3b8; margin-right: 2px; }
.dt-appt-edit-btn {
    font-size: .7rem;
    text-decoration: none !important;
    margin-top: 2px;
    color: #64748b !important;
}
.dt-appt-edit-btn:hover { color: var(--dt-primary) !important; }
.dt-appt-edit { font-size: .82rem; }
.dt-appt-edit .form-control,
.dt-appt-edit .form-select { font-size: .78rem; }
.dt-appt-edit .form-label { font-size: .7rem; color: #64748b; }

/* Toggle button in queue sidebar header */
.dt-appts-toggle { font-size: .78rem; }

/* Mobile: appt column stacks below */
@media (max-width: 991.98px) {
    .dt-queue-appts {
        flex: 0 0 auto;
        height: auto;
        max-height: 50vh;
        position: relative;
        top: 0;
        border-left: 0;
        border-top: 1px solid #e2e8f0;
    }
}

/* ===== Queue content card color hierarchy (focus cues) ===== */
.dt-queue-content .card { border-left-width: 0; }

/* SOAP card — blue accent */
.dt-queue-content form[action*="/soap"].card {
    border-left: 4px solid #0ea5e9 !important;
    background: #fafdff;
}
.dt-queue-content form[action*="/soap"] > .card-header {
    background: #e0f2fe !important;
    color: #075985;
}

/* Items (หัตถการ) — green accent */
.dt-queue-content .card:has(form[action*="/items"]) {
    border-left: 4px solid #16a34a !important;
}
.dt-queue-content .card:has(form[action*="/items"]) > .card-header {
    background: #dcfce7;
    color: #14532d;
}

/* Products (ยา) — purple accent */
.dt-queue-content .card:has(form[action*="/products"]) {
    border-left: 4px solid #8b5cf6 !important;
}
.dt-queue-content .card:has(form[action*="/products"]) > .card-header {
    background: #ede9fe;
    color: #5b21b6;
}

/* Summary row — yellow tint */
.dt-queue-content .row.g-3 > .col-md-7 > .card,
.dt-queue-content .row.g-3 > .col-md-5 > .card {
    background: #fffef5;
    border-left: 3px solid #f59e0b !important;
}

/* --- Right content area (treatment details)
   Outer container does NOT scroll. It's a flex-column whose first children
   (action bar + patient card) are fixed, and the inner .dt-vd-scrollable
   takes the rest and scrolls. This guarantees the patient card stays put. --- */
.dt-queue-content {
    flex: 1 1 0;
    min-width: 0;
    padding: 1.25rem 1.5rem;
    height: calc(100vh - 60px);
    max-height: calc(100vh - 60px);
    overflow: hidden;                  /* IMPORTANT: outer must not scroll */
    position: relative;
    display: flex;
    flex-direction: column;
}

.dt-empty-state {
    padding: 4rem 1.5rem;
    color: #94a3b8;
    flex: 1 1 0;                    /* fill available space inside flex-column parent */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}
.dt-empty-state i.bi { color: #cbd5e1; }

/* Action bar above patient card stays fixed */
.dt-queue-content > .d-flex {
    flex: 0 0 auto;
}

/* --- Mobile: stack vertically --- */
@media (max-width: 991.98px) {
    .dt-queue-wrapper {
        flex-direction: column;
        margin: -1.5rem;
    }
    .dt-queue-sidebar {
        flex: 0 0 auto;
        height: auto;
        max-height: 50vh;
        position: relative;
        top: 0;
        border-right: 0;
        border-bottom: 1px solid #e2e8f0;
    }
    .dt-queue-content {
        padding: 1rem;
        height: auto;
        max-height: none;
        overflow: visible;             /* on mobile, let the page itself scroll */
    }
    .dt-vd-scrollable {
        overflow: visible;
        flex: 0 0 auto;
    }
    .dt-patient-card {
        max-height: none;
    }
    .dt-vd-frozen {
        max-height: none;
    }
    .dt-vd-frozen .card {
        max-height: none;
        overflow: visible;
    }
    .dt-vd-frozen .card-body { overflow: visible; }
    .dt-mp-listwrap        { overflow: visible; }
}

/* ===== Popover ส่วนลด % (ปุ่ม % ในตารางหัตถการ/ยา + ฟอร์มเพิ่มรายการ) =====
   เด้งตรงปุ่มที่กด — วางด้วยพิกัดเทียบเอกสาร (JS ใน views/partials/visit_detail.php) */
.dt-disc-pop {
    position: absolute;
    z-index: 1080;
    width: 232px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, .16);
    padding: 10px;
    font-size: .8rem;
    animation: dtDiscIn .12s ease-out;
}
@keyframes dtDiscIn {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}
.dt-disc-head {
    font-size: .75rem; color: #64748b;
    padding-bottom: 6px; margin-bottom: 8px;
    border-bottom: 1px solid #f1f5f9;
}
.dt-disc-head b { color: #0f172a; }
.dt-disc-empty { font-size: .78rem; color: #b45309; }

.dt-disc-chips { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.dt-disc-chip {
    border: 1px solid #e2e8f0; background: #f8fafc; color: #0f172a;
    border-radius: 7px; padding: 6px 0; font-size: .8rem; font-weight: 600;
    cursor: pointer; transition: background .12s, border-color .12s, color .12s;
}
.dt-disc-chip:hover  { background: #e0f2fe; border-color: #7dd3fc; }
.dt-disc-chip.is-on  { background: #0ea5e9; border-color: #0ea5e9; color: #fff; }

.dt-disc-row { display: flex; align-items: center; gap: 6px; margin-top: 8px; }
.dt-disc-input {
    width: 76px; border: 1px solid #cbd5e1; border-radius: 7px;
    padding: 5px 8px; font-size: .8rem; text-align: right;
    -moz-appearance: textfield;   /* ซ่อนลูกศรขึ้น-ลง ให้ดูสะอาด */
}
.dt-disc-input::-webkit-outer-spin-button,
.dt-disc-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
/* ช่องเงิน/% ในตารางหัตถการ + จำหน่ายสินค้า (ราคา/ส่วนลด/DF) — ซ่อนลูกศรขึ้น-ลง เพิ่มทีละ 1 ไม่เหมาะกับเงิน
   ช่องจำนวน (.dt-edit-qty) คงลูกศรไว้ · กันปุ่ม ↑/↓ และ scroll เมาส์เปลี่ยนค่าอยู่ใน bindRow (visit_detail.php) */
.dt-edit-price, .dt-edit-discount, .dt-edit-df { -moz-appearance: textfield; appearance: textfield; }
.dt-edit-price::-webkit-outer-spin-button, .dt-edit-price::-webkit-inner-spin-button,
.dt-edit-discount::-webkit-outer-spin-button, .dt-edit-discount::-webkit-inner-spin-button,
.dt-edit-df::-webkit-outer-spin-button, .dt-edit-df::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.dt-disc-input:focus { outline: 0; border-color: #0ea5e9; box-shadow: 0 0 0 3px rgba(14,165,233,.15); }
.dt-disc-unit    { color: #64748b; }
.dt-disc-preview { margin-left: auto; font-weight: 600; color: #0f766e; white-space: nowrap; }

.dt-disc-foot { display: flex; gap: 6px; margin-top: 10px; }
.dt-disc-clear, .dt-disc-ok {
    flex: 1; border-radius: 7px; padding: 6px 0;
    font-size: .78rem; font-weight: 600; cursor: pointer;
    border: 1px solid transparent;
}
.dt-disc-clear { background: #fff; border-color: #e2e8f0; color: #64748b; }
.dt-disc-clear:hover { background: #f8fafc; color: #dc2626; border-color: #fecaca; }
.dt-disc-ok { background: #0ea5e9; color: #fff; }
.dt-disc-ok:hover { background: #0284c7; }

@media print { .dt-disc-pop { display: none !important; } }

/* ===== คอลัมน์เสริมในตารางหัตถการ/ยา (คอร์ส + ส่วนลด) — ซ่อน/แสดงได้ =====
   ไม่ได้ใช้ทุกเคส ซ่อนไว้ให้ตารางโล่ง กดปุ่มในหัวการ์ดเพื่อเปิดดู (จำค่าไว้ใน localStorage) */
.dt-optcols-hidden .dt-col-opt { display: none !important; }

.dt-optcols-toggle {
    font-size: .78rem; color: #64748b; line-height: 1.2;
}
.dt-optcols-toggle:hover  { color: #0ea5e9; }
.dt-optcols-toggle.is-on  { color: #0ea5e9; font-weight: 600; }

/* บาทที่ลดจริง แสดงใต้ช่อง % (ช่องกรอกเป็น % แต่เงินที่หักคือบาท ต้องเห็นทั้งคู่)
   ลอย (absolute) อยู่ในระยะ padding ล่างของช่อง — ไม่กินความสูง ช่องส่วนลดจึงตรงแนวกับช่องอื่นในแถว */
.dt-disc-cell { position: relative; }
.dt-disc-hint {
    position: absolute; right: .5rem; bottom: 1px;
    font-size: .68rem; color: #64748b; line-height: 1.1; text-align: right; pointer-events: none;
}
.dt-disc-hint:empty { display: none; }
/* padding บน-ล่างเท่ากันทุกช่อง (ทุกช่องกึ่งกลางแนวเดียว) + เผื่อที่ให้ยอดลดบาทที่ลอยอยู่ใต้ช่องส่วนลด */
#dtItemsTbody > tr > td, #dtProductsTbody > tr > td { padding-top: .7rem; padding-bottom: .7rem; }
/* ตารางหัตถการ/จำหน่ายสินค้า: คอลัมน์ช่องกรอก — หัว + ช่อง กึ่งกลางทั้งคู่ → กึ่งกลางตรงกันทุกคอลัมน์ไม่ว่าช่องกว้างเท่าไร
   (คอลัมน์ "รวม" อ่านอย่างเดียว คงชิดขวา) */
.dt-c { text-align: center !important; }
.dt-col-name { min-width: 160px; }
/* ความกว้างช่องพอดีข้อมูล (ch = ความกว้างตัวเลข 1 ตัว)
   จำนวน: จำนวนเต็ม 2–3 หลัก + ลูกศร · ราคา/DF: สูงสุด 99999.99 · หมอ: กว้างเท่าชื่อหมอที่ยาวที่สุดใน dropdown (width:auto ของ select) */
.dt-edit-qty   { display: inline-block; width: calc(3ch + 2.4rem); text-align: center; }
.dt-edit-price { display: inline-block; width: calc(8ch + 1.4rem); text-align: right; }
.dt-df-wrap    { display: inline-flex; width: auto; }
.dt-df-wrap > .dt-edit-df { flex: 0 0 auto; width: calc(8ch + 1.4rem); }
.form-select.dt-edit-doctor { display: inline-block; width: auto; max-width: 100%; }
.dt-disc-cell .dt-disc-hint { right: auto; left: 50%; transform: translateX(-50%); }

/* "= ยอดรวม" บรรทัดเดียว เครื่องหมาย = จางลง */
.dt-line-eq { color: #94a3b8; font-weight: 400; }

/* DF เหมาจ่าย (฿) — สีม่วงอ่อนให้ต่างจาก % ส่วนแบ่ง เห็นปุ๊บรู้ว่าเป็นยอดตายตัว */
.dt-edit-df.dt-df-fixed { background: #f3e8ff; color: #6b21a8; font-weight: 600; }
/* ปุ่มหน่วย % / ฿ ต่อท้ายช่องส่วนลด + DF — ขอบเหลืองโทนเดียวกับ .dt-cell-edit สูงเท่าช่องตัวเลข
   .dt-seg-on = หน่วย/โหมดที่ใช้อยู่ (พื้นเหลืองเข้ม ตัวหนา) · ไม่มี = กดได้ (พื้นขาว ตัวจาง) */
.input-group > .dt-seg {
    background: #fff; color: #94a3b8; font-weight: 600;
    border: 1px solid #fde68a !important; min-width: 26px;
    display: flex; align-items: center; justify-content: center; box-shadow: none;
}
.input-group > .dt-seg:hover:not(.dt-seg-on):not(:disabled) { background: #fffbeb; color: #b45309; }
.input-group > .dt-seg.dt-seg-on,
.input-group > .dt-seg.dt-seg-on:hover,
.input-group > .dt-seg.dt-seg-on:focus { background: #fde68a; color: #78350f; cursor: default; }
.input-group > .dt-seg:disabled { opacity: .55; }
.dt-df-fixed-badge { background: #f3e8ff; color: #6b21a8; font-weight: 600; }
.dt-df-fixed-text  { color: #6b21a8; }

/* ── ตารางล่าง "รายการที่เลื่อน / ผิดนัด / ยกเลิก" (หน้าตารางนัด) ──
   ห้องละตาราง → ความกว้างคอลัมน์ตายตัวจาก <colgroup> ชุดเดียวกัน ให้ทุกห้องตรงแนว
   ข้อความยาวขึ้นบรรทัดใหม่ในช่อง (ไม่ตัดทิ้ง) · จอแคบกว่า 960px ให้ .table-responsive เลื่อนแทนการบีบคอลัมน์ */
.dt-arch-table { table-layout: fixed; width: 100%; min-width: 960px; }
.dt-arch-table th, .dt-arch-table td { overflow-wrap: anywhere; }

/* ── ช่องเลือกหมอแบบพิมพ์ค้นหา (dtDoctorPicker ใน app.js) — ฟอร์มลงเวรหมอ ── */
.dt-docpick { position: relative; }
.dt-docpick-menu { width: 100%; max-height: 260px; overflow-y: auto; margin-top: 2px; }
.dt-docpick-menu.show { display: block; position: absolute; left: 0; top: 100%; z-index: 1070; }
.dt-docpick-empty { padding: .35rem .9rem; color: #94a3b8; font-size: .85rem; }

/* ── ปุ่มลัดเวลาเวร (shift_presets()) ── */
.dt-shift-quick { cursor: pointer; font-weight: 500; }
.dt-shift-quick:hover { background: #dbeafe !important; color: #1e40af !important; }

/* ── วันหยุดราชการ (config/public_holidays.php · holiday_flag()) — ธงแดงเฉย ๆ ไม่มีผลกับการลงนัด ── */
.dt-hol { color: #dc2626; font-size: .8em; margin-left: .3em; cursor: help; }
.dt-hol-abs { position: absolute; top: 2px; right: 3px; color: #dc2626; font-size: .65rem; line-height: 1; pointer-events: none; }
.dt-datecal-day, .cbk-cal-day, .dt-date-pill { position: relative; }   /* ช่องวัน → ให้ธง .dt-hol-abs ลอยมุมได้ */

/* ===== กล่อง "คัดลอกชื่อ + เปิด Messenger" (dtFbHandoff ใน app.js) — ห้อง FB ที่เลย 24 ชม. ===== */
.dt-fbh-pop {
    position: fixed; z-index: 1090; width: 300px; max-width: calc(100vw - 16px);
    background: #fff; border: 1px solid #e2e8f0; border-radius: 10px;
    box-shadow: 0 10px 28px rgba(15,23,42,.18); font-size: .84rem; overflow: hidden;
}
.dt-fbh-head { padding: 8px 12px; background: #f1f5f9; color: #334155; font-weight: 600; display: flex; gap: 6px; align-items: center; }
.dt-fbh-body { padding: 10px 12px 12px; }
.dt-fbh-sub { color: #64748b; margin-bottom: 8px; }
.dt-fbh-row { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.dt-fbh-lbl { flex: 0 0 62px; color: #94a3b8; font-size: .78rem; }
.dt-fbh-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.dt-fbh-warn { margin-top: 6px; font-size: .76rem; color: #b45309; background: #fffbeb; border-radius: 6px; padding: 3px 8px; }
.dt-fbh-toast {
    position: fixed; top: 14px; left: 50%; transform: translateX(-50%); z-index: 99999;
    background: #1e293b; color: #fff; padding: 8px 16px; border-radius: 10px; font-size: .85rem;
    box-shadow: 0 6px 20px rgba(0,0,0,.3); max-width: calc(100vw - 24px);
}

/* ปุ่ม FB เกิน 24 ชม. บนการ์ดนัด — สีเทา + นาฬิกาเล็ก (กดแล้วไปตอบใน Messenger) */
.dt-apt-fbx-btn {
    position: relative;
    flex: 0 0 auto;
    display: flex; align-items: center; justify-content: center;
    color: #94a3b8; opacity: .8; font-size: .95rem; padding: 0 3px;
    background: transparent; border: none; cursor: pointer;
    transition: transform .1s, opacity .1s;
}
.dt-apt-fbx-btn:hover { opacity: 1; color: #0866FF; transform: scale(1.18); }
.dt-apt-fbx-btn .dt-fbx-clock {
    position: absolute; right: -1px; bottom: -3px; font-size: .55rem;
    color: #f59e0b; background: #fff; border-radius: 50%; line-height: 1;
}

/* กล่องแนะนำ "ตอบผ่าน Messenger" — ห้อง FB เกิน 24 ชม. (views/chat/_fb_closed.php) */
.dt-fb-closed {
    flex: 0 0 auto;
    background: #fef2f2; border: 1px solid #fecaca; border-radius: 10px;
    padding: 10px 12px; margin: 6px 0; color: #7f1d1d; font-size: .84rem;
}
.dt-fb-closed-head { display: flex; gap: 6px; align-items: flex-start; font-weight: 600; color: #991b1b; }
.dt-fb-closed-steps { margin: 8px 0 10px; padding-left: 1.3rem; color: #57534e; font-weight: 400; }
.dt-fb-closed-steps li { margin-bottom: 2px; }
.dt-mchat-body .dt-fb-closed { margin: 0; border-radius: 0; border-width: 1px 0 0; }
