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

: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;
        box-shadow: 0 0 24px rgba(0,0,0,.18);
    }
    .dt-main { width: 100%; }
}

/* ---- 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: 600;
    font-size: .88rem;
    margin-bottom: .1rem;
    line-height: 1.25;
}
.dt-queue-card-meta {
    font-size: .7rem;
    color: #64748b;
}
.dt-queue-card-symp {
    font-size: .72rem;
    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 { display: none !important; }
    .dt-main { width: 100% !important; }
    .dt-content { padding: 0 !important; }
}

/* =====================================================================
   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;
    /* CSS variables for sticky offsets */
    --top-h: 52px;
    --toolbar-h: 50px;
    --datestrip-h: 64px;
    --grid-head-y: calc(var(--top-h) + var(--toolbar-h) + var(--datestrip-h));
    --grid-header-h: 38px;
    --grid-doctor-h: 36px;
    --grid-subhead-h: 22px;
}

.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: 5px 4px;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,.04);
    margin-bottom: .5rem;
    display: flex;
    align-items: center;
    gap: 4px;
    position: sticky;
    top: calc(var(--top-h) + var(--toolbar-h) + 4px);
    z-index: 98;
}
.dt-apt-datestrip {
    flex: 1 1 auto;
    overflow-x: auto;
    overflow-y: hidden;
    display: flex;
    gap: 5px;
    scroll-behavior: smooth;
    scrollbar-width: thin;
    padding: 2px 0;
}
.dt-apt-datestrip::-webkit-scrollbar { height: 5px; }
.dt-apt-datestrip::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 5px; }

.dt-date-pill {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 50px;
    padding: 4px 8px;
    border-radius: 8px;
    text-decoration: none;
    line-height: 1.1;
    transition: transform .12s, box-shadow .12s;
    border: 2px solid transparent;
}
.dt-date-pill-day { font-size: .65rem; opacity: .85; }
.dt-date-pill-num { font-size: 1.1rem; line-height: 1.1; }
.dt-date-pill-mo  { font-size: .6rem; opacity: .65; }
.dt-date-pill:hover { transform: scale(1.06); }
.dt-date-pill.today {
    border-color: rgba(0,0,0,.25);
}
.dt-date-pill.active {
    border-color: var(--dt-primary);
    box-shadow: 0 2px 8px rgba(25,118,210,.3);
    transform: scale(1.08);
    z-index: 1;
}

/* 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; }
/* ส่วน scroll ที่ครอบตาราง — สูงสุดเท่าหน้าจอลบ topbar เพื่อให้ thead สามารถ stick ได้ */
.dt-sched-scroll {
    max-height: calc(100vh - 240px);
    overflow: auto;
    border-radius: .375rem;
}
.dt-sched-table {
    table-layout: fixed;
    width: 100%;
    margin-bottom: 0;
}
.dt-sched-table th,
.dt-sched-table td {
    padding: .4rem .55rem;
    vertical-align: top;
    word-wrap: break-word;
    overflow-wrap: break-word;
}
/* Sticky thead — โผล่อยู่บนเสมอเวลา scroll */
.dt-sched-table thead th {
    position: sticky;
    top: 0;
    background: #f8fafc;
    z-index: 5;
    box-shadow: inset 0 -1px 0 #dee2e6;
}
.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 {
    /* width is distributed equally by table-layout: fixed
       (90px date + 60px action + remaining split evenly across rooms) */
    min-width: 0;
}
.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: .65rem .9rem !important; }
.dt-patient-card h1.h5      { font-size: 1.02rem; }

/* Profile photo avatar in patient info card */
.dt-pat-photo {
    flex: 0 0 56px;
    width: 56px;
    height: 56px;
    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: 2rem;
    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: 42vh;              /* 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: 42vh;
    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; }
.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); }

/* === Slideshow nav buttons (prev/next/play) === */
.dt-lightbox-nav {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    width: 48px;
    height: 64px;
    border-radius: 6px;
    border: 0;
    background: rgba(255,255,255,.18);
    color: #fff;
    font-size: 1.6rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background .15s;
    z-index: 1080;
}
.dt-lightbox-nav:hover { background: rgba(255,255,255,.36); }
.dt-lightbox-prev { left: 1rem; }
.dt-lightbox-next { right: 1rem; }
.dt-lightbox-slideshow {
    position: fixed;
    top: 1rem;
    left: 1rem;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 0;
    background: rgba(255,255,255,.18);
    color: #fff;
    font-size: 1.4rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 1080;
}
.dt-lightbox-slideshow:hover { background: rgba(255,255,255,.36); }
.dt-lightbox-counter {
    position: fixed;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,.5);
    color: #fff;
    padding: 4px 12px;
    border-radius: 999px;
    font-size: .85rem;
    z-index: 1080;
}

/* =====================================================================
   Patient Dashboard (Journey / KPI / Reliability)
   ===================================================================== */
.dt-pat-dashboard {
    background: linear-gradient(135deg, #f8fafc 0%, #fff 60%);
}
.dt-pat-kpi {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: .75rem;
    padding: .65rem .75rem;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: .15rem;
    min-height: 100%;
    transition: transform .12s, box-shadow .12s;
}
.dt-pat-kpi:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0,0,0,.06);
}
.dt-pat-kpi-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    margin-bottom: .15rem;
}
.dt-pat-kpi-val {
    font-size: 1.5rem;
    font-weight: 800;
    line-height: 1;
    font-variant-numeric: tabular-nums;
    color: #1e293b;
}
.dt-pat-kpi-label {
    font-size: .72rem;
    color: #64748b;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .03em;
}
.dt-pat-journey {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    padding-top: .5rem;
    border-top: 1px dashed #e2e8f0;
}
.dt-pat-journey-item {
    display: flex;
    align-items: flex-start;
    gap: .5rem;
    flex: 1 1 180px;
    min-width: 180px;
}
.dt-pat-journey-item > i {
    font-size: 1.25rem;
    margin-top: 2px;
}

/* =====================================================================
   OPD Cards (แฟ้มประวัติเดิม) — Capture & View
   ===================================================================== */
.dt-opd-capture {
    max-width: 640px;
    margin: 0 auto;
    padding-bottom: 120px;
}
.dt-opd-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .75rem;
    margin: -1rem -1rem 1rem;
    background: #0f172a;
    color: #fff;
    border-radius: 0 0 .75rem .75rem;
}
.dt-opd-cn-input {
    font-size: 1.75rem;
    font-weight: 700;
    color: #2563eb;
    background: transparent;
    padding: .25rem 0;
}
.dt-opd-cn-input:focus { box-shadow: none; }

/* Patient banner (locked) */
.dt-opd-patient-banner {
    background: linear-gradient(135deg, #eff6ff 0%, #fff 50%);
    border-left: 4px solid #2563eb !important;
}
.dt-opd-banner-cn {
    text-align: center;
    min-width: 72px;
    padding-right: .75rem;
    border-right: 1px solid #e2e8f0;
}
.dt-opd-banner-cn-num {
    font-size: 1.6rem;
    font-weight: 800;
    color: #2563eb;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}
.dt-opd-gallery-wrap {
    border-radius: 1rem;
    border: 2px dashed #cbd5e1;
    background: rgba(241, 245, 249, .5);
    padding: 1rem;
    min-height: 200px;
}
.dt-opd-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: .75rem;
}
.dt-opd-tile {
    aspect-ratio: 3/4;
    border-radius: .75rem;
    overflow: hidden;
    border: 1px solid #e2e8f0;
    box-shadow: 0 2px 6px rgba(0,0,0,.06);
    background: #fff;
    position: relative;
}
.dt-opd-tile img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    filter: grayscale(.6) contrast(1.15);
}
.dt-opd-tile-tag {
    position: absolute;
    top: 6px;
    left: 6px;
    background: #16a34a;
    color: #fff;
    font-size: .7rem;
    padding: 2px 6px;
    border-radius: 999px;
}
.dt-opd-bottombar {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    background: rgba(255,255,255,.96);
    backdrop-filter: blur(8px);
    border-top: 1px solid #e2e8f0;
    padding: 1rem;
    display: flex;
    gap: .75rem;
    z-index: 30;
}
.dt-opd-shot-btn  { flex: 2; height: 60px; font-size: 1.05rem; font-weight: 700; }
.dt-opd-done-btn  { flex: 1; height: 60px; font-weight: 700; }
.dt-opd-cropmodal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.95);
    z-index: 1100;
    display: flex;
    flex-direction: column;
}
.dt-opd-cropmodal-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px;
    background: rgba(0,0,0,.7);
    flex-wrap: wrap;
}
.dt-opd-cropmodal-canvas {
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.dt-opd-cropmodal-canvas img {
    display: block;
    max-width: 100%;
    max-height: 100%;
}

/* === View page (gallery feed) === */
.dt-opd-feed {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    align-items: center;
}
.dt-opd-card-row {
    background: #fff;
    border-radius: 1rem;
    box-shadow: 0 4px 16px rgba(0,0,0,.06);
    border: 1px solid #e2e8f0;
    overflow: hidden;
    width: 100%;
    max-width: 900px;
}
.dt-opd-card-img-wrap {
    background: #f8fafc;
    padding: 8px;
}
.dt-opd-card-img-wrap img {
    width: 100%;
    height: auto;
    display: block;
    border-radius: .5rem;
    filter: grayscale(1) contrast(1.5) brightness(1.1);
    mix-blend-mode: multiply;
    cursor: zoom-in;
}
.dt-opd-zoom {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.92);
    z-index: 1080;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.dt-opd-zoom img {
    max-width: 95vw;
    max-height: 92vh;
}
.dt-opd-zoom-close {
    position: fixed;
    top: 1rem;
    right: 1rem;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 0;
    background: rgba(255,255,255,.18);
    color: #fff;
    font-size: 1.1rem;
    cursor: pointer;
}

/* === Cropper overlay === */
.dt-lightbox-cropper {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.92);
    z-index: 1090;
    display: flex;
    flex-direction: column;
}
.dt-lightbox-cropper-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: rgba(0,0,0,.7);
    flex-wrap: wrap;
}
.dt-lightbox-cropper-canvas {
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.dt-lightbox-cropper-canvas img {
    display: block;
    max-width: 100%;
    max-height: 100%;
}

/* === 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-list { }
.dt-mp-item {
    padding: .55rem .7rem;
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-radius: 6px;
    margin-bottom: .5rem;
    line-height: 1.4;
    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: .85rem;
    color: #1e293b;
    margin-bottom: .35rem;
    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; }

/* =====================================================================
   Auto-sync — fade out before reload to hide flicker
   ===================================================================== */
.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; }

.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; }

/* 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: 3;
    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 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: 12;
    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: 11;
    flex-shrink: 0;
}
/* Sub-column header (หลัก / สำรอง) sticky too */
.dt-apt-subcol-header {
    position: sticky;
    top: calc(var(--grid-head-y) + var(--grid-header-h) + var(--grid-doctor-h));
    z-index: 10;
}

.dt-apt-time {
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #64748b;
    font-size: .75rem;
    font-variant-numeric: tabular-nums;
    background: #f8fafc;
}

.dt-apt-slot {
    min-height: 28px;
    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);
}

.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)
   ===================================================================== */
.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(28px * 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; }

/* ===== LINE confirmation indicator (per-card) =====
   แสดงผลคนไข้ตอบกลับมาจาก LINE: ยืนยัน / ขอเลื่อน / ปฏิเสธ
*/
.dt-apt-conf-ind {
    font-size: .82rem;
    margin-right: 3px;
    vertical-align: -1px;
    flex: 0 0 auto;
}
.apt-conf-confirmed {
    box-shadow: inset 3px 0 0 #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;
}

/* 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-main {
    flex: 1 1 0;
    min-width: 0;            /* allow flex shrink for ellipsis */
    display: flex;
    align-items: center;     /* vertical center */
    padding: 1px 4px;
    overflow: hidden;        /* ellipsis on long text */
    line-height: 1.2;
    cursor: pointer;
}

/* 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;
}

/* 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: 2px solid #d97706;
}
.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;
}

/* 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 slot=1 cards (28px — no room) */
.apt-slots-1 .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-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; }
}
