/* dropdown ของเว็บเราเอง (คู่กับ dropdown.js) ใช้สีจากตัวแปรของแต่ละหน้า: --red, --line, --bg ฯลฯ */
.dd { position: relative; }
.dd-native { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; pointer-events: none; }

.dd-btn {
  width: 100%; min-height: 50px; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 11px 14px 11px 16px; border-radius: 12px; border: 1.5px solid var(--line); background: #fff;
  font: inherit; font-size: 16px; color: var(--ink); text-align: left; cursor: pointer;
  transition: border-color .2s, box-shadow .2s, background-color .2s;
}
.dd-btn:hover:not(:disabled) { border-color: #cbd5e1; }
.dd-btn:focus-visible, .dd.open .dd-btn { outline: none; border-color: var(--red); box-shadow: 0 0 0 4px var(--red-soft); }
.dd-btn:disabled { background: var(--bg); color: #94a3b8; cursor: not-allowed; }
.dd-value { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dd-value.placeholder { color: #5f6878; }
.dd-btn:disabled .dd-value { color: #94a3b8; }
.dd-chev {
  width: 9px; height: 9px; flex-shrink: 0; margin: -4px 4px 0 0;
  border-right: 2.5px solid #64748b; border-bottom: 2.5px solid #64748b; border-radius: 1px;
  transform: rotate(45deg); transition: transform .2s cubic-bezier(.2,.7,.2,1), margin .2s;
}
.dd.open .dd-chev { transform: rotate(-135deg); margin-top: 4px; border-color: var(--red); }
.field.err .dd-btn { border-color: var(--warn, #b42318); background-color: #fffafa; }

.dd-panel {
  position: fixed; z-index: 60; box-sizing: border-box;
  display: flex; flex-direction: column; padding: 6px; max-height: 340px;
  background: #fff; border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 24px 48px -12px rgba(15,23,42,.22), 0 8px 16px -8px rgba(15,23,42,.1);
  animation: dd-in .16s cubic-bezier(.2,.7,.2,1);
}
.dd-panel[hidden] { display: none; }
.dd-panel.up { animation-name: dd-in-up; }
@keyframes dd-in { from { opacity: 0; transform: translateY(-4px); } }
@keyframes dd-in-up { from { opacity: 0; transform: translateY(4px); } }

.dd-search {
  flex-shrink: 0; width: 100%; min-height: 42px !important; margin: 0 0 6px; padding: 9px 12px 9px 38px !important;
  border-radius: 10px !important; border: 1.5px solid var(--line) !important; font: inherit; font-size: 16px !important; /* 16px: iPhone ไม่ซูมหน้าเว็บเองตอนแตะช่องค้นหา */
  background: var(--bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='M20 20l-3.5-3.5'/%3E%3C/svg%3E") no-repeat 12px center !important;
}
.dd-search:focus { outline: none; border-color: var(--red) !important; background-color: #fff !important; box-shadow: none !important; }
.dd-search[hidden] { display: none; }

.dd-list { flex: 1 1 auto; min-height: 0; list-style: none; margin: 0; padding: 0; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; outline: none; }
.dd-list ul { list-style: none; margin: 0; padding: 0; }
.dd-opt {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  min-height: 44px; padding: 9px 12px; border-radius: 10px; cursor: pointer; font-size: 15.5px; line-height: 1.4; color: var(--ink);
}
.dd-opt[hidden], .dd-group[hidden] { display: none; }
.dd-opt > span { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.dd-opt.active { background: var(--bg); }
.dd-opt[aria-selected="true"] { color: var(--red-dark); font-weight: 600; background: var(--red-soft); }
.dd-check { width: 18px; height: 18px; flex-shrink: 0; fill: none; stroke: var(--red); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; visibility: hidden; }
.dd-opt[aria-selected="true"] .dd-check { visibility: visible; }
.dd-group-label { display: block; padding: 10px 12px 4px; font-size: 13px; font-weight: 700; color: #556072; letter-spacing: .02em; }
.dd-group + .dd-group { border-top: 1px solid var(--line); margin-top: 4px; }
.dd-empty { padding: 14px 12px; color: #64748b; font-size: 15px; text-align: center; }

/* ---------- มือถือ: bottom sheet ---------- */
.dd-head { display: none; }
.dd-backdrop { position: fixed; inset: 0; z-index: 59; background: rgba(15,23,42,.45); animation: dd-fade .2s ease-out; }
.dd-backdrop[hidden] { display: none; }
html.dd-lock, html.dd-lock body { overflow: hidden; }
@keyframes dd-fade { from { opacity: 0; } }
@keyframes dd-sheet { from { transform: translateY(100%); } }

.dd-panel.sheet {
  left: 0; right: 0; bottom: 0; top: auto; width: auto;
  max-height: min(72vh, 560px); max-height: min(72dvh, 560px);
  padding: 0 12px calc(12px + env(safe-area-inset-bottom));
  border: 0; border-radius: 22px 22px 0 0;
  box-shadow: 0 -16px 40px -12px rgba(15,23,42,.3);
  animation: dd-sheet .3s cubic-bezier(.22,1,.36,1);
}
.dd-panel.sheet .dd-head {
  position: relative; flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 22px 4px 12px 8px;
}
/* ขีดจับด้านบน บอกว่าเป็นแผ่นที่เลื่อนขึ้นมา */
.dd-panel.sheet .dd-head::before {
  content: ""; position: absolute; top: 8px; left: 50%; width: 40px; height: 4px; margin-left: -20px;
  border-radius: 4px; background: #d5dbe3;
}
.dd-title { font-size: 18px; font-weight: 700; color: var(--ink); }
.dd-close {
  width: 40px; height: 40px; flex-shrink: 0; display: grid; place-items: center; padding: 0;
  border: 0; border-radius: 50%; background: var(--bg); cursor: pointer; touch-action: manipulation;
}
.dd-close svg { width: 18px; height: 18px; fill: none; stroke: #475569; stroke-width: 2.4; stroke-linecap: round; }
.dd-close:focus-visible { outline: 3px solid var(--focus, #2563eb); outline-offset: 2px; }
.dd-panel.sheet .dd-search { min-height: 48px !important; margin-bottom: 8px; }
.dd-panel.sheet .dd-opt { min-height: 52px; padding: 12px 14px; font-size: 16.5px; }
.dd-panel.sheet .dd-opt + .dd-opt { border-top: 1px solid #f1f4f8; }
.dd-panel.sheet .dd-opt[aria-selected="true"] + .dd-opt, .dd-panel.sheet .dd-opt.active + .dd-opt { border-top-color: transparent; }
.dd-panel.sheet .dd-opt:active { background: var(--red-soft); }

@media (prefers-reduced-motion: reduce) {
  .dd-panel, .dd-panel.sheet, .dd-backdrop { animation: none; }
}
