/* How carrying attachments by hand looks. The behaviour is in ./AttachmentDragDrop.js. */

/* Shared attachment preview tiles used by the main UI and the shop. */
.attachment-preview {
    position: relative;
    width: 60px;
    height: 60px;
    border-radius: 8px;
    background-color: var(--input-bg);
    border: 3px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.attachment-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    display: block;
}

.attachment-preview video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    display: block;
    background: #000;
}

.attachment-preview .video-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.attachment-preview .video-overlay .play-button {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
}

.attachment-preview .video-overlay .play-button::before {
    content: '';
    width: 0;
    height: 0;
    border-top: 7px solid transparent;
    border-bottom: 7px solid transparent;
    border-left: 11px solid rgba(255, 255, 255, 0.9);
    transform: translateX(1px);
}

.attachment-preview a {
    display: flex;
    width: 100%;
    height: 100%;
    align-items: center;
    justify-content: center;
    text-align: center;
    word-break: break-all;
    font-size: 0.7em;
}

.attachment-preview .remove-attachment {
    position: absolute;
    top: 4px;
    right: 4px;
    background: rgba(0, 0, 0, 0.5);
    border: none;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    padding: 0;
    /* Draw the cross so it stays vertically centered regardless of the active font. */
    font-size: 0;
    line-height: 0;
}

.attachment-preview .remove-attachment::before,
.attachment-preview .remove-attachment::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 9px;
    height: 2px;
    background-color: currentColor;
}

.attachment-preview .remove-attachment::before {
    transform: translate(-50%, -50%) rotate(45deg);
}

.attachment-preview .remove-attachment::after {
    transform: translate(-50%, -50%) rotate(-45deg);
}

.attachment-preview .remove-attachment:hover {
    background: rgba(0, 0, 0, 0.7);
}

/* An attachment that can be picked up says so under the pointer. */
[data-tnx-attachment-source] [draggable="true"],
[data-tnx-attachment-draggable="1"] {
    cursor: grab;
}

[data-tnx-attachment-source] [draggable="true"]:active,
[data-tnx-attachment-draggable="1"]:active {
    cursor: grabbing;
}

/* Picked out with CTRL, and waiting to travel with the others. */
.is-tnx-attachment-selected {
    outline: 2px solid var(--primary-color);
    outline-offset: 1px;
}

/* On its way somewhere. */
.is-tnx-attachment-group-dragging {
    opacity: 0.45;
}

/* A place that would take what is being carried. */
.is-tnx-attachment-drop-active {
    outline: 2px dashed var(--primary-color);
    outline-offset: -2px;
    background-color: color-mix(in srgb, var(--primary-color) 12%, transparent);
}

/* Where carried attachments would land: one empty outline per attachment, in the strip above the
   input, so their places are already drawn before the drop. It borrows the size and the rounding
   of a real tile from the page it is on and only trades the filling for an outline. */
.attachment-preview.is-tnx-attachment-drop-placeholder {
    background-color: transparent;
    border-style: dashed;
    border-color: var(--link-color);
    pointer-events: none;
}

/* Shared entry and table attachment areas. */
  .drop-area {
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    padding: 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background-color: var(--input-bg);
  }

  .drop-area:hover:not(.highlight):not(.invalid-drag) {
    border-color: var(--primary-color);
    background-color: var(--bg-color);
  }

  .drop-area.highlight {
    border-color: var(--primary-color);
    background-color: var(--bg-color);
  }

  .drop-area.invalid-drag,
  .drop-area.invalid-drag:hover {
    border-color: var(--border-color);
    background-color: var(--input-bg);
  }

  .drop-area-content {
    color: var(--text-color);
    opacity: 0.7;
  }

  .preview-container {
    /* One row that scrolls sideways, with the same custom track and thumb the tables use
     (built by ./TableInteractions.js through ./PreviewStrip.js). The native scrollbar is
     hidden rather than thinned, exactly as in ./tools/PDFEditing.php. */
    display: flex;
    flex-wrap: nowrap;
    gap: 10px;
    margin-top: 10px;
    min-height: 50px;
    overflow-x: auto;
  }

  .preview-container > * { flex-shrink: 0; }

  .preview-container.tnx-table-scroll-viewport {
    scrollbar-width: none;
  }

  .preview-container.tnx-table-scroll-viewport::-webkit-scrollbar {
    display: none;
    height: 0;
  }

  .preview-container:empty {
     margin-top: 0;
     min-height: 0;
   }

  .preview-item {
    position: relative;
    width: 100px;
    height: 100px;
    border: 3px solid var(--border-color);
    border-radius: 8px;
    background-color: var(--input-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    cursor: move;
    transition: transform 0.2s, box-shadow 0.2s;
    user-select: none;
  }

  .preview-item--placeholder {
    pointer-events: none;
  }

  .preview-container--readonly .preview-item {
    cursor: default;
  }

  .preview-item:first-child {
    border: 3px solid var(--primary-color);
  }

  .preview-item.is-entry-attachment-selected {
    border: 1px solid var(--primary-color);
    box-shadow: 0 2px 4px var(--shadow-color);
  }

  .preview-item.is-entry-attachment-group-dragging {
    opacity: 0.55;
  }

  .preview-item.sortable-ghost {
    opacity: 0.4;
    background: var(--primary-color);
  }

  .preview-item.sortable-chosen {
    box-shadow: 0 0 10px rgba(0,0,0,0.2);
  }

  .preview-item.image-preview {
    padding: 0;
  }

  .preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .preview-item video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: #000;
  }

  .preview-item.media-preview-loading .preview-link {
    position: relative;
  }

  .preview-item.media-preview-loading .media-loading-fallback {
    box-sizing: border-box;
    padding: 12px 10px;
  }

  .preview-item.media-preview-loading img,
  .preview-item.media-preview-loading video {
    position: absolute;
    inset: 0;
    opacity: 0;
  }

  .preview-item.media-preview-loading .video-overlay {
    opacity: 0;
  }

  .preview-item.media-preview-loading.is-media-loaded img,
  .preview-item.media-preview-loading.is-media-loaded video,
  .preview-item.media-preview-loading.is-media-loaded .video-overlay {
    opacity: 1;
  }

  .preview-item.media-preview-loading.is-media-loaded .media-loading-fallback {
    display: none;
  }

  .preview-item .video-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
  }

  .preview-item .video-overlay .play-button {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .preview-item .video-overlay .play-button::before {
    content: '';
    width: 0;
    height: 0;
    border-top: 8px solid transparent;
    border-bottom: 8px solid transparent;
    border-left: 12px solid rgba(255, 255, 255, 0.9);
    transform: translateX(1px);
  }

  .preview-link {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    text-decoration: none;
    color: inherit;
    text-align: center;
    padding: 4px;
    cursor: pointer;
  }

  .preview-item.image-preview .preview-link {
    padding: 0;
  }

  .preview-item.file-preview .preview-link {
    padding: 12px 10px;
  }

  .preview-item .preview-link:hover {
    opacity: 0.8;
  }

  .preview-item .file-name {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    width: 100%;
    height: 100%;
    max-width: 100%;
    font-size: var(--attachment-preview-font-size, 0.72rem);
    line-height: 1.1;
    font-weight: 500;
    color: var(--link-color);
    text-align: center;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
  }

  .preview-item .file-name__extension {
    opacity: 0.5;
  }

  .preview-item button.remove-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    background-color: rgba(0, 0, 0, 0.5);
    border: none;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    color: white;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    padding: 0;
    z-index: 1;
    /* the cross itself is drawn instead of typed, because the × glyph follows the
       font baseline and therefore sits below the middle of the circle */
    font-size: 0;
    line-height: 0;
  }

  .preview-item button.remove-btn::before,
  .preview-item button.remove-btn::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 9px;
    height: 2px;
    background-color: currentColor;
  }

  .preview-item button.remove-btn::before {
    transform: translate(-50%, -50%) rotate(45deg);
  }

  .preview-item button.remove-btn::after {
    transform: translate(-50%, -50%) rotate(-45deg);
  }

  .preview-item button.remove-btn:hover {
    background-color: rgba(0, 0, 0, 0.7);
  }


/* Workflow, email and shop uploads share the same one-row scrollbar as entry previews. */
.attachments-preview.attachments-preview {
    display: flex;
    flex-wrap: nowrap;
    max-height: none;
    overflow-x: auto;
    overflow-y: hidden;
}
.attachments-preview > * { flex: 0 0 auto; }
.attachments-preview.tnx-table-scroll-viewport { scrollbar-width: none; }
.attachments-preview.tnx-table-scroll-viewport::-webkit-scrollbar { display: none; }
