.thread-attachment-list {
    border-top: 1px solid var(--c--contextuals--border--surface--primary);
    padding-top: var(--c--globals--spacings--base);
}

.thread-attachment-list__header {
    margin-bottom: var(--c--globals--spacings--sm);
}

.thread-attachment-list__body {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: var(--c--globals--spacings--base);
}

.attachment-item {
    position: relative;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: var(--c--globals--spacings--base);
    background-color: var(--c--contextuals--background--surface--tertiary);
    padding: var(--c--globals--spacings--xs);
    padding-right: var(--c--globals--spacings--2xs);
    border-radius: 4px;
    border: 1px solid var(--c--contextuals--border--surface--primary);
    transition: opacity var(--c--globals--transitions--duration) var(--c--globals--transitions--ease-out);
}

.attachment-item--loading {
    opacity: 0.5;
}

.attachment-item--previewable {
    cursor: pointer;

    &:hover {
        border-color: var(--c--contextuals--border--semantic--brand--primary);
    }
}

// Stretched primary action covering the whole card. The focus ring lands on
// the card boundary thanks to ``inset: 0`` + ``outline-offset``.
.attachment-item-preview-trigger {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    border-radius: inherit;
    cursor: pointer;

    &:focus-visible {
        outline: 2px solid var(--c--contextuals--border--semantic--brand--primary);
        outline-offset: 2px;
    }
}

// Reuses the deep-link focus animation declared in thread-view/_index.scss
// so attachment items pulse the same way messages and events do when the
// "Show in conversation" action lands on them.
.attachment-item.thread-view__highlight {
    animation: thread-view-highlight-focus 1700ms cubic-bezier(0.34, 1.56, 0.64, 1);
    position: relative;
    z-index: 3;
}

.attachment-item--error {
    border-color: var(--c--contextuals--border--semantic--error--primary);
    background-color: var(--c--contextuals--background--semantic--error--tertiary);

    .attachment-item-name {
        color: var(--c--contextuals--content--semantic--error--primary);
    }
}

.attachment-item-actions {
    // ``position: relative`` lifts the buttons above the stretched preview
    // trigger: both share the same stacking level, but the actions come later
    // in the DOM so they paint on top and stay independently clickable.
    // We deliberately avoid ``z-index`` here: any integer value would open a
    // stacking context that traps the Drive upload tooltip inside this item,
    // leaving it stuck below the action buttons of a later attachment item.
    position: relative;
    display: flex;
    flex-direction: row;
    gap: var(--c--globals--spacings--4xs);
    flex-wrap: nowrap;
    flex: 0 0 auto;
}

.attachment-item-metadata {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.attachment-item-icon-container {
    position: relative;
}

.attachment-item-icon {
    font-size: 24px;
    width: 32px;
    text-align: center;
    color: var(--c--contextuals--content--semantic--brand--primary);
}

.attachment-item-icon-drive,
.attachment-item-icon-inline {
    background: #FFF;
    border-radius: 4px;
    position: absolute;
    top: -3px;
    left: -3px;
    width: 18px;
    height: 18px;
    padding: 2px;
    color: var(--c--contextuals--content--semantic--brand--primary);
    background-color: var(--c--contextuals--background--surface--tertiary);
    border: 1px solid var(--c--contextuals--border--surface--primary);
}

.attachment-item-icon-inline {
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.attachment-item-upload-button-container {
    position: relative;
}

.attachment-item-icon--error {
    color: var(--c--contextuals--content--semantic--error--primary);
}

.attachment-item-size {
    font-size: var(--c--globals--font--sizes--xs);
    color: var(--c--contextuals--content--semantic--neutral--secondary);
}

.attachment-item-content {
    font-size: var(--c--globals--font--sizes--sm);
    display: flex;
    flex-direction: column;
    flex: 1;
}

.attachment-item-name {
    color: var(--c--contextuals--content--semantic--neutral--primary);
    line-clamp: 2;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    margin: 0;
    word-break: break-all;
}

.attachment-item-error-message {
    font-size: var(--c--globals--font--sizes--xs);
    color: var(--c--contextuals--content--semantic--error--tertiary);
    margin: 0;
}

.attachment-item-drive-upload-button-container {
    position: relative;
}

.attachment-item-drive-upload-button:disabled {
    pointer-events: none;
    &[data-state="error"] {
        color: var(--c--contextuals--content--semantic--error--tertiary);
    }
    &[data-state="success"] {
        color: var(--c--contextuals--content--semantic--success--tertiary);
    }
}

.attachment-item--drive-upload-tooltip {
    position: absolute;
    right: -20%;
    top: 50%;
    transform: translateY(0%);
    background-color: var(--c--contextuals--background--semantic--brand--tertiary);
    border: 1px solid var(--c--contextuals--border--semantic--brand--tertiary);
    font-size: var(--c--globals--font--sizes--sm);
    color: var(--c--contextuals--content--semantic--brand--primary);
    width: max-content;
    max-width: 300px;
    border-radius: 4px;
    padding: var(--c--globals--spacings--3xs) var(--c--globals--spacings--2xs);
    box-shadow: 0 0 10px 0 var(--c--contextuals--background--semantic--contextual--primary-hover);
    visibility: hidden;
    opacity: 0;
    z-index: 1000;
    transition-property: transform, all;
    transition-delay: 0.1s, 0s;
    transition-duration: 0.25s, 0.4s;
    transition-timing-function: var(--c--globals--transitions--ease-out);

    &--error {
        background-color: var(--c--contextuals--background--semantic--error--tertiary);
        border: 1px solid var(--c--contextuals--border--semantic--error--tertiary);
        color: var(--c--contextuals--content--semantic--error--primary);
    }

    &--visible {
        opacity: 1;
        visibility: visible;
        transform: translateY(50%);
        transition-delay: 0s, 0.1s;
        transition-duration: 0.4s, 0.25s;
    }
}
