/* Shared attachment presentation. Keep the original inputs and upload handlers. */
@font-face {
    font-family: "dropify";
    src: url("../dist/fonts/dropify.woff") format("woff"),
         url("../dist/fonts/dropify.ttf") format("truetype");
    font-weight: 400;
    font-style: normal;
    font-display: block;
}

body .dropify-wrapper {
    --cb-file-surface: var(--bs-input-bg, var(--pu-surface, #fff));
    --cb-file-text: var(--pu-text-primary, #334155);
    --cb-file-muted: var(--pu-text-secondary, #52657a);
    --cb-file-border: var(--pu-border, #cbd5e1);
    min-height: 34px;
    background-color: var(--cb-file-surface);
    color: var(--cb-file-text);
}

body .dropify-wrapper .dropify-message,
body .dropify-wrapper.touch-fallback .dropify-message {
    position: absolute;
    inset-inline: 8px;
    top: 50%;
    width: auto;
    padding: 0;
    transform: translateY(-50%);
    font-size: 13px;
    line-height: 20px;
}

body .dropify-wrapper .dropify-message p { margin: 0; }
body .dropify-wrapper .dropify-message .dropi18 { color: inherit; vertical-align: middle; }
body .dropify-wrapper.has-preview .dropify-message { visibility: hidden; }

body .dropify-wrapper .dropify-preview,
body .dropify-wrapper.touch-fallback .dropify-preview {
    position: absolute;
    inset: 0;
    height: 100%;
    padding: 3px 8px;
    background: var(--cb-file-surface);
    color: var(--cb-file-text);
    text-align: start;
}

body .dropify-wrapper .dropify-preview .dropify-render,
body .dropify-wrapper.touch-fallback .dropify-preview .dropify-render {
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    inset-inline-start: 8px;
    top: 3px;
    bottom: 3px;
    width: 26px;
}

body .dropify-wrapper .dropify-preview .dropify-render img,
body .dropify-wrapper.touch-fallback .dropify-preview .dropify-render img {
    position: static;
    transform: none;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    background: transparent;
}

body .dropify-wrapper .dropify-preview .dropify-render i,
body .dropify-wrapper.touch-fallback .dropify-preview .dropify-render i {
    position: static;
    transform: none;
    font-size: 22px;
    line-height: 1;
    color: inherit;
}

body .dropify-wrapper .dropify-preview .dropify-render i::before,
body .dropify-wrapper.touch-fallback .dropify-preview .dropify-render i::before {
    margin: 0;
}
body .dropify-wrapper.touch-fallback .dropify-preview .dropify-render .dropify-font-file::before { margin: 0; }

/* The filename already includes the extension; avoid text over the file glyph. */
body .dropify-wrapper .dropify-preview .dropify-extension,
body .dropify-wrapper.touch-fallback .dropify-preview .dropify-extension { display: none; }

body .dropify-wrapper .dropify-preview .dropify-infos,
body .dropify-wrapper.touch-fallback .dropify-preview .dropify-infos {
    position: absolute;
    inset-inline-start: 42px;
    inset-inline-end: 80px;
    background: transparent;
    opacity: 1;
    pointer-events: none;
}

/* Disabled/read-only widgets can omit the remove button. */
body .dropify-wrapper > input + .dropify-preview .dropify-infos { inset-inline-end: 8px; }

body .dropify-wrapper .dropify-preview .dropify-infos .dropify-infos-inner,
body .dropify-wrapper.touch-fallback .dropify-preview .dropify-infos .dropify-infos-inner {
    display: flex;
    flex-direction: column;
    justify-content: center;
    position: static;
    transform: none;
    height: 100%;
    padding: 0;
    margin: 0;
}

body .dropify-wrapper .dropify-preview .dropify-infos .dropify-infos-inner p,
body .dropify-wrapper.touch-fallback .dropify-preview .dropify-infos .dropify-infos-inner p {
    color: var(--cb-file-text);
    text-align: start;
    line-height: 16px;
    font-size: 12px;
}

body .dropify-wrapper .dropify-preview .dropify-infos .dropify-infos-inner p.dropify-infos-message,
body .dropify-wrapper.touch-fallback .dropify-preview .dropify-infos .dropify-infos-inner p.dropify-infos-message {
    padding: 0;
    margin: 0;
    font-size: 10px;
    line-height: 12px;
    font-weight: 400;
    opacity: 1;
    color: var(--cb-file-muted);
}

body .dropify-wrapper .dropify-preview .dropify-infos .dropify-infos-inner p.dropify-infos-message::before,
body .dropify-wrapper.touch-fallback .dropify-preview .dropify-infos .dropify-infos-inner p.dropify-infos-message::before {
    display: none;
}

body .dropify-wrapper .dropify-filename span.file-icon::before { content: "\e801"; }

body .dropify-wrapper .dropify-clear,
body .dropify-wrapper.touch-fallback .dropify-clear {
    inset-inline-end: 5px;
    inset-inline-start: auto;
    top: 50%;
    bottom: auto;
    transform: translateY(-50%);
    opacity: 1;
    max-width: 72px;
    padding: 0 6px;
    line-height: 24px;
    color: var(--cb-file-text);
    background: var(--cb-file-surface);
    /* Legacy themes declare the complete border important. */
    border: 1px solid var(--cb-file-border) !important;
    border-radius: 4px;
}

body .dropify-wrapper .dropify-clear:hover { background: var(--pu-surface-alt, #edf2f6); }
body .dropify-wrapper:focus-within { outline: 2px solid var(--pu-primary, #3b6ea5); outline-offset: 2px; }
body .dropify-wrapper .dropify-clear:focus-visible { outline: 2px solid var(--pu-primary, #3b6ea5); }

/* Let validation messages determine the height, including compact public themes. */
body .dropify-wrapper.has-error {
    height: auto !important;
    border-color: #b42318 !important;
}
body .dropify-wrapper.has-error .dropify-message {
    position: relative;
    inset: auto;
    transform: none;
    padding: 6px 8px;
    white-space: normal;
}
body .dropify-wrapper.has-error .dropify-message p { white-space: normal; }
body .dropify-wrapper.has-error .dropify-message .dropify-error { color: #b42318; }
body .dropify-wrapper.has-error .dropify-errors-container {
    position: relative;
    inset: auto;
    opacity: 1;
    visibility: visible;
    background: #fff1f0;
}
body .dropify-wrapper.has-error .dropify-errors-container ul {
    position: static;
    transform: none;
    padding: 6px 12px;
}
body .dropify-wrapper.has-error .dropify-errors-container ul li {
    margin-inline-start: 16px;
    color: #9f2018;
    font-size: 12px;
    line-height: 18px;
    overflow-wrap: anywhere;
}

/* Native pickers stay native: names, selected files, validation and resets survive. */
input[type="file"] { max-width: 100%; }
input[type="file"]::file-selector-button {
    padding: 4px 10px 4px 32px;
    margin-inline-end: 10px;
    border: 1px solid var(--pu-border, #cbd5e1);
    border-radius: 4px;
    background-color: var(--pu-surface-alt, #edf2f6);
    background-image: url("attachment.svg");
    background-repeat: no-repeat;
    background-size: 16px 16px;
    background-position: 10px center;
    color: var(--pu-text-primary, #334155);
    font: inherit;
    line-height: 20px;
    cursor: pointer;
}

input[type="file"].form-control:not(.filestyle):not(.dropify) {
    height: auto;
    min-height: 38px;
    padding: 3px;
}
input[type="file"]:disabled::file-selector-button { cursor: not-allowed; opacity: .6; }
[dir="rtl"] input[type="file"]::file-selector-button {
    padding: 4px 32px 4px 10px;
    background-position: right 10px center;
}
body.dark .dropify-wrapper,
[data-theme="dark"] .dropify-wrapper {
    --cb-file-surface: #1f2937;
    --cb-file-text: #e5e7eb;
    --cb-file-muted: #cbd5e1;
    --cb-file-border: #64748b;
}
body.dark .dropify-wrapper .dropify-clear:hover { background: #374151; }
body.dark .dropify-wrapper.has-error .dropify-message .dropify-error { color: #fda29b; }
body.dark input[type="file"]::file-selector-button,
[data-theme="dark"] input[type="file"]::file-selector-button {
    background-color: #e2e8f0;
    color: #1e293b;
    border-color: #94a3b8;
}
