:root {
  --modal_backdrop: 20, 20, 20;
  --modal_box_background: 98, 98, 98;
  --modal_box_color: 255, 255, 255;
}

/* Zaledi skrol kada je bilo koji modal otvoren */
body:has(modal-box:popover-open),
body:has(modal-picture:popover-open),
body:has(modal-gallery:popover-open),
body:has(modal-confirm:popover-open),
body:has(modal-alert:popover-open),
body:has(modal-video:popover-open),
body:has(modal-wizard:popover-open) {
  overflow: hidden;
}

/* Fizički, nevidljivi štit koji sprečava "hover" efekte i klikove na pozadinu */
body:has(modal-box:popover-open)::after,
body:has(modal-picture:popover-open)::after,
body:has(modal-gallery:popover-open)::after,
body:has(modal-confirm:popover-open)::after,
body:has(modal-alert:popover-open)::after,
body:has(modal-video:popover-open)::after,
body:has(modal-wizard:popover-open)::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: auto;
  background: transparent;
}

modal-box {
  display: none;
  margin: auto;
  width: fit-content;
  height: fit-content;
  min-width: 300px;
  min-height: 100px;
  max-width: 90vw;
  max-height: 90vh;
  background-color: rgb(var(--modal_box_background));
  color: rgb(var(--modal_box_color));
  border: none;
  border-radius: 6px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
  flex-direction: column;
  padding: 20px;
  z-index: 21;
}

/* Nativna pseudo-klasa :popover-open proverava da li je modal otvoren */
modal-box:popover-open {
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  justify-content: flex-start;
  align-items: stretch;
}

modal-box::backdrop {
  background-color: rgba(var(--modal_backdrop), 0.5);
  backdrop-filter: blur(5px);
  pointer-events: auto;
}

modal-close svg,
modal-fullscreen svg,
gallery-prev svg,
gallery-next svg,
gallery-playpause svg {
  display: block;
  width: 30px !important;
  height: 30px !important;
  margin: 0 !important;
  fill: currentColor;
}

modal-header {
  display: flex;
  align-items: center;
  font-size: 1.4rem;
  font-weight: bold;
  border-bottom: 1px solid rgba(var(--modal_box_color), 0.5);
  padding-bottom: 10px;
  margin-bottom: 10px;
  user-select: none;
}

modal-close {
  position: absolute;
  top: 15px;
  right: 20px;
  cursor: pointer;
  font-family: sans-serif;
  font-size: 30px;
  font-weight: bold;
  line-height: 1;
  color: inherit;
  transition: transform 0.1s ease-in-out;
  user-select: none;
  z-index: 22;
}
modal-close:hover {
  transform: scale(1.2);
}

[locked]:not([locked="false"]) modal-close,
[forced]:not([forced="false"]) modal-close {
  display: none !important;
}

modal-main {
  display: block;
  flex: 1;
  overflow-y: auto;
}

modal-footer {
  display: flex;
  justify-content: space-evenly;
  align-items: center;
  gap: 10px;
  border-top: 1px solid rgba(var(--modal_box_color), 0.5);
  padding-top: 10px;
  margin-top: 10px;
}

/* ==========================================
   MODAL PICTURE
   ========================================== */
modal-picture {
  display: none;
  margin: auto;
  padding: 0;
  border: none;
  background-color: transparent;
  user-select: none;
  box-shadow: none !important;
  outline: none;
  overflow: hidden;
  max-width: 100vw;
  max-height: 100vh;
  width: 100%;
  height: 100%;
  z-index: 21;
}

modal-picture:popover-open {
  display: flex;
  justify-content: center;
  align-items: center;
}

modal-picture::backdrop {
  background-color: rgba(var(--modal_backdrop), 0.8);
  backdrop-filter: blur(5px);
  pointer-events: auto;
}

modal-picture > modal-close {
  color: white;
  text-shadow: 0px 0px 5px rgba(0,0,0,0.8);
  top: 20px;
  right: 30px;
  font-size: 30px;
}

modal-picture picture {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

modal-picture img {
  max-width: calc(100vw - 140px);
  max-height: calc(100vh - 144px);
  width: auto;
  height: auto;
  object-fit: contain;
  transform-origin: center center;
  will-change: transform;
}

modal-picture[zoom] img,
modal-picture[zoom-free] img,
modal-picture img.zoom_in,
modal-picture img.zoom_free {
  cursor: grab;
}

modal-picture picture-info {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.8) 0%, rgba(0, 0, 0, 0) 100%);
  color: #ffffff;
  padding: 30px 20px 15px 20px;
  box-sizing: border-box;
  font-family: sans-serif;
  pointer-events: none;
  z-index: 10;
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  justify-content: flex-start;
  align-items: center;
}

modal-picture picture-title {
  display: block;
  font-size: 1.2rem;
  font-weight: bold;
  text-shadow: 1px 1px 3px rgba(0,0,0,0.8);
  background-color: rgba(var(--modal_backdrop), 0.8);
  backdrop-filter: blur(5px);
  padding: 0px 10px;
  border-radius: 5px;
}

modal-picture picture-description {
  display: block;
  margin: 0;
  font-size: 0.9rem;
  opacity: 0.8;
  text-shadow: 1px 1px 3px rgba(0,0,0,0.8);
  background-color: rgba(var(--modal_backdrop), 0.8);
  backdrop-filter: blur(5px);
  padding: 0px 10px;
  border-radius: 5px;
}

modal-loader {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 50px;
  height: 50px;
  border: 4px solid rgba(255, 255, 255, 0.2);
  border-top: 4px solid #ffffff;
  border-radius: 50%;
  animation: modal-spin 1s linear infinite;
  z-index: 5;
  pointer-events: none;
}

@keyframes modal-spin {
  0% { transform: translate(-50%, -50%) rotate(0deg); }
  100% { transform: translate(-50%, -50%) rotate(360deg); }
}

/* ==========================================
   MODAL GALLERY
   ========================================== */
modal-gallery {
  display: none;
  margin: auto;
  padding: 0;
  border: none;
  background-color: transparent;
  user-select: none;
  box-shadow: none !important;
  outline: none;
  overflow: hidden;
  max-width: 100vw;
  max-height: 100vh;
  width: 100%;
  height: 100%;
  z-index: 21;
}

modal-gallery:popover-open {
  display: flex;
  justify-content: center;
  align-items: center;
}

modal-gallery::backdrop {
  background-color: rgba(var(--modal_backdrop), 0.8);
  backdrop-filter: blur(5px);
  pointer-events: auto;
}

modal-gallery > modal-close {
  color: white;
  text-shadow: 0px 0px 5px rgba(0,0,0,0.8);
  top: 21px;
  right: 20px;
  font-size: 30px;
  z-index: 23;
}

modal-gallery picture {
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

modal-gallery img {
  max-width: calc(100vw - 140px);
  max-height: calc(100vh - 144px);
  width: auto;
  height: auto;
  object-fit: contain;
  transform-origin: center center;
  will-change: transform;
}

modal-gallery[zoom] img,
modal-gallery[zoom-free] img,
modal-gallery img.zoom_in,
modal-gallery img.zoom_free {
  cursor: grab;
}

modal-gallery picture-info {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.8) 0%, rgba(0, 0, 0, 0) 100%);
  color: #ffffff;
  padding: 30px 20px 15px 20px;
  box-sizing: border-box;
  font-family: sans-serif;
  pointer-events: none;
  z-index: 10;
  flex-direction: column;
  flex-wrap: nowrap;
  justify-content: flex-start;
  align-items: center;
}

modal-gallery picture-title {
  display: block;
  font-size: 1.2rem;
  font-weight: bold;
  text-shadow: 1px 1px 3px rgba(0,0,0,0.8);
  background-color: rgba(var(--modal_backdrop), 0.8);
  backdrop-filter: blur(5px);
  padding: 0px 10px;
  border-radius: 5px;
}

modal-gallery picture-description {
  display: block;
  margin: 0;
  font-size: 0.9rem;
  opacity: 0.8;
  text-shadow: 1px 1px 3px rgba(0,0,0,0.8);
  background-color: rgba(var(--modal_backdrop), 0.8);
  backdrop-filter: blur(5px);
  padding: 0px 10px;
  border-radius: 5px;
}

gallery-prev,
gallery-next {
  position: absolute;
  top: 72px;
  font-family: sans-serif;
  font-weight: bold;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 70px;
  height: calc(100vh - 144px);
  border-radius: 50%;
  font-size: 40px;
  color: white;
  cursor: pointer;
  z-index: 22;
  text-shadow: 0 2px 10px rgba(0,0,0,0.8);
  transition: transform 0.1s ease, opacity 0.2s ease;
  opacity: 0.7;
  padding: 20px;
}

gallery-prev:hover,
gallery-next:hover {
  opacity: 1;
  transform: scale(1.2);
  text-shadow: 0 2px 10px rgba(0,0,0,1);
}

gallery-prev { left: 0px; }
gallery-next { right: 0px; }

gallery-dots {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  z-index: 22;
  padding: 10px;
  background-color: rgba(0, 0, 0, 0.3);
  border-radius: 20px;
}

.gallery-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background-color: rgba(255, 255, 255, 0.5);
  cursor: pointer;
  transition: background-color 0.2s ease, transform 0.2s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,0.5);
}

.gallery-dot:hover {
  background-color: rgba(255, 255, 255, 0.8);
  transform: scale(1.2);
}

.gallery-dot.active {
  background-color: rgba(255, 255, 255, 1);
  transform: scale(1.2);
}

gallery-playpause {
  position: absolute;
  top: 21px;
  right: 120px;
  font-family: sans-serif;
  font-size: 30px;
  font-weight: bold;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  color: white;
  cursor: pointer;
  z-index: 23;
  text-shadow: 0px 0px 5px rgba(0,0,0,0.8);
  transition: transform 0.1s ease, color 0.2s ease;
  user-select: none;
}

gallery-playpause:hover {
  transform: scale(1.2);
}

/* ==========================================
   FULLSCREEN DUGME
   ========================================== */
modal-fullscreen {
  position: absolute;
  top: 21px;
  right: 70px;
  cursor: pointer;
  font-family: sans-serif;
  font-size: 30px;
  font-weight: bold;
  line-height: 1;
  color: white;
  text-shadow: 0px 0px 5px rgba(0,0,0,0.8);
  transition: transform 0.1s ease-in-out;
  user-select: none;
  z-index: 22;
}

modal-fullscreen:hover {
  transform: scale(1.15);
}

modal-picture > modal-fullscreen,
modal-gallery > modal-fullscreen {
  color: white;
}

@media (max-width: 768px) {
  gallery-prev, gallery-next {
    display: none;
  }
}

@keyframes galleryFadeInAnim {
  0% {
    opacity: 0;
    transform: scale(0.98);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

modal-gallery picture.gallery-fade-in,
modal-gallery picture-info.gallery-fade-in {
  animation: galleryFadeInAnim 0.3s ease-out forwards;
}
/* ==========================================
   MODAL CONFIRM, MODAL ALERT & MODAL WIZARD
   ========================================== */
modal-confirm,
modal-alert,
modal-wizard {
  display: none;
  margin: auto;
  width: fit-content;
  height: fit-content;
  min-width: 320px;
  min-height: 100px;
  max-width: 90vw;
  max-height: 90vh;
  background-color: rgb(var(--modal_box_background));
  color: rgb(var(--modal_box_color));
  border: none;
  border-radius: 6px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
  flex-direction: column;
  padding: 20px;
  z-index: 21;
}

modal-confirm:popover-open,
modal-alert:popover-open,
modal-wizard:popover-open {
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  justify-content: flex-start;
  align-items: stretch;
}

modal-confirm::backdrop,
modal-alert::backdrop,
modal-wizard::backdrop {
  background-color: rgba(var(--modal_backdrop), 0.5);
  backdrop-filter: blur(5px);
  pointer-events: auto;
}

/* Standardna dugmad za Confirm / Alert / Wizard */
.modal-btn {
  padding: 8px 18px;
  border: none;
  border-radius: 4px;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.1s ease;
}
.modal-btn:hover {
  opacity: 0.9;
}
.modal-btn:active {
  transform: scale(0.97);
}
.modal-btn-confirm {
  background-color: #3498db;
  color: #ffffff;
}
.modal-btn-cancel {
  background-color: rgba(255, 255, 255, 0.2);
  color: rgb(var(--modal_box_color));
}

/* Statusne ikonice (info, success, warning, error) */
.modal-status-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-right: 10px;
}
.modal-status-icon svg {
  width: 26px;
  height: 26px;
  fill: currentColor;
}
[type="info"] .modal-status-icon { color: #3498db; }
[type="success"] .modal-status-icon { color: #2ecc71; }
[type="warning"] .modal-status-icon { color: #f1c40f; }
[type="error"] .modal-status-icon { color: #e74c3c; }

/* ==========================================
   MODAL WIZARD DODACI (Stepper)
   ========================================== */
wizard-steps-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 15px;
  margin-bottom: 15px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(var(--modal_box_color), 0.2);
  user-select: none;
}

.wizard-step-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  opacity: 0.45;
  font-size: 0.9rem;
  transition: opacity 0.2s ease;
}

.wizard-step-indicator.active,
.wizard-step-indicator.completed {
  opacity: 1;
}

.wizard-step-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background-color: rgba(var(--modal_box_color), 0.2);
  font-weight: bold;
  font-size: 0.85rem;
}

.wizard-step-indicator.active .wizard-step-number {
  background-color: #3498db;
  color: #ffffff;
}

.wizard-step-indicator.completed .wizard-step-number {
  background-color: #2ecc71;
  color: #ffffff;
}

wizard-step {
  display: none;
  flex: 1;
  overflow-y: auto;
  min-height: 80px;
}

/* ==========================================
   WIZARD CUSTOM DUGMIĆI
   ========================================== */
wizard-previous,
wizard-next,
wizard-finish {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 18px;
  border-radius: 4px;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  user-select: none;
  transition: opacity 0.15s ease, transform 0.1s ease;
}

wizard-previous:hover,
wizard-next:hover,
wizard-finish:hover {
  opacity: 0.9;
}

wizard-previous:active,
wizard-next:active,
wizard-finish:active {
  transform: scale(0.97);
}

wizard-previous {
  background-color: rgba(255, 255, 255, 0.2);
  color: rgb(var(--modal_box_color));
}

wizard-next {
  background-color: #3498db;
  color: #ffffff;
}

wizard-finish {
  background-color: #2ecc71;
  color: #ffffff;
}

.wizard-step-indicator {
  cursor: pointer;
}

/* ==========================================
   MODAL VIDEO
   ========================================== */
modal-video {
  display: none;
  margin: auto;
  padding: 0;
  border: none;
  background-color: transparent;
  user-select: none;
  box-shadow: none !important;
  outline: none;
  overflow: hidden;
  max-width: 100vw;
  max-height: 100vh;
  width: 100%;
  height: 100%;
  z-index: 21;
}

modal-video:popover-open {
  display: flex;
  justify-content: center;
  align-items: center;
}

modal-video::backdrop {
  background-color: rgba(var(--modal_backdrop), 0.85);
  backdrop-filter: blur(5px);
  pointer-events: auto;
}

modal-video > modal-close {
  color: white;
  text-shadow: 0px 0px 5px rgba(0,0,0,0.8);
  top: 20px;
  right: 30px;
}

video-wrapper {
  max-width: calc(100vw - 140px);
  max-height: calc(100vh - 144px);
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  display: flex;
  justify-content: center;
  align-items: center;
}

video-wrapper video,
video-wrapper iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

modal-video picture-info {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.8) 0%, rgba(0, 0, 0, 0) 100%);
  color: #ffffff;
  padding: 30px 20px 15px 20px;
  box-sizing: border-box;
  font-family: sans-serif;
  pointer-events: none;
  z-index: 10;
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  justify-content: flex-start;
  align-items: center;
}

/* ==========================================
   MODAL TOAST (Ne-blokirajuće obaveštenje)
   ========================================== */
modal-toast {
  display: none;
  position: fixed;
  margin: 0;
  padding: 14px 45px 14px 18px;
  min-width: 260px;
  max-width: 400px;
  background-color: rgb(var(--modal_box_background));
  color: rgb(var(--modal_box_color));
  border: none;
  border-radius: 6px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
  z-index: 30;
  font-family: sans-serif;
  transition: top 0.25s ease, bottom 0.25s ease, opacity 0.2s ease;
}

modal-toast:popover-open {
  display: flex;
  align-items: center;
  gap: 10px;
  animation: toastFadeIn 0.25s ease-out forwards;
}

modal-toast::backdrop {
  display: none;
}

modal-toast > modal-close {
  top: 50%;
  right: 10px;
  transform: translateY(-50%);
}
modal-toast > modal-close:hover {
  transform: translateY(-50%) scale(1.15);
}
modal-toast > modal-close svg {
  width: 20px !important;
  height: 20px !important;
}

/* Pozicije za Toast */
modal-toast[position="bottom-right"] { bottom: 20px; right: 20px; top: auto; left: auto; }
modal-toast[position="bottom-left"]  { bottom: 20px; left: 20px; top: auto; right: auto; }
modal-toast[position="top-right"]    { top: 20px; right: 20px; bottom: auto; left: auto; }
modal-toast[position="top-left"]     { top: 20px; left: 20px; bottom: auto; right: auto; }
modal-toast[position="bottom-center"]{ bottom: 20px; left: 50%; top: auto; right: auto; transform: translateX(-50%); }
modal-toast[position="top-center"]   { top: 20px; left: 50%; bottom: auto; right: auto; transform: translateX(-50%); }

@keyframes toastFadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
