.tviframe {
  --tviframe-width: 100%;
  --tviframe-max-width: 1200px;
  --tviframe-min-width: 0;
  --tviframe-align: center;
  --tviframe-bg: transparent;
  --tviframe-border-width: 0px;
  --tviframe-border-color: #c9c9c9;
  --tviframe-radius: 0;
  --tviframe-head-bg: #123f65;
  --tviframe-head-color: #fff;
  --tviframe-head-height: 48px;
  --tviframe-overlay-color: #000000;
  --tviframe-overlay-opacity: 0;
  --tviframe-overlay-blur: 0px;
  --tviframe-shadow: 0 16px 44px rgba(0,0,0,.18);
  position: relative;
  width: min(var(--tviframe-width), 100%);
  max-width: var(--tviframe-max-width);
  min-width: var(--tviframe-min-width);
  margin-left: auto;
  margin-right: auto;
  box-sizing: border-box;
}

.tviframe-shell {
  position: relative;
  z-index: 2;
  overflow: hidden;
  background: var(--tviframe-bg);
  border: var(--tviframe-border-width) solid var(--tviframe-border-color);
  border-radius: var(--tviframe-radius);
  box-sizing: border-box;
  box-shadow: var(--tviframe-shadow);
}


/* Inline: draw the decorative frame on the outer tviframe container itself.
   This keeps the border visible independently of iframe sizing/content. */
.tviframe-mode-inline {
  background: var(--tviframe-bg);
  border: var(--tviframe-border-width) solid var(--tviframe-border-color);
  border-radius: var(--tviframe-radius);
  box-shadow: var(--tviframe-shadow);
  overflow: hidden;
}
.tviframe-mode-inline .tviframe-shell {
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: transparent;
}

.tviframe-frame {
  display: block;
  width: 100%;
  min-height: 1px;
  border: 0;
  background: transparent;
}

.tviframe-head {
  position: relative;
  display: grid;
  grid-template-columns: minmax(80px,1fr) minmax(0,2fr) minmax(80px,1fr);
  align-items: center;
  min-height: var(--tviframe-head-height);
  background: var(--tviframe-head-bg);
  color: var(--tviframe-head-color);
  padding: 0 8px;
  box-sizing: border-box;
}

.tviframe-head-actions { display:flex; gap:4px; align-items:center; }
.tviframe-head-left { justify-content:flex-start; }
.tviframe-head-right { justify-content:flex-end; }
.tviframe-head-title { font-weight:600; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; padding:0 8px; }
.tviframe-title-left { text-align:left; }
.tviframe-title-center { text-align:center; }
.tviframe-title-right { text-align:right; }

.tviframe-head-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: inherit;
  min-width: 34px;
  height: 34px;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  font-size: 18px;
  line-height: 1;
}
.tviframe-head-btn:hover,
.tviframe-head-btn:focus-visible { background: rgba(255,255,255,.16); outline:none; }

.tviframe-overlay { display:none; }

html.tviframe-scroll-locked,
body.tviframe-scroll-locked {
  overflow: hidden !important;
  overscroll-behavior: none;
}

.tviframe-mode-modal,
.tviframe-mode-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 10000;
  width: 100%;
  max-width: none;
  min-width: 0;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  box-sizing: border-box;
  overscroll-behavior: contain;
}
.tviframe-mode-modal .tviframe-overlay,
.tviframe-mode-fullscreen .tviframe-overlay {
  display:block;
  position:absolute;
  inset:0;
  z-index:1;
  background: transparent;
  backdrop-filter: blur(var(--tviframe-overlay-blur));
  -webkit-backdrop-filter: blur(var(--tviframe-overlay-blur));
}
.tviframe-mode-modal .tviframe-overlay::before,
.tviframe-mode-fullscreen .tviframe-overlay::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--tviframe-overlay-color);
  opacity: var(--tviframe-overlay-opacity);
  pointer-events: none;
}

/* Modal: viewport is the outer limit. The iframe gets the scroll, never Grav. */
.tviframe-mode-modal .tviframe-shell {
  display:flex;
  flex-direction:column;
  width: min(var(--tviframe-width), 100%);
  max-width: var(--tviframe-max-width);
  max-height: calc(100dvh - 48px);
  overflow:hidden;
}
.tviframe-mode-modal .tviframe-head { flex: 0 0 auto; }
.tviframe-mode-modal .tviframe-frame {
  flex: 1 1 auto;
  min-height: 0;
  max-height: calc(100dvh - 48px - var(--tviframe-head-height));
}
.tviframe-mode-modal[data-autoheight="1"] .tviframe-shell {
  height: auto;
}
.tviframe-mode-modal[data-autoheight="1"] .tviframe-frame {
  flex: 0 0 auto;
  height: min(70dvh, 700px);
}

/* Fullscreen always owns the viewport and scrolls inside the iframe. */
.tviframe-mode-fullscreen { padding:0; }
.tviframe-mode-fullscreen .tviframe-shell {
  display:flex;
  flex-direction:column;
  width:100%;
  max-width:none;
  height:100dvh;
  max-height:100dvh;
  border-radius:0;
  overflow:hidden;
}
.tviframe-mode-fullscreen .tviframe-head { flex:0 0 auto; }
.tviframe-mode-fullscreen .tviframe-frame {
  flex:1 1 auto;
  min-height:0;
  height:auto !important;
  max-height:calc(100dvh - var(--tviframe-head-height));
}
.tviframe-closed { display:none !important; }
.tviframe-error { padding:12px 16px; border:1px solid #b42318; background:#fef3f2; color:#7a271a; border-radius:6px; }

@media (max-width: 640px) {
  .tviframe-mode-modal { padding:8px; }
  .tviframe-head { grid-template-columns:minmax(64px,auto) minmax(0,1fr) minmax(64px,auto); }
}

.tviframe-debug { margin-top:10px; }
.tviframe-debug summary { cursor:pointer; font-weight:600; }
.tviframe-debug pre { white-space:pre-wrap; overflow:auto; margin:.5rem 0 0; font-size:.9em; }


/* tviframe 0.1.11 – horizontal alignment for inline containers. */
.tviframe-mode-inline[data-align="left"] { margin-left:0; margin-right:auto; }
.tviframe-mode-inline[data-align="center"] { margin-left:auto; margin-right:auto; }
.tviframe-mode-inline[data-align="right"] { margin-left:auto; margin-right:0; }
