.theme-topic-attachments {
    display: grid;
    gap: 6px;
    margin-top: 8px;
    padding: 8px 10px;
    border-radius: var(--radius-md);
    background: var(--color-surface);
}

.theme-topic-attachments-head {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--color-muted);
    font-size: 12px;
    line-height: 1;
}

.theme-topic-attachments-head span {
    font-weight: 500;
}

.theme-topic-attachments-head small {
    font-size: 11px;
}

.theme-attachment-list {
    margin-top: 0;
}

.theme-attachment-item {
    background: var(--color-canvas-soft);
}

.theme-attachment-meta {
    color: var(--color-muted);
    font-size: 12px;
}

label.theme-attachment-upload {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 18px;
}

.theme-attachment-upload-label {
    color: var(--color-body);
    font-size: 14px;
    font-weight: 500;
}

.theme-attachment-upload-button {
    position: relative;
    display: inline-flex;
    min-height: 32px;
    align-items: center;
    justify-content: center;
    overflow: visible;
    border-radius: var(--radius-button);
    background: var(--control-bg-active);
    color: var(--control-text-active);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    line-height: 1;
    padding: 0 12px;
}

.theme-attachment-upload-button input {
    position: absolute;
    inset: 0;
    width: 100%;
    min-height: 0;
    height: 100%;
    cursor: pointer;
    opacity: 0;
    padding: 0;
}

.theme-attachment-upload-file {
    min-width: 0;
    max-width: min(100%, 320px);
    overflow: hidden;
    color: var(--color-muted);
    font-size: 13px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.theme-attachment-upload.has-pending-preview {
    margin-bottom: 6px;
}

.theme-attachment-upload-clear {
    border: 0;
    border-radius: var(--radius-pill);
    background: transparent;
    color: var(--color-muted);
    cursor: pointer;
    font-size: 12px;
    line-height: 1;
    padding: 8px 10px;
}

.theme-attachment-upload-clear:hover,
.theme-attachment-upload-clear:focus-visible,
.theme-attachment-upload-button:hover,
.theme-attachment-upload-button:focus-within {
    background: var(--control-bg-active);
    color: var(--control-text-active);
}

.theme-attachment-pending {
    display: grid;
    gap: 6px;
    margin: 0 0 18px;
}

.theme-attachment-pending[hidden] {
    display: none;
}

.theme-attachment-upload-status {
    display: inline-flex;
    width: fit-content;
    margin: -8px 0 16px;
    color: var(--color-muted);
    font-size: 12px;
    line-height: 1.4;
}

.theme-attachment-upload-status[hidden] {
    display: none;
}

.theme-attachment-pending-head {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--color-muted);
    font-size: 12px;
    line-height: 1;
}

.theme-attachment-pending-head span {
    font-weight: 500;
}

.theme-attachment-pending-head small {
    font-size: 11px;
}

.theme-attachment-pending-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr));
    gap: 6px;
}

.theme-attachment-pending-item {
    display: grid;
    min-width: 0;
    grid-template-columns: 32px minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    border-radius: var(--radius-md);
    padding: 6px;
    background: var(--color-canvas-soft);
}

.theme-attachment-pending-remove {
    display: inline-flex;
    min-height: 26px;
    align-items: center;
    border: 0;
    border-radius: var(--radius-pill);
    background: transparent;
    color: var(--color-muted);
    cursor: pointer;
    font-size: 11px;
    line-height: 1;
    padding: 0 6px;
    white-space: nowrap;
}

.theme-attachment-pending-remove:hover,
.theme-attachment-pending-remove:focus-visible {
    background: var(--color-surface-strong);
    color: var(--color-ink);
}

.theme-attachment-pending .theme-attachment-preview,
.theme-attachment-pending .theme-attachment-file-icon {
    width: 32px;
    height: 28px;
    font-size: 9px;
}

.theme-attachment-pending .theme-attachment-name {
    font-size: 12px;
}

.theme-attachment-pending .theme-attachment-meta {
    font-size: 11px;
}

.attachment-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
    gap: 10px;
    margin-top: 16px;
}

.attachment-item {
    display: grid;
    min-width: 0;
    grid-template-columns: 42px minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    border: 0;
    border-radius: var(--radius-md);
    padding: 8px;
    background: var(--color-surface);
}

.theme-attachment-preview,
.theme-attachment-file-icon {
    display: inline-flex;
    width: 42px;
    height: 34px;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border-radius: var(--radius-sm);
    background: var(--color-surface-strong);
    color: var(--color-muted);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0;
    line-height: 1;
}

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

.theme-attachment-body {
    display: grid;
    min-width: 0;
    gap: 2px;
}

.theme-attachment-name {
    overflow: hidden;
    color: var(--color-ink);
    font-size: 13px;
    font-weight: 500;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.theme-attachment-actions {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
}

.theme-attachment-actions form {
    margin: 0;
}

.theme-attachment-action {
    display: inline-flex;
    min-height: 30px;
    align-items: center;
    border: 0;
    border-radius: var(--radius-button);
    background: var(--color-canvas-soft);
    color: var(--color-error);
    cursor: pointer;
    font-size: 12px;
    line-height: 1;
    padding: 0 8px;
    white-space: nowrap;
}

.theme-attachment-action:hover,
.theme-attachment-action:focus-visible {
    background: color-mix(in srgb, var(--color-error) 10%, var(--color-canvas-soft));
    color: var(--color-error);
}

.theme-topic-attachment-list {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr));
    gap: 6px;
}

.theme-topic-attachments .attachment-item {
    grid-template-columns: 32px minmax(0, 1fr) auto;
    gap: 8px;
    padding: 6px;
    background: var(--color-canvas-soft);
}

.theme-topic-attachments .theme-attachment-preview,
.theme-topic-attachments .theme-attachment-file-icon {
    width: 32px;
    height: 28px;
    font-size: 9px;
}

.theme-topic-attachments .theme-attachment-name {
    font-size: 12px;
}

.theme-topic-attachments .theme-attachment-meta {
    font-size: 11px;
}

.theme-topic-attachments .theme-attachment-action {
    min-height: 26px;
    font-size: 11px;
    padding: 0 6px;
}

@media (max-width: 720px) {
    .attachment-item,
    .theme-attachment-upload-button,
    .theme-attachment-upload-clear {
        width: 100%;
    }

    .theme-attachment-upload-file {
        max-width: 100%;
    }

    .theme-attachment-item {
        grid-template-columns: 42px minmax(0, 1fr);
    }

    .theme-topic-attachments .theme-attachment-item {
        grid-template-columns: 32px minmax(0, 1fr);
    }

    .theme-attachment-pending-item {
        grid-template-columns: 32px minmax(0, 1fr);
    }

    .theme-attachment-actions {
        grid-column: 2;
        justify-content: flex-start;
    }

    .theme-attachment-pending-remove {
        grid-column: 2;
        justify-self: flex-start;
    }

    .theme-attachment-upload {
        align-items: stretch;
        flex-direction: column;
    }
}
