@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@400;500;600;700&display=swap');

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --bg: #f4f6fb;
    --card: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --muted: #64748b;
    --pending: #f59e0b;
    --progress: #3b82f6;
    --done: #16a34a;
    --cancel: #dc2626;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Sarabun', sans-serif;
    background: var(--bg);
    color: var(--text);
}

.topbar {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.topbar-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 14px 24px;
    display: flex;
    align-items: center;
    gap: 24px;
    flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 18px; color: var(--primary-dark); }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a {
    text-decoration: none;
    color: var(--muted);
    padding: 8px 14px;
    border-radius: 8px;
    font-weight: 500;
    font-size: 15px;
}
.nav a:hover { background: #eef2ff; color: var(--primary-dark); }
.nav a.active { background: var(--primary); color: #fff; }
.user-info { display: flex; align-items: center; gap: 12px; font-size: 14px; color: var(--muted); }
.user-info small { color: #94a3b8; }
.btn-logout {
    text-decoration: none;
    color: #dc2626;
    border: 1px solid #fecaca;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 13px;
}
.btn-logout:hover { background: #fef2f2; }

.container { max-width: 1200px; margin: 0 auto; padding: 28px 24px 60px; }

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 24px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}

h1.page-title { font-size: 22px; margin: 0 0 18px; color: var(--text); }
h2.section-title { font-size: 17px; margin: 28px 0 12px; color: var(--text); border-left: 4px solid var(--primary); padding-left: 10px; }

label { font-size: 14px; font-weight: 500; color: var(--text); display: block; margin-bottom: 6px; }
input[type=text], input[type=password], input[type=date], input[type=number], textarea, select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: inherit;
    font-size: 14px;
    background: #fff;
    color: var(--text);
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.12); }
textarea { resize: vertical; min-height: 70px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.form-row { margin-bottom: 16px; }
.full { grid-column: 1 / -1; }

.radio-group { display: flex; gap: 18px; flex-wrap: wrap; }
.radio-group label { display: flex; align-items: center; gap: 6px; font-weight: 400; margin: 0; }
.radio-group input { width: auto; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { border: 1px solid var(--border); padding: 8px 10px; text-align: left; vertical-align: top; }
th { background: #f8fafc; font-weight: 600; color: var(--muted); font-size: 13px; }
/* ===== ตาราง "รายการสินค้าที่ต้องการ" (form.php) =====
   ใช้ table-layout: fixed + ความกว้างต่อคอลัมน์ เพื่อไม่ให้ตารางล้นออกนอกการ์ด */
.items-table { table-layout: fixed; width: 100%; min-width: 880px; }
.items-table th, .items-table td { min-width: 0; overflow-wrap: anywhere; }
.items-table input, .items-table textarea, .items-table select {
    font-size: 13px;
    padding: 6px 8px;
    width: 100%;
    max-width: 100%;
}
.items-table textarea { min-height: 62px; }

.items-table th.col-no,    .items-table td.row-no  { width: 34px;  text-align: center; padding-left: 4px; padding-right: 4px; }
.items-table th.col-spec,  .items-table td.col-spec { width: 17%; }
.items-table th.col-detail { width: auto; }
.items-table th.col-date   { width: 142px; }
.items-table th.col-qty    { width: 82px; }
.items-table th.col-unit   { width: 88px; }
.items-table th.col-price  { width: 104px; }
.items-table th.col-act    { width: 56px; padding-left: 4px; padding-right: 4px; }
.items-table td.col-act    { text-align: center; padding-left: 4px; padding-right: 4px; }

/* input[type=date] / file ไม่ให้ดันคอลัมน์กว้างเกิน */
.items-table input[type="date"] { min-width: 0; padding-left: 5px; padding-right: 5px; }
.items-table .item-file { width: 100%; max-width: 100%; font-size: 11px; padding: 0; }
.items-table .item-remove { width: auto; padding: 5px 8px; }

.btn {
    display: inline-block;
    padding: 10px 20px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-family: inherit;
    font-weight: 600;
    font-size: 14px;
    text-decoration: none;
    text-align: center;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #f1f5f9; color: var(--text); }
.btn-secondary:hover { background: #e2e8f0; }
.btn-danger { background: #fee2e2; color: #b91c1c; }
.btn-danger:hover { background: #fecaca; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

/* ===== ปุ่ม Export ===== */
.btn-csv    { background: #2563eb; color: #fff; }
.btn-csv:hover  { background: #1d4ed8; color: #fff; }
.btn-excel  { background: #16a34a; color: #fff; }
.btn-excel:hover { background: #15803d; color: #fff; }

.btn-row { display: flex; gap: 10px; margin-top: 20px; }

.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #eef2ff, #f4f6fb);
}
.login-card { width: 380px; padding: 36px; }
.login-card h1 { font-size: 20px; text-align: center; margin-bottom: 4px; }
.login-card p.sub { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 24px; }
.error-box {
    background: #fef2f2; border: 1px solid #fecaca; color: #b91c1c;
    padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 16px;
}
.success-box {
    background: #f0fdf4; border: 1px solid #bbf7d0; color: #15803d;
    padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 16px;
}

.warning-box {
    background: #fffbeb; border: 1px solid #fde68a; color: #92400e;
    padding: 12px 16px; border-radius: 8px; font-size: 14px; margin-bottom: 16px;
    line-height: 1.6;
}

/* fieldset ครอบฟอร์ม: ปกติไม่มีกรอบ; เมื่อ disabled จะทำให้ดูจางและกดไม่ได้ */
.form-fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
.form-fieldset:disabled { opacity: 0.55; }

.badge {
    display: inline-block; padding: 3px 10px; border-radius: 999px;
    font-size: 12px; font-weight: 600;
}
.badge-pending { background: #fef3c7; color: #92400e; }
.badge-progress { background: #dbeafe; color: #1d4ed8; }
.badge-done { background: #dcfce7; color: #166534; }
.badge-cancel { background: #fee2e2; color: #b91c1c; }
.badge-info { background: #e0e7ff; color: #4338ca; }
.badge-quote { background: #fae8ff; color: #a21caf; }
.badge-quote-ok { background: #f3e8ff; color: #7e22ce; }
.badge-ordered { background: #cffafe; color: #0e7490; }

.update-flag {
    display: inline-block;
    margin-left: 8px;
    padding: 2px 8px;
    border-radius: 10px;
    background: #fef08a;
    color: #854d0e;
    font-size: 12px;
    font-weight: 600;
    vertical-align: middle;
    animation: updatePulse 1.6s ease-in-out infinite;
}
@keyframes updatePulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.55; }
}

/* ===== SLA badges ===== */
.sla-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}
.sla-exceed       { background: #dcfce7; color: #166534; }  /* เขียว  */
.sla-meet         { background: #dbeafe; color: #1d4ed8; }  /* น้ำเงิน */
.sla-partial      { background: #fef3c7; color: #92400e; }  /* ส้ม    */
.sla-unacceptable { background: #fee2e2; color: #b91c1c; }  /* แดง    */
.sla-line { margin-top: 4px; }
.sla-sub { font-size: 11px; margin-top: 2px; }
.sla-summary {
    margin: 6px 0 14px;
    padding: 8px 12px;
    background: #f8fafc;
    border-left: 3px solid #cbd5e1;
    border-radius: 4px;
    font-size: 14px;
}

.filter-bar {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px 16px;
    margin-bottom: 20px;
    align-items: end;
}
.filter-bar .form-row { margin-bottom: 0; min-width: 0; }
.filter-bar label {
    display: block; font-size: 13px; color: #64748b;
    font-weight: 500; margin-bottom: 5px;
}
.filter-bar select,
.filter-bar input[type="text"],
.filter-bar input[type="date"],
.filter-bar .ms-toggle {
    height: 40px; box-sizing: border-box; width: 100%;
}
/* แถวที่ 2: ค้นหา (input ยืดเต็ม) + ปุ่ม ต่อท้ายในบรรทัดเดียว */
.filter-bar .search-row { grid-column: 1 / -1; }
.search-line { display: flex; gap: 8px; align-items: center; }
.search-line input[type="text"] { flex: 1; height: 40px; box-sizing: border-box; }
.search-line .btn { height: 40px; white-space: nowrap; }

@media (max-width: 820px) {
    .filter-bar { grid-template-columns: 1fr 1fr; }
    .filter-bar .search-row { grid-column: 1 / -1; }
}

.list-table tr:hover { background: #f8fafc; cursor: pointer; }
.muted { color: var(--muted); font-size: 13px; }
.add-row-btn { margin-top: 8px; }
.item-remove { background: #fee2e2; color: #b91c1c; border: none; border-radius: 6px; padding: 6px 10px; cursor: pointer; font-size: 12px; }

.stat-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.stat-card { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; }
.stat-card .num { font-size: 26px; font-weight: 700; }
.stat-card .lbl { font-size: 13px; color: var(--muted); margin-top: 4px; }

@media (max-width: 768px) {
    .form-grid { grid-template-columns: 1fr; }
    .stat-cards { grid-template-columns: repeat(2, 1fr); }
}

/* ===== แนบรูปสินค้าในฟอร์ม / แสดงรูปย่อในหน้ารายละเอียด ===== */
.file-label {
    display: block;
    margin-top: 6px;
    font-size: 12px;
    color: #64748b;
}
.item-file {
    display: block;
    margin-top: 4px;
    font-size: 12px;
}
.item-thumb {
    margin-top: 8px;
}
.item-thumb img {
    max-width: 120px;
    max-height: 120px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    object-fit: cover;
}

/* ===== หน้าจัดการสิทธิ์ผู้ใช้ ===== */
.search-bar {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}
.search-bar input[type="text"] {
    flex: 1;
    min-width: 220px;
    max-width: 420px;
}
.inline-role-form {
    display: flex;
    gap: 8px;
    align-items: center;
}
.inline-role-form select {
    min-width: 150px;
}

/* ===== แถบแบ่งหน้า Monitor ===== */
.pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 16px;
}
.pagination-info { color: #64748b; font-size: 14px; }
.pagination-btns { display: flex; gap: 8px; }
.btn.disabled {
    opacity: .5;
    pointer-events: none;
    cursor: default;
}

/* ===== หัวเอกสารฟอร์ม: ชื่อซ้าย / วันที่-เวลาเปิด ขวาบน ===== */
.doc-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    flex-wrap: wrap;
}
.doc-meta {
    text-align: right;
    font-size: 14px;
    color: #334155;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 8px 14px;
    line-height: 1.7;
    white-space: nowrap;
}
.doc-meta-label { color: #64748b; }

/* ===== request_detail header: บริษัทซ้าย / เลขที่+วันที่เอกสารขวาบน ===== */
.detail-head { position: relative; padding-right: 220px; margin-bottom: 8px; }
.detail-company { font-size: 20px; font-weight: 700; color: var(--text); margin-bottom: 16px; }
.detail-header-right {
    position: absolute;
    top: 0;
    right: 0;
    text-align: right;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 8px 14px;
    white-space: nowrap;
}
.detail-docno { font-size: 18px; font-weight: 700; color: var(--text); }
.detail-docdate { font-size: 13px; color: #334155; margin-top: 4px; line-height: 1.5; }
.detail-info .form-row { display: flex; align-items: baseline; gap: 6px; margin-bottom: 10px; }
.detail-info .form-row label { color: #64748b; font-size: 14px; margin: 0; white-space: nowrap; }
.detail-info .form-row label::after { content: ' :'; }
.detail-info .form-row > div { color: var(--text); font-size: 15px; }
@media (max-width: 640px) {
    .detail-head { padding-right: 0; }
    .detail-header-right { position: static; margin-bottom: 14px; display: inline-block; }
    .detail-info-row { grid-template-columns: 1fr; gap: 0; }
}

/* ชื่อพนักงาน + แผนก/สาขา อยู่บรรทัดเดียวกัน */
.detail-info-row { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; }

/* ลิงก์ในรายละเอียดสินค้า: ตัวเอียง + ขีดเส้นใต้ */
.detail-link { font-style: italic; text-decoration: underline; color: #1d4ed8; }

/* ข้อมูลเพิ่มเติมจากผู้ขอ: ไฮไลท์สีน้ำเงิน (คงรายละเอียดเดิมไว้) */
.added-detail {
    margin-top: 6px;
    padding: 6px 10px;
    background: #eff6ff;
    border-left: 3px solid #3b82f6;
    border-radius: 4px;
    color: #1e40af;
    font-size: 13px;
    line-height: 1.6;
}
.added-detail-tag {
    display: inline-block;
    background: #3b82f6;
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    padding: 1px 8px;
    border-radius: 999px;
    margin-right: 6px;
}
/* กล่องแสดงรายละเอียดเดิม (อ่านอย่างเดียว) ในฟอร์มแก้ไข */
.detail-original {
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 6px 10px;
    color: #475569;
    font-size: 13px;
    line-height: 1.6;
}

/* ===== ช่องที่ล็อกห้ามแก้ไข ===== */
.locked-field {
    background: #f1f5f9;
    color: #334155;
    cursor: not-allowed;
}

/* ป้าย "จำเป็น" */
.req { color: #dc2626; font-weight: 600; font-size: 12px; }

/* ===== แถวขยายดูรายการสินค้าในหน้า Monitor ===== */
.expand-btn {
    border: 1px solid #cbd5e1;
    background: #fff;
    color: #475569;
    width: 22px;
    height: 22px;
    line-height: 1;
    border-radius: 5px;
    cursor: pointer;
    margin-right: 6px;
    font-size: 12px;
    vertical-align: middle;
}
.expand-btn:hover { background: #f1f5f9; }
.expand-btn.open { background: #2563eb; color: #fff; border-color: #2563eb; }
.items-subrow > td { background: #f8fafc; padding: 10px 14px; }
.subitems { width: 100%; border-collapse: collapse; background: #fff; }
.subitems th, .subitems td {
    border: 1px solid #e2e8f0;
    padding: 6px 10px;
    font-size: 13px;
    text-align: left;
}
.subitems th { background: #f1f5f9; color: #475569; font-weight: 600; }
/* หมายเหตุ: format_detail() ทำ nl2br() มาให้แล้ว จึงห้ามใช้ white-space: pre-wrap
   (จะทำให้ขึ้นบรรทัดซ้ำซ้อน + ช่องว่าง/ย่อหน้าของ HTML template ถูกแสดงจริง) */
.subitem-detail {
    max-width: 420px;
    white-space: normal;
    word-break: break-word;
    overflow-wrap: anywhere;
    line-height: 1.55;
}
.subitem-detail br + br { display: none; }

/* ตารางรายการในหน้า request_detail: พอดีจอเสมอ (fixed layout) */
.detail-table { table-layout: fixed; width: 100%; }
.detail-table th, .detail-table td { min-width: 0; white-space: normal; word-break: break-word; overflow-wrap: anywhere; }
.detail-table input, .detail-table select, .detail-table textarea { width: 100%; box-sizing: border-box; }

/* รูปย่อ + ช่องแก้ไขในตารางย่อย (Line Item) หน้า Monitor */
.subitem-thumb img { max-width: 48px; max-height: 48px; border: 1px solid #e2e8f0; border-radius: 4px; object-fit: cover; display: block; }
.subitems select, .subitems input[type="text"] { width: 100%; box-sizing: border-box; font-size: 12px; padding: 4px 6px; }

/* ตัวกรองสถานะแบบ dropdown + checkbox + ปุ่ม Export */
.status-filter { min-width: 0; }
.ms-dropdown { position: relative; display: block; }
.ms-toggle {
    width: 100%; text-align: left; cursor: pointer;
    border: 1px solid #cbd5e1; border-radius: 8px; background: #fff;
    padding: 9px 12px; font-size: 14px; color: #334155;
    display: flex; justify-content: space-between; align-items: center;
}
.ms-toggle:hover { border-color: #94a3b8; }
.ms-caret { color: #64748b; margin-left: 8px; }
.ms-panel {
    position: absolute; z-index: 30; top: calc(100% + 4px); left: 0;
    min-width: 100%; width: max-content; max-width: 420px;
    background: #fff; border: 1px solid #e2e8f0; border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,.12); padding: 6px;
    max-height: 300px; overflow-y: auto; display: none;
}
.ms-panel.open { display: block; }
.ms-opt {
    display: flex; align-items: flex-start; gap: 8px; padding: 6px 8px;
    border-radius: 6px; font-weight: 400; font-size: 13px; cursor: pointer; white-space: normal;
}
.ms-opt:hover { background: #f1f5f9; }
.ms-opt input { width: auto; margin-top: 2px; }
.ms-divider { height: 1px; background: #e2e8f0; margin: 4px 0; }
.filter-actions { display: flex; gap: 8px; align-items: flex-end; }
.btn-success { background: #16a34a; color: #fff; }
.btn-success:hover { background: #15803d; }
/* ============ หน้า Log รวม (logs.php) ============ */
.log-filter { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; }
.log-filter input[type="text"] { width: 140px; flex: 0 0 auto; }
.log-filter input[type="date"] { width: 150px; flex: 0 0 auto; }
.log-filter select { width: 160px; flex: 0 0 auto; }
.log-filter .btn { flex: 0 0 auto; }
.log-export { margin-left: auto; display: flex; gap: 8px; }
.table-wrap { overflow-x: auto; }
.log-table td { vertical-align: top; }
.link { color: #2563eb; text-decoration: none; }
.link:hover { text-decoration: underline; }
.pager { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; }
.pager-btns { display: flex; align-items: center; gap: 10px; }

/* badge ตามชนิด action (ใช้ทั้งหน้า Log และ popup) */
.logact { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.logact-status { background: #e6f1fb; color: #0c447c; }
.logact-remark { background: #f1efe8; color: #444441; }
.logact-price  { background: #e1f5ee; color: #0f6e56; }
.logact-quote  { background: #eeedfe; color: #3c3489; }
.logact-edit   { background: #faeeda; color: #854f0b; }
.logact-cancel { background: #fcebeb; color: #a32d2d; }
.logact-create { background: #eaf3de; color: #3b6d11; }

/* ============ Quick-view Log popup (monitor.php) ============ */
.log-btn { background: none; border: none; cursor: pointer; font-size: 15px; margin-left: 8px; padding: 0; opacity: 0.75; }
.log-btn:hover { opacity: 1; }

.log-overlay { position: fixed; inset: 0; background: rgba(15,23,42,0.45); display: none; z-index: 1000; }
.log-overlay.open { display: block; }
.log-panel { position: absolute; top: 0; right: 0; height: 100%; width: 350px; max-width: 92vw;
    background: #fff; box-shadow: -8px 0 24px rgba(0,0,0,0.15); padding: 18px 20px; overflow-y: auto; }
.log-panel-head { display: flex; align-items: center; justify-content: space-between; font-size: 15px; font-weight: 700; color: #1e293b; }
.log-panel-sub { font-size: 12px; margin-bottom: 16px; }
.log-close { background: none; border: none; cursor: pointer; font-size: 18px; color: #64748b; line-height: 1; }

.log-timeline { position: relative; padding-left: 18px; }
.log-timeline::before { content: ''; position: absolute; left: 4px; top: 4px; bottom: 6px; width: 2px; background: #e2e8f0; }
.log-tl-item { position: relative; margin-bottom: 16px; }
.log-tl-item::before { content: ''; position: absolute; left: -18px; top: 3px; width: 10px; height: 10px; border-radius: 50%; background: #94a3b8; }
.log-tl-item.logact-status::before { background: #378add; }
.log-tl-item.logact-remark::before { background: #94a3b8; }
.log-tl-item.logact-price::before  { background: #1d9e75; }
.log-tl-item.logact-quote::before  { background: #7f77dd; }
.log-tl-item.logact-edit::before   { background: #ba7517; }
.log-tl-item.logact-cancel::before { background: #e24b4a; }
.log-tl-item.logact-create::before { background: #639922; }
.log-tl-time { font-size: 12px; color: #94a3b8; }
.log-tl-action { font-size: 13px; color: #1e293b; margin-top: 1px; }
.log-tl-detail { font-size: 12px; line-height: 1.5; }
.log-tl-actor { font-size: 12px; }

/* ฟอร์มขอสินค้า: บริษัท + ผู้ขอ + แผนก อยู่บรรทัดเดียวกัน */
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 24px; align-items: start; margin-bottom: 4px; }
.form-grid-3 > .form-row { min-width: 0; }
.form-grid-3 input { width: 100%; box-sizing: border-box; }
.form-grid-3 .radio-group { display: flex; flex-wrap: nowrap; gap: 6px 14px; }
/* จับปุ่มเรดิโอกับข้อความไว้ด้วยกัน ไม่ให้ตัดคำหรือเบียดทับ */
.form-grid-3 .radio-group label { white-space: nowrap; flex: 0 0 auto; }
.form-grid-3 .radio-group input { width: auto; flex: 0 0 auto; margin: 0; }

/* แท็บเล็ต/ไอแพด (≈681–1024px): ช่องบริษัทกว้างตามเนื้อหา (3 ปุ่มอยู่บรรทัดเดียวเสมอ)
   ที่เหลือแบ่งให้ผู้ขอ/แผนกเท่ากัน ไม่บีบจนตัวอักษรทับ */
@media (max-width: 1024px) {
    .form-grid-3 { grid-template-columns: max-content 1fr 1fr; gap: 16px; }
}
/* จอแคบ (มือถือ/ไอแพดแนวตั้งที่แคบมาก): เรียงลงทีละบรรทัด */
@media (max-width: 680px) {
    .form-grid-3 { grid-template-columns: 1fr; gap: 14px; }
    .form-grid-3 .radio-group { flex-wrap: wrap; }
}

/* ฟอร์มแก้ไขข้อมูล (ผู้ขอ) แบบ inline ในคอลัมน์รายละเอียด */
.inline-edit-form { margin-top: 10px; padding: 10px; background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 6px; }
.inline-edit-form .form-row { margin-bottom: 8px; }
.inline-edit-form .form-row label { display: block; font-size: 12px; color: #475569; margin-bottom: 3px; }
.inline-edit-form textarea { min-height: 60px; width: 100%; }
.inline-edit-form select, .inline-edit-form input { width: 100%; }
.inline-edit-form .form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* รูปสินค้าในไลน์ item: thumbnail เล็ก + คลิกดูรูปเต็ม (lightbox) */
.item-thumbs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.item-thumb-img { width: 52px; height: 52px; object-fit: cover; border: 1px solid #e2e8f0; border-radius: 6px; cursor: pointer; transition: transform .12s, box-shadow .12s; }
.item-thumb-img:hover { transform: scale(1.06); box-shadow: 0 2px 8px rgba(0,0,0,0.18); }

.img-lightbox { position: fixed; inset: 0; background: rgba(15,23,42,0.82); display: none; align-items: center; justify-content: center; z-index: 1100; cursor: zoom-out; }
.img-lightbox.open { display: flex; }
.img-lightbox img { max-width: 92vw; max-height: 88vh; border-radius: 8px; box-shadow: 0 8px 40px rgba(0,0,0,0.5); }
.img-lightbox-close { position: absolute; top: 18px; right: 24px; color: #fff; font-size: 30px; cursor: pointer; line-height: 1; }

/* ============ หน้า Report (report.php) ============ */
.report-table { font-size: 12px; white-space: nowrap; }
.report-table th { padding: 8px 8px; font-weight: 600; }
.report-table td { padding: 8px 8px; }
.report-table tr.report-group td { background: #eef2ff; color: #3730a3; font-weight: 600; }
.report-table .ts-cell { text-align: center; }
.report-table .ts-cell .ts-date { display: block; line-height: 1.35; }
.report-table .ts-cell .ts-time { display: block; font-size: 11px; font-weight: 400; color: #64748b; line-height: 1.3; }
.report-table .ts-cell.ts-done { color: #15803d; font-weight: 600; }
.report-table .ts-cell.ts-cancel { color: #b91c1c; font-weight: 600; }