/* Everything that floats over the page: confirm popups, the detail popup and the three <dialog> modals.
   They share one scrim, one surface and one close button. */

.popup-scrim {
  position: fixed; inset: 0; z-index: 1100; display: grid; place-items: center; padding: 24px;
  background: var(--scrim); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
  animation: fade-in .16s ease-out;
}
.planmodal::backdrop, .qrmodal::backdrop, .demomodal::backdrop {
  background: var(--scrim); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
}

.popup, .planmodal, .qrmodal, .demomodal {
  border: 1px solid var(--line); border-radius: var(--r-xl);
  background: var(--panel); color: var(--ink); box-shadow: var(--sh-float);
}
.planmodal, .qrmodal, .demomodal { margin: auto; padding: 0; }

.pm-close, .qm-close, .dm-close, .detail-close {
  display: grid; place-items: center; flex: none; margin-left: auto;
  width: 32px; height: 32px; border: 0; border-radius: var(--r-m);
  background: transparent; color: var(--ink-4); font-size: 18px; line-height: 1; cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.pm-close:hover, .qm-close:hover, .dm-close:hover, .detail-close:hover { background: var(--panel-3); color: var(--ink); }
.detail-close svg { width: 16px; height: 16px; }

/* ---------- Confirm popup ---------- */
.popup {
  --tone: var(--brand-text); --on-tone: var(--on-brand);
  width: min(460px, 100%); padding: 22px; animation: pop-in .18s var(--ease);
}
.popup.success { --tone: var(--ok); --on-tone: var(--on-ok); }
.popup.warning { --tone: var(--warn); --on-tone: var(--on-warn); }
.popup.error { --tone: var(--bad); --on-tone: var(--on-bad); }
.popup .p-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.popup .p-icon {
  display: grid; place-items: center; flex: none; width: 30px; height: 30px; border-radius: 50%;
  background: var(--tone); color: var(--on-tone); font-size: var(--fs-s); font-weight: 700;
}
.popup .p-title { font-size: var(--fs-l); font-weight: 600; letter-spacing: var(--tr-snug); color: var(--ink); }
.popup .p-msg { font-size: var(--fs-s); line-height: 1.6; color: var(--ink-3); overflow-wrap: break-word; }
.popup .p-msg p { margin: 0; }
.popup .p-msg p + p { margin-top: 10px; }
.popup .p-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 22px; }

/* ---------- Detail popup ----------
   Head, scrolling body and action bar are separate bands; only the body scrolls. */
.popup.detail {
  display: flex; flex-direction: column; overflow: hidden;
  width: min(540px, 100%); max-height: calc(100dvh - 48px); padding: 0;
}
.detail-head { display: flex; align-items: flex-start; gap: 14px; padding: 20px 20px 18px 22px; border-bottom: 1px solid var(--line); }
.detail-icon {
  display: grid; place-items: center; flex: none; width: 38px; height: 38px;
  border-radius: var(--r-l); background: var(--brand-soft); color: var(--brand-text);
}
.detail-icon svg { width: 18px; height: 18px; }
.detail-icon.bad { background: var(--bad-soft); color: var(--bad); }
.detail-headtext { flex: 1; min-width: 0; padding-top: 1px; }
.detail-title { margin: 0; font-size: var(--fs-l); font-weight: 600; line-height: 1.3; color: var(--ink); overflow-wrap: anywhere; }
.detail-sub { margin-top: 3px; font-size: var(--fs-xs); color: var(--ink-4); }
.detail-sub:empty { display: none; }
.detail-close { margin: -4px -4px 0 0; }
.detail-body { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 22px 22px; }
.detail-label {
  display: block; margin: 18px 0 8px;
  font-size: var(--fs-2xs); font-weight: 600; letter-spacing: var(--tr-caps); text-transform: uppercase; color: var(--ink-4);
}
.detail-list { margin: 0; padding: 0; list-style: none; }
.detail-list li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line-soft); font-size: var(--fs-s); color: var(--ink); }
.detail-list li:last-child { border-bottom: 0; }
.detail-list li > svg { width: 30px; height: 30px; flex: none; padding: 7px; border-radius: var(--r-m); background: var(--brand-soft); color: var(--brand-text); }
.detail-list .pill { flex: none; }
.detail-grow { flex: 1; min-width: 0; }
.detail-key { flex: none; min-width: 120px; color: var(--ink-4); }
.detail-value { flex: 1; min-width: 0; text-align: right; font-weight: 500; overflow-wrap: anywhere; }
.detail-note { margin: 16px 0 0; font-size: var(--fs-s); line-height: 1.55; color: var(--ink-3); }
.detail-error {
  margin: 0; padding: 10px 12px; border: 1px solid var(--bad-line); border-radius: var(--r-m);
  background: var(--bad-soft); color: var(--bad); font-size: var(--fs-s); line-height: 1.5;
}
.detail-code {
  max-height: 300px; margin: 0; padding: 12px 14px; overflow: auto;
  border-radius: var(--r-m); background: var(--band); color: var(--band-ink);
  font-family: var(--mono); font-size: var(--fs-xs); line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere;
}
.detail-field { display: flex; gap: 8px; }
.detail-field .input { flex: 1; min-width: 0; }
.detail-foot {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 14px 22px; border-top: 1px solid var(--line); background: var(--panel-2);
}
.detail-foot form { margin: 0; }
.detail-foot .btn { min-width: 96px; }

.rd-eye { display: inline-grid; place-items: center; width: 28px; height: 28px; color: var(--ink-4); }
.rd-eye:hover { color: var(--brand-text); }
.rd-eye.is-locked { color: var(--ink-5); }
.rd-eye svg { width: 15px; height: 15px; }
.rd-id { display: flex; align-items: center; gap: 6px; }

/* ---------- Plan modal ---------- */
.planmodal { width: min(1180px, calc(100vw - 48px)); max-height: calc(100vh - 64px); }
.planmodal.narrow { width: min(620px, calc(100vw - 32px)); }
.planmodal .pm-head {
  position: sticky; top: 0; z-index: 2; display: flex; align-items: flex-start; gap: 12px;
  padding: 18px 22px 14px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.planmodal .pm-head h3 { font-size: var(--fs-xl); font-weight: 700; }
.planmodal .pm-head .sub { margin: 3px 0 0; font-size: var(--fs-s); color: var(--ink-3); }
.planmodal .pm-body { padding: 20px 22px 24px; overflow-y: auto; }
.planmodal .pm-loading { padding: 30px 0; text-align: center; font-size: var(--fs-s); color: var(--ink-3); }
.planmodal .pm-error { padding: 26px 0; text-align: center; }
.planmodal .pm-error p { margin: 0 0 14px; font-size: var(--fs-s); color: var(--ink-2); }

/* ---------- QR code modal ---------- */
.qrmodal { width: min(340px, calc(100vw - 24px)); }
.qrmodal .qm-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.qrmodal .qm-head h3 { font-size: var(--fs-m); font-weight: 600; }
.qrmodal .qm-body { padding: 18px; background: var(--paper); }
.qrmodal .qm-body svg { display: block; width: 100%; height: auto; }
.qrmodal .qm-foot { margin: 0; padding: 12px 16px; border-top: 1px solid var(--line); font-size: var(--fs-xs); color: var(--ink-4); }

/* ---------- Demo modal ---------- */
.demomodal {
  position: relative;
  width: min(calc(100vw - 32px), calc((100dvh - 48px) * 1.924));
  height: fit-content; max-width: none; max-height: calc(100dvh - 32px);
  overflow: hidden; background: var(--demo-bg);
}
.demomodal .dm-close {
  position: absolute; top: 10px; right: 10px; z-index: 2;
  width: 32px; height: 32px; margin: 0;
  border-radius: var(--r-full); background: var(--bad); color: var(--on-bad);
}
.demomodal .dm-close:hover { background: var(--bad-hover); color: var(--on-bad); }
.demomodal .dm-close svg { width: 16px; height: 16px; }
.demomodal .dm-body { position: relative; width: 100%; aspect-ratio: 1.924; overflow: hidden; background: var(--demo-bg); }
.demomodal .dm-body iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; display: block; background: var(--demo-bg); }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(8px) scale(.985); } to { opacity: 1; transform: none; } }

@media (max-width: 720px) {
  .planmodal { width: calc(100vw - 16px); max-height: calc(100vh - 24px); }
  .planmodal .pm-body { padding: 14px 14px 18px; }
}

@media (max-width: 560px) {
  .popup-scrim { padding: 12px; }
  .popup.detail { max-height: calc(100dvh - 24px); }
  .detail-head { padding: 16px 16px 14px 18px; }
  .detail-body { padding: 2px 18px 18px; }
  .detail-foot { padding: 12px 18px; }
  .detail-key { min-width: 0; }
}
