/* ---------- Study: images, tables, context bar, notice, drag-to-move ---------- */

/* ----- images ----- */
.study-img {
  position: relative;
  display: block;
  width: fit-content;
  max-width: 100%;
  margin: 0.6em 0;
  line-height: 0;
}

.study-img[data-align="center"] {
  margin-left: auto;
  margin-right: auto;
}

.study-img[data-align="right"] {
  margin-left: auto;
}

.study-img img {
  display: block;
  max-width: 100%;
  height: auto;
  min-height: 24px;
  border-radius: 6px;
  cursor: pointer;
}

.study-img.is-selected img {
  outline: 2px solid var(--green);
  outline-offset: 2px;
}

.study-img.is-uploading img {
  opacity: 0.5;
}

.study-img__badge {
  position: absolute;
  left: 8px;
  bottom: 8px;
  padding: 3px 8px;
  font-size: 0.75rem;
  line-height: 1.3;
  color: var(--text);
  background: rgba(3, 4, 9, 0.85);
  border: 1px solid var(--border);
  border-radius: 999px;
  pointer-events: none;
}

.study-img__badge:empty {
  display: none;
}

.study-img.is-missing {
  min-width: 220px;
  min-height: 70px;
  background: rgba(255, 107, 142, 0.08);
  border: 1px dashed var(--red);
  border-radius: 6px;
}

.study-img.is-missing .study-img__badge {
  left: 50%;
  top: 50%;
  bottom: auto;
  transform: translate(-50%, -50%);
  white-space: nowrap;
}

/* corner resize handle (bottom-right), only while selected */
.study-img__handle {
  position: absolute;
  right: -7px;
  bottom: -7px;
  display: none;
  width: 16px;
  height: 16px;
  background: var(--green);
  border: 2px solid var(--bg);
  border-radius: 5px;
  cursor: nwse-resize;
  touch-action: none;
}

.study-img.is-selected .study-img__handle {
  display: block;
}

/* ----- context bar (image / table) ----- */
.study-ctx {
  flex-basis: 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
  padding-top: 6px;
  border-top: 1px dashed var(--border);
}

.study-ctx[hidden] {
  display: none;
}

.study-ctx__btn {
  padding: 4px 10px;
  font: inherit;
  font-size: 0.78rem;
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
}

.study-ctx__btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.study-ctx__btn.is-active {
  color: var(--green);
  border-color: rgba(61, 255, 180, 0.45);
  background: rgba(61, 255, 180, 0.12);
}

.study-ctx__btn.is-danger {
  color: var(--red);
}

/* ----- tables ----- */
.study-prose .tableWrapper {
  overflow-x: auto;
  margin: 0.8em 0;
}

.study-prose table {
  width: 100%;
  margin: 0;
  border-collapse: collapse;
  table-layout: fixed;
}

.study-prose th,
.study-prose td {
  position: relative;
  min-width: 60px;
  padding: 7px 10px;
  text-align: left;
  vertical-align: top;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.study-prose th {
  font-weight: 600;
  background: rgba(61, 255, 180, 0.1);
}

.study-prose th > p,
.study-prose td > p {
  margin: 0;
}

.study-prose .selectedCell::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(61, 255, 180, 0.18);
  pointer-events: none;
}

.study-prose .column-resize-handle {
  position: absolute;
  top: 0;
  right: -2px;
  bottom: -2px;
  width: 4px;
  background: var(--green);
  pointer-events: none;
}

.study-prose.resize-cursor {
  cursor: col-resize;
}

/* ----- upload / error banner ----- */
.study-notice {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px var(--space-4);
  font-size: 0.85rem;
  color: var(--red);
  background: rgba(255, 107, 142, 0.1);
  border-bottom: 1px solid rgba(255, 107, 142, 0.35);
}

.study-notice[hidden] {
  display: none;
}

.study-notice span {
  flex: 1;
}

.study-notice button {
  padding: 0 6px;
  font-size: 1.1rem;
  line-height: 1;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}

/* ----- drag a note onto a folder ----- */
.st-note.is-dragging {
  opacity: 0.4;
}

.st-row.is-drop {
  background: rgba(61, 255, 180, 0.14);
  border-color: var(--green);
}

.study-tree.is-drop-root {
  outline: 1px dashed var(--green);
  outline-offset: -3px;
}

.st-menu__item:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ----- YouTube videos ----- */
.study-video {
  position: relative;
  display: block;
  width: fit-content;
  max-width: 100%;
  margin: 0.8em 0;
}

.study-video[data-align="center"] {
  margin-left: auto;
  margin-right: auto;
}

.study-video[data-align="right"] {
  margin-left: auto;
}

.study-video__frame {
  position: relative;
  max-width: 100%;
  aspect-ratio: 16 / 9; /* always 16:9, whatever the width */
  background: #000;
  border-radius: 8px;
  overflow: visible;
}

.study-video__frame iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  border-radius: 8px;
}

/* Until the block is selected, a transparent shield catches the first click
   so it selects the video (handle + options) instead of starting playback. */
.study-video__shield {
  position: absolute;
  inset: 0;
  border-radius: 8px;
  cursor: pointer;
}

.study-video.is-selected .study-video__shield {
  display: none;
}

.study-video.is-selected .study-video__frame {
  outline: 2px solid var(--green);
  outline-offset: 2px;
}

.study-video__handle {
  position: absolute;
  right: -7px;
  bottom: -7px;
  z-index: 2;
  display: none;
  width: 16px;
  height: 16px;
  background: var(--green);
  border: 2px solid var(--bg);
  border-radius: 5px;
  cursor: nwse-resize;
  touch-action: none;
}

.study-video.is-selected .study-video__handle {
  display: block;
}

/* only visible when printing (see study-print.css) */
.study-video__print {
  display: none;
}

.study-videopop {
  flex-direction: column;
  gap: 6px;
  max-width: min(480px, calc(100vw - 16px));
}

.study-videopop__row {
  display: flex;
  gap: 4px;
}

.study-videopop__row input {
  flex: 1;
  min-width: 0;
  width: 280px;
}

.study-videopop__err {
  margin: 0;
  max-width: 440px;
  font-size: 0.78rem;
  line-height: 1.4;
  color: var(--red);
}

.study-videopop__err[hidden] {
  display: none;
}

.study-video.is-resizing iframe {
  pointer-events: none;
}
