/*
 * จัดระเบียบ/ออกแบบฟอร์ม "ร่างเรื่องใหม่" (admin/new_ticket.php)
 * scope ที่ .ticket-create เท่านั้น เพื่อไม่กระทบหน้าอื่น
 */

/* ===== หน้าร่างเรื่องใหม่ = ป๊อปอัพ (modal กลางจอ เลื่อนได้) ===== */
.main__content.ticket-create {
    position: fixed !important;
    inset: 0;
    z-index: 3000;
    margin: 0 !important;
    max-width: none !important;
    padding: 24px 16px !important;
    display: flex !important;      /* จัดกล่องให้อยู่กลางจอ */
    align-items: safe center !important;   /* กลางแนวตั้ง (safe = ไม่ตัดบนเมื่อยาว) */
    justify-content: center !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;   /* เลื่อนทั้งกล่องได้ (ไม่ clip dropdown) */
    border: 0 !important;
    border-radius: 0 !important;
    background: rgba(9, 9, 11, .45) !important;
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    box-shadow: none !important;
    font-size: 15px;
}

/* การ์ด dialog — margin:auto ทำให้อยู่กลางแนวตั้งเมื่อพื้นที่พอ และเลื่อนได้เมื่อยาว */
.ticket-create > .table-wrap {
    position: relative;
    width: min(1020px, 100%);
    margin: 0 !important;          /* ยกเลิก margin-right:200px เดิม ให้ flex จัดกลาง */
    padding: 0 28px 0 !important;
    overflow: visible !important;
    border: 1px solid #e4e4e7 !important;
    border-radius: 18px !important;
    background: #fff !important;
    box-shadow: 0 24px 60px rgba(16, 24, 40, .28) !important;
}

/* ปุ่มปิดป๊อปอัพ */
.ticket-create .wiz-close {
    position: absolute;
    top: 16px;
    right: 18px;
    z-index: 5;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: #f4f4f5;
    color: #52525b;
    font-size: 24px;
    line-height: 1;
    text-decoration: none;
    transition: background-color .15s ease, color .15s ease;
}

.ticket-create .wiz-close:hover {
    background: #e4e4e7;
    color: #18181b;
}

/* ซ่อนข้อความหัวที่ไม่ต้องการในป๊อปอัพ (แบบฟอร์ม.../เพิ่มข้อมูล.../ต้องบันทึก...) */
.ticket-create > .table-wrap > h3,
.ticket-create > .table-wrap > h4,
.ticket-create .notice-flash {
    display: none !important;
}

/* ระยะห่างแต่ละหัวข้อในแต่ละ step ให้เท่ากันทั้งหมด (ใช้ gap ของกริดเป็นตัวเว้นเดียว) */
.ticket-create .wiz-panel > .form-group,
.ticket-create .wiz-panel > .param,
.ticket-create .wiz-panel > #emaildiv,
.ticket-create .wiz-panel > #customfield,
.ticket-create .wiz-panel > #customfield > .form-group,
.ticket-create .wiz-panel > .attachments,
.ticket-create .wiz-panel > .checkbox-list,
.ticket-create .wiz-panel > #ticket-status-div {
    margin: 0 !important;
}

.ticket-create h3 {
    max-width: 940px;
    margin: 6px auto 2px !important;
    font-size: 20px !important;
    font-weight: 800;
    color: #18181b;
}

.ticket-create > .table-wrap > h4 {
    max-width: 940px;
    margin: 0 auto 14px;
    color: #71717a;
    font-size: 13px;
    font-weight: 500;
}

.ticket-create #submit-ticket {
    display: block !important;   /* ทับ form{display:grid} เดิม ไม่ให้ wizard เพี้ยน */
    max-width: 980px;
    margin: 0 auto;
}

/* ===== Wizard แบ่งเป็น step ===== */
.ticket-create .wiz-steps {
    position: relative;        /* ให้ปุ่มปิด absolute อ้างอิงแถบนี้ */
    z-index: 8;
    display: flex;
    gap: 6px;
    margin: 0 -28px 16px;      /* ขยายเต็มความกว้าง dialog */
    padding: 18px 76px 14px 28px;  /* เว้นขวาให้ปุ่มปิด */
    background: #fff;
    border-bottom: 1px solid #f0f1f4;
    border-radius: 18px 18px 0 0;
    list-style: none;
}

.ticket-create .wiz-step {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 11px 12px;
    border: 1px solid #e4e4e7;
    border-radius: 12px;
    background: #fff;
    color: #71717a;
    font-family: inherit;
    cursor: pointer;
    transition: border-color .15s ease, background-color .15s ease, color .15s ease;
}

.ticket-create .wiz-step__num {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: #f1f1f4;
    color: #71717a;
    font-size: 13px;
    font-weight: 800;
}

.ticket-create .wiz-step__label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: clamp(11px, 0.95vw, 13.5px);
    font-weight: 700;
}

.ticket-create .wiz-step.is-active {
    border-color: #1877f2;
    background: #eff6ff;
    color: #1d4ed8;
}

.ticket-create .wiz-step.is-active .wiz-step__num {
    background: #1877f2;
    color: #fff;
}

.ticket-create .wiz-step.is-done {
    color: #15803d;
    border-color: #bbf7d0;
    background: #f0fdf4;
}

.ticket-create .wiz-step.is-done .wiz-step__num {
    background: #16a34a;
    color: #fff;
}

/* แผงแต่ละ step (อยู่ใน dialog แล้ว — ไม่ต้องเป็นการ์ดซ้อน) */
.ticket-create .wiz-panel {
    margin: 0 auto;
    padding: 6px 0 8px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px 24px;
    align-items: start;
}

.ticket-create .wiz-panel__title {
    grid-column: 1 / -1;
    margin: 0 0 2px;
    padding-bottom: 12px;
    border-bottom: 1px solid #f1f1f4;
    color: #18181b;
    font-size: 16px;
    font-weight: 800;
}

/* ฟิลด์ที่ควรเต็มความกว้าง */
.ticket-create .wiz-panel > .form-group:has(textarea),
.ticket-create .wiz-panel > .form-group:has([name="options"]),
.ticket-create .wiz-panel > .form-group:has(#office),
.ticket-create .wiz-panel > .form-group:has([name="subject"]),
.ticket-create .wiz-panel > .form-group:has([name="message"]),
.ticket-create .wiz-panel > .form-group:has([name="custom13"]),
.ticket-create .wiz-panel > .form-group:has(.dropzone),
.ticket-create .wiz-panel > #customfield,
.ticket-create .wiz-panel > .attachments,
.ticket-create .wiz-panel > .checkbox-list,
.ticket-create .wiz-panel > #submit,
.ticket-create .wiz-panel > #assign {
    grid-column: 1 / -1;
}

/* ข้อมูลผู้ร้อง (อายุ/อาชีพ/ที่อยู่/เลขบัตร/เบอร์ ฯลฯ) -> 2 คอลัมน์ ช่องไฟสม่ำเสมอ */
.ticket-create .wiz-panel > #customfield {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 22px 22px;
    align-items: start;
}

/* ฟิลด์ยาว/หลายตัวเลือก -> เต็มแถว (ที่อยู่/การปกปิดข้อมูล/รายละเอียด) */
.ticket-create .wiz-panel > #customfield > .form-group:has(textarea),
.ticket-create .wiz-panel > #customfield > .form-group:has(.radio-list),
.ticket-create .wiz-panel > #customfield > .form-group:has(.checkbox-list),
.ticket-create .wiz-panel > #customfield > h3,
.ticket-create .wiz-panel > #customfield > h4 {
    grid-column: 1 / -1;
}

/* หัวข้อกลุ่ม "ข้อมูลผู้ร้อง" — ชิดซ้าย มีเส้นคั่นบาง ๆ ไม่จัดกึ่งกลาง */
.ticket-create .wiz-panel > #customfield > h3,
.ticket-create .wiz-panel > #customfield > h4 {
    text-align: left !important;
    margin: 6px 0 2px !important;
    padding: 0 0 8px !important;
    border-bottom: 1px solid #eef0f3;
    font-size: 15px !important;
    font-weight: 800 !important;
    color: #344054 !important;
}

/* ระยะ label -> ช่องกรอก สม่ำเสมอทุกฟิลด์ (label ชิดช่องตัวเอง ไม่ชิดช่องบน) */
.ticket-create .wiz-panel > #customfield > .form-group {
    margin: 0 !important;
    gap: 7px;
}
.ticket-create .wiz-panel > #customfield > .form-group > label {
    margin: 0 !important;
    line-height: 1.3;
}

@media screen and (max-width: 760px) {
    .ticket-create .wiz-panel > #customfield {
        grid-template-columns: 1fr;
    }
}

/* แถบปุ่ม ย้อนกลับ / ถัดไป — ล่างสุดของกล่อง */
.ticket-create .wiz-foot {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 18px -28px 0;
    padding: 14px 28px 18px;
    background: #fff;
    border-top: 1px solid #f0f1f4;
    border-radius: 0 0 18px 18px;
}

.ticket-create .wiz-foot .wiz-spacer {
    flex: 1 1 auto;
}

.ticket-create .wiz-foot .btn {
    min-height: 44px;
    padding: 0 24px !important;
    border-radius: 10px !important;
    font-weight: 800;
}

.ticket-create .wiz-back {
    border: 1px solid #d4d4d8 !important;
    background: #fff !important;
    color: #3f3f46 !important;
}

@media screen and (max-width: 760px) {
    .ticket-create .wiz-panel {
        grid-template-columns: 1fr;
    }
    .ticket-create .wiz-step__label {
        display: none;   /* จอเล็ก: เหลือแค่หมายเลข step */
    }
    .ticket-create .wiz-step {
        flex: 0 0 auto;
        justify-content: center;
    }
}

/* ===== ป้ายกำกับ + ช่องกรอก: ขนาดอ่านง่าย พอดี ===== */
.ticket-create .form-group > label,
.ticket-create .param.calendar > label {
    margin-bottom: 6px;
    color: #344054;
    font-size: 13.5px;
    font-weight: 600;
}

.ticket-create .important {
    color: #e0245e;
}

.ticket-create input.form-control,
.ticket-create textarea.form-control,
.ticket-create select,
.ticket-create .datepicker {
    width: 100%;
    min-height: 44px;
    padding: 10px 14px;
    border: 1px solid #d0d5dd !important;
    border-radius: 10px !important;
    background: #fff;
    font-size: 14.5px;
}

.ticket-create textarea.form-control {
    min-height: 120px;
}

.ticket-create input.form-control:focus,
.ticket-create textarea.form-control:focus,
.ticket-create select:focus,
.ticket-create .datepicker:focus {
    border-color: #1877f2 !important;
    box-shadow: 0 0 0 3px rgba(24, 119, 242, .12) !important;
    outline: 0;
}

/* ===== เลือกเงื่อนไขความเป็นส่วนตัวของผู้ร้อง -> การ์ดเลือกได้ ===== */
.ticket-create .form-group:has([name="options"]) > .form-control {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

.ticket-create .form-group:has([name="options"]) > .form-control > h4 {
    grid-column: 1 / -1;
    margin: 0 0 2px;
    color: #18181b;
    font-size: 15px;
    font-weight: 800;
}

.ticket-create .form-check {
    position: relative;
    display: flex !important;
    align-items: flex-start !important;
    gap: 10px;
    margin: 0 !important;
    padding: 14px 14px 14px 14px;
    border: 1.5px solid #e4e4e7;
    border-radius: 12px;
    background: #fff;
    cursor: pointer;
    transition: border-color .15s ease, box-shadow .15s ease, background-color .15s ease;
}

.ticket-create .form-check:hover {
    border-color: #c7d2fe;
    background: #fafbff;
}

.ticket-create .form-check .form-check-input {
    margin: 2px 0 0 !important;
    width: 18px;
    height: 18px;
    accent-color: #1877f2;
    flex: 0 0 auto;
}

.ticket-create .form-check .form-check-label {
    margin: 0 !important;
    color: #3f3f46;
    font-size: 13.5px;
    font-weight: 600;
    line-height: 1.4;
    cursor: pointer;
}

/* การ์ดที่ถูกเลือก */
.ticket-create .form-check:has(.form-check-input:checked) {
    border-color: #1877f2;
    background: #eff6ff;
    box-shadow: 0 0 0 3px rgba(24, 119, 242, .12);
}

@media screen and (max-width: 760px) {
    .ticket-create .form-group:has([name="options"]) > .form-control {
        grid-template-columns: 1fr;
    }
}

/* ===== ชั้นความเร็ว / ชั้นความลับ / priority / สถานะ : ให้หน้าตาเหมือนกัน ===== */
.ticket-create .dropdown-select,
.ticket-create .selectize-control {
    width: 100% !important;
    min-width: 0 !important;
}

.ticket-create .dropdown-select > .label,
.ticket-create .selectize-input {
    min-height: 44px !important;
    display: flex !important;
    align-items: center;
    padding: 8px 14px !important;
    border: 1px solid #d0d5dd !important;
    border-radius: 10px !important;
    background: #fff !important;
    font-size: 14.5px;
}

/* ===== สถานะ: ดอทสีจัดการใน priority.css (.dropdown-select.status) แล้ว ===== */
.ticket-create .form-group.ts .dropdown-select > .label {
    font-weight: 700;
}

/* ===== ปฏิทิน (วันที่ยื่นเรื่อง ฯลฯ) ===== */
.ticket-create .param.calendar {
    display: flex;
    flex-direction: column;
}

.ticket-create .param.calendar .calendar--button {
    position: relative;
    display: flex;
    align-items: center;
}

.ticket-create .param.calendar .calendar--button > button {
    position: absolute;
    left: 10px;
    display: inline-flex;
    align-items: center;
    background: transparent;
    border: 0;
    cursor: pointer;
}

.ticket-create .param.calendar .calendar--button > button .icon {
    width: 18px;
    height: 18px;
    fill: #71717a;
}

.ticket-create .param.calendar .datepicker {
    padding-left: 38px;
}

/* (บล็อก Select2 ชุดเก่าถูกยุบไปรวมกับชุด v2 ด้านล่างแล้ว — ของเดิมเจาะจงกว่าจึงทับ v2 ทำให้แก้ไม่ขึ้น) */

/* dropdown ของ select2 ลอยเหนือทุกอย่าง ไม่ถูกบัง */
.select2-container--open .select2-dropdown {
    z-index: 5000;
    border: 1px solid #e4e4e7;
    border-radius: 10px;
    box-shadow: 0 12px 28px rgba(16, 24, 40, .14);
    overflow: hidden;
}

.select2-dropdown .select2-search__field {
    min-height: 38px;
    padding: 8px 12px;
    border: 1px solid #e4e4e7 !important;
    border-radius: 8px;
}

.select2-results__option {
    padding: 9px 12px;
    font-size: 14px;
}

.select2-container--default .select2-results__option--highlighted[aria-selected] {
    background: #1877f2;
}

/* ===== ปุ่ม submit ===== */
.ticket-create .block--submit,
.ticket-create .form__submit {
    margin-top: 8px;
}

/* ===== แก้ปฏิทิน/Dropdown ถูกป๊อปอัพทับ หรือจมล่างจอ ===== */
/* ปฏิทิน (air-datepicker) ถูก append ที่ body -> ยกให้ลอยเหนือ overlay */
.datepickers-container,
.datepicker,
.datepicker.active {
    z-index: 6000 !important;
}

/* selectize "ประเภทย่อยของเรื่อง" ฯลฯ -> ลอยเหนือ + จำกัดสูง เลื่อนในตัวได้ */
.ticket-create .selectize-dropdown,
.ticket-create .dropdown-select .dropdown-list {
    z-index: 6000 !important;
    max-height: 240px;
    overflow-y: auto;
}

/* ===== "หน่วยงานรับผิดชอบดำเนินการ" (Select2 เลือกได้หลายหน่วยงาน) — ออกแบบใหม่ v2 =====
   ปัญหาเดิม 3 อย่างที่ทำให้กล่องนี้ดูรก/ซ้ำซ้อน:
   1) select2 4.1 ใช้ <button> จริงเป็นปุ่มลบ/ล้าง ถ้าไม่รีเซ็ต appearance จะได้ปุ่มเทาแบบ OS
   2) ช่องค้นหาในกล่องเป็น <textarea> ที่ resize ได้ จึงมี "มือจับย่อ-ขยาย" โผล่ใต้กล่อง
   3) ปุ่ม ✕ ของชิปวางทับข้อความ เพราะจัดตำแหน่งแบบ absolute
   ทั้งหมดแก้ที่นี่ และไม่ผูกกับ .ticket-create เพื่อให้ใช้ได้ทุกหน้าที่มีช่องนี้ */
#office,
.select2-container { width: 100% !important; max-width: 100% !important; }

.select2-container--default .select2-selection--multiple {
    position: relative;
    /* กล่องเป็น flex เอง เพราะ select2 วาง <ul> ของชิป กับ <span> ช่องพิมพ์ไว้เป็นพี่น้องกัน
       ถ้าไม่รวมให้ไหลแถวเดียวกัน เคอร์เซอร์จะตกไปอยู่บรรทัดล่างโดดเดี่ยวและล้นออกนอกกล่อง */
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    min-height: 52px;
    padding: 6px 44px 6px 10px;   /* เว้นที่ด้านขวาให้ปุ่มล้างทั้งหมด ไม่ให้ชิปมุดใต้ปุ่ม */
    border: 1.5px solid #d0d5dd !important;
    border-radius: 12px !important;
    background: #fff;
    cursor: text;
}
.select2-container--default.select2-container--focus .select2-selection--multiple,
.select2-container--default.select2-container--open .select2-selection--multiple {
    border-color: #1877f2 !important;
    box-shadow: 0 0 0 3px rgba(24, 119, 242, .12);
}

/* ปล่อยให้ชิปกลายเป็นลูกโดยตรงของกล่อง จะได้ไหลต่อกับช่องพิมพ์ในแถวเดียว */
.select2-container--default .select2-selection--multiple .select2-selection__rendered {
    display: contents;
}
.select2-container--default .select2-selection--multiple .select2-search--inline {
    /* flex-basis เล็ก = ต่อท้ายป้ายหน่วยงานในบรรทัดเดียวกันได้เสมอ แล้วค่อยยืดเต็มที่ว่างที่เหลือ
       (ถ้าตั้ง basis ใหญ่ จะถูกดันลงบรรทัดใหม่ กลายเป็นแถวว่าง ๆ ใต้ป้าย) */
    flex: 1 1 24px;
    min-width: 24px;
    display: flex;
    align-items: center;
}

/* ช่องพิมพ์ค้นหาในกล่อง: เป็น textarea -> ปิดมือจับย่อขยายและกรอบซ้อน */
textarea.select2-search__field,
.select2-container--default .select2-selection--multiple .select2-search--inline .select2-search__field {
    width: 100% !important;
    resize: none !important;
    overflow: hidden;
    /* กฎ textarea กลางของธีมบังคับ min-height 110-160px ซึ่งไม่เกี่ยวกับช่องพิมพ์เล็ก ๆ ในกล่องนี้
       ถ้าไม่ล็อกความสูงไว้ กล่องจะสูงผิดปกติและเคอร์เซอร์จะลอยอยู่คนละระดับกับป้ายหน่วยงาน */
    height: 32px !important;
    min-height: 0 !important;
    max-height: 32px !important;
    margin: 0;
    padding: 0 2px;
    border: 0 !important;
    background: transparent;
    box-shadow: none !important;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    font-family: inherit;
    font-size: 14px;
    line-height: 30px;
}


/* ชิปหน่วยงานที่เลือกแล้ว: ปุ่มลบอยู่ขวาของชื่อ ไม่ทับข้อความ */
.select2-container--default .select2-selection--multiple .select2-selection__choice {
    position: static;
    display: inline-flex;
    flex-direction: row-reverse;   /* DOM วางปุ่มลบไว้หน้าข้อความ -> กลับด้านให้ปุ่มไปอยู่ขวา */
    align-items: center;
    gap: 7px;
    max-width: 100%;
    margin: 0;
    padding: 6px 8px 6px 13px;
    border: 0;
    border-radius: 999px;
    background: #eff6ff;
    color: #1d4ed8;
    font-size: 13.5px;
    font-weight: 600;
    line-height: 1.35;
    overflow-wrap: anywhere;
}
.select2-container--default .select2-selection--multiple .select2-selection__choice__remove {
    position: static;
    transform: none;
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 19px;
    height: 19px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 999px;
    background: rgba(37, 99, 235, .13);
    color: #1d4ed8;
    font-size: 13px;
    font-weight: 800;
    line-height: 1;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
}
.select2-container--default .select2-selection--multiple .select2-selection__choice__remove:hover {
    background: #fee4e2;
    color: #b42318;
}

/* ปุ่ม "ล้างทั้งหมด": ปุ่มมีคำกำกับ วางแถวบนของกล่อง แยกจากชิปชัดเจน
   (ของเดิมเป็น ✕ เทาลอยกลางกล่อง เลยดูเหมือนปุ่มลบของชิปใดชิปหนึ่ง) */
.select2-container--default .select2-selection--multiple .select2-selection__clear {
    position: absolute;
    right: 9px;
    top: 8px;
    transform: none;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    width: auto;
    height: 26px;
    margin: 0;
    padding: 0 11px 0 9px;
    border: 0;
    border-radius: 999px;
    background: #f1f4f9;
    color: #667085;
    font-size: 15px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
}
.select2-container--default .select2-selection--multiple .select2-selection__clear::after {
    content: "ล้างทั้งหมด";
    font-size: 12.5px;
    font-weight: 700;
}
.select2-container--default .select2-selection--multiple .select2-selection__clear:hover {
    background: #fee4e2;
    color: #b42318;
}

/* เลือกไว้รายการเดียว: ชิปมีปุ่ม ✕ ของตัวเองอยู่แล้ว ปุ่ม "ล้างทั้งหมด" จึงซ้ำซ้อน -> ซ่อน
   (จะโผล่มาก็ต่อเมื่อเลือกตั้งแต่ 2 หน่วยงานขึ้นไป ซึ่งการล้างทีเดียวเริ่มมีประโยชน์) */
.select2-container--default .select2-selection--multiple:not(:has(.select2-selection__choice ~ .select2-selection__choice)) .select2-selection__clear {
    display: none;
}
.select2-container--default .select2-selection--multiple:not(:has(.select2-selection__choice ~ .select2-selection__choice)) {
    padding-right: 12px;
}

.select2-container--default .select2-selection__placeholder { color: #98a2b3; }

/* จอมือถือ: กล่องสูงขึ้นเล็กน้อยให้ชิปหลายบรรทัดอ่านสบาย */
@media screen and (max-width: 620px) {
    .select2-container--default .select2-selection--multiple {
        padding: 8px 42px 8px 10px;
        border-radius: 14px !important;
    }
    .select2-container--default .select2-selection--multiple .select2-selection__choice { font-size: 13px; }
}

/* เลือก 2 หน่วยงานขึ้นไป: เว้นแถวบนไว้ให้ปุ่มล้างทั้งหมดโดยเฉพาะ ชิปจะไม่ไปเบียดกับปุ่ม */
.select2-container--default .select2-selection--multiple:has(.select2-selection__choice ~ .select2-selection__choice) {
    padding-top: 40px;
    padding-right: 10px;
}

/* dropdown ของ select2: ลอยเหนือป๊อปอัพ + ดีไซน์ตามธีม */
.select2-container--open {
    z-index: 6000 !important;
}

.select2-container--open .select2-dropdown {
    z-index: 6000 !important;
    border: 1px solid #e4e4e7;
    border-radius: 12px;
    box-shadow: 0 14px 34px rgba(16, 24, 40, .18);
    overflow: hidden;
}

.select2-dropdown .select2-search__field {
    min-height: 40px;
    margin: 6px;
    padding: 8px 12px;
    width: calc(100% - 12px);
    border: 1px solid #e4e4e7 !important;
    border-radius: 9px;
}

.select2-results__option {
    padding: 10px 14px;
    font-size: 14px;
}

.select2-container--default .select2-results__option--highlighted[aria-selected] {
    background: #1877f2;
}

/* =========================================================================
   เอกสารแนบ (Dropzone) — ดีไซน์สไตล์ originui file-input
   ========================================================================= */
.attachments .dropzone,
.dropzone {
    min-height: 168px !important;
    display: flex !important;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 26px 20px !important;
    border: 2px dashed #d0d5dd !important;
    border-radius: 14px !important;
    background: #fbfcfe !important;
    text-align: center;
    cursor: pointer;
    transition: border-color .15s ease, background-color .15s ease;
}
.dropzone:hover,
.dropzone.dz-drag-hover,
.dropzone.dz-started:hover {
    border-color: #1877f2 !important;
    background: #f5f9ff !important;
}
/* ไอคอนอัพโหลดวงกลม */
.dropzone::before {
    content: "";
    flex: 0 0 auto;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: #eef2ff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%231877f2' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4'/%3E%3Cpolyline points='17 8 12 3 7 8'/%3E%3Cline x1='12' y1='3' x2='12' y2='15'/%3E%3C/svg%3E") no-repeat center / 24px;
}
/* ข้อความในกล่อง */
.dropzone .dz-message {
    margin: 0 !important;
    color: #475467;
    font-size: 14px;
    font-weight: 600;
}
.dropzone .dz-message .dz-button {
    background: transparent;
    border: 0;
    color: inherit;
    font: inherit;
    cursor: pointer;
}
/* preview ไฟล์ที่อัพแล้ว = แถวการ์ดสะอาด */
.dropzone .dz-preview {
    margin: 10px 6px 0 !important;
    min-height: auto;
}
.dropzone .dz-preview .dz-image {
    border-radius: 10px;
}
.dropzone .dz-preview .dz-details {
    padding: 8px;
}

/* ปุ่ม "อัพโหลดไฟล์" — ปุ่มหลักใต้กล่อง */
.attachments .fileinput-button,
.fileinput-button.filedropbutton-filedrop {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: auto !important;
    min-width: 170px;
    margin: 12px auto 0 !important;
    padding: 11px 22px !important;
    border: 1px solid #d0d5dd !important;
    border-radius: 11px !important;
    background: #fff !important;
    color: #1877f2 !important;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: background-color .15s ease, border-color .15s ease, transform .12s ease;
}
.attachments .fileinput-button:hover,
.fileinput-button.filedropbutton-filedrop:hover {
    background: #f5f9ff !important;
    border-color: #1877f2 !important;
    transform: translateY(-1px);
}
/* ลิงก์ข้อจำกัดการอัพโหลด — เล็ก จาง อยู่กลาง */
.attachments > a.link,
.attachments a.link {
    display: block;
    margin-top: 10px;
    color: #98a2b3 !important;
    font-size: 12.5px;
    text-align: center;
    text-decoration: none;
}
.attachments > a.link:hover { color: #1877f2 !important; text-decoration: underline; }

/* จัดกล่องแนบให้อยู่กลาง */
.ticket-create .attachments {
    display: flex;
    flex-direction: column;
}

/* =========================================================================
   หน่วยงานรับผิดชอบ (#office select2) — กันกล่อง/ดรอปดาวน์ทับ label
   ========================================================================= */
.ticket-create .form-group:has(#office) > label {
    display: block;          /* label เป็น block -> กล่อง select2 ไปอยู่บรรทัดล่าง ไม่ทับ */
    margin-bottom: 8px;
}
.ticket-create .form-group:has(#office) .select2-container {
    display: block !important;   /* กัน inline-block มาอยู่บรรทัดเดียวกับ label */
    margin-top: 0;
}

/* =========================================================================
   ปุ่ม "บันทึก-ส่งเรื่อง" อยู่กึ่งกลางจอ (ไม่เต็มแถว)
   ========================================================================= */
.ticket-create #submit {
    display: flex !important;
    justify-content: center;
    margin-top: 10px;
}
.ticket-create #submit .btn,
.ticket-create #submit button[type="submit"] {
    width: auto !important;
    min-width: 300px;
    max-width: 460px;
    min-height: 48px;
    padding: 0 32px !important;
    border: 0 !important;
    border-radius: 12px !important;
    background: #1877f2 !important;
    color: #fff !important;
    font-size: 15px;
    font-weight: 800;
    box-shadow: 0 8px 20px rgba(24, 119, 242, .28) !important;
    transition: background-color .15s ease, transform .12s ease;
}
.ticket-create #submit .btn:hover,
.ticket-create #submit button[type="submit"]:hover {
    background: #1567d8 !important;
    transform: translateY(-1px);
}

/* =========================================================================
   ฟิลด์วันที่ (วันที่ยื่นเรื่อง / ครบกำหนดรายงานผล) — จัดระเบียบให้สวย
   ========================================================================= */
.ticket-create .param.calendar {
    display: flex;
    flex-direction: column;
    gap: 7px;
    margin: 0;
}
.ticket-create .param.calendar > label {
    margin: 0;
    color: #344054;
    font-size: 13.5px;
    font-weight: 600;
}
.ticket-create .param.calendar .calendar--button {
    position: relative !important;
    display: block !important;
    width: 100% !important;
}
.ticket-create .param.calendar .calendar--button > button {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: auto !important;
    min-height: 0 !important;
    padding: 0;
    border: 0;
    background: transparent;
    z-index: 2;
}
.ticket-create .param.calendar .datepicker {
    width: 100% !important;
    min-width: 0 !important;
    min-height: 44px !important;
    height: 44px !important;
    box-sizing: border-box;
    padding: 10px 14px 10px 40px !important;
    cursor: pointer;
}
/* ชิปแสดงวันที่ที่เลือก — สะอาด เล็ก ไม่รก */
.ticket-create .param.calendar .calendar--value {
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    padding: 6px 8px 6px 12px;
    width: -moz-fit-content;
    width: fit-content;
    border-radius: 9px;
    background: #eff6ff;
    color: #1456b8;
    font-size: 13px;
    font-weight: 600;
}
.ticket-create .param.calendar .calendar--value span i { font-style: normal; }
.ticket-create .param.calendar .calendar--value .close {
    display: inline-flex;
    align-items: center;
    cursor: pointer;
}
.ticket-create .param.calendar .calendar--value .close .icon {
    width: 13px;
    height: 13px;
    fill: #1456b8;
}

/* =========================================================================
   ระยะห่างของช่องกรอกในวิซาร์ด (อาร์มแจ้ง ๒๑ ส.ค. ๒๕๖๙)
   ปัญหา: บางกลุ่มอยู่ในกล่อง grid ที่มี gap 18px จึงเว้นระยะสวย
          แต่บางกลุ่มถูกวางซ้อนกันใน <div> ธรรมดาที่ไม่มี gap
          ป้ายชื่อช่องถัดไปเลยไปติดกับกล่องกรอกด้านบน
   ========================================================================= */
html body:not(.cust-help) .main__content.ticket-create div:not([class]) > .form-group:not(:last-child),
html body:not(.cust-help) .main__content.ticket-create #customfield > .form-group:not(:last-child),
html body:not(.cust-help) .main__content.ticket-create #customfield > .form-row:not(:last-child) {
    margin-bottom: 18px !important;   /* .form-row = แถวที่อยู่ (บ้านเลขที่/หมู่/ถนน/...) ก็ต้องเว้นเหมือนกัน */
}
/* ป้ายชื่อช่อง: เว้นใต้ป้ายเท่ากันทุกช่อง (บางช่องเป็น 0 อยู่) */
html body:not(.cust-help) .main__content.ticket-create .form-group > label {
    display: block;
    margin-bottom: 7px !important;
}

/* =========================================================================
   ช่องวันที่ (ครบกำหนดรายงานผล / วันที่ยื่นเรื่อง) — ให้เป็นช่องกรอกใบเดียว
   ปัญหาเดิม: ค่าที่เลือกเป็น "เม็ดยา" สีฟ้าลอยอยู่กลางช่อง + ปุ่มกากบาททับตัวเลข
   ========================================================================= */
html body:not(.cust-help) .main__content .param.calendar {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 7px;
}
html body:not(.cust-help) .main__content .param.calendar > label {
    margin: 0 !important;
    text-align: left;
}
html body:not(.cust-help) .main__content .param.calendar .calendar--button {
    display: flex !important;
    align-items: center;
    gap: 9px;
    min-height: 38px;
    padding: 0 10px 0 12px !important;
    border: 1px solid var(--dd-border, #cfdcee);
    border-radius: var(--dd-radius, 10px);
    background: #fff;
}
html body:not(.cust-help) .main__content .param.calendar .calendar--button > button {
    display: inline-flex;
    align-items: center;
    padding: 0 !important;
    border: 0 !important;
    background: none !important;
    color: #7286a3;
}
html body:not(.cust-help) .main__content .param.calendar .calendar--button > button .icon {
    width: 17px;
    height: 17px;
}
html body:not(.cust-help) .main__content .param.calendar input.datepicker {
    flex: 1 1 auto;
    min-width: 0;
    height: auto !important;
    min-height: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    outline: 0 !important;
    color: #22314f;
    font-size: 13.5px;
    font-weight: 600;
}
/* ค่าที่เลือกแล้ว: อยู่ในกรอบเดียวกัน ไม่ใช่เม็ดยาซ้อน และกากบาทอยู่ขวาสุด ไม่ทับตัวเลข */
html body:not(.cust-help) .main__content .param.calendar .calendar--value {
    align-items: center;
    gap: 8px;
    flex: 1 1 auto;
    min-width: 0;
    margin: 0 !important;
    padding: 0 !important;
    border-radius: 0 !important;
    background: transparent !important;
    color: #22314f;
    font-size: 13.5px;
    font-weight: 600;
}
html body:not(.cust-help) .main__content .param.calendar .calendar--value > span {
    flex: 1 1 auto;
    min-width: 0;
}
html body:not(.cust-help) .main__content .param.calendar .calendar--value .close {
    position: static !important;
    top: auto !important;
    right: auto !important;
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    margin-left: 6px;
    border-radius: 50%;
    color: #98a2b3;
    cursor: pointer;
}
html body:not(.cust-help) .main__content .param.calendar .calendar--value .close:hover {
    background: #f2f4f7;
    color: #d64545;
}
html body:not(.cust-help) .main__content .param.calendar .calendar--value .close .icon {
    width: 13px;
    height: 13px;
}

@media screen and (max-width: 899px) {
    html body:not(.cust-help) .main__content .param.calendar .calendar--button {
        min-height: 46px;
        border-radius: var(--dd-radius-m, 12px);
    }
    html body:not(.cust-help) .main__content .param.calendar input.datepicker,
    html body:not(.cust-help) .main__content .param.calendar .calendar--value { font-size: 14.5px; }
}

/* ไอคอนปฏิทินของธีมถูกวางแบบ absolute ทำให้ทับตัวเลขวันที่ — ให้เป็นไอเทมในแถวปกติ */
html body:not(.cust-help) .main__content .param.calendar .calendar--button > button {
    position: static !important;
    flex: 0 0 auto;
    order: 0;
    width: auto !important;
    height: auto !important;
    margin: 0 !important;
}
html body:not(.cust-help) .main__content .param.calendar input.datepicker { order: 1; }
html body:not(.cust-help) .main__content .param.calendar .calendar--value { order: 2; }

/* ปุ่มล้างค่า (กากบาท) ให้เล็กและจางเท่ากับไอคอนอื่น ไม่เด่นกว่าตัวเลขวันที่ */
html body:not(.cust-help) .main__content .param.calendar .calendar--value .close svg,
html body:not(.cust-help) .main__content .param.calendar .calendar--value .close .icon {
    width: 13px !important;
    height: 13px !important;
    color: #98a2b3 !important;
    fill: currentColor;
    stroke: currentColor;
}
html body:not(.cust-help) .main__content .param.calendar .calendar--value .close:hover svg {
    color: #d64545 !important;
}

/* =========================================================================
   ช่องวันที่ — ที่เดียวจบ ใช้ได้ทั้งจอคอมและมือถือ
   โครง: .calendar--button (กรอบ) > [ปุ่มไอคอนปฏิทิน] [input.datepicker] [.calendar--value]
   สถานะ:
     ยังไม่เลือก -> โชว์ input (มี placeholder ของธีม) · ซ่อนกล่องค่า+ปุ่มลบ
     เลือกแล้ว   -> ซ่อน input · โชว์ค่า + ปุ่มลบ (ไม่ทับกัน)
   (เดิมมีสองชุดคนละแบบใน mobile-trip.css กับที่นี่ ทำให้บนมือถือทับกันมั่ว — ลบชุดนั้นแล้ว)
   ========================================================================= */
html body:not(.cust-help) .main__content .param.calendar .calendar--button {
    display: flex !important;
    align-items: center !important;      /* ไอคอนปฏิทินอยู่กึ่งกลางแนวตั้งเสมอ */
    gap: 8px;
    box-sizing: border-box;
    min-height: 38px;
    padding: 0 10px 0 12px !important;
    border: 1px solid #cfdcee;
    border-radius: 10px;
    background: #fff;
}
html body:not(.cust-help) .main__content .param.calendar .calendar--button > button {
    flex: 0 0 auto;
    align-self: center;
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 22px !important;
    height: 22px !important;
    margin: 0 !important;
    padding: 0 !important;
    /* กฎเก่าเคยวางปุ่มแบบ absolute แล้วใช้ transform: translateY(-50%) จัดกึ่งกลาง
       ตอนนี้เป็น flex item แล้ว transform ที่ค้างอยู่จึงดันไอคอนลอยขึ้นครึ่งตัว */
    position: static !important;
    transform: none !important;
    top: auto !important;
    left: auto !important;
    line-height: 0;
}
html body:not(.cust-help) .main__content .param.calendar .calendar--button > button .icon,
html body:not(.cust-help) .main__content .param.calendar .calendar--button > button svg {
    display: block;
    width: 18px !important;
    height: 18px !important;
    margin: 0 !important;
}
html body:not(.cust-help) .main__content .param.calendar input.datepicker {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0 !important;
    height: auto !important;
    padding: 0 !important;
    border: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
}
/* --- สลับสถานะด้วย :has() ไม่ต้องพึ่ง JS --- */
html body:not(.cust-help) .main__content .param.calendar.has-date input.datepicker {
    display: none !important;
}
html body:not(.cust-help) .main__content .param.calendar:not(.has-date) .calendar--value {
    display: none !important;
}
html body:not(.cust-help) .main__content .param.calendar.has-date .calendar--value {
    display: flex !important;
}

@media screen and (max-width: 899px) {
    html body:not(.cust-help) .main__content .param.calendar .calendar--button {
        min-height: 46px;
        border-radius: 12px;
        padding: 0 10px 0 13px !important;
    }
    html body:not(.cust-help) .main__content .param.calendar input.datepicker,
    html body:not(.cust-help) .main__content .param.calendar .calendar--value { font-size: 14.5px; }
}
