/* ==========================================================================
   หน้าต่าง "ดาวน์โหลดหลายไฟล์" (โหมดธรรมดา + โหมดกลุ่มงาน)
   แบบอ้างอิง: Frontend/design/mockups/file-download-v1.html (ผู้ใช้อนุมัติ 2026-10-04)
   กติกาและประวัติ: Frontend/ADMIN_FILE_WORK_GROUPS_STABILITY.md, ADMIN_FILE_WORK_GROUPS_BUG_HISTORY.md
   - ภาษาออกแบบเดียวกับหน้าแชท: สี/ฟอนต์จากตัวแปร --site-* ใน public-site-kit.css,
     "เลือกอยู่" = พื้นขาว + ขอบไล่สีม่วง-ฟ้า, กระจกหลอกตา (ขาวเกือบทึบ + ขอบไล่แสง + เงาม่วงนุ่ม)
   - ห้าม backdrop-filter ทุกชั้น (ฉากหลัง ตัวหน้าต่าง ปุ่ม หัววันแบบ sticky) และห้ามแอนิเมชันตอนเปิด
     เพราะหน้าต่างมีพื้นที่เลื่อนภายใน (MODAL_PERFORMANCE_STABILITY.md)
   - ไม่ใช้คลาส .primary-btn / .secondary-btn / *modal-card* เพื่อไม่รับกฎกลาง !important ของ styles.css
   - แถวไฟล์ห้ามขยับตอน hover (ห้าม transform) และแถวที่เลือกอัปเดตด้วย aria-checked ไม่วาดใหม่ทั้งรายการ
   - แถบเลื่อนใช้แบบของระบบ ห้ามแต่งสี/ทำแบบบาง (GLASSMORPHISM_DESIGN_SYSTEM.md หัวข้อ Scroll Containers)
   ========================================================================== */

body.file-picker-modal-open {
  overflow: hidden;
}

.file-dl-overlay {
  --fdl-ink: var(--site-ink, #141129);
  --fdl-muted: var(--site-muted, #5b5677);
  --fdl-faint: var(--site-faint, #8c87a7);
  --fdl-violet: var(--site-violet, #6a4cf5);
  --fdl-grad: var(--site-grad, linear-gradient(120deg, #6a4cf5 0%, #4a6cf0 55%, #10b3c8 100%));
  --fdl-ring: linear-gradient(120deg, rgba(106, 76, 245, 0.85), rgba(16, 179, 200, 0.85));
  --fdl-tile: linear-gradient(140deg, rgba(124, 92, 255, 0.14), rgba(16, 179, 200, 0.12));
  --fdl-rim: linear-gradient(155deg, #fff 0%, rgba(255, 255, 255, 0.55) 22%, rgba(255, 255, 255, 0.18) 55%, rgba(255, 214, 236, 0.7) 85%, rgba(190, 225, 255, 0.85) 100%);
  --fdl-sunk: #f5f4fc;
  --fdl-hair: rgba(88, 66, 200, 0.09);
  --fdl-line: rgba(88, 66, 200, 0.16);
  --fdl-amber: var(--site-amber, #b85f05);
  --fdl-ok: var(--site-ok, #0f9150);
  --fdl-danger: var(--site-danger, #b4233a);
  --fdl-font: var(--site-font-body, "IBM Plex Sans Thai", "Anuphan", system-ui, sans-serif);
  --fdl-font-display: var(--site-font-display, "Anuphan", "IBM Plex Sans Thai", system-ui, sans-serif);

  position: fixed;
  inset: 0;
  z-index: 3200;
  display: none;
  align-items: center;
  justify-content: center;
  padding:
    max(24px, calc(env(safe-area-inset-top, 0px) + 12px))
    24px
    max(24px, calc(env(safe-area-inset-bottom, 0px) + 12px));
  background: rgba(28, 20, 72, 0.36);
  color: var(--fdl-ink);
  font-family: var(--fdl-font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.file-dl-overlay.is-visible {
  display: flex;
}

/* ทุกชิ้นที่ JS ซ่อนด้วย hidden ต้องหายจริง แม้กฎ display ของชิ้นนั้นจะเขียนไว้ */
.file-dl-overlay [hidden] {
  display: none !important;
}

/* :where() ทำให้กฎตั้งต้นของปุ่มเบาที่สุด คลาสของปุ่มแต่ละแบบจึงกำหนดสี/ตัวหนังสือทับได้เสมอ */
.file-dl-overlay :where(button) {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.file-dl-overlay :focus-visible {
  outline: 3px solid rgba(106, 76, 245, 0.3);
  outline-offset: 2px;
}

.file-dl-ic {
  flex: none;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.file-dl-short,
.file-dl-when-groups {
  display: none;
}

/* ---------- ตัวหน้าต่าง: กระจกหลอกตา ขอบไล่แสงวาดครั้งเดียวด้วย mask ไม่เบลอ ---------- */
.file-dl-overlay .file-dl {
  position: relative;
  width: min(820px, 100%);
  max-height: min(860px, 100%);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 28px;
  background: linear-gradient(165deg, #ffffff 0%, #fcfbff 55%, #f8f8ff 100%);
  box-shadow: 0 50px 110px -40px rgba(60, 40, 170, 0.62), 0 2px 8px rgba(30, 20, 80, 0.08);
}

.file-dl-overlay .file-dl:focus {
  outline: none;
}

.file-dl-overlay .file-dl::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 6;
  padding: 1.5px;
  border-radius: inherit;
  background: var(--fdl-rim);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

.file-dl-overlay .file-dl.has-groups {
  width: min(1180px, 100%);
}

.file-dl.has-groups .file-dl-when-simple {
  display: none;
}

.file-dl.has-groups .file-dl-when-groups {
  display: inline;
}

/* ---------- หัว: ชื่อเดียวกับเมนูที่กดเข้ามา + เลือกทั้งหมด + ปิด ---------- */
.file-dl-head {
  flex: none;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 20px 20px 16px 24px;
}

.file-dl-tile {
  flex: none;
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border: 1px solid #fff;
  border-radius: 15px;
  background: var(--fdl-tile), #fff;
  box-shadow: inset 0 1px 0 #fff, 0 10px 22px -14px rgba(106, 76, 245, 0.7);
  color: var(--fdl-violet);
}

.file-dl-tile .file-dl-ic {
  width: 22px;
  height: 22px;
}

.file-dl-title {
  flex: 1;
  min-width: 0;
}

.file-dl-overlay .file-dl-title h3 {
  margin: 0;
  color: var(--fdl-ink);
  font: 600 21px/1.25 var(--fdl-font-display);
  letter-spacing: -0.01em;
}

.file-dl-title p {
  margin: 3px 0 0;
  color: var(--fdl-muted);
  font-size: 13.5px;
  line-height: 1.45;
}

.file-dl-soft-btn {
  flex: none;
  height: 40px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid rgba(88, 66, 200, 0.14);
  border-radius: 12px;
  background: #fff;
  box-shadow: inset 0 1px 0 #fff, 0 6px 14px -12px rgba(76, 52, 200, 0.6);
  color: var(--fdl-violet);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  transition: border-color 0.16s ease, background-color 0.16s ease;
}

.file-dl-soft-btn:hover:not(:disabled) {
  border-color: rgba(106, 76, 245, 0.32);
  background: #faf9ff;
}

.file-dl-soft-btn:disabled {
  color: var(--fdl-faint);
  box-shadow: none;
  cursor: not-allowed;
}

.file-dl-close {
  flex: none;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(88, 66, 200, 0.12);
  border-radius: 999px;
  background: #fff;
  color: var(--fdl-muted);
  transition: color 0.16s ease, border-color 0.16s ease;
}

.file-dl-close:hover {
  border-color: rgba(88, 66, 200, 0.24);
  color: var(--fdl-ink);
}

/* แถบเตือนไฟล์ยังเข้าไม่ครบ อยู่นอกพื้นที่เลื่อนจึงเห็นตลอด */
.file-dl-alert {
  flex: none;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin: 0 20px 14px 24px;
  padding: 12px 14px;
  border: 1px solid rgba(214, 130, 20, 0.22);
  border-radius: 16px;
  background: #fff7eb;
  color: #7a4a06;
}

.file-dl-alert .file-dl-ic {
  margin-top: 2px;
  color: var(--fdl-amber);
}

.file-dl-alert strong {
  display: block;
  font-size: 14px;
  font-weight: 600;
}

.file-dl-alert span {
  display: block;
  margin-top: 2px;
  font-size: 13px;
  line-height: 1.5;
}

/* แท็บ ไฟล์ / กลุ่มงาน ใช้เฉพาะมือถือโหมดกลุ่มงาน (จอคอมแสดงสองคอลัมน์คู่กัน) */
.file-dl-tabs {
  display: none;
}

/* ---------- พื้นที่รายการ ---------- */
.file-dl-body {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  border-top: 1px solid var(--fdl-hair);
  background: var(--fdl-sunk);
}

.file-dl.has-groups .file-dl-body {
  grid-template-columns: minmax(0, 1fr) 420px;
}

.file-dl-list {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 0 18px 18px;
}

.file-dl-list.is-busy .file-dl-row {
  cursor: progress;
}

/* หัววัน: ติดด้านบนตอนเลื่อน พื้นทึบ ไม่เบลอ + ปุ่มเลือกทั้งวัน */
.file-dl-day {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 4px 9px 6px;
  background: var(--fdl-sunk);
}

.file-dl-day strong {
  font: 600 15.5px/1.2 var(--fdl-font-display);
}

.file-dl-day small {
  color: var(--fdl-faint);
  font-size: 13px;
}

.file-dl-day small::before {
  content: "·";
  margin-right: 8px;
}

.file-dl-day-btn {
  height: 32px;
  margin-left: auto;
  padding: 0 11px;
  display: inline-flex;
  align-items: center;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--fdl-violet);
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  transition: background-color 0.16s ease;
}

.file-dl-day-btn:hover:not(:disabled) {
  background: rgba(106, 76, 245, 0.08);
}

.file-dl-day-btn:disabled {
  color: var(--fdl-faint);
  cursor: not-allowed;
}

/* หัวรอบที่ลูกค้าส่ง (ห่างกันเกิน 1 ชั่วโมงในวันเดียว): แยกดาวน์โหลดเป็นรอบได้ ไม่ติดด้านบนเพื่อไม่ทับหัววัน */
.file-dl-batch {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 0 6px;
  padding: 0 4px 0 8px;
}

.file-dl-batch::after {
  content: "";
  order: 1;
  flex: 1;
  height: 1px;
  background: var(--fdl-line);
}

.file-dl-batch-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--fdl-muted);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.file-dl-batch-label .file-dl-ic {
  width: 15px;
  height: 15px;
  color: var(--fdl-faint);
}

.file-dl-batch-btn {
  order: 2;
  height: 30px;
  padding: 0 10px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--fdl-violet);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.file-dl-batch-btn:hover:not(:disabled) {
  background: rgba(106, 76, 245, 0.08);
}

.file-dl-batch-btn:disabled {
  color: var(--fdl-faint);
  cursor: not-allowed;
}

/* แถวไฟล์: ทั้งแถวกดเลือกได้ / เลือกแล้ว = พื้นขาว + ขอบไล่สี แบบ "เลือกอยู่" ในหน้าแชท */
.file-dl-row {
  width: 100%;
  display: grid;
  grid-template-columns: 24px 54px minmax(0, 1fr);
  align-items: center;
  gap: 14px;
  margin: 0 0 6px;
  padding: 10px 16px 10px 14px;
  border: 1.5px solid rgba(255, 255, 255, 0.95);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: 0 1px 2px rgba(40, 24, 120, 0.05);
  color: var(--fdl-ink);
  text-align: left;
  transition: background-color 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}

.file-dl-row:hover {
  background: #fff;
  box-shadow: 0 8px 18px -14px rgba(76, 52, 200, 0.5);
}

.file-dl-row[aria-checked="true"] {
  border-color: transparent;
  background: linear-gradient(#fff, #fff) padding-box, var(--fdl-ring) border-box;
  box-shadow: 0 12px 24px -18px rgba(106, 76, 245, 0.85);
}

.file-dl-check {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border: 1.6px solid rgba(88, 66, 200, 0.3);
  border-radius: 8px;
  background: #fff;
  color: transparent;
  transition: background-color 0.16s ease, border-color 0.16s ease;
}

.file-dl-check .file-dl-ic {
  width: 15px;
  height: 15px;
  stroke-width: 2.6;
}

.file-dl-row[aria-checked="true"] .file-dl-check {
  border-color: transparent;
  background: var(--fdl-grad) border-box;
  box-shadow: 0 6px 14px -6px rgba(106, 76, 245, 0.75);
  color: #fff;
}

.file-dl-thumb {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid rgba(88, 66, 200, 0.08);
  border-radius: 14px;
  background: #f1effa;
  color: var(--fdl-faint);
}

.file-dl-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.file-dl-thumb.is-tile,
.file-workgroup-mini.is-tile {
  font: 700 11px/1 var(--fdl-font);
  letter-spacing: 0.05em;
}

.file-dl-overlay .is-pdf {
  background: linear-gradient(140deg, #ffe4e8, #fdecee);
  color: #c0263d;
}

.file-dl-overlay .is-word {
  background: linear-gradient(140deg, #dce8ff, #eef4ff);
  color: #1d4ed8;
}

.file-dl-overlay .is-excel {
  background: linear-gradient(140deg, #d6f5e6, #ecfbf3);
  color: #047857;
}

.file-dl-overlay .is-ppt {
  background: linear-gradient(140deg, #ffe9d6, #fff4ea);
  color: #c2410c;
}

.file-dl-overlay .is-zip,
.file-dl-overlay .is-other {
  background: linear-gradient(140deg, #ece9f8, #f5f3fc);
  color: var(--fdl-muted);
}

.file-dl-overlay .is-audio,
.file-dl-overlay .is-image {
  background: var(--fdl-tile), #fff;
  color: var(--fdl-violet);
}

.file-dl-info {
  display: block;
  min-width: 0;
}

/* ชื่อยาวตัดตรงกลาง นามสกุลไฟล์ยังเห็นเสมอ */
.file-dl-name {
  display: flex;
  min-width: 0;
  font-size: 14.5px;
  font-weight: 600;
  line-height: 1.35;
}

.file-dl-name-base {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-dl-name-ext {
  flex: none;
}

.file-dl-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 6px;
  margin-top: 4px;
  color: var(--fdl-muted);
  font-size: 12.5px;
  line-height: 1.4;
}

.file-dl-dot {
  color: var(--fdl-faint);
}

.file-dl-chip {
  min-height: 20px;
  padding: 1px 7px;
  display: inline-flex;
  align-items: center;
  border-radius: 7px;
  background: rgba(106, 76, 245, 0.08);
  color: var(--fdl-violet);
  font-size: 11.5px;
  font-weight: 600;
}

.file-dl-chip.is-status {
  background: rgba(214, 130, 20, 0.12);
  color: var(--fdl-amber);
}

/* ไฟล์ที่เลือกไม่ได้แล้ว: จาง เส้นประ บอกเหตุผลสีส้ม */
.file-dl-row[aria-disabled="true"] {
  border-style: dashed;
  border-color: rgba(88, 66, 200, 0.16);
  background: rgba(255, 255, 255, 0.4);
  box-shadow: none;
  cursor: not-allowed;
}

.file-dl-row[aria-disabled="true"] .file-dl-check {
  border-style: dashed;
  border-color: rgba(88, 66, 200, 0.2);
  background: transparent;
}

.file-dl-row[aria-disabled="true"] .file-dl-thumb {
  background: rgba(241, 239, 250, 0.7);
  color: var(--fdl-faint);
}

.file-dl-row[aria-disabled="true"] .file-dl-name {
  color: var(--fdl-faint);
}

.file-dl-meta.is-unavailable {
  color: var(--fdl-amber);
}

.file-dl-meta.is-unavailable .file-dl-ic {
  width: 14px;
  height: 14px;
}

/* ป้ายกลุ่มงานใต้ชื่อไฟล์: สีประจำกลุ่มชุดเดียวกับป้ายในแชท, AI = เส้นประ */
.file-dl-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 7px;
}

.file-dl-overlay .file-work-summary-tag {
  max-width: 100%;
  min-height: 22px;
  padding: 1px 8px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  overflow: hidden;
  border: 1px solid var(--file-work-group-border, rgba(106, 76, 245, 0.28));
  border-radius: 7px;
  background: var(--file-work-group-soft, #f5f3ff);
  color: var(--file-work-group-text, #5b21b6);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.3;
}

.file-dl-overlay .file-work-summary-tag span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-dl-overlay .file-work-summary-tag .file-dl-ic {
  width: 13px;
  height: 13px;
}

.file-dl-overlay .file-work-summary-tag.is-ai {
  border-style: dashed;
  background: #fff;
}

.file-dl-overlay .file-work-summary-tag.is-history {
  border-style: dashed;
  opacity: 0.82;
  cursor: default;
}

.file-dl-overlay .file-work-summary-tag.is-unsure {
  border: 1px dashed rgba(214, 130, 20, 0.4);
  background: #fff;
  color: var(--fdl-amber);
}

/* ว่าง */
.file-dl-empty {
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 64px 24px 72px;
  text-align: center;
}

.file-dl-empty .file-dl-tile {
  width: 60px;
  height: 60px;
  margin-bottom: 8px;
  border-radius: 19px;
}

.file-dl-empty strong {
  font: 600 17px/1.3 var(--fdl-font-display);
}

.file-dl-empty span {
  max-width: 340px;
  color: var(--fdl-muted);
  font-size: 13.5px;
  line-height: 1.6;
}

/* ---------- ท้าย: ยอดที่เลือก + ปุ่มหลักปุ่มเดียว ---------- */
.file-dl-foot {
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px 18px 24px;
  border-top: 1px solid var(--fdl-hair);
  background: #fff;
}

.file-dl-sum {
  flex: 1;
  min-width: 0;
}

.file-dl-sum-line {
  min-height: 28px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.file-dl-count {
  color: var(--fdl-muted);
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
}

.file-dl-count.has-selection {
  color: var(--fdl-ink);
  font-weight: 600;
}

.file-dl-count em {
  color: var(--fdl-violet);
  font-style: normal;
}

.file-dl-hint {
  display: block;
  color: var(--fdl-faint);
  font-size: 12.5px;
}

.file-dl-link-btn {
  height: 28px;
  padding: 0 8px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--fdl-violet);
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
}

.file-dl-link-btn:hover:not(:disabled) {
  background: rgba(106, 76, 245, 0.08);
}

.file-dl-btn {
  flex: none;
  height: 48px;
  padding: 0 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  transition: box-shadow 0.2s ease, background-color 0.16s ease, border-color 0.16s ease;
}

.file-dl-btn--soft {
  border-color: rgba(88, 66, 200, 0.18);
  background: #fff;
  color: var(--fdl-ink);
}

.file-dl-btn--soft .file-dl-ic {
  color: var(--fdl-violet);
}

.file-dl-btn--soft:hover:not(:disabled) {
  border-color: rgba(106, 76, 245, 0.34);
}

.file-dl-btn--soft:disabled {
  color: var(--fdl-faint);
  cursor: not-allowed;
}

.file-dl-btn--main {
  background: var(--fdl-grad) border-box;
  box-shadow: 0 14px 30px -12px rgba(90, 70, 240, 0.75), inset 0 1px 0 rgba(255, 255, 255, 0.25);
  color: #fff;
}

.file-dl-btn--main:hover:not(:disabled) {
  box-shadow: 0 18px 36px -12px rgba(90, 70, 240, 0.9), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

/* กดไม่ได้ต้องดูออกทันที ไม่ใช่สีไล่เฉดจาง ๆ ที่เหมือนกดได้ */
.file-dl-btn--main:disabled {
  background: rgba(106, 76, 245, 0.08);
  box-shadow: none;
  color: rgba(88, 66, 200, 0.42);
  cursor: not-allowed;
}

.file-dl-btn--main.is-busy:disabled {
  background: var(--fdl-grad) border-box;
  color: #fff;
  opacity: 0.82;
  cursor: progress;
}

.file-dl-btn-icon {
  display: inline-flex;
}

.file-dl-btn .file-dl-ic-busy,
.file-dl-btn.is-busy .file-dl-ic-idle {
  display: none;
}

.file-dl-btn.is-busy .file-dl-ic-busy {
  display: block;
  animation: file-dl-spin 0.9s linear infinite;
}

@keyframes file-dl-spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- คอลัมน์กลุ่มงาน: โผล่เฉพาะเมื่อมีกลุ่มจริงหรือข้อเสนอ AI ---------- */
.file-dl-groups {
  display: none;
}

.file-dl.has-groups .file-dl-groups {
  display: block;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 16px 18px 22px;
  border-left: 1px solid var(--fdl-hair);
  background: #fdfcff;
}

.file-dl-gp-head {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 12px;
}

.file-dl-overlay .file-dl-gp-head h4 {
  margin: 0;
  color: var(--fdl-ink);
  font: 600 16.5px/1.2 var(--fdl-font-display);
}

.file-dl-save {
  min-height: 24px;
  padding: 1px 9px;
  display: inline-flex;
  align-items: center;
  border-radius: 8px;
  background: rgba(106, 76, 245, 0.08);
  color: var(--fdl-violet);
  font-size: 12px;
  font-weight: 600;
}

.file-dl-save[data-tone="success"] {
  background: rgba(15, 145, 80, 0.1);
  color: var(--fdl-ok);
}

.file-dl-save[data-tone="error"] {
  background: #fdecee;
  color: var(--fdl-danger);
}

.file-dl-more {
  position: relative;
  margin-left: auto;
}

.file-dl-icon-btn {
  flex: none;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--fdl-muted);
}

.file-dl-icon-btn:hover:not(:disabled) {
  background: rgba(106, 76, 245, 0.08);
  color: var(--fdl-ink);
}

.file-dl-icon-btn:disabled {
  color: var(--fdl-faint);
  cursor: not-allowed;
}

/* เมนู ⋯ ลอยชั่วคราว พื้นขาวเกือบทึบ ไม่เบลอ */
.file-dl-pop {
  position: absolute;
  top: 42px;
  right: 0;
  z-index: 8;
  width: 260px;
  padding: 6px;
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 24px 50px -20px rgba(40, 24, 120, 0.45);
}

.file-dl-pop-item {
  width: 100%;
  min-height: 42px;
  padding: 0 11px;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 0;
  border-radius: 11px;
  background: none;
  font-size: 14px;
  text-align: left;
}

.file-dl-pop-item.is-danger {
  color: var(--fdl-danger);
}

.file-dl-pop-item:hover:not(:disabled) {
  background: rgba(180, 35, 58, 0.06);
}

.file-dl-pop-item:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.file-dl-pop small {
  display: block;
  padding: 2px 11px 6px;
  color: var(--fdl-faint);
  font-size: 12px;
  line-height: 1.45;
}

.file-dl-note {
  margin: 0 0 12px;
  padding: 11px 13px;
  display: flex;
  gap: 10px;
  border: 1px solid var(--fdl-line);
  border-radius: 16px;
  background: #fff;
  color: var(--fdl-muted);
  font-size: 13px;
  line-height: 1.5;
}

.file-dl-note > .file-dl-ic {
  margin-top: 1px;
}

.file-dl-note strong {
  display: block;
  color: var(--fdl-ink);
  font-size: 13.5px;
  font-weight: 600;
}

.file-dl-note.is-warning {
  border: 1px dashed rgba(214, 130, 20, 0.4);
  background: #fffaf2;
  color: #7a4a06;
}

.file-dl-note.is-warning > .file-dl-ic,
.file-dl-note.is-warning strong {
  color: var(--fdl-amber);
}

.file-dl-note.is-error {
  border-color: rgba(180, 35, 58, 0.22);
  background: #fff6f7;
}

.file-dl-note.is-error > .file-dl-ic,
.file-dl-note.is-error strong {
  color: var(--fdl-danger);
}

.file-dl-note-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.file-dl-chip-btn {
  height: 32px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--fdl-line);
  border-radius: 10px;
  background: #fff;
  color: var(--fdl-ink);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.file-dl-chip-btn:hover:not(:disabled) {
  border-color: rgba(106, 76, 245, 0.32);
}

.file-dl-chip-btn:disabled {
  color: var(--fdl-faint);
  cursor: not-allowed;
}

.file-dl-chip-btn .file-dl-ic {
  width: 15px;
  height: 15px;
}

.file-dl-spin {
  animation: file-dl-spin 0.9s linear infinite;
}

.file-dl-ai-note {
  margin: 0 0 12px;
  padding: 13px 14px;
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  gap: 4px 12px;
  border: 1px solid #fff;
  border-radius: 18px;
  background: var(--fdl-tile), #fff;
  box-shadow: inset 0 1px 0 #fff;
}

.file-dl-ai-ic {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  background: #fff;
  box-shadow: 0 6px 14px -10px rgba(106, 76, 245, 0.8);
  color: var(--fdl-violet);
}

.file-dl-ai-note strong {
  display: block;
  font-size: 14px;
  font-weight: 600;
}

.file-dl-ai-note p {
  margin: 2px 0 0;
  color: var(--fdl-muted);
  font-size: 12.5px;
  line-height: 1.5;
}

.file-dl-ai-note .file-dl-chip-btn {
  grid-column: 2;
  justify-self: start;
  margin-top: 6px;
  color: var(--fdl-muted);
}

.file-workgroups-cards {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

/* การ์ดกลุ่ม: แถบสีประจำกลุ่มด้านซ้าย, กลุ่มที่ AI เสนอใช้กรอบเส้นประ */
.file-dl-overlay .file-workgroup-card {
  position: relative;
  padding: 14px 14px 10px 16px;
  border: 1px solid rgba(88, 66, 200, 0.1);
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 10px 22px -20px rgba(76, 52, 200, 0.6);
}

.file-dl-overlay .file-workgroup-card::before {
  content: "";
  position: absolute;
  top: 16px;
  left: -1px;
  width: 4px;
  height: 26px;
  border-radius: 0 4px 4px 0;
  background: var(--file-work-group-solid, var(--fdl-violet));
}

.file-dl-overlay .file-workgroup-card.is-ai {
  border: 1.5px dashed var(--file-work-group-border, rgba(106, 76, 245, 0.35));
  box-shadow: none;
}

.file-workgroup-card-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.file-workgroup-title-input,
.file-workgroup-title {
  flex: 1;
  min-width: 0;
  height: 34px;
  margin-left: -8px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--fdl-ink);
  font: 600 15px/34px var(--fdl-font);
}

.file-workgroup-title {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-workgroup-title-input:hover:not(:disabled) {
  border-color: rgba(88, 66, 200, 0.14);
}

.file-workgroup-title-input:focus,
.file-workgroup-instruction-input:focus {
  outline: none;
  border-color: transparent;
  background: linear-gradient(#fff, #fff) padding-box, var(--fdl-ring) border-box;
  box-shadow: 0 0 0 4px rgba(106, 76, 245, 0.1);
}

.file-workgroup-title-input:disabled,
.file-workgroup-instruction-input:disabled {
  color: var(--fdl-muted);
}

.file-workgroup-ai-chip {
  flex: none;
  min-height: 22px;
  padding: 1px 8px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border-radius: 7px;
  background: rgba(106, 76, 245, 0.08);
  color: var(--fdl-violet);
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}

.file-workgroup-ai-chip .file-dl-ic {
  width: 13px;
  height: 13px;
}

.file-workgroup-instruction-input {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 9px 11px;
  border: 1px solid rgba(88, 66, 200, 0.1);
  border-radius: 12px;
  background: var(--fdl-sunk);
  color: var(--fdl-ink);
  font: 13.5px/1.5 var(--fdl-font);
  resize: vertical;
}

.file-workgroup-instruction-text {
  margin: 6px 0 0;
  color: var(--fdl-muted);
  font-size: 13.5px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.file-workgroup-files {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
}

.file-workgroup-mini {
  flex: none;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid rgba(88, 66, 200, 0.08);
  border-radius: 9px;
  background: #f1effa;
  color: var(--fdl-faint);
}

.file-workgroup-mini.is-tile {
  font-size: 7.5px;
}

.file-workgroup-mini img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.file-workgroup-mini .file-dl-ic {
  width: 15px;
  height: 15px;
}

.file-workgroup-more-count {
  color: var(--fdl-muted);
  font-size: 12px;
  font-weight: 600;
}

.file-workgroup-count {
  margin-left: 4px;
  color: var(--fdl-muted);
  font-size: 12.5px;
  white-space: nowrap;
}

.file-workgroup-files .file-dl-link-btn {
  margin-left: auto;
}

.file-workgroup-file-options {
  margin-top: 8px;
  padding: 6px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 2px;
  border-radius: 14px;
  background: var(--fdl-sunk);
}

.file-workgroup-file-option {
  min-width: 0;
  min-height: 40px;
  padding: 4px 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: 10px;
  font-size: 13px;
  cursor: pointer;
}

.file-workgroup-file-option:hover {
  background: #fff;
}

.file-workgroup-file-option input {
  flex: none;
  width: 17px;
  height: 17px;
  margin: 0;
  accent-color: var(--fdl-violet);
}

.file-workgroup-file-option span:last-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-workgroup-source-jump {
  height: 34px;
  margin: 8px 0 0 -8px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  border-radius: 9px;
  background: none;
  color: var(--fdl-violet);
  font-size: 13px;
  font-weight: 600;
}

.file-workgroup-source-jump:hover {
  background: rgba(106, 76, 245, 0.08);
}

.file-workgroup-source-jump .file-dl-ic {
  width: 16px;
  height: 16px;
}

.file-workgroups-empty {
  padding: 18px 16px;
  border: 1px dashed var(--fdl-line);
  border-radius: 16px;
  background: #fff;
  color: var(--fdl-muted);
  font-size: 13px;
  line-height: 1.55;
  text-align: center;
}

.file-dl-overlay .file-work-round-history {
  border: 1px solid var(--fdl-hair);
  border-radius: 16px;
  background: #fff;
}

.file-dl-overlay .file-work-round-history > summary {
  height: 46px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--fdl-muted);
  font-size: 13.5px;
  font-weight: 600;
  list-style: none;
  cursor: pointer;
}

.file-dl-overlay .file-work-round-history > summary::-webkit-details-marker {
  display: none;
}

.file-dl-overlay .file-work-round-history > summary small {
  color: var(--fdl-faint);
  font-weight: 500;
}

.file-dl-overlay .file-work-round-history > summary .file-dl-chev {
  margin-left: auto;
  width: 16px;
  height: 16px;
  transition: transform 0.2s ease;
}

.file-dl-overlay .file-work-round-history[open] > summary .file-dl-chev {
  transform: rotate(180deg);
}

.file-work-round-history-card {
  padding: 10px 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  border-top: 1px solid var(--fdl-hair);
  color: var(--fdl-muted);
  font-size: 12.5px;
}

.file-work-round-history-card strong {
  color: var(--fdl-ink);
  font-weight: 600;
}

.file-work-round-history-tags {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.file-work-round-history-tags span {
  min-height: 22px;
  padding: 1px 8px;
  display: inline-flex;
  align-items: center;
  border-radius: 7px;
  background: var(--fdl-sunk);
  color: var(--fdl-muted);
  font-size: 12px;
}

/* ================= จอแคบกว่า 920px (แท็บเล็ต / หน้าต่างแคบ) =================
   สองคอลัมน์ของโหมดกลุ่มงานจะบีบรายการไฟล์จนอ่านชื่อไม่ออก จึงสลับดูทีละส่วนด้วยแท็บ
   และท้ายหน้าต่างเป็น 2 แถว: ยอดที่เลือก (+ จัดกลุ่ม) / ปุ่มดาวน์โหลดเต็มกว้าง */
@media (max-width: 920px) {
  .file-dl-overlay .file-dl.has-groups {
    width: min(820px, 100%);
  }

  .file-dl.has-groups .file-dl-tabs {
    display: flex;
    gap: 4px;
    margin: 0 20px 14px 24px;
    padding: 4px;
    border: 1px solid rgba(255, 255, 255, 0.9);
    border-radius: 15px;
    background: var(--fdl-sunk);
    box-shadow: inset 0 1px 2px rgba(76, 52, 200, 0.06);
  }

  .file-dl-tab {
    flex: 1;
    height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    border: 1px solid transparent;
    border-radius: 12px;
    background: transparent;
    color: var(--fdl-muted);
    font-size: 15px;
    font-weight: 600;
  }

  .file-dl-tab[aria-pressed="true"] {
    background: linear-gradient(#fff, #fff) padding-box, var(--fdl-ring) border-box;
    box-shadow: 0 10px 24px -12px rgba(106, 76, 245, 0.65);
    color: var(--fdl-violet);
  }

  .file-dl-tab-count {
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 10px;
    background: rgba(106, 76, 245, 0.1);
    color: var(--fdl-violet);
    font-size: 12px;
    line-height: 20px;
  }

  .file-dl.has-groups .file-dl-body {
    grid-template-columns: minmax(0, 1fr);
  }

  .file-dl.has-groups:not(.is-tab-groups) .file-dl-groups,
  .file-dl.has-groups.is-tab-groups .file-dl-list {
    display: none;
  }

  .file-dl.has-groups .file-dl-groups {
    padding: 4px 18px 18px;
    border-left: 0;
    background: var(--fdl-sunk);
  }

  .file-dl-foot {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px 10px;
  }

  .file-dl-sum {
    grid-column: 1;
  }

  .file-dl-foot .file-dl-btn--soft {
    grid-column: 2;
    height: 40px;
    padding: 0 14px;
    font-size: 14px;
  }

  .file-dl-foot .file-dl-btn--main {
    grid-column: 1 / -1;
  }
}

/* ================= จอมือถือ: แผ่นล่าง (bottom sheet) เต็มกว้าง ปุ่มกดง่าย 44px ขึ้นไป ================= */
@media (max-width: 640px) {
  .file-dl-overlay {
    align-items: flex-end;
    padding: calc(28px + env(safe-area-inset-top, 0px)) 0 0;
  }

  .file-dl-overlay .file-dl,
  .file-dl-overlay .file-dl.has-groups {
    width: 100%;
    max-height: 100%;
    border-radius: 26px 26px 0 0;
  }

  .file-dl-head {
    gap: 10px;
    padding: 16px 12px 12px 18px;
  }

  .file-dl-head .file-dl-tile {
    display: none;
  }

  .file-dl-overlay .file-dl-title h3 {
    font-size: 19px;
  }

  .file-dl-title p {
    font-size: 13px;
  }

  .file-dl.has-groups .file-dl-title p {
    display: none;
  }

  .file-dl-soft-btn {
    height: 42px;
    padding: 0 12px;
  }

  .file-dl-soft-btn .file-dl-ic {
    display: none;
  }

  .file-dl-close {
    width: 42px;
    height: 42px;
  }

  .file-dl-long {
    display: none;
  }

  .file-dl-short {
    display: inline;
  }

  .file-dl-alert {
    margin: 0 12px 12px;
  }

  .file-dl-list {
    padding: 0 10px 14px;
  }

  .file-dl-day {
    padding: 14px 2px 8px 6px;
  }

  .file-dl-day-btn,
  .file-dl-batch-btn {
    height: 36px;
  }

  .file-dl-row {
    grid-template-columns: 24px 52px minmax(0, 1fr);
    gap: 12px;
    padding: 10px 12px;
  }

  .file-dl-thumb {
    width: 52px;
    height: 52px;
  }

  .file-dl-name {
    font-size: 15px;
  }

  .file-dl-meta {
    font-size: 13px;
  }

  .file-dl.has-groups .file-dl-tabs {
    margin: 0 12px 12px;
  }

  .file-dl.has-groups .file-dl-groups {
    padding: 6px 10px 16px;
  }

  .file-dl-foot {
    padding: 10px 12px calc(12px + var(--app-bottom-safe-area-effective, env(safe-area-inset-bottom, 0px)));
  }

  .file-dl-hint {
    display: none;
  }

  .file-dl-foot .file-dl-btn--main {
    height: 50px;
  }

  .file-dl-pop {
    width: 240px;
  }
}
