/*
 * SPRU Attachments
 * Source line breaks in the post remain authoritative. PHP restores missing
 * <br> markers around inline attachments when phpBB drops them during BBCode
 * rendering; adjacent [attachment] BBCodes without a newline stay in one row.
 */
.inline-attachment {
    display: inline-block;
    vertical-align: top;
    max-width: 100%;
    margin: 3px 6px 3px 0;
}

.inline-attachment dl.thumbnail,
.inline-attachment dl.file {
    display: inline-block;
    vertical-align: top;
    max-width: 100%;
    margin: 0;
}

.inline-attachment img.postimage {
    max-width: 100%;
    height: auto;
}

/* Do not turn the ordinary attachment block into a gallery. */
.attachbox > dd > dl.file,
.attachbox > dd > dl.thumbnail {
    display: block;
}

/*
 * Posting/editor attachment manager.
 * phpBB renders this as a table. We keep the same DOM (so core JS continues
 * to work) but present its tbody as a responsive card grid.
 */
#file-list-container {
    display: block;
    clear: both;
    float: none;
    width: 100%;
    box-sizing: border-box;
    margin-top: 8px;
    padding: 0;
    background: transparent;
    border: 0;
}

#file-list-container > .inner {
    margin: 0;
}

#file-list-container table.table1 {
    display: block;
    width: 100%;
    margin: 0;
    background: transparent;
    border: 0;
}

#file-list-container table.table1 > thead {
    display: none;
}

#file-list {
    display: grid;
    clear: both;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 10px;
    width: 100%;
    max-width: none;
}

/*
 * A small number of attachments should not look like tiny islands in a huge
 * posting form. With 1–3 files we give the cards more room; once the list
 * grows, it falls back to the compact auto-fill grid above.
 */
#file-list.spru-attach-count-1 {
    grid-template-columns: minmax(0, 1fr);
    max-width: 360px;
}

#file-list.spru-attach-count-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    max-width: 650px;
}

#file-list.spru-attach-count-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    max-width: 840px;
}

#file-list .attach-row {
    display: flex;
    flex-direction: column;
    min-width: 0;
    box-sizing: border-box;
    padding: 9px;
    border: 1px solid #d4d9de;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.42);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

#file-list .attach-row-tpl {
    display: none !important;
}

#file-list .attach-row > td {
    display: block;
    width: auto !important;
    min-width: 0;
    padding: 0;
    border: 0;
    background: transparent !important;
    box-sizing: border-box;
}

#file-list .attach-row .attach-name {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    width: 100% !important;
    min-width: 0;
}

/* Attachment comments are intentionally not used in this UI. */
#file-list .attach-comment,
.spru-attachment-comment-hidden {
    display: none !important;
}

#file-list .attach-filesize {
    margin-top: 5px;
    text-align: center;
    font-size: 11px;
    line-height: 1.2;
    color: #6b737b;
}

#file-list .attach-status {
    margin-top: 5px;
    text-align: center;
}

#file-list .file-progress {
    max-width: 100%;
    margin: 0 auto;
}

#file-list .file-name {
    display: block;
    width: 100%;
    min-width: 0;
    margin: 0 0 7px;
    overflow: visible;
    text-align: center;
    text-overflow: clip;
    white-space: normal !important;
    overflow-wrap: anywhere;
    word-break: break-word;
    font-size: 12px;
    line-height: 1.25;
    font-weight: 600;
}

#file-list .file-name a {
    display: block;
    overflow: visible;
    text-overflow: clip;
    white-space: normal !important;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.spru-attachment-preview {
    display: flex;
    width: 100%;
    height: 112px;
    margin: 0 0 8px;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border: 1px solid #c9ced3;
    border-radius: 7px;
    background: rgba(255, 255, 255, 0.62);
    box-sizing: border-box;
}

.spru-attachment-preview img {
    display: block;
    width: auto;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    object-fit: contain;
}

#file-list .attach-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 5px;
    width: 100%;
    margin: auto 0 0;
}

#file-list .attach-controls > .button2,
#file-list .attach-controls > .button1 {
    margin: 0;
}

/* Let our controls participate in the same flex row as phpBB's buttons. */
.spru-attachment-tools {
    display: contents;
}

#file-list .spru-copy-url {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 29px;
    padding-left: 9px;
    padding-right: 9px;
    cursor: pointer;
}

#file-list .file-delete {
    margin-left: 5px !important;
}

.spru-copy-url.is-copied {
    font-weight: 600;
}

.spru-attachment-hide {
    display: flex;
    width: 100%;
    align-items: center;
    justify-content: center;
    gap: 5px;
    box-sizing: border-box;
    margin: 2px 0 0;
    padding: 3px 4px 1px;
    font-size: 11px;
    line-height: 1.2;
    text-align: center;
    cursor: pointer;
    user-select: none;
}

.spru-attachment-hide span {
    min-width: 0;
    overflow-wrap: anywhere;
}

.spru-attachment-hide input {
    margin: 0;
}

.spru-attachment-status {
    display: block;
    width: 100%;
    min-height: 28px;
    box-sizing: border-box;
    margin-top: 6px;
    text-align: center;
    font-size: 11px;
    line-height: 1.25;
    color: #53616f;
}

.spru-attachment-status::before {
    content: "";
    display: inline-block;
    width: 6px;
    height: 6px;
    margin: 0 5px 1px 0;
    border-radius: 50%;
    background: currentColor;
    opacity: .65;
}

.spru-attachment-status.is-inline,
.spru-attachment-status.is-url {
    color: #3b7150;
}

.spru-attachment-status.is-hidden,
.spru-attachment-status.is-copied {
    color: #8a6532;
}

@media (max-width: 700px) {
    #file-list,
    #file-list.spru-attach-count-3 {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        max-width: none;
        gap: 8px;
    }

    #file-list.spru-attach-count-1 {
        grid-template-columns: minmax(0, 1fr);
        max-width: 360px;
    }

    #file-list.spru-attach-count-2 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        max-width: none;
    }

    .spru-attachment-preview {
        height: 96px;
    }

    #file-list .attach-row {
        padding: 7px;
    }
}

@media (max-width: 430px) {
    #file-list,
    #file-list.spru-attach-count-2,
    #file-list.spru-attach-count-3 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        max-width: none;
    }

    #file-list.spru-attach-count-1 {
        grid-template-columns: minmax(0, 1fr);
        max-width: 100%;
    }

    .spru-attachment-preview {
        height: 86px;
    }
}
