/*
    Universal Input Component Framework CSS

    This stylesheet provides the minimal structural CSS needed to make
    .universal-input divs function as form element primitives.

    IMPORTANT: Developers should style .universal-input elements using the
    same selectors they use for textarea and input elements. Example:

        textarea, input, .universal-input {
            border: solid 1px grey;
            border-radius: 6px;
            padding: 6pt;
        }

    This framework CSS cancels specific textarea properties so that the
    parent div's styling shows through, creating a unified visual object.
    The parent div expands or contracts to fit the textarea's size, allowing
    the textarea to be resized while maintaining visual containment.
*/

.universal-input {
    display: flex;
    flex-direction: column;
    position: relative; /* Positioning context for edit button */
    overflow: visible; /* Allow children to expand beyond initial bounds */
    min-width: 0; /* Prevent flex from preventing width collapse */
    min-height: 0; /* Prevent flex from preventing height collapse */
}

/* Remove padding from the .universal-input wrapper div */
.universal-input:has(> .textarea-wrapper){
    padding: 0 !important;
}

.textarea-wrapper {
    position: relative;
    display: flex;
    flex-direction: column;
}

.universal-input textarea, .universal-input textarea:focus {
    border: none;
    flex-shrink: 0;
    flex-grow: 0;
    background: transparent;
    width: 100%;
}

.universal-input .attachments-panel {
    border-top: 1px solid var(--light-grey, lightgrey);
    padding: 2pt 6pt;
    display: none; /* Hidden until files are attached */
    max-height: 7em;
    overflow-y: auto; /* Adds a scrollbar when content exceeds max-height */
    width: 100%; /* Match parent width */
}

.universal-input .attachments-panel ~ .edit-attachments-btn {
    display: none !important; /* Hide edit button when panel is hidden */
}

.universal-input .attachments-panel[style*="display: block"] ~ .edit-attachments-btn {
    display: flex !important; /* Show edit button when panel is visible */
}

.attachment-item {
    display: inline-block; /* Needed for margins to apply when items wrap */
    margin: 2pt;
    white-space: nowrap;
    cursor: pointer;
}

.attachment-thumb-wrapper {
    position: relative;
    display: inline-block; /* Needed for height property to apply */
    height: 3.3em;
    line-height: 3.3em;
    /* margin: 0 auto; */
}

.attachment-thumb {
    display: inline-block;  /* Needed for height property to apply */
    height: 100%; /* Constrains thumbnail to height of its parent */
    margin-right: 2pt;
    vertical-align: middle;
    border-radius: 4px;
}

.attachment-thumb-wrapper i.fa-file {
    font-size: 3.3em;
    line-height: 1;
    vertical-align: middle;
}

.attachment-thumb-wrapper .spinner-small {
    display: inline-block;
    vertical-align: middle;
    position: relative;
    left: 12pt;
}

.attachment-thumb-delete {
    display: none;
    position: absolute;
    top: -0.2em;
    right: -0.1em;
    font-size: 1em;
    color: var(--med-grey, grey);
    background: white;
    border-radius: 50%;
    font-size: 1.2em;
    box-shadow: 0 0 2px rgba(0,0,0,0.2);
    cursor: pointer;
    z-index: 2;
    padding: 0.05em;
}

.attachment-item:hover .attachment-thumb-delete /*,
.attachement-item:active .attachment-thumb-delete */
{
    display: inline;
}

.edit-attachments-btn {
    position: absolute;
    bottom: 4px;
    right: 8px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background-color: rgba(0, 0, 0, 0.06);
    color: var(--med-grey, grey);
    cursor: pointer;
    display: none; /* Hidden on desktop; shown on mobile via JS */
    align-items: center;
    justify-content: center;
    font-size: 16px;
    z-index: 10;
    transition: background-color 0.2s, color 0.2s, transform 0.2s, box-shadow 0.2s;
    transform: translateY(-2px);
    /* transition: background-color 0.2s, color 0.2s; */
    pointer-events: auto; /* Ensure button is clickable */
}

.attachment-item .attachment-thumb-delete {
    display: none; /* Hidden by default */
}

.attachments-panel.edit-mode .attachment-item .attachment-thumb-delete {
    display: inline; /* Show delete indicators in edit mode */
}

.attachment-filename {
    font-size: 0.85em;
    display: inline;
    vertical-align: middle;
    white-space: nowrap;
}

.camera-button {
    position: absolute;
    bottom: 4px;
    right: 8px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background-color: rgba(0, 0, 0, 0.06);
    color: var(--med-grey, grey);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    z-index: 10;
    transition: background-color 0.2s, color 0.2s, transform 0.2s, box-shadow 0.2s;
    transform: translateY(-2px);
}

.camera-button:hover, .edit-attachments-btn:hover {
    background-color: rgba(0, 0, 0, 0.15);
    color: var(--grey, grey);
}

.edit-attachments-btn.active, .textarea-wrapper.drag-active .camera-button {
    border: 2px solid rgba(0, 0, 0, 0.2);
}

.camera-button:active,
.edit-attachments-btn:active {
    transform: scale(0.95);
}

@media (hover: none) and (pointer: coarse) {
    /* Mobile devices: don't show delete on hover/tap */
    .attachment-item:hover .attachment-thumb-delete,
    .attachment-item:active .attachment-thumb-delete {
        display: none !important;
    }
}