/* Bigger modal rollouts must live in their own stylesheet, e.g. modal-newmodal.css */
:root{
  --pos-modal-layer:1000;
  --pos-modal-margin-x:2vw;
  --pos-modal-margin-y:2vh;
  --pos-modal-radius:clamp(18px,2.4vw,32px);
  --pos-modal-shadow:0 24px 64px rgba(7,20,40,0.33);
  --pos-modal-border:1px solid rgba(255,255,255,0.12);
  --pos-modal-bg:#0b5a9b;
  --pos-modal-header-bg:#09477f;
  --pos-modal-footer-bg:#09477f;
  --pos-modal-body-bg:#0b5a9b;
  --pos-modal-transition:220ms cubic-bezier(.22,.65,.4,1);
  --pos-modal-backdrop:rgba(2,8,20,0.62);
  --pos-modal-backdrop-blur:16px;
  --pos-modal-card-width:calc(100vw - var(--pos-modal-margin-x)*2);
  --pos-modal-card-height:calc(100vh - var(--pos-modal-margin-y)*2);
  --pos-modal-safe-area:env(safe-area-inset,0px);
}

body.modal-open{overflow:hidden;touch-action:none;}

.modal-stash{display:none !important;}
.modal-fragment{width:100%;}

.pos-modal{
  position:fixed;
  inset:0;
  z-index:var(--pos-modal-layer);
  display:flex;
  align-items:center;
  justify-content:center;
  padding:var(--pos-modal-margin-y) var(--pos-modal-margin-x);
  pointer-events:none;
  visibility:hidden;
  opacity:0;
  transition:opacity var(--pos-modal-transition),visibility var(--pos-modal-transition);
  font:inherit;
  color:#f4f8ff;
  backdrop-filter:none;
}

.pos-modal.is-open,
.pos-modal.is-active,
.pos-modal[data-open="true"],
.pos-modal[aria-hidden="false"]{
  pointer-events:auto;
  visibility:visible;
  opacity:1;
}

.pos-modal__backdrop{
  position:absolute;
  inset:0;
  background:var(--pos-modal-backdrop);
  backdrop-filter:blur(var(--pos-modal-backdrop-blur));
  -webkit-backdrop-filter:blur(var(--pos-modal-backdrop-blur));
  opacity:1;
  transition:opacity var(--pos-modal-transition);
}

.pos-modal:not(.is-open):not(.is-active):not([data-open="true"]):not([aria-hidden="false"]) .pos-modal__backdrop{
  opacity:0;
}

.pos-modal__card{
  position:relative;
  width:min(var(--pos-modal-card-width),calc(100% - var(--pos-modal-safe-area)*2));
  height:var(--pos-modal-card-height);
  min-height:var(--pos-modal-card-height);
  max-height:var(--pos-modal-card-height);
  background:var(--pos-modal-bg);
  border-radius:var(--pos-modal-radius);
  border:var(--pos-modal-border);
  box-shadow:var(--pos-modal-shadow);
  display:flex;
  flex-direction:column;
  overflow:hidden;
  isolation:isolate;
  transform:translate3d(0,8px,0) scale(0.98);
  transition:transform var(--pos-modal-transition),opacity var(--pos-modal-transition);
}

.pos-modal.is-open .pos-modal__card,
.pos-modal.is-active .pos-modal__card,
.pos-modal[data-open="true"] .pos-modal__card,
.pos-modal[aria-hidden="false"] .pos-modal__card{
  transform:translate3d(0,0,0) scale(1);
}

.pos-modal__header,
.pos-modal__footer{
  position:sticky;
  z-index:1;
  display:flex;
  align-items:center;
  gap:clamp(12px,2vw,18px);
  padding:clamp(16px,2vw,24px);
  backdrop-filter:blur(12px);
  -webkit-backdrop-filter:blur(12px);
}

.pos-modal__header{
  top:0;
  justify-content:space-between;
  background:var(--pos-modal-header-bg);
  border-bottom:var(--pos-modal-border);
}

.pos-modal__footer{
  bottom:0;
  justify-content:flex-end;
  background:var(--pos-modal-footer-bg);
  border-top:var(--pos-modal-border);
}

.pos-modal__title{
  font-size:clamp(1.1rem,1.2vw + .9rem,1.65rem);
  font-weight:700;
  margin:0;
}

.pos-modal__close{
  border:1px solid rgba(255,255,255,0.35);
  background:transparent;
  color:inherit;
  font-size:1.5rem;
  width:44px;
  height:44px;
  border-radius:50%;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  cursor:pointer;
  transition:background var(--pos-modal-transition),transform 160ms ease;
}

.pos-modal__close:hover,
.pos-modal__close:focus-visible{
  background:rgba(255,255,255,0.12);
  outline:none;
  transform:scale(1.05);
}

.pos-modal__body{
  flex:1;
  min-height:0;
  overflow:auto;
  padding:clamp(18px,2.6vw,28px);
  background:var(--pos-modal-body-bg);
  scrollbar-gutter:stable;
  overscroll-behavior:contain;
  display:flex;
  flex-direction:column;
  gap:clamp(12px,2vw,20px);
}

.pos-modal__body > :last-child{margin-bottom:0;}

.pos-modal--small{
  --pos-modal-card-width:clamp(280px,70vw,520px);
}

.pos-modal--small .pos-modal__card{
  height:auto;
  min-height:0;
  max-height:calc(100vh - var(--pos-modal-margin-y)*2);
}

.pos-modal--wide{
  --pos-modal-card-width:calc(100vw - var(--pos-modal-margin-x)*2);
}

.pos-modal--fullscreen{
  --pos-modal-card-width:100vw;
  --pos-modal-card-height:100vh;
}

.pos-modal--fullscreen .pos-modal__card{
  border-radius:0;
  max-height:100vh;
  height:100%;
  width:100%;
}

@media (max-width:720px){
  .pos-modal{
    padding:calc(var(--pos-modal-safe-area) + 8px);
    align-items:stretch;
    justify-content:stretch;
  }
  .pos-modal__card{
    width:100%;
    height:100%;
    max-height:100%;
    border-radius:0;
    border:none;
  }
  .pos-modal__header,
  .pos-modal__footer{
    padding:clamp(14px,4vw,22px);
  }
  .pos-modal__close{
    width:40px;
    height:40px;
  }
}

@supports(height:100dvh){
  :root{
    --pos-modal-card-height:calc(100dvh - var(--pos-modal-margin-y)*2);
  }
  .pos-modal--fullscreen .pos-modal__card{
    max-height:100dvh;
    height:100dvh;
  }
}

@media (prefers-reduced-motion:reduce){
  .pos-modal,
  .pos-modal__card,
  .pos-modal__backdrop,
  .pos-modal__close{
    transition:none;
  }
}

/* Legacy overlay modal shell (will be retired once all modals move to pos-modal) */
.modal-back,
.modal-frame{
  position:fixed;
  inset:0;
  height:calc(var(--vh, 1vh) * 100);
  width:100%;
  background:rgba(0,0,0,.5);
  display:block;
  z-index:100;
  overflow:hidden;
  touch-action:none;
  -webkit-overflow-scrolling:none;
}

.modal-back#modalBack{ z-index:1000; }

.modal{
  --modal-base-width:1200px;
  --modal-base-height:800px;
  --modal-scale:1;
  background:#0b5a9b;
  border-radius:clamp(12px,1.6vw,18px);
  padding:clamp(14px,2vw,22px);
  box-sizing:border-box;
  display:flex;
  flex-direction:column;
  gap:clamp(12px,1.6vw,18px);
  width:var(--modal-base-width);
  height:var(--modal-base-height);
  overflow:hidden;
  position:absolute;
  top:0;
  left:0;
  transform-origin:top left;
  transition:transform .18s ease, filter .18s ease;
  font-size:clamp(0.9rem, 0.6vw + 0.85rem, 1rem);
  line-height:1.4;
  will-change:transform, filter, border-radius;
  box-shadow:0 16px 44px rgba(0,0,0,.32);
}

body.android-keyboard .modal{ transition:filter .18s ease; }

.modal-shell{ width:var(--modal-base-width); height:var(--modal-base-height); }

.modal.modal-scaled{ filter:saturate(.98); }

.modal input,
.modal select,
.modal button,
.modal textarea{
  font-size:clamp(.88rem,0.45vw + .84rem,1rem);
  padding:clamp(10px,1.6vw,14px);
  border-radius:clamp(10px,1.4vw,14px);
}

.modal .title{ font-size:clamp(1.05rem,0.7vw + 1rem,1.35rem); margin-bottom:clamp(10px,1.4vw,14px); }
.modal .muted{ font-size:clamp(.78rem,0.4vw + .74rem,.95rem); }

.modal-back:not(.ghost){ animation:modalBackdropIn 220ms cubic-bezier(.16,.84,.44,1) backwards; }

@keyframes modalBackdropIn{ from{ opacity:0; } to{ opacity:1; } }

.modal-back:not(.ghost) .modal{
  animation:modalIn 360ms cubic-bezier(.2,.8,.2,1) backwards;
  will-change:opacity, filter;
}

@keyframes modalIn{
  0%{ opacity:0; filter:blur(10px) saturate(1.05); }
  60%{ opacity:1; filter:blur(2px) saturate(1.0); }
  100%{ opacity:1; filter:none; }
}

@media (prefers-reduced-motion:reduce){
  .modal-back:not(.ghost){ animation:none; }
  .modal-back:not(.ghost) .modal{ animation:none; }
}

@media (max-width:760px){
  .modal{
    width:calc(100vw - 2 * var(--modal-safe-gap,18px));
    max-width:calc(100vw - 2 * var(--modal-safe-gap,18px));
    border-radius:clamp(14px,4vw,20px);
  }
  .modal .row{ grid-template-columns:1fr; }
  .modal .row > *{ width:100%; }
  .modal .row button,
  .modal .action-row button,
  .modal .barcode-actions button{ width:100%; }
}

@media (max-width:520px){
  .modal-back{ --modal-safe-gap:clamp(10px,3vw,18px); }
  .modal{ gap:clamp(10px,2vw,16px); }
}

.modal-back:not(.ghost) .modal,
.modal-back:not(.ghost){ touch-action:none; }

.modal-fragment{ width:100%; }

.modal-stash{ display:none !important; }

/* Checkout + invoice modals: fullscreen sizing and touch-friendly scaling */
#checkoutBack{
  z-index:980;
  align-items:center;
  padding-top:0;
  padding-bottom:0;
}

#checkoutBack .modal{
  --modal-base-height:820px;
}

#checkoutBack .modal,
#modalBack .modal{
  left:2% !important;
  top:2% !important;
  width:96% !important;
  height:96% !important;
  transform:none !important;
  max-width:none !important;
  max-height:none !important;
  box-sizing:border-box;
  overflow:auto;
}

#modalBack .modal{ position:relative; }

#checkoutBack .modal,
#modalBack .modal{
  font-size:clamp(15px,1.9vh,18px);
  line-height:1.5;
}

#checkoutBack .modal .title,
#modalBack .modal .title,
#modalBack .modal .inv-number{
  font-size:clamp(18px,2.4vh,22px);
}

#checkoutBack .modal input,
#checkoutBack .modal select,
#checkoutBack .modal textarea,
#checkoutBack .modal button,
#modalBack .modal input,
#modalBack .modal select,
#modalBack .modal textarea,
#modalBack .modal button{
  font-size:clamp(15px,2.1vh,18px);
  padding:clamp(10px,1.8vh,14px) clamp(12px,2.2vh,16px);
  border-radius:clamp(10px,1.6vh,14px);
}

#modalBack #invoiceInfo{ margin-bottom:8px; }

/* Invoice summary modal content */
.multi-invoice-summary{
  border:1px solid rgba(255,255,255,0.18);
  border-radius:14px;
  padding:14px;
  background:rgba(0,0,0,0.08);
  margin-bottom:10px;
  display:flex;
  flex-direction:column;
  gap:10px;
}

.multi-invoice-summary.ghost{ display:none; }

.multi-invoice-head{ display:flex; justify-content:space-between; align-items:flex-start; gap:12px; }
.multi-invoice-title{ font-size:1.1em; font-weight:700; display:flex; align-items:baseline; gap:12px; flex-wrap:wrap; }
.multi-invoice-total{ font-size:0.95em; font-weight:600; opacity:0.85; }
.multi-invoice-list{ display:flex; flex-direction:column; gap:10px; }
.multi-invoice-card{ border:1px solid rgba(255,255,255,0.18); border-radius:12px; padding:12px 14px; display:flex; gap:16px; align-items:flex-start; justify-content:space-between; background:rgba(0,0,0,0.05); }
.multi-invoice-card-left{ display:flex; flex-direction:column; gap:6px; min-width:0; flex:1 1 auto; }
.multi-invoice-card-left .cart-label{ font-weight:700; letter-spacing:0.2px; }
.multi-invoice-card-left .doc-info{ font-weight:600; }
.multi-invoice-card-left .product-list{ font-size:0.9em; opacity:0.85; }
.multi-invoice-card-left .total{ font-size:0.95em; font-weight:600; }
.multi-invoice-card-right{ flex:0 0 auto; min-width:160px; display:flex; align-items:center; justify-content:flex-end; }
.multi-invoice-card-right .print-flag{ display:flex; align-items:center; gap:10px; font-weight:600; }
.multi-invoice-card-right .print-flag input{ width:20px; height:20px; }

.modal-close-btn{
  position:absolute;
  top:18px;
  right:18px;
  width:42px;
  height:42px;
  border-radius:50%;
  border:1px solid rgba(255,255,255,0.25);
  background:rgba(0,0,0,0.28);
  color:#fff;
  font-size:22px;
  line-height:1;
  display:flex;
  align-items:center;
  justify-content:center;
  cursor:pointer;
  transition:background .18s ease, transform .12s ease;
}

.modal-close-btn:hover{ background:rgba(255,255,255,0.18); transform:scale(1.02); }
.modal-close-btn:focus-visible{ outline:2px solid rgba(255,255,255,0.6); outline-offset:2px; }

.invoice-print-row{ display:flex; gap:10px; justify-content:flex-end; flex-wrap:wrap; margin-top:6px; }
.invoice-print-row .btn{ min-width:150px; }

.email-send-box{ margin-top:12px; padding-top:12px; border-top:1px solid rgba(255,255,255,0.12); display:flex; flex-direction:column; gap:12px; }
.email-section-title{ font-weight:600; }
.email-input-row{ display:flex; gap:10px; flex-wrap:wrap; }
.email-input-row .email-input{ flex:1 1 48%; min-width:220px; padding:12px 14px; border-radius:12px; border:1px solid rgba(255,255,255,0.18); background:rgba(6,36,72,0.55); color:#fff; }
.email-input-row .email-input::placeholder{ color:rgba(255,255,255,0.65); }
.email-action-row{ display:flex; justify-content:flex-end; }
.email-action-row .btn{ flex:0 0 auto; }
.email-info{ min-height:1.2em; }

#modalBack #emailSendBox{ border-top:1px solid rgba(255,255,255,0.12); padding-top:10px; }
#modalBack #emailSendBox input{ min-width:min(320px,100%); }
#modalBack #emailSendBox .btn{ min-height:44px; }

@media (max-width:720px){
  .modal-close-btn{ top:14px; right:14px; width:38px; height:38px; font-size:18px; }
  .email-input-row .email-input{ flex:1 1 100%; min-width:0; }
  .email-action-row{ justify-content:flex-start; }
  .invoice-print-row{
    display:grid;
    grid-template-columns:repeat(2, minmax(0, 1fr));
    grid-template-rows:repeat(2, auto);
    grid-template-areas:"print-a thermal-a" "print-b thermal-b";
    justify-content:stretch;
    align-items:stretch;
  }
  #btnPrint1{ grid-area:print-a; }
  #btnPrint2{ grid-area:print-b; }
  #btnThermal1{ grid-area:thermal-a; }
  #btnThermal2{ grid-area:thermal-b; }
  .invoice-print-row .btn{ width:100%; min-width:0; }
}
