/* ระบบบริหาร — component ของหน้าตารางและรายละเอียด (Phase 1)
   สีและระยะทั้งหมดมาจาก /shared/tokens.css ห้ามใส่ค่าสีตรง ๆ ในไฟล์นี้ */

/* ================= แถบเครื่องมือ ================= */
.toolbar { display: flex; gap: var(--sp-3); align-items: center; flex-wrap: wrap; }
.toolbar__spacer { flex: 1; }
.search { display: flex; align-items: center; gap: var(--sp-2); height: 42px; padding: 0 12px; width: 240px; border: 1px solid var(--c-border-strong); border-radius: var(--radius); background: var(--c-surface); color: var(--c-text-muted); }
.search__input { border: 0; background: transparent; flex: 1; min-width: 0; font-size: 15px; color: var(--c-text); }
.search__input:focus { outline: none; }
.field-inline .field__select { height: 42px; min-width: 150px; }
.field__req { color: var(--c-danger); }

/* ================= ตาราง ================= */
.th-inner { display: inline-flex; align-items: center; gap: 4px; }
.table th.is-sortable { cursor: pointer; user-select: none; }
.table th.is-sortable:hover { color: var(--c-text); }
.table tr.is-selected td { background: var(--c-brand-tint); }
.table-wrap.is-refreshing { opacity: .6; }
.cell-strong { font-weight: 700; }
.cell-link { font-weight: 600; color: var(--c-brand-deep); }
.cell-muted { color: var(--c-text-muted); }

.pager { display: flex; align-items: center; gap: var(--sp-3); padding: 12px 18px; font-size: var(--fs-sm); color: var(--c-text-muted); border-top: 1px solid var(--c-border); flex-wrap: wrap; }
.pager__spacer { flex: 1; }
.pager__size select { height: 30px; border: 1px solid var(--c-border-strong); border-radius: 8px; background: var(--c-surface); }
.pager__pages { display: flex; gap: 4px; align-items: center; }
.pager__btn { min-width: 32px; height: 32px; padding: 0 8px; border: 1px solid var(--c-border); border-radius: 8px; background: var(--c-surface); font-weight: 600; cursor: pointer; }
.pager__btn.is-active { background: var(--c-brand-deep); border-color: var(--c-brand-deep); color: #fff; }
.pager__btn:disabled { opacity: .4; cursor: default; }
.pager__gap { padding: 0 4px; }

/* ================= แท็บ ================= */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--c-border); overflow-x: auto; }
.tabs__tab { padding: 10px 16px; border: 0; border-bottom: 3px solid transparent; background: transparent; color: var(--c-text-muted); font-weight: 600; font-size: 15px; cursor: pointer; display: flex; gap: 8px; align-items: center; white-space: nowrap; }
.tabs__tab.is-active { border-bottom-color: var(--c-brand-deep); color: var(--c-brand-deep); font-weight: 700; }
.tabs__count { font-size: 12px; background: var(--c-surface-sunk); border-radius: 999px; padding: 0 8px; }

/* ================= drawer และ dialog ================= */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(23, 36, 51, .35); z-index: 90; display: flex; justify-content: flex-end; }
.drawer { width: min(480px, 100%); background: var(--c-surface); height: 100%; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.drawer--wide { width: min(760px, 100%); }
.drawer__head { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--c-border); }
.drawer__title { font-size: 17px; margin: 0; flex: 1; }
.drawer__body { flex: 1; overflow: auto; padding: var(--sp-5); }
.drawer__foot { display: flex; gap: var(--sp-2); justify-content: flex-end; padding: var(--sp-3) var(--sp-5); border-top: 1px solid var(--c-border); }

.dialog-backdrop { position: fixed; inset: 0; background: rgba(23, 36, 51, .35); z-index: 95; display: grid; place-items: center; padding: var(--sp-4); }
.dialog { width: min(560px, 100%); background: var(--c-surface); border-radius: var(--radius); box-shadow: 0 24px 48px rgba(23,36,51,.2); display: flex; flex-direction: column; gap: var(--sp-4); padding: var(--sp-5); max-height: 90vh; }
.dialog__head { display: flex; align-items: center; gap: var(--sp-3); }
.dialog__title { font-size: var(--fs-lg); margin: 0; }
.dialog__body { overflow: auto; font-size: 15px; }
.dialog__foot { display: flex; gap: var(--sp-2); justify-content: flex-end; }

/* ================= รายละเอียด ================= */
.desc { display: grid; grid-template-columns: 120px 1fr; gap: 8px 12px; margin: 0; font-size: 15px; }
.desc dt { color: var(--c-text-muted); }
.desc dd { margin: 0; overflow-wrap: anywhere; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--sp-5); }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-4); }
@media (max-width: 1100px) { .grid-3 { grid-template-columns: 1fr; } }
.timeline { display: flex; flex-direction: column; gap: 14px; }
.timeline__row { display: flex; gap: 12px; }
.timeline__time { width: 120px; flex: none; font-size: 13px; color: var(--c-text-muted); padding-top: 3px; }
.timeline__body { display: flex; flex-direction: column; gap: 2px; font-size: 14px; min-width: 0; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.photo-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.photo { position: relative; aspect-ratio: 4/3; border-radius: 12px; overflow: hidden; border: 1px solid var(--c-border); background: var(--c-surface-sunk); display: grid; place-items: center; color: var(--c-text-muted); }
.photo img { width: 100%; height: 100%; object-fit: cover; }
.photo__del { position: absolute; top: 6px; right: 6px; }
.photo__open { display: block; width: 100%; height: 100%; padding: 0; border: 0; background: transparent; cursor: zoom-in; }
.photo__open:focus-visible { outline: 3px solid var(--c-brand); outline-offset: -3px; }
/* ดูรูปขนาดใหญ่ */
.lightbox { position: fixed; inset: 0; z-index: 1000; background: rgba(23,36,51,.88); display: grid; place-items: center; padding: 48px; outline: none; }
.lightbox img { max-width: 100%; max-height: calc(100vh - 120px); border-radius: 10px; box-shadow: 0 8px 40px rgba(0,0,0,.5); cursor: zoom-out; }
.lightbox__close { position: absolute; top: 14px; right: 14px; width: 44px; height: 44px; border: 0; border-radius: 999px; background: rgba(255,255,255,.15); color: #fff; display: grid; place-items: center; cursor: pointer; }
.lightbox__nav { position: absolute; top: 50%; transform: translateY(-50%); width: 48px; height: 48px; border: 0; border-radius: 999px; background: rgba(255,255,255,.15); color: #fff; display: grid; place-items: center; cursor: pointer; }
.lightbox__nav--prev { left: 14px; } .lightbox__nav--next { right: 14px; }
.lightbox__caption { position: absolute; bottom: 14px; left: 0; right: 0; text-align: center; color: #fff; font-size: 14px; opacity: .9; }
.photo--add { border: 2px dashed var(--c-border-strong); cursor: pointer; font-size: 13px; display: flex; flex-direction: column; gap: 4px; align-items: center; justify-content: center; }
.map-frame { width: 100%; height: 220px; border: 1px solid var(--c-border); border-radius: 12px; }
.map-placeholder { height: 170px; border-radius: 12px; background: var(--c-surface-sunk); border: 1px solid var(--c-border); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; color: var(--c-text-muted); font-size: 13px; }
.order-list { display: flex; flex-direction: column; gap: 8px; }
.order-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--c-border); border-radius: 12px; background: var(--c-surface); cursor: grab; }
.order-item.is-dragging { opacity: .4; }
.order-item__num { width: 28px; height: 28px; border-radius: 999px; background: var(--c-surface-sunk); display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: none; }
.progress { height: 8px; border-radius: 999px; background: var(--c-surface-sunk); overflow: hidden; }
.progress__bar { height: 100%; background: var(--c-ok); }
.password-box { font-family: monospace; font-size: 20px; font-weight: 700; padding: 8px 14px; background: var(--c-surface); border-radius: 10px; border: 1px solid var(--c-border); letter-spacing: .04em; }
.seg { display: flex; gap: 4px; padding: 4px; background: var(--c-surface-sunk); border-radius: 12px; }
.seg__btn { flex: 1; text-align: center; padding: 8px; border-radius: 9px; border: 0; background: transparent; font-weight: 600; font-size: 14px; color: var(--c-text-muted); cursor: pointer; }
.seg__btn.is-active { background: var(--c-surface); color: var(--c-text); font-weight: 700; box-shadow: var(--shadow-sm); }
.stat-row { display: flex; gap: var(--sp-4); }
.stat { flex: 1; padding: 14px 18px; }
.stat__label { font-size: 13px; color: var(--c-text-muted); font-weight: 600; }
.stat__value { font-size: 28px; font-weight: 700; }
.split { display: flex; gap: var(--sp-5); align-items: flex-start; }
.split__main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: var(--sp-4); }
.split__side { width: 440px; flex: none; }
@media (max-width: 1100px) { .split { flex-direction: column; } .split__side { width: 100%; } }
.detail-head { display: flex; align-items: center; gap: var(--sp-4); }
.detail-head__title { font-size: 24px; margin: 0; }
.breadcrumb { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--c-text-muted); }
.breadcrumb a { text-decoration: none; }
.checkbox { width: 18px; height: 18px; }

/* ================= ป้าย QR (§9) ================= */
/* ส่วนพิมพ์จริงซ่อนบนจอ แสดงเฉพาะตอนพิมพ์ ตัวอย่างป้ายบนจอคือ .label--preview */
.labels { display: none; grid-template-columns: repeat(2, 378px); justify-content: center; }
.label { width: 378px; height: 378px; border: 1px dashed var(--c-border-strong); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 20px; background: #fff; page-break-inside: avoid; break-inside: avoid; }
.label__code { font-size: 40px; font-weight: 700; letter-spacing: .04em; line-height: 1; text-align: center; overflow-wrap: anywhere; }
.label__meta { font-size: 14px; color: var(--c-text-muted); text-align: center; }
@media print {
    @page { size: A4; margin: 10mm; }
    body { background: #fff; }
    .side-nav, .top-bar, .no-print, .toast { display: none !important; }
    .shell { display: block; }
    .page { padding: 0; }
    .labels { display: grid; }
    .label--preview { display: none; }
    .label { border: 1px dashed #999; }
}
