/* modal.css
   CSS is independent: sizing is controlled by class names, not modal IDs.

   Key class:
   - .modal--opsPanel : use the same sizing rule set (scan + item + post)
     On mobile, max-height <= 80% of viewport operation area.
*/

:root{
  --modal-gap-y: 1.5em;   /* requested top/bottom safe margin */
  --modal-gap-x: 12px;    /* left/right safe margin */
  --ops-wide-max: 980px;  /* max width for opsPanel modals */
}

/* Mobile stability */
html, body{
  width: 100%;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

img, video, canvas{
  max-width: 100%;
  height: auto;
}

/* iOS Safari: prevent focus auto zoom */
input, select, textarea, button{
  font-size: 16px;
}

/* Reduce accidental double-tap zoom */
button, a, .tileBtn{
  touch-action: manipulation;
}

/* Overlay: safe edges + scroll container */
.modalOverlay.is-open{
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--modal-gap-y) var(--modal-gap-x);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ✅ 補全：拖動 modal 用（避免 overlay 滾動同拖動打架） */
.modalOverlay.modalOverlay--dragHost.is-open{
  overflow: hidden;
}

/* Base modal behavior: column layout, body scrolls, no overflow */
.modal{
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-height: calc(100svh - (var(--modal-gap-y) * 2));
  max-height: calc(100vh - (var(--modal-gap-y) * 2)); /* fallback */
}

.modal__head{
  position: sticky;
  top: 0;
  z-index: 2;
  background: inherit;
}

.modal__body{
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  min-height: 0; /* critical for flex overflow */
}

/* Wide modal width normalization (works for all wide modals) */
.modal--wide{
  width: min(var(--ops-wide-max), calc(100vw - (var(--modal-gap-x) * 2)));
}

/* =========================
   OpsPanel sizing (independent, class-driven)
========================= */
.modal--opsPanel{
  width: min(var(--ops-wide-max), calc(100vw - (var(--modal-gap-x) * 2)));
}

/* ✅ Mobile: cap opsPanel height to 80% operation-area height */
@media (max-width: 720px){
  .modal--opsPanel{
    max-height: 80svh;
    max-height: 80vh; /* fallback */
  }
}

/* ✅ 補全：可拖動 modal（只做手感/手勢設定；實際拖動靠 index.js） */
.modal--draggable .modal__head{
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none; /* allow pointermove without page scroll */
}
.modal--draggable .modal__head:active{
  cursor: grabbing;
}

/* Photo modal helper (3 buttons) */
.photoActions3{
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}
@media (max-width: 520px){
  .photoActions3{ grid-template-columns: 1fr; }
}

/* Keep camera preview stable */
.cameraStage__video,
.cameraStage__canvas{
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  display: block;
}

/* =========================
   Item detail layout fix INSIDE opsPanel (still independent)
========================= */
@media (max-width: 720px){
  .modal--opsPanel .itemDetail{
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 0;
  }

  .modal--opsPanel .itemDetail__img{
    width: 100%;
    height: auto;
    aspect-ratio: 4 / 3;
    object-fit: cover;

    /* prevent image from taking all of the 80% modal height */
    max-height: 30svh;
    max-height: 30vh;
  }

  .modal--opsPanel .itemDetail__right{
    width: 100%;
    min-width: 0;
    min-height: 0;
  }
}

@media (max-width: 420px){
  .modal--opsPanel .itemDetail__img{
    max-height: 26svh;
    max-height: 26vh;
  }
}
/* ✅ Photo modal：相機畫面固定 1:1，而且最大只到 480px */
#photoModal .modal__body{
  display: grid;
  grid-template-rows: auto auto;
  gap: 12px;
}
#photoModal .cameraStage{
  width: min(100%, 480px);  /* 關鍵：最大 480px */
  aspect-ratio: 1 / 1;      /* 正方形 */
  margin: 0 auto;           /* 置中（因為可能比 modal 窄） */
  overflow: hidden;
  border-radius: 12px;
  background: rgba(0,0,0,.06);
}
/* 影像填滿相機框 */
#photoModal .cameraStage__video,
#photoModal .cameraStage__canvas{
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;        /* 想唔裁切就改 contain */
  pointer-events: none;     /* 保證唔會擋到按鈕點擊 */
}
/* 按鈕永遠在下方、可按 */
#photoModal .modal__actions{
  position: relative;
  z-index: 10;
}