/* AIDC Lightbox v2 */

:root{
  --aidc-bg: rgba(4,6,10,.82);
  --aidc-card: rgba(16,18,24,.92);
  --aidc-stroke: rgba(255,255,255,.12);
  --aidc-text: rgba(255,255,255,.9);
  --aidc-muted: rgba(255,255,255,.58);
  --aidc-soft: rgba(255,255,255,.06);
  --aidc-accent: #ff2ea6;
  --aidc-accent2: #6dd5ff;
  --icon-color: #c9cbd1;
  --aidc-danger: #ff3b3b;

  --lb-radius: 18px;
  --lb-gap: 16px;
  --lb-shadow: 0 18px 70px rgba(0,0,0,.62);
}

body.aidc-gal-open{
  overflow: hidden !important;
}

/* Root overlay */
.aidc-lb[hidden]{ display:none !important; }
.aidc-lb__panel[hidden]{ display:none !important; }
.aidc-lb{
  position: fixed;
  inset: 0;
  z-index: 999999;
  display: grid;
  place-items: center;
}
.aidc-lb__backdrop{
  position:absolute;
  inset:0;
  background: rgba(0,0,0,.74);
  backdrop-filter: blur(10px);
}
.aidc-lb__shell{
  position: relative;
  width: min(1320px, calc(100vw - 48px));
  height: min(86vh, calc(100vh - 48px));
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: var(--lb-gap);
  padding: 18px;
  border-radius: var(--lb-radius);
  background: linear-gradient(180deg, rgba(255,255,255,.06), rgba(255,255,255,.02));
  border: 1px solid var(--aidc-stroke);
  box-shadow: var(--lb-shadow);
  overflow: hidden; /* Prevent zoomed content from overflowing shell */
}

/* Close */
.aidc-lb__close{
  position:absolute;
  top: 14px;
  right: 14px;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.06);
  color: var(--aidc-text);
  cursor: pointer;
  display:grid;
  place-items:center;
}
.aidc-lb__close:hover{
  border-color: rgba(255,46,166,.55);
  box-shadow: 0 0 0 6px rgba(255,46,166,.12);
}
.aidc-lb__back{
  position:absolute;
  top: 14px;
  left: 14px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.14);
  background: rgba(0,0,0,.35);
  color: rgba(255,255,255,.85);
  font-size: 12px;
  cursor: pointer;
  z-index: 1200;
  pointer-events: auto;
}
.aidc-lb__back:hover{
  border-color: rgba(255,46,166,.55);
  box-shadow: 0 0 0 6px rgba(255,46,166,.12);
}

/* Main preview area */
.aidc-lb__main{
  position: relative;
  z-index: 1; /* Lower than panel to ensure zoomed images don't overlap */
  border-radius: var(--lb-radius);
  overflow: hidden;
  /* Isolate stacking context and clip transformed children */
  isolation: isolate;
  contain: paint;
  background: rgba(0,0,0,.35);
  border: 1px solid rgba(255,255,255,.10);
  display: grid;
  place-items: center;
}
.aidc-lb__media{
  width: 100%;
  height: 100%;
  display:flex;
  place-content:center;
  overflow: hidden;
  /* Clip any transformed/zoomed children */
  contain: paint;
  box-sizing: border-box;
}

.aidc-media-box::before,
.aidc-media-loader{
  pointer-events: none !important;
}

/* ===== Zoom clip wrapper ===== */
/* Жёсткая clip-область для зума — единственная зона трансформации */
.aidc-lb__zoomHost{
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;      /* КРИТИЧНО: физически обрезает transform */
  isolation: isolate;    /* отдельный stacking context */
  display: grid;
  place-items: center;
}
/* img/video трансформируются ТОЛЬКО внутри zoomHost */
.aidc-lb__zoomHost > img,
.aidc-lb__zoomHost > video,
.aidc-lb__zoomHost .aidc-lb__pinwrap,
.aidc-lb__zoomHost .aidc-media-preview{
  will-change: transform;
  transform-origin: center center;
}

.aidc-lb[data-active-tab="details"] .aidc-lb__media,
.aidc-lb[data-active-tab="details"] .aidc-lb__img,
.aidc-lb[data-active-tab="details"] .aidc-lb__pinwrap{
  cursor: zoom-in;
}
.aidc-lb[data-active-tab="comments"] .aidc-lb__media,
.aidc-lb[data-active-tab="comments"] .aidc-lb__img,
.aidc-lb[data-active-tab="comments"] .aidc-lb__pinwrap{
  cursor: url("/assets/icons/ui/lb-comment.svg") 12 12, crosshair;
}
.aidc-lb__img,
.aidc-lb__video{
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.aidc-lb__placeholder{
  color: var(--aidc-muted);
  font-size: 16px;
  letter-spacing:.02em;
}

/* Add symmetric padding so media is vertically centered inside viewport
   and use border-box so clientWidth/clientHeight include padding. */
.aidc-lb__media{
  padding: 48px; /* tweak value if needed: 32/48/56 */
  box-sizing: border-box;
}

/* SAFETY: placeholder must never push media down when hidden */
.aidc-lb__media .aidc-lb__placeholder[hidden]{
  display: none !important;
}

/* Soft loader: when thumb is already visible, don't visually block the image.
   This matches JS behavior: dom.loader.classList.add('is-soft') on thumb_ready
   and removal on preview_ready. */
.aidc-media-loader.is-soft{
  background: transparent;
  pointer-events: none; /* allow clicks through to underlying image */
}
.aidc-media-loader.is-soft .aidc-media-loader-text{
  display: none; /* hide textual message when soft */
}
.aidc-media-loader.is-soft .aidc-media-spinner{
  opacity: 0; /* hide spinner visually (can use display:none if preferred) */
  transition: opacity 160ms ease-in-out;
}

/* Top-left tags overlay */
.aidc-lb__tags{
  position:absolute;
  top: 14px;
  left: 14px;
  display:flex;
  flex-wrap: wrap;
  gap: 8px;
  max-width: calc(100% - 110px);
  pointer-events: none;
}
.aidc-tag{
  pointer-events: none;
  display:inline-flex;
  align-items:center;
  gap: 8px;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.14);
  background: rgba(5,7,13,.55);
  color: rgba(255,255,255,.82);
  font-size: 12px;
  backdrop-filter: blur(10px);
  white-space: nowrap;
}
.aidc-tag--accent{
  border-color: rgba(109,213,255,.35);
  color: rgba(109,213,255,.92);
}

/* Nav arrows */
.aidc-lb__nav{
  position:absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 46px;
  height: 46px;
  border-radius: 16px;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.06);
  color: var(--aidc-text);
  cursor:pointer;
  display:grid;
  place-items:center;
}
.aidc-lb__nav:hover{
  border-color: rgba(255,255,255,.22);
  background: rgba(255,255,255,.09);
}
.aidc-lb__nav[disabled]{
  opacity: .35;
  pointer-events:none;
}
.aidc-lb__nav--prev{ left: 14px; }
.aidc-lb__nav--next{ right: 14px; }

.aidc-lb[data-viewer-kind="reference"] .aidc-lb__nav{
  display: grid;
}

/* Back visibility for generation frames is controlled by JS so the
   button can be shown for single-frame generations (UX requirement).
   Previously this rule hid the Back button for all generation viewers.
   Removed to allow script to toggle visibility. */
/* When Back button is visible, shift tags right so they don't overlap */
.aidc-lb[data-viewer-kind="reference"] .aidc-lb__tags,
.aidc-lb[data-viewer-kind="upload"] .aidc-lb__tags{
  left: auto;
  right: 14px;
}
/* Nav arrows for uploads: visibility is now controlled by JS (canNav logic in renderAll).
   Previously display:none hid arrows even when multiple uploads exist. */
.aidc-lb[data-viewer-kind="upload"] .aidc-lb__tabs,
.aidc-lb[data-viewer-kind="reference"] .aidc-lb__tabs{
  display: none;
}

/* Right panel */
.aidc-lb__panel{
  position: relative;
  z-index: 10; /* Ensure panel is always above zoomed media */
  /* Isolate stacking context */
  isolation: isolate;
  border-radius: var(--lb-radius);
  background: rgba(10,12,18,.72);
  border: 1px solid rgba(255,255,255,.10);
  overflow: hidden;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
}

/* Panel header: author + share */
.aidc-lb__phead{
  padding: 14px 14px 10px;
  display:flex;
  align-items:center;
  justify-content: space-between;
  gap: 12px;
}
.aidc-lb__author{
  display:flex;
  align-items:center;
  gap: 10px;
  min-width: 0;
}
.aidc-lb__ava{
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.14);
  background: rgba(255,255,255,.08);
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: rgba(255,255,255,.85);
  background-size: cover;
  background-position: center;
}
.aidc-lb__aname{
  display:flex;
  flex-direction: column;
  min-width: 0;
}
.aidc-lb__aname strong{
  font-size: 13px;
  color: var(--aidc-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.aidc-lb__aname span{
  font-size: 11px;
  color: var(--aidc-muted);
}
.aidc-lb__share{
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.06);
  color: var(--aidc-text);
  padding: 9px 12px;
  cursor: pointer;
  display:inline-flex;
  align-items:center;
  gap: 8px;
  font-size: 12px;
}
.aidc-lb__share:hover{
  border-color: rgba(109,213,255,.35);
  box-shadow: 0 0 0 6px rgba(109,213,255,.10);
}

/* Tabs */
.aidc-lb__tabs{
  padding: 0 10px 10px;
  display:flex;
  gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.aidc-lb__tab{
  flex: 1;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.10);
  background: rgba(255,255,255,.05);
  color: rgba(255,255,255,.78);
  padding: 10px 12px;
  cursor: pointer;
  font-size: 12px;
}
.aidc-lb__tab.is-active{
  background: rgba(255,255,255,.08);
  border-color: rgba(255,46,166,.40);
  color: var(--aidc-text);
  box-shadow: 0 0 0 6px rgba(255,46,166,.10);
}

/* Scrollable content */
.aidc-lb__content{
  padding: 12px;
  overflow: auto;
}
.aidc-lb__section{
  border-radius: 16px;
  border: 1px solid rgba(255,255,255,.10);
  background: rgba(255,255,255,.04);
  padding: 12px;
  margin-bottom: 10px;
}
.aidc-lb__section h4{
  margin: 0 0 10px;
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: rgba(255,255,255,.62);
  display:flex;
  align-items:center;
  justify-content: space-between;
  gap: 10px;
}
.aidc-lb__kv{
  display:grid;
  gap: 10px;
}
.aidc-lb__kvrow{
  display:flex;
  align-items:center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  color: rgba(255,255,255,.85);
}
.aidc-lb__k{
  color: rgba(255,255,255,.55);
  font-size: 12px;
}
.aidc-lb__v{
  color: rgba(255,255,255,.9);
  text-align: right;
}
.aidc-lb__row{
  display:flex;
  align-items:center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  color: rgba(255,255,255,.82);
}
.aidc-lb__row span{
  color: rgba(255,255,255,.55);
  font-size: 12px;
}
.aidc-lb__mono{
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

/* Prompt block */
.aidc-lb__prompt{
  margin: 0;
  color: rgba(255,255,255,.78);
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 240px;
  overflow: auto;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,.10);
  background: rgba(0,0,0,.22);
  padding: 10px;
}
.aidc-lb__prompt.is-collapsed{
  max-height: 0;
  padding: 0;
  border-color: transparent;
  background: transparent;
  overflow: hidden;
}
.aidc-lb__prompt-toggle{
  margin-top: 8px;
  border: 0;
  background: transparent;
  color: rgba(255,255,255,.6);
  font-size: 12px;
  cursor: pointer;
  padding: 0;
  text-align: left;
}
.aidc-lb__prompt-toggle:hover{
  color: rgba(255,255,255,.85);
}
.aidc-lb__tools{
  display:flex;
  gap: 8px;
}
.aidc-lb__iconbtn{
  width: 34px;
  height: 34px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.05);
  color: var(--aidc-text);
  cursor:pointer;
  display:grid;
  place-items:center;
}
.aidc-lb__iconbtn:hover{
  border-color: rgba(109,213,255,.35);
}
.aidc-lb__refrow{
  display:flex;
  align-items:center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
}
.aidc-lb__refs{
  display:flex;
  gap: 6px;
  flex-wrap: wrap;
}
.aidc-lb__ref{
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,.14);
  background: #0d0d0d;
  overflow: hidden;
  cursor: pointer;
}
.aidc-lb__ref img{
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.aidc-lb__ref:hover{
  border-color: rgba(255,46,166,.45);
  box-shadow: 0 0 0 4px rgba(255,46,166,.10);
}

/* Used in projects list */
.aidc-lb__chips{
  display:flex;
  flex-wrap: wrap;
  gap: 8px;
}
.aidc-chip{
  display:inline-flex;
  align-items:center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(0,0,0,.18);
  color: rgba(255,255,255,.82);
  font-size: 12px;
  cursor: pointer;
}
.aidc-chip:hover{
  border-color: rgba(255,46,166,.40);
  box-shadow: 0 0 0 6px rgba(255,46,166,.10);
}

/* Bottom action zone (RIGHT BOTTOM inside info container!) */
.aidc-lb__actions{
  padding: 12px;
  border-top: 1px solid rgba(255,255,255,.08);
  display:grid;
  gap: 10px;
  background: rgba(10,12,18,.75);
  align-content: start;
  margin-top: auto;
}

.aidc-lb__zoomcontrols{
  display:flex;
  gap:8px;
  align-items:center;
  justify-self: end;
}
.aidc-lb__zoomcontrols img{ display:block; width:18px; height:18px; }
.aidc-lb--webapp.is-video .aidc-lb__zoomcontrols{
  display: none !important;
  pointer-events: none !important;
}
.aidc-lb--webapp.is-video .aidc-lb__media,
.aidc-lb--webapp.is-video .aidc-lb__img,
.aidc-lb--webapp.is-video .aidc-lb__pinwrap{
  cursor: default !important;
}
.aidc-lb__primary{
  width: 100%;
  border: none;
  border-radius: 14px;
  padding: 12px 12px;
  cursor:pointer;
  font-weight: 800;
  letter-spacing: .02em;
  color: rgba(10,10,16,.92);
  background: linear-gradient(90deg, #d8ff00, #baff00);
}
.aidc-lb__primary:hover{
  filter: brightness(1.04);
}
.aidc-lb__grid{
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  align-content: start;
  align-items: start;
  grid-auto-rows: minmax(44px, auto);
}
.aidc-lb__btn{
  width: 100%;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.05);
  color: rgba(255,255,255,.86);
  padding: 10px 10px;
  cursor:pointer;
  font-size: 12px;
  display:flex;
  align-items:center;
  justify-content: center;
  gap: 10px;
  height: 44px;
}
.aidc-lb__btn:hover{
  border-color: rgba(255,255,255,.22);
  background: rgba(255,255,255,.08);
}
.aidc-lb__btn--danger{
  border-color: rgba(255,59,59,.35);
  color: rgba(255,180,180,.95);
}
.aidc-lb__btn--danger:hover{
  background: rgba(255,59,59,.10);
}

@media (max-width: 980px){
  /* Apply mobile layout only when running inside WebApp context */
  html.tg .aidc-lb__shell{
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
    height: min(92vh, calc(100vh - 24px));
    width: min(980px, calc(100vw - 24px));
  }
  html.tg .aidc-lb__panel{
    grid-template-rows: auto auto 1fr auto;
  }
}


/* ---- WebApp (TG) mode: full-screen + bottom buttons ---- */
.aidc-lb__wabottom[hidden]{ display:none !important; }
.aidc-lb__wabottom{
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(14px + env(safe-area-inset-bottom));
  display:flex;
  gap: 10px;
  padding: 8px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(5,7,13,.45);
  backdrop-filter: blur(14px);
  box-shadow: 0 14px 40px rgba(0,0,0,.45);
  pointer-events: auto;
  z-index: 100; /* Above loader and other overlays */
}
.aidc-lb__wabtn{
  appearance: none;
  border: 1px solid rgba(255,255,255,.14);
  background: rgba(255,255,255,.06);
  color: rgba(255,255,255,.90);
  border-radius: 999px;
  padding: 12px 16px;
  font-size: 12px;
  letter-spacing:.02em;
  cursor:pointer;
  min-height: 44px;
  min-width: 110px;
}
.aidc-lb__wabtn:hover{
  border-color: rgba(109,213,255,.35);
  box-shadow: 0 0 0 6px rgba(109,213,255,.10);
}
.aidc-lb__wabtn:active{
  transform: translateY(1px);
}
.aidc-lb__wabtnText{ font-weight: 700; }

/* Full-screen layout */
.aidc-lb--webapp{
  place-items: stretch;
}
.aidc-lb--webapp .aidc-lb__shell{
  width: 100vw !important;
  width: 100dvw !important;
  height: 100vh !important;
  height: 100dvh !important;
  padding: 0 !important;
  border-radius: 0 !important;
  grid-template-columns: 1fr !important;
  gap: 0 !important;
  border: none !important;
  background: rgba(0,0,0,.18) !important;
  box-shadow: none !important;
}
.aidc-lb--webapp .aidc-lb__main{
  border-radius: 0;
  border: none;
  background: rgba(0,0,0,.48);
  width: 100%;
  height: 100%;
  min-height: 200px;
}
.aidc-lb--webapp .aidc-lb__media{
  width: 100%;
  height: 100%;
  min-height: 200px;
}
.aidc-lb--webapp .aidc-media-box{
  width: 100% !important;
  height: 100% !important;
  max-width: 100% !important;
  max-height: 100% !important;
}
.aidc-lb--webapp .aidc-lb__panel{
  display: none !important;
}
.aidc-lb--webapp .aidc-lb__backdrop{
  background: rgba(0,0,0,.82);
}
.aidc-lb--webapp .aidc-lb__close{
  top: 10px;
  right: 10px;
}
/* Shell-level close button shown specifically in webapp mode when panel is hidden */
.aidc-lb__close--shell{ display:none; }
.aidc-lb--webapp .aidc-lb__close--shell{ display:block; position:absolute; z-index:1100; top:10px; right:10px; }

/* Hide the panel-internal close visually in webapp when panel is collapsed, keep it accessible for a11y */
.aidc-lb--webapp .aidc-lb__panel .aidc-lb__close{ visibility:hidden; pointer-events:none; }

/* WebApp INFO overlay as bottom-sheet on small screens */
@media (max-width: 520px){
  /* Bottom-sheet INFO overlay only for WebApp context */
  html.tg .aidc-lb__overlayCard{
    width: 100%;
    max-width: none;
    border-radius: 22px 22px 0 0;
    margin: 0;
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: calc(78vh - env(safe-area-inset-bottom));
  }
  html.tg .aidc-lb__overlayBody{
    max-height: calc(78vh - 64px - env(safe-area-inset-bottom));
    overflow: auto;
  }
}

/* ---- Used in projects (webapp) ---- */
.aidc-lb__projlist{
  display:flex;
  flex-direction: column;
  gap: 10px;
}
.aidc-lb__projrow{
  width: 100%;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.05);
  color: rgba(255,255,255,.88);
  padding: 12px 12px;
  cursor:pointer;
  display:flex;
  align-items:center;
  justify-content: space-between;
  gap: 10px;
  min-height: 48px;
}
.aidc-lb__projrow:hover{
  border-color: rgba(255,46,166,.40);
  box-shadow: 0 0 0 6px rgba(255,46,166,.10);
}
.aidc-lb__projname{
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}
.aidc-lb__projopen{
  flex: 0 0 auto;
  font-size: 12px;
  color: rgba(109,213,255,.92);
}

/* ---- Aliases for chip list (site) ---- */
.aidc-lb__chiplist{ display:flex; flex-wrap:wrap; gap: 8px; }
.aidc-lb__projchip{
  display:inline-flex;
  align-items:center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(0,0,0,.18);
  color: rgba(255,255,255,.82);
  font-size: 12px;
  cursor:pointer;
}
.aidc-lb__projchip:hover{
  border-color: rgba(255,46,166,.40);
  box-shadow: 0 0 0 6px rgba(255,46,166,.10);
}

/* Better 'more' button */
.aidc-lb__more{
  width: 100%;
  margin-top: 10px;
  border-radius: 12px;
  border: 1px dashed rgba(255,255,255,.18);
  background: rgba(255,255,255,.03);
  color: rgba(255,255,255,.78);
  padding: 10px 12px;
  cursor:pointer;
  font-size: 12px;
}
.aidc-lb__more:hover{
  border-color: rgba(109,213,255,.35);
}

/* Actions sheet buttons (webapp) */
.aidc-lb__sheetBtn{
  width: 100%;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.05);
  color: rgba(255,255,255,.90);
  padding: 14px 12px;
  cursor:pointer;
  font-size: 13px;
  min-height: 48px;
  display:flex;
  align-items:center;
  justify-content: center;
}
.aidc-lb__sheetBtn:hover{
  border-color: rgba(109,213,255,.35);
  box-shadow: 0 0 0 6px rgba(109,213,255,.10);
}
.aidc-lb__sheetBtn.is-danger{
  border-color: rgba(255,59,59,.35);
  color: rgba(255,180,180,.95);
}


/* ===== AIDC Lightbox WebApp additions (v2.1) ===== */

/* NOTE: legacy duplicate rules for .aidc-lb were removed here to avoid
   z-index/display conflicts with the main root definition above.
   See FINAL OVERRIDE at the end of this file which enforces correct
   stacking for the lightbox root. */

/* Skeleton loader shown while media is loading */
:root{
  /* default height for lightbox skeleton/placeholder; can be overridden per-theme */
  --aidc-lb-skeleton-height: 420px;
}

/* Skeleton loader shown while media is loading */
.aidc-lb__skeleton{
  width: 100%;
  height: var(--aidc-lb-skeleton-height, 420px);
  border-radius: 12px;
  background: linear-gradient(90deg,#0b0d11 0%, #0f1114 50%, #0b0d11 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255,255,255,0.25);
}

/* Placeholder when preview is not available */
.aidc-lb__placeholder{
  width: 100%;
  height: var(--aidc-lb-skeleton-height, 420px);
  border-radius: 12px;
  display:flex;
  align-items:center;
  justify-content:center;
  background: rgba(0,0,0,0.28);
  color: rgba(255,255,255,0.5);
}

/* Responsive adjustments */
@media (max-width: 520px){
  :root{ --aidc-lb-skeleton-height: 280px; }
  .aidc-lb__skeleton, .aidc-lb__placeholder{ border-radius: 10px; }
}

@media (min-width: 1024px){
  :root{ --aidc-lb-skeleton-height: 520px; }
}

.aidc-lb--webapp .aidc-lb__shell{
  width: 100vw;
  height: 100vh;
  max-width: none;
  max-height: none;
  border-radius: 0;
  padding: 0;
}
.aidc-lb--webapp .aidc-lb__main{
  border-radius: 0;
}
.aidc-lb--webapp .aidc-lb__nav{
  top: 50%;
  transform: translateY(-50%);
}
.aidc-lb--webapp .aidc-lb__close{
  top: 12px;
  right: 12px;
}

/* WebApp bottom bar */
.aidc-lb__wabottom{
  position: absolute;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 18px;
  background: rgba(10,14,22,.35);
  border: 1px solid rgba(255,255,255,.10);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  pointer-events: auto;
  z-index: 100; /* Above loader and other overlays */
}

/* buttons (not system white) */
.aidc-btn{
  appearance: none;
  border: 1px solid rgba(255,255,255,.14);
  background: rgba(12,16,24,.55);
  color: rgba(255,255,255,.92);
  border-radius: 14px;
  padding: 10px 14px;
  font: inherit;
  font-weight: 600;
  letter-spacing: .2px;
  cursor: pointer;
  transition: transform .08s ease, background .15s ease, border-color .15s ease;
}
.aidc-btn:active{ transform: translateY(1px) scale(.99); }
.aidc-btn--primary{
  background: rgba(119,77,255,.85);
  border-color: rgba(180,160,255,.35);
}
.aidc-btn--glass{
  background: rgba(12,16,24,.40);
}
.aidc-btn--ghost{
  background: transparent;
}
.aidc-btn--wide{ width: 100%; justify-content: center; }

.aidc-btn--icon{
  width: 36px; height: 36px;
  border-radius: 12px;
  padding: 0;
  display:flex; align-items:center; justify-content:center;
  background: rgba(12,16,24,.55);
}

/* WebApp button overrides - use TG pink gradient style */
html.tg .aidc-btn{
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.04);
  color: #e8ebff;
  border-radius: 14px;
}
html.tg .aidc-btn--primary{
  background: linear-gradient(120deg, #ff62c5, #ff008c);
  border-color: rgba(255,255,255,.26);
  color: #0b0c12;
}
html.tg .aidc-btn--glass{
  background: rgba(255,255,255,.04);
}

/* INFO overlay - hidden by default, shown with .is-open */
.aidc-lb__overlay{
  position: absolute;
  inset: 0;
  z-index: 20;
  display: none;
  place-items: center;
}
.aidc-lb__overlay.is-open{
  display: grid;
}
.aidc-lb__overlayBackdrop{
  position:absolute; inset:0;
  background: rgba(0,0,0,.55);
}
.aidc-lb__overlayCard{
  position: relative;
  width: min(520px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  overflow: hidden;
  border-radius: 18px;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(12,16,24,.92);
  box-shadow: 0 18px 50px rgba(0,0,0,.55);
}
.aidc-lb__overlayHead{
  display:flex;
  align-items:center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 12px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.aidc-lb__overlayTitle{ font-weight: 800; }
.aidc-lb__overlayBody{
  padding: 12px 12px 16px;
  overflow:auto;
  max-height: calc(100vh - 140px);
}
@media (max-width: 520px){
  /* Ensure overlay becomes bottom-sheet only in WebApp */
  html.tg .aidc-lb__overlay{
    place-items: end center;
  }
  html.tg .aidc-lb__overlayCard{
    width: 100vw;
    border-radius: 18px 18px 0 0;
    max-height: calc(100vh - 10px);
  }
}

/* Hidden states for overlay and sheet */
.aidc-lb__overlay[hidden]{ display:none !important; }
.aidc-lb__sheet[hidden]{ display:none !important; }

/* Actions sheet - hidden by default, shown with .is-open */
.aidc-lb__sheet{
  position:absolute; inset:0;
  z-index: 30;
  display:none;
}
.aidc-lb__sheet.is-open{
  display:block;
}
.aidc-lb__sheetBackdrop{
  position:absolute; inset:0;
  background: rgba(0,0,0,.55);
}
.aidc-lb__sheetCard{
  position:absolute;
  left: 0; right: 0;
  bottom: 0;
  border-radius: 18px 18px 0 0;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(12,16,24,.94);
  overflow:hidden;
  box-shadow: 0 -18px 50px rgba(0,0,0,.55);
}
.aidc-lb__sheetGrab{
  width: 42px; height: 5px;
  border-radius: 999px;
  background: rgba(255,255,255,.18);
  margin: 10px auto 6px;
}
.aidc-lb__sheetHead{
  display:flex;
  align-items:center;
  justify-content: space-between;
  padding: 10px 12px 12px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.aidc-lb__sheetTitle{ font-weight: 800; }
.aidc-lb__sheetList{
  padding: 10px 12px 16px;
  display:flex;
  flex-direction: column;
  gap: 8px;
  max-height: 55vh;
  overflow:auto;
}
.aidc-sheetitem{
  width: 100%;
  display:flex;
  align-items:center;
  gap: 12px;
  padding: 12px 12px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,.10);
  background: rgba(18,22,32,.55);
  color: rgba(255,255,255,.92);
  cursor: pointer;
}
.aidc-sheetitem:active{ transform: translateY(1px); }
.aidc-sheetitem.is-danger{
  border-color: rgba(255,80,80,.35);
  background: rgba(255,40,40,.18);
  color: #ff6b6b;
}
.aidc-sheetitem.is-danger .aidc-sheetitem__ico{
  background: rgba(255,60,60,.22);
  border-color: rgba(255,100,100,.35);
}
.aidc-sheetitem__ico{
  width: 28px; height: 28px;
  border-radius: 10px;
  display:flex; align-items:center; justify-content:center;
  background: rgba(119,77,255,.18);
  border: 1px solid rgba(180,160,255,.22);
}

/* WebApp sheetitem overrides - use TG style */
html.tg .aidc-sheetitem{
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.04);
  color: #e8ebff;
}
html.tg .aidc-sheetitem__ico{
  background: rgba(255,0,140,.15);
  border: 1px solid rgba(255,0,140,.25);
}
html.tg .aidc-sheetitem.is-danger{
  border-color: rgba(255,80,80,.35);
  background: rgba(255,40,40,.12);
  color: #ff6b6b;
}
.aidc-sheetitem__txt{ font-weight: 700; }

/* Used in projects rows */
.aidc-prows{ display:flex; flex-direction: column; gap: 8px; }
.aidc-prow{
  width:100%;
  display:flex;
  align-items:center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 12px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,.10);
  background: rgba(18,22,32,.45);
  color: rgba(255,255,255,.92);
  cursor:pointer;
  text-align:left;
}
.aidc-prow__main{ min-width: 0; flex: 1; }
.aidc-prow__title{
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.aidc-prow__meta{ font-size: 12px; color: rgba(255,255,255,.65); margin-top: 2px; }
.aidc-prow__open{ font-weight: 700; color: rgba(180,160,255,.95); }

/* Toast */
.aidc-lb__toast{
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  background: rgba(12,16,24,.92);
  border: 1px solid rgba(255,255,255,.12);
  color: rgba(255,255,255,.92);
  padding: 10px 12px;
  border-radius: 14px;
  z-index: 10000;
  opacity: 0;
  pointer-events: none;
  transition: opacity .16s ease, transform .16s ease;
}
.aidc-lb__toast.is-show{
  opacity: 1;
  transform: translateX(-50%) translateY(-6px);
}

/* =========================
   ZOOM + PAN
   ========================= */

.aidc-lb__media{
  position: relative;
  overflow: hidden;
}

.aidc-lb__img,
.aidc-lb__video{
  max-width: 100%;
  max-height: 100%;
  display: block;
  margin: 0 auto;
  user-select: none;
  -webkit-user-drag: none;
}

.aidc-lb__img{
  cursor: zoom-in;
  transform-origin: center center;
  touch-action: none; /* чтобы drag работал на touch */
}

.aidc-lb__img.is-zoomed{
  cursor: grab;
}

.aidc-lb__img.is-zoomed.is-dragging{
  cursor: grabbing;
}

/* Smooth zoom transition; disabled while dragging */

/* =========================================================
   DESKTOP (SITE) — Higgsfield-like fullscreen lightbox (FINAL)
   ========================================================= */

.aidc-lb{
  position: fixed;
  inset: 0;
  z-index: 1000000;
  display: grid;
  place-items: stretch; /* важно: stretch, не center */
}

.aidc-lb__backdrop{
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.74);
  backdrop-filter: blur(10px);
}

.aidc-lb__shell{
  position: relative;
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px; /* как в рефе */
  gap: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: transparent;
  overflow: hidden;
}

.aidc-lb__main{
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: transparent;
  min-width: 0;
  /* Clip ALL children including transformed ones */
  contain: paint;
}

.aidc-lb__media{
  position: relative;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  overflow: hidden;
  contain: paint;
  z-index: 1;
}

.aidc-lb__img,
.aidc-lb__video{
  max-width: calc(100vw - 420px - 48px);
  max-height: calc(100vh - 48px);
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(0,0,0,.45);
}

/* close — в углу экрана */
.aidc-lb__close{
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 1000001;
}

/* panel */
.aidc-lb__panel{
  height: 100%;
  border-left: 1px solid rgba(255,255,255,.08);
  background: rgba(10,12,18,.72);
  backdrop-filter: blur(10px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-width: 0;
  z-index: 10; /* above main content */
}

/* тело панели скроллится */
.aidc-lb__pbody,
.aidc-lb__content{
  overflow: auto;
  min-height: 0;
}
.aidc-lb__pbody{
  flex: 1 1 auto;
}

/* actions всегда видны снизу */
.aidc-lb__actions,
[data-lb-actions]{
  position: sticky;
  bottom: 0;
  padding: 14px;
  border-top: 1px solid rgba(255,255,255,.08);
  background: linear-gradient(to bottom, rgba(10,12,18,0), rgba(10,12,18,.96) 35%);
  backdrop-filter: blur(10px);
}

/* красивые кнопки: одинаковая геометрия */
.aidc-lb__primary{
  min-height: 50px;
  border-radius: 14px;
  font-weight: 800;
}

.aidc-lb__grid{
  margin-top: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.aidc-lb__btn{
  min-height: 44px;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.aidc-lb__btn-icon{
  width: 18px;
  height: 18px;
  display: inline-block;
  background-color: var(--icon-color);
  -webkit-mask: var(--lb-icon) center / contain no-repeat;
  mask: var(--lb-icon) center / contain no-repeat;
}

/* tabs — фикс высоты, чтобы не превращались в "бочки" */
.aidc-lb__tabs{ padding: 10px 14px 12px; }
.aidc-lb__tab{
  height: 40px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.aidc-lb__nav{
  z-index: 2;
}

.aidc-lb__zoomoverlay{
  position: absolute;
  right: 16px;
  bottom: 16px;
  display: flex;
  gap: 8px;
  padding: 8px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(10,12,18,.6);
  backdrop-filter: blur(10px);
  z-index: 3;
}

.aidc-lb[data-media-kind="video"] .aidc-lb__zoomoverlay{
  display: none;
}
.aidc-lb[data-media-kind="video"] .aidc-lb__media,
.aidc-lb[data-media-kind="video"] .aidc-lb__img,
.aidc-lb[data-media-kind="video"] .aidc-lb__pinwrap,
.aidc-lb[data-media-kind="video"] .aidc-media-box{
  cursor: default;
}

/* AUDIO MODE: disable zoom UX — same as video */
.aidc-lb[data-media-kind="audio"] .aidc-lb__zoomoverlay{
  display: none !important;
}
.aidc-lb[data-media-kind="audio"] .aidc-lb__media,
.aidc-lb[data-media-kind="audio"] .aidc-lb__img,
.aidc-lb[data-media-kind="audio"] .aidc-lb__pinwrap,
.aidc-lb[data-media-kind="audio"] .aidc-media-box{
  cursor: default !important;
}

.aidc-lb__zoom-icon{
  width: 18px;
  height: 18px;
  display: inline-block;
  background-color: var(--icon-color);
  -webkit-mask: var(--lb-icon) center / contain no-repeat;
  mask: var(--lb-icon) center / contain no-repeat;
}

.aidc-lb__img{
  transition: transform 220ms cubic-bezier(.2,.8,.2,1);
}
.aidc-lb__img.is-dragging,
.aidc-lb__img.is-zoomed.is-dragging{
  transition: none !important;
}

/* VIDEO MODE: disable zoom UX (cursor, zoom buttons, zoom handlers) */
.aidc-lb--webapp.is-video .aidc-lb__zoomoverlay,
.aidc-lb--webapp.is-video .aidc-lb__zoomcontrols{
  display: none !important;
}
.aidc-lb--webapp.is-video[data-active-tab="details"] .aidc-lb__media,
.aidc-lb--webapp.is-video[data-active-tab="details"] .aidc-lb__img,
.aidc-lb--webapp.is-video[data-active-tab="details"] .aidc-lb__pinwrap{
  cursor: default !important;
}

/* ===== FULLSCREEN ZOOM MODE (Desktop) ===== */
/* When image is zoomed (scale > 1), keep layout size intact — CSS transform
   handles visual scaling without changing the element's box dimensions.
   Previously max-width/max-height were removed which caused the image to
   expand to its natural resolution and disappear outside the clip area. */
.aidc-lb__img.is-zoomed,
.aidc-media-preview.is-zoomed{
  cursor: grab;
}

/* Class-based zoom mode (JS adds .is-zoomed-mode to .aidc-lb) */
/* Zoom only inside parent - all containers clip overflow */
.aidc-lb.is-zoomed-mode .aidc-lb__main{
  overflow: hidden !important;
}
.aidc-lb.is-zoomed-mode .aidc-lb__media{
  overflow: hidden !important;
}
.aidc-lb.is-zoomed-mode .aidc-media-box{
  overflow: hidden !important;
  /* Do NOT resize the box on zoom — CSS transform handles visual scaling.
     Resizing here caused the container to change dimensions the moment
     .is-zoomed was added, invalidating the translate offsets calculated
     by clampPan() right before applyZoom() → black screen. */
}
.aidc-lb.is-zoomed-mode .aidc-lb__pinwrap{
  overflow: hidden !important;
}
.aidc-lb.is-zoomed-mode .aidc-lb__panel{
  /* Keep panel fully interactive during zoom. UX requires panel
     controls to remain clickable even when image is zoomed. */
  opacity: 1 !important;
  pointer-events: auto !important;
  transition: opacity 200ms ease;
}
.aidc-lb.is-zoomed-mode .aidc-lb__nav{
  opacity: 0;
  pointer-events: none;
}
.aidc-lb.is-zoomed-mode .aidc-lb__thumbs{
  opacity: 0;
  pointer-events: none;
}

/* Fallback: :has() selector for browsers that support it */
/* Zoom only inside parent - all containers clip overflow */
.aidc-lb__main:has(.is-zoomed){
  overflow: hidden !important;
}
.aidc-lb__media:has(.is-zoomed){
  overflow: hidden !important;
}
.aidc-media-box:has(.is-zoomed){
  overflow: hidden !important;
  /* No resize — see .is-zoomed-mode comment above */
}
.aidc-lb__pinwrap:has(.is-zoomed){
  overflow: hidden !important;
  /* No resize — keep natural aspect-ratio-constrained size */
}
.aidc-lb:has(.is-zoomed) .aidc-lb__panel{
  /* Keep panel fully interactive for browsers that support :has() */
  opacity: 1 !important;
  pointer-events: auto !important;
  transition: opacity 200ms ease;
}
.aidc-lb:has(.is-zoomed) .aidc-lb__nav{
  opacity: 0;
  pointer-events: none;
}
.aidc-lb:has(.is-zoomed) .aidc-lb__thumbs{
  opacity: 0;
  pointer-events: none;
}

/* =========================================================
   AIDC Lightbox — Higgsfield panel 1:1 (AIDC colors)
   ========================================================= */

:root{
  --aidc-primary-grad: linear-gradient(90deg, #ff2ea6, #ff5fc0);
  --aidc-panel-w: 420px;
  --aidc-radius: 16px;
}

.aidc-lb__nav{
  pointer-events: auto !important;
  z-index: 5 !important;
}

.aidc-lb__shell{
  grid-template-columns: minmax(0,1fr) var(--aidc-panel-w) !important;
}

/* WebApp: the right panel is hidden; force a single-column shell grid.
   This rule must appear AFTER the generic .aidc-lb__shell panel layout above. */
.aidc-lb--webapp .aidc-lb__shell{
  grid-template-columns: minmax(0, 1fr) !important;
}

.aidc-lb__panel{
  grid-template-rows: auto auto 1fr auto !important;
  min-height: 0 !important;
}

.aidc-lb__pbody{
  overflow: hidden !important;
  min-height: 0 !important;
}
.aidc-lb__content{
  overflow-y: auto !important;
  overflow-x: hidden !important;
  min-height: 0 !important;
  padding: 12px 12px 14px !important;
}

.aidc-lb__phead{
  padding: 14px 14px 10px !important;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.aidc-lb__role{
  font-size: 11px;
  color: rgba(255,255,255,.58);
}

.aidc-lb__tabs{
  padding: 10px 14px 12px !important;
  gap: 10px !important;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.aidc-lb__tab{
  height: 40px !important;
  border-radius: 999px !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  font-size: 12px !important;
}

.aidc-lb__section{
  border-radius: var(--aidc-radius) !important;
  padding: 12px !important;
  margin-bottom: 10px !important;
}
.aidc-lb__sectionTitle{
  margin: 0 0 10px;
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: rgba(255,255,255,.62);
}

.aidc-lb__mono{
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 12px;
  line-height: 1.5;
  color: rgba(255,255,255,.78);
  max-height: 240px;
  overflow: auto;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,.10);
  background: rgba(0,0,0,.22);
  padding: 10px;
}

.aidc-lb__actions{
  position: sticky !important;
  bottom: 0 !important;
  padding: 14px !important;
  border-top: 1px solid rgba(255,255,255,.08) !important;
  background: linear-gradient(to bottom, rgba(10,12,18,0), rgba(10,12,18,.96) 35%) !important;
  backdrop-filter: blur(10px);
}

.aidc-lb__primary{
  min-height: 50px !important;
  border-radius: 14px !important;
  font-weight: 800 !important;
  letter-spacing: .02em !important;
  color: rgba(10,10,16,.92) !important;
  background: var(--aidc-primary-grad) !important;
}
.aidc-lb__primary:hover{ filter: brightness(1.04); }

.aidc-lb__mode{
  margin-top: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.aidc-lb__mode-btn{
  min-height: 44px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.04);
  color: rgba(255,255,255,.86);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
}
.aidc-lb__mode-btn:hover{
  border-color: rgba(255,255,255,.22);
  background: rgba(255,255,255,.08);
}

/* Favorite (star) button styling */
.aidc-lb__mode-btn[data-act="favorite"] .aidc-lb__btn-icon {
  --lb-icon: url('/assets/icons/star.svg');
}
.aidc-lb__mode-btn[data-act="favorite"] .aidc-lb__btn-icon{
  /* default star color */
  background-color: var(--icon-color);
}
.aidc-lb__mode-btn[data-act="favorite"].is-on .aidc-lb__btn-icon{
  background-color: #FFD166; /* warm yellow */
}
.aidc-lb__mode-btn[data-act="favorite"].is-on{
  /* subtle left stripe to highlight selected favorite */
  box-shadow: inset 6px 0 0 0 rgba(255,209,102,1);
  border-color: rgba(255,209,102,.36);
}

/* ── Local CSS tooltip for Canvas button ──
   Uses ::after pseudo-element instead of global position:fixed tooltip
   to avoid zoom/stacking-context positioning issues inside lightbox. */
.aidc-lb__canvas-tip{
  position: relative;
}
.aidc-lb__canvas-tip::after{
  content: attr(data-canvas-tip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 14px;
  border-radius: 10px;
  background: rgba(24,26,32,.94);
  border: 1px solid rgba(255,255,255,.10);
  color: rgba(255,255,255,.88);
  font-size: 13px;
  line-height: 1.35;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity .15s ease;
  z-index: 10;
}
.aidc-lb__canvas-tip:hover::after{
  opacity: 1;
}

.aidc-lb__grid{
  margin-top: 0 !important;
  gap: 10px !important;
}
.aidc-lb__btn{
  min-height: 44px !important;
  border-radius: 14px !important;
}

.aidc-lb__empty{
  color: rgba(255,255,255,.58);
  font-size: 13px;
  padding: 6px 2px;
}

.aidc-lb__iconbtn{
  color: var(--icon-color);
  border-color: rgba(255,255,255,.16);
  background: rgba(255,255,255,.04);
}

/* ===== Pins / Comments overlay ===== */
.aidc-lb__pinwrap{
  position: relative;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  overflow: hidden;
  /* Clip zoomed content */
  contain: paint;
}
/* FIX: CSS display:grid overrides HTML hidden attribute;
   ensure pinwrap is truly hidden when JS sets hidden=true (audio mode). */
.aidc-lb__pinwrap[hidden]{
  display: none !important;
}

.aidc-lb__pinsLayer{
  position: absolute;
  inset: 0;
  pointer-events: none; /* pins turn on pointer-events themselves */
  will-change: transform;
  z-index: 6; /* FIX: pins must be above preview image */
}

.aidc-lb__pin{
  position: absolute;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  border: 2px solid rgba(255,255,255,.85);
  background: rgba(125,255,90,.95);
  background-size: cover;
  background-position: center;
  box-shadow: 0 10px 30px rgba(0,0,0,.35);
  cursor: pointer;
  color: rgba(255,255,255,.9);
  font-size: 12px;
  display:grid;
  place-items:center;
}
.aidc-lb__pin::after{
  content: "";
  position: absolute;
  inset: -8px;
  margin: auto;
  width: 16px;
  height: 16px;
  background-color: var(--icon-color);
  mask: url("/assets/icons/ui/lb-comment.svg") center / contain no-repeat;
  -webkit-mask: url("/assets/icons/ui/lb-comment.svg") center / contain no-repeat;
  opacity: 0;
  transition: opacity 160ms ease;
}
.aidc-lb__pin:hover::after,
.aidc-lb__pin:focus-visible::after{
  opacity: 1;
}
.aidc-lb__pin.is-active{
  background: var(--aidc-accent);
  outline: 2px solid rgba(255,255,255,.8);
  outline-offset: 2px;
  box-shadow: 0 0 0 8px rgba(255,46,166,.18), 0 10px 30px rgba(0,0,0,.35);
}
.aidc-lb__pin.is-dragging{
  cursor: grabbing;
  transform: translate(-50%, -50%) scale(1.08);
}

.aidc-lb__popover{
  position: fixed;
  width: 320px;
  max-width: calc(100vw - 24px);
  border-radius: 16px;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(10,12,18,.86);
  backdrop-filter: blur(14px);
  box-shadow: 0 18px 70px rgba(0,0,0,.6);
  z-index: 1000005;
  overflow: hidden;
}

.aidc-lb__popoverHead{
  display:flex;
  align-items:center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255,255,255,.10);
  color: rgba(255,255,255,.9);
}
.aidc-lb__popoverLeft{
  display:flex;
  align-items:center;
  gap: 8px;
}
.aidc-lb__popoverAva{
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: rgba(255,255,255,.08);
  display:grid;
  place-items:center;
  font-size: 11px;
  color: rgba(255,255,255,.85);
  background-size: cover;
  background-position: center;
}
.aidc-lb__popoverActions{
  display:flex;
  align-items:center;
  gap: 6px;
}
.aidc-lb__popoverDelete{
  width: 30px;
  height: 30px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.06);
  cursor: pointer;
  display:grid;
  place-items:center;
  --icon-color: rgba(255,255,255,.9);
}
.aidc-lb__popoverDelete:hover{
  border-color: rgba(255,59,59,.55);
  box-shadow: 0 0 0 4px rgba(255,59,59,.15);
  --icon-color: #ff3b3b;
}
.aidc-lb__popoverClose{
  width: 32px;
  height: 32px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.06);
  color: rgba(255,255,255,.9);
  cursor: pointer;
}

.aidc-lb__popoverBody{
  max-height: 220px;
  overflow: auto;
  padding: 10px 12px;
}

.aidc-lb__popoverInput{
  display:flex;
  gap: 10px;
  padding: 10px 12px 12px;
  border-top: 1px solid rgba(255,255,255,.10);
}
.aidc-lb__popoverInput textarea{
  flex:1;
  min-height: 42px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(0,0,0,.25);
  color: rgba(255,255,255,.9);
  padding: 8px 12px;
  resize: none;
}
.aidc-lb__send{
  width: 40px;
  height: 38px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.06);
  color: rgba(255,255,255,.9);
  cursor:pointer;
}

.aidc-lb__msg{ display:flex; gap:10px; padding: 8px 0; }
.aidc-lb__msgAva{
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: rgba(255,255,255,.08);
  overflow:hidden;
  flex: 0 0 auto;
}
.aidc-lb__msgAva img{ width:100%; height:100%; object-fit: cover; }
.aidc-lb__msgMeta{ font-size: 12px; color: rgba(255,255,255,.72); display:flex; gap:8px; align-items: baseline; }
.aidc-lb__msgMeta span{ color: rgba(255,255,255,.45); font-size: 11px; }
.aidc-lb__msgText{ color: rgba(255,255,255,.86); font-size: 13px; line-height: 1.35; margin-top: 2px; }
.aidc-lb__msgDelete{
  margin-left: auto;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.06);
  color: rgba(255,255,255,.8);
  cursor: pointer;
  display:grid;
  place-items:center;
  --icon-color: rgba(255,255,255,.8);
}
.aidc-lb__msgDelete:hover{
  border-color: rgba(255,46,166,.45);
  box-shadow: 0 0 0 4px rgba(255,46,166,.10);
  --icon-color: #ff3b3b;
}
.aidc-lb__popoverActions .aidc-lb__btn-icon,
.aidc-lb__msgDelete .aidc-lb__btn-icon{
  width: 16px;
  height: 16px;
  display: inline-block;
  background-color: var(--icon-color, rgba(255,255,255,.85));
  -webkit-mask: var(--lb-icon) center / contain no-repeat;
  mask: var(--lb-icon) center / contain no-repeat;
}

.aidc-lb__threads{ display:flex; flex-direction: column; gap: 8px; }
.aidc-lb__thread{
  width: 100%;
  text-align: left;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,.10);
  background: rgba(255,255,255,.04);
  padding: 10px 12px;
  display:flex;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
}
.aidc-lb__threadStack{
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,.08);
  background: rgba(0,0,0,.18);
  padding: 10px 12px;
  margin: 6px 0 10px;
}
.aidc-lb__threadMsg{
  font-size: 12px;
  color: rgba(255,255,255,.78);
  padding: 6px 0;
}
.aidc-lb__threadMsg span{
  color: rgba(255,255,255,.5);
  font-size: 11px;
  margin-left: 6px;
}
.aidc-lb__threadBody{
  color: rgba(255,255,255,.9);
  margin-top: 4px;
}
.aidc-lb__threadActions{
  display:flex;
  justify-content: flex-end;
  margin-top: 6px;
}
.aidc-lb__threadToggle{
  border: 0;
  background: transparent;
  color: rgba(255,255,255,.65);
  font-size: 12px;
  cursor: pointer;
}
.aidc-lb__threadToggle:hover{
  color: rgba(255,255,255,.95);
}
.aidc-lb__thread.is-active{
  border-color: rgba(255,46,166,.45);
  box-shadow: 0 0 0 6px rgba(255,46,166,.12);
}
.aidc-lb__threadTop{ display:flex; gap: 10px; align-items:center; min-width: 0; }
.aidc-lb__dot{ width: 10px; height: 10px; border-radius: 999px; background: rgba(125,255,90,.95); border: 2px solid rgba(255,255,255,.85); }
.aidc-lb__threadTxt{ color: rgba(255,255,255,.86); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.aidc-lb__threadMeta{ color: rgba(255,255,255,.55); font-size: 12px; flex: 0 0 auto; }

.aidc-lb__hint{ margin-top: 10px; color: rgba(255,255,255,.45); font-size: 12px; }

/* ===== Stateful media renderer ===== */
.aidc-media-box{
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 100%;
  max-height: 100%;
  width: 100%;
  height: 100%;
  border-radius: 16px;
  overflow: hidden;
  /* Clip transformed children (zoom) within this container */
  contain: paint;
  box-shadow: none; /* Removed glow/shadow */
  background: transparent;
  box-sizing: border-box;
  aspect-ratio: var(--aidc-media-ratio, 16 / 9);
  transition: none !important;
  will-change: auto;
}
.aidc-media-thumb,
.aidc-media-preview,
.aidc-media-blur,
.aidc-media-video{
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.aidc-media-video{
  /* FIX: video fills its box but starts hidden (JS controls visibility).
     display is NOT set here — ensureDOM sets hidden=true + display:none,
     and render() video branch reveals it when needed. */
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 5;
  pointer-events: auto;
  object-fit: contain;
}
.aidc-media-thumb{
  z-index: 1;
  opacity: 1;
  transition: opacity 200ms ease;
}
.aidc-media-thumb.is-hidden{
  opacity: 0;
}
.aidc-media-blur{
  /* Simple semi-transparent overlay during loading - NO blur effect */
  display: none; /* Hide blur layer completely - use simple overlay instead */
}
.aidc-media-blur.is-active{
  display: none;
}
/* Loading overlay - simple dark semi-transparent layer */
.aidc-media-box::before{
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 2;
  opacity: 0;
  transition: opacity 200ms ease;
  pointer-events: none;
}
.aidc-media-box.is-loading::before{
  opacity: 1;
}
.aidc-media-preview{
  opacity: 0;
  transition: opacity 220ms ease;
  z-index: 3;
}
.aidc-media-preview.is-ready{
  opacity: 1;
}
.aidc-media-loader{
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: rgba(255,255,255,.85);
  /* Default: do not cover media (thumb) with a dark blanket. */
  background: transparent;
  z-index: 5;
  pointer-events: none; /* Allow clicks through loader */
}
.aidc-media-loader[hidden]{
  display: none !important;
}
.aidc-media-loader:not(.is-soft){
  /* When needed (pre-thumb), JS may keep loader without .is-soft. */
  background: rgba(12,6,10,0.35);
}
.aidc-media-loader.is-soft{
  background: transparent;
  pointer-events: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
.aidc-media-loader.is-soft .aidc-media-spinner{
  width: 28px;
  height: 28px;
  border-width: 2px;
}
.aidc-media-loader.is-soft .aidc-media-loader-text{
  opacity: 0;
}
.aidc-media-spinner{
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.1);
  border-top-color: #ff3ba6;
  animation: aidc-media-spin 0.9s linear infinite;
}
.aidc-media-loader-text{
  font-size: 12px;
  color: rgba(255,255,255,.9);
}
.aidc-media-error{
  position: absolute;
  left: 12%;
  right: 12%;
  bottom: 14%;
  text-align: center;
  color: rgba(255,255,255,.7);
  font-size: 12px;
  z-index: 6;
}
.aidc-media-box .aidc-lb__pinwrap{
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
}
.aidc-media-box .aidc-lb__img{
  border-radius: 0;
  box-shadow: none;
}
/* FIX: preview inside media-box must stay stretched to fill the box,
   NOT inherit width:auto/height:auto from desktop .aidc-lb__img rule.
   Without this, switching thumb→preview visually shrinks the image on
   laptops because max-width:calc(100vw-420px-48px) clips the preview. */
.aidc-media-box .aidc-media-preview.aidc-lb__img{
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  max-width: 100% !important;
  max-height: 100% !important;
  object-fit: contain;
}

/* ===== WebApp (Telegram) media box overrides ===== */
html.tg .aidc-lb{
  /* Ensure fixed positioning works in TG WebApp */
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  width: 100dvw !important;
  height: 100vh !important;
  height: 100dvh !important;
  min-width: 100vw !important;
  min-height: 100vh !important;
}
html.tg .aidc-lb__shell{
  width: 100% !important;
  height: 100% !important;
  grid-template-columns: 1fr !important;
  grid-template-rows: 1fr auto !important;
}
html.tg .aidc-lb__main{
  width: 100% !important;
  height: 100% !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  border: none !important;
  background: #000 !important;
}
html.tg .aidc-lb__media{
  /* Media container - centers the image */
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: 100% !important;
  height: 100% !important;
  padding: 0 !important;
  margin: 0 !important;
  background: #000;
  overflow: hidden !important;
  box-sizing: border-box !important;
}
html.tg .aidc-media-box{
  /* Box fills available space */
  position: relative !important;
  width: 100% !important;
  height: 100% !important;
  max-width: 100% !important;
  max-height: 100% !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  background: transparent !important;
  overflow: hidden !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}

/* TG fullscreen fixes */
html.tg .aidc-lb__shell{
  padding: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
}
html.tg .aidc-lb__main{
  border: 0 !important;
  border-radius: 0 !important;
  background: #000 !important;
}
html.tg .aidc-lb__media{
  width: 100% !important;
  height: 100% !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  overflow: hidden !important;
}
html.tg .aidc-media-box{
  position: relative !important;
  width: 100% !important;
  height: 100% !important;
  max-width: 100% !important;
  max-height: 100% !important;
  aspect-ratio: var(--aidc-media-ratio, 16/9);
  display: grid !important;
  place-items: center !important;
  overflow: hidden !important;
}
/* TG video: base layout rules WITHOUT display/z-index overrides.
   display and z-index are set only inside .is-video scope below,
   so that JS resetVideo(dom) can hide the <video> element via
   inline style.display = 'none' when item is an image. */
html.tg video.aidc-media-video,
html.tg .aidc-lb__video{
  position: absolute !important;
  inset: 0 !important;
  width: 100% !important;
  height: 100% !important;
  min-width: 100% !important;
  min-height: 100% !important;
  max-width: 100% !important;
  max-height: 100% !important;
  object-fit: contain !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  /* No display/z-index here — see .is-video block below */
}
/* Images in TG: fill container while keeping aspect ratio */
html.tg .aidc-media-thumb{
  position: relative !important;
  width: 100% !important;
  height: 100% !important;
  max-width: 100% !important;
  max-height: 100% !important;
  object-fit: contain !important;
  display: block !important;
  z-index: 1;
}
html.tg .aidc-media-preview{
  position: absolute !important;
  inset: 0 !important;
  width: 100% !important;
  height: 100% !important;
  object-fit: contain !important;
  display: block !important;
  z-index: 3;
  opacity: 0;
  transition: opacity 200ms ease;
}
html.tg .aidc-media-preview.is-ready{
  opacity: 1;
}
html.tg .aidc-media-blur{
  display: none !important;
}
html.tg .aidc-media-box::before{
  display: none !important;
}
/* Pinwrap in TG should also fill container */
html.tg .aidc-lb__pinwrap{
  position: absolute !important;
  inset: 0 !important;
  width: 100% !important;
  height: 100% !important;
}
/* Ensure .aidc-lb__img in TG context also fills */
html.tg .aidc-lb__img{
  width: 100% !important;
  height: 100% !important;
  max-width: 100% !important;
  max-height: 100% !important;
  object-fit: contain !important;
  border-radius: 0 !important;
  box-shadow: none !important;
}

/* TG Video mode: ensure media box fills the screen */
html.tg .aidc-lb.is-video .aidc-media-box,
html.tg .aidc-lb--webapp.is-video .aidc-media-box{
  position: relative !important;
  width: 100% !important;
  height: 100% !important;
  min-width: 100% !important;
  min-height: 100% !important;
  max-width: 100% !important;
  max-height: 100% !important;
  aspect-ratio: unset !important; /* Let video element control aspect ratio via object-fit */
}
html.tg .aidc-lb.is-video .aidc-media-video,
html.tg .aidc-lb--webapp.is-video .aidc-media-video{
  position: absolute !important;
  inset: 0 !important;
  width: 100% !important;
  height: 100% !important;
  min-width: 100% !important;
  min-height: 100% !important;
  object-fit: contain !important;
  /* Show video ONLY in video-mode — keeps JS resetVideo() effective for images */
  display: block !important;
  z-index: 5 !important;
}

/* TG Video mode: поднять панель кнопок выше тулбара управления видео */
html.tg .aidc-lb.is-video .aidc-lb__wabottom,
html.tg .aidc-lb--webapp.is-video .aidc-lb__wabottom{
  bottom: calc(56px + env(safe-area-inset-bottom)) !important;
}

/* Hide extra UI elements in TG that create gray bars */
html.tg .aidc-lb__tags{
  display: none !important;
}
html.tg .aidc-lb__header{
  display: none !important;
}
html.tg .aidc-media-loader{
  background: transparent !important;
}

/* Fix blur bleeding outside image in desktop browser too */
.aidc-media-box{
  overflow: hidden !important;
  contain: paint !important;
}

@keyframes aidc-media-spin{
  to{ transform: rotate(360deg); }
}

/* FINAL: Ensure zoom clipping and panel stacking take precedence.
   Some layouts in this file define multiple variants; browsers or
   external styles may accidentally override the intended stacking.
   These final rules are intentionally specific and use !important
   only where necessary to guarantee the panel stays above zoomed media.
*/
.aidc-lb__zoomHost{
  overflow: hidden !important;
  position: relative !important;
  box-sizing: border-box !important;
  isolation: isolate !important;
  z-index: 1 !important; /* keep zoom host below panel */
}

.aidc-lb__main,
.aidc-lb__media,
.aidc-media-box,
.aidc-lb__pinwrap{
  overflow: hidden !important;
  contain: paint !important;
  z-index: 1 !important;
}

/* Force panel above all transformed/zoomed content */
.aidc-lb__panel{
  z-index: 1000010 !important;
  position: relative !important;
  isolation: isolate !important;
  /* Ensure panel remains interactive and visible when image is zoomed */
  pointer-events: auto !important;
  opacity: 1 !important;
}

/* ===== Mobile browser (non-TG): fullscreen layout for small screens ===== */
/* Mirrors html.tg rules so mobile Chrome/Safari behaves like TG WebApp */
@media (max-width: 600px) {
  .aidc-lb{
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    width: 100dvw !important;
    height: 100vh !important;
    height: 100dvh !important;
  }
  .aidc-lb__shell{
    width: 100% !important;
    height: 100% !important;
    padding: 0 !important;
    border: 0 !important;
    border-radius: 0 !important;
    background: #000 !important;
    grid-template-columns: 1fr !important;
    grid-template-rows: 1fr auto !important;
    gap: 0 !important;
  }
  .aidc-lb__main{
    width: 100% !important;
    height: 100% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    border: none !important;
    border-radius: 0 !important;
    background: #000 !important;
  }
  .aidc-lb__media{
    width: 100% !important;
    height: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: hidden !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    box-sizing: border-box !important;
  }
  .aidc-media-box{
    position: relative !important;
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    background: transparent !important;
    overflow: hidden !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
  }
  .aidc-media-preview,
  .aidc-lb__img{
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
    object-fit: contain !important;
    border-radius: 0 !important;
    box-shadow: none !important;
  }
  .aidc-lb__panel{
    /* On mobile, panel (tabs/actions) slides in as bottom sheet */
    grid-row: 2 !important;
    width: 100% !important;
    height: auto !important;
    max-height: 55vh !important;
    border-radius: 16px 16px 0 0 !important;
    border: none !important;
    border-top: 1px solid rgba(255,255,255,.10) !important;
    overflow-y: auto !important;
  }
  .aidc-lb__backdrop{
    background: rgba(0,0,0,.88) !important;
  }
  /* Hide desktop nav arrows on mobile — swipe is used instead */
  .aidc-lb__nav{
    display: none !important;
  }
  /* Keep close button accessible */
  .aidc-lb__close{
    position: fixed !important;
    top: max(14px, env(safe-area-inset-top, 14px)) !important;
    right: 14px !important;
    z-index: 1000020 !important;
  }
}
