/* Popup: sửa đơn (.dlg-edit) và hủy đơn (.dlg-cancel). Khung chung .dlg: đầu/chân dính, thân cuộn.
   Điện thoại: popup sửa toàn màn hình, popup hủy là tấm trượt từ đáy. */

/* ---------- khung chung ---------- */
dialog.dlg { padding: 0; border: 0; border-radius: 16px; background: var(--surface); color: var(--text);
             box-shadow: var(--shadow-lg); overflow: hidden; max-width: none; max-height: none; }
dialog.dlg[open] { display: flex; animation: dlg-in .16s ease-out; }
dialog.dlg::backdrop { background: rgba(13, 27, 42, .55); backdrop-filter: blur(2px); }
@keyframes dlg-in { from { opacity: 0; transform: translateY(8px) scale(.985); } to { opacity: 1; transform: none; } }

.dlg-form { display: flex; flex-direction: column; flex: 1; min-height: 0; min-width: 0; width: 100%; margin: 0; }
.dlg-head { display: flex; align-items: flex-start; gap: 12px; padding: 18px 20px 14px; border-bottom: 1px solid var(--line);
            background: var(--surface); flex: none; }
.dlg-title { flex: 1; min-width: 0; }
.dlg-title h2 { font-size: 18px; font-weight: 700; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.dlg-title .order-id { font-size: 15px; color: var(--text-2); background: var(--grey-50); padding: 2px 8px; border-radius: 6px; }
.dlg-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 8px; font-size: 13px; }
.dlg-x { margin: -4px -6px 0 0; flex: none; }

.dlg-body { flex: 1; min-height: 0; overflow: auto; padding: 18px 20px; overscroll-behavior: contain; }

.dlg-foot { display: flex; align-items: center; gap: 10px; padding: 12px 20px; border-top: 1px solid var(--line);
            background: var(--surface-2); flex: none; }
.dlg-foot-msg { flex: 1; min-width: 0; font-size: 13px; }
.dlg-hint { color: var(--text-2); }
.dlg-err { color: var(--danger); background: var(--danger-50); border: 1px solid var(--danger-100); border-radius: var(--radius-sm);
           padding: 7px 10px; margin-bottom: 4px; }
.dlg-err:empty { display: none; }
.dlg-foot .btn { flex: none; }

.btn.is-busy { opacity: .85; cursor: progress; }
.dlg-spin { width: 14px; height: 14px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent;
            animation: dlg-spin .7s linear infinite; flex: none; }
@keyframes dlg-spin { to { transform: rotate(360deg); } }

/* ---------- sửa đơn ---------- */
dialog.dlg-edit { width: min(1120px, calc(100vw - 48px)); height: min(880px, calc(100vh - 48px)); }
dialog.dlg-edit.is-locked { height: fit-content; max-height: calc(100vh - 48px); width: min(640px, calc(100vw - 48px)); }

/* dải phạm vi sửa */
.oe-scope-wrap { flex: none; }
.oe-scope-wrap:empty { display: none; }
.oe-scope { padding: 12px 20px 14px; border-bottom: 1px solid var(--line); font-size: 13px; }
.oe-scope.m-full    { background: var(--ok-50);     --scope: var(--ok);     --scope-line: var(--ok-100); }
.oe-scope.m-contact { background: var(--warn-50);   --scope: var(--warn);   --scope-line: var(--warn-100); }
.oe-scope.m-none    { background: var(--danger-50); --scope: var(--danger); --scope-line: var(--danger-100); }
.oe-scope-head { display: flex; gap: 10px; align-items: flex-start; }
.oe-scope-head b { color: var(--scope); font-weight: 600; font-size: 14px; }
.oe-scope-head p { margin: 2px 0 0; color: var(--text-2); }
.oe-scope-ic { width: 26px; height: 26px; border-radius: 50%; background: var(--scope); color: #fff; flex: none;
               display: inline-flex; align-items: center; justify-content: center; margin-top: 1px; }
.oe-rules-box { margin: 6px 0 0 36px; }
.oe-rules-box > summary { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; list-style: none;
                          font-size: 12.5px; font-weight: 500; color: var(--scope); user-select: none; border-radius: 4px; }
.oe-rules-box > summary::-webkit-details-marker { display: none; }
.oe-rules-box > summary::after { content: ""; width: 6px; height: 6px; border: solid currentColor; border-width: 0 1.6px 1.6px 0;
                                 transform: rotate(45deg) translate(-1px, -1px); margin-left: 4px; transition: transform .15s; }
.oe-rules-box[open] > summary::after { transform: rotate(-135deg) translate(-1px, -1px); }
.oe-rules-box > summary:focus-visible { outline: 2px solid var(--scope); outline-offset: 2px; }
dialog.dlg-edit.is-locked .oe-rules-box { margin-left: 0; }
dialog.dlg-edit.is-locked .oe-rules-box > summary { display: none; }
.oe-rules { list-style: none; margin: 8px 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
            gap: 6px; }
.oe-rules li { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--scope-line);
               border-radius: var(--radius-sm); padding: 6px 10px; min-width: 0; }
.oe-rule-ic { width: 20px; height: 20px; border-radius: 50%; flex: none; display: inline-flex; align-items: center; justify-content: center; }
.oe-rules li.ok .oe-rule-ic { background: var(--ok-50); color: var(--ok); }
.oe-rules li.off .oe-rule-ic { background: var(--grey-50); color: var(--muted); }
.oe-rule-name { flex: 1; min-width: 0; font-weight: 500; }
.oe-rules li.off .oe-rule-name { color: var(--muted); }
.oe-rule-how { font-size: 12px; color: var(--text-2); white-space: nowrap; }
.oe-rules li.off .oe-rule-how { color: var(--muted); }
dialog.dlg-edit.is-locked .oe-scope { border-bottom: 0; }
dialog.dlg-edit.is-locked .oe-rules { grid-template-columns: 1fr; }

/* thân 2 cột: bản đồ đứng yên bên trái, cột thẻ bên phải cuộn riêng */
.oe-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 500px); padding: 0; overflow: hidden; }
.oe-body[hidden] { display: none; }
.oe-loading { display: contents; }
.oe-loading > * { margin: 18px 20px; }
.oe-map-col { display: flex; flex-direction: column; gap: 8px; min-height: 0; padding: 18px 0 14px 20px; }
.oe-map { flex: 1; min-height: 240px; border-radius: var(--radius); border: 1px solid var(--line); overflow: hidden; background: var(--grey-50); }
.oe-map-tip { margin: 0; font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.oe-map-tip svg { flex: none; }
.oe-form-col { min-width: 0; min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 18px 20px 24px;
               display: flex; flex-direction: column; gap: 18px; }
.oe-sec-title { font-size: 13px; font-weight: 600; color: var(--text-2); margin: 0 0 10px; }
.oe-points { display: flex; flex-direction: column; gap: 10px; }
.oe-add { margin-top: 10px; width: 100%; border-style: dashed; color: var(--brand); }
.oe-add:disabled { color: var(--muted); }

/* ô bị khoá: nền xám + biểu tượng khoá */
.dlg-edit input:disabled:not([type=checkbox]):not([type=radio]),
.dlg-edit select:disabled,
.dlg-edit textarea:disabled {
  background-color: var(--grey-50); color: var(--muted); border-color: var(--line); cursor: not-allowed;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a94a6' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='5' y='11' width='14' height='10' rx='2'/%3E%3Cpath d='M8 11V8a4 4 0 0 1 8 0v3'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-size: 14px 14px; background-position: right 10px center; padding-right: 32px;
}
.dlg-edit select:disabled { appearance: none; -webkit-appearance: none; }
.dlg-edit label:has(> input[type=checkbox]:disabled),
.dlg-edit label:has(> input[type=radio]:disabled) { opacity: .55; cursor: not-allowed; }
.dlg-edit .field:has(> input:disabled, > select:disabled, > textarea:disabled) > span { color: var(--muted); }
.dlg-edit button[data-remove]:disabled { opacity: .4; cursor: not-allowed; }

/* ---------- hủy đơn ---------- */
dialog.dlg-cancel { width: min(480px, calc(100vw - 32px)); max-height: calc(100vh - 48px); }
.cx-warn { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; margin-bottom: 16px; border-radius: var(--radius-sm);
           background: var(--warn-50); color: var(--warn); font-size: 13px; }
.cx-warn svg { flex: none; }
.cx-warn span { color: var(--text); padding-top: 1px; }
.cx-reasons { display: flex; flex-direction: column; gap: 6px; }
.cx-opt { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm);
          cursor: pointer; font-size: 14px; transition: border-color .12s, background .12s; }
.cx-opt:hover { border-color: var(--line-2); background: var(--surface-2); }
.cx-opt.on { border-color: var(--danger); background: var(--danger-50); }
.cx-opt input { accent-color: var(--danger); }
.cx-other-input { padding: 2px 0 0; }
.cx-other-input input:focus { border-color: var(--danger); box-shadow: 0 0 0 3px var(--danger-50); }
.btn.btn-danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.btn-danger-solid:hover { background: #b42318; border-color: #b42318; }

/* ---------- màn hình vừa ---------- */
@media (max-width: 1000px) {
  .oe-body { grid-template-columns: minmax(0, 1fr) minmax(0, 420px); }
}

/* ---------- điện thoại ---------- */
@media (max-width: 760px) {
  dialog.dlg-edit { width: 100vw; height: 100vh; height: 100dvh; max-height: none; margin: 0; border-radius: 0; inset: 0; }
  /* đơn không sửa được: chỉ có dải thông báo, hiện dạng tấm trượt từ đáy */
  dialog.dlg-edit.is-locked { width: 100vw; height: fit-content; max-height: 90vh; margin: auto 0 0; border-radius: 16px 16px 0 0; }
  dialog.dlg-edit[open] { animation: dlg-up .2s ease-out; }
  .dlg-head { padding: 12px 16px 10px; padding-top: calc(12px + env(safe-area-inset-top)); }
  .dlg-title h2 { font-size: 16px; }
  .dlg-body { padding: 14px 16px; }
  .dlg-foot { padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); flex-wrap: wrap; }
  .dlg-foot-msg { flex-basis: 100%; }
  .dlg-foot-msg:not(:has(> :not(:empty):not([hidden]))) { display: none; }
  .dlg-foot .btn { flex: 1; height: 44px; }

  .oe-scope { padding: 10px 16px 12px; max-height: 34vh; overflow: auto; }
  .oe-rules { grid-template-columns: 1fr; }
  /* dải phạm vi luôn hiện: thu lời giải thích còn 2 dòng, mở "Chi tiết từng phần" thì hiện đủ */
  .oe-scope:not(:has(details[open])) .oe-scope-head p { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  dialog.dlg-edit.is-locked .oe-scope-wrap { flex: 1; overflow: auto; }
  dialog.dlg-edit.is-locked .oe-scope { max-height: none; }
  .oe-body { display: block; overflow: auto; }
  .oe-body[hidden] { display: none; }
  .oe-loading { display: block; }
  .oe-loading > * { margin: 14px 16px; }
  .oe-map-col { padding: 14px 16px 0; }
  .oe-form-col { overflow: visible; padding: 16px 16px 20px; }
  .oe-map { height: 230px; min-height: 230px; flex: none; }

  dialog.dlg-cancel { width: 100vw; max-height: 90vh; margin: auto 0 0; border-radius: 16px 16px 0 0; }
  dialog.dlg-cancel[open] { animation: dlg-up .2s ease-out; }
}
@keyframes dlg-up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }

/* vị trí bị khoá: ẩn chữ "Sửa" ở dòng toạ độ */
.dlg-edit .pt-card.addr-locked .pt-coord-edit { display: none; }
.dlg-edit .pt-card.addr-locked .pt-coord > summary { cursor: default; }
