/*
   Attached Files module (ASIModule.Client.AttachedFiles).
   Global rather than scoped: module .razor.css bundles are unreliable in production.
   All colors come from themes.css custom properties.
*/

.attached-files-module {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Suppress the focus ring for pointer clicks only; keyboard focus keeps its ring so the
   view toggle doesn't look permanently selected after being clicked. */
.attached-files-module .btn-theme:focus:not(:focus-visible) {
    box-shadow: none;
    outline: none;
}

/* ---------- Header: dropzone + staging ---------- */

.af-header {
    display: flex;
    align-items: stretch;
    gap: 1rem;
}

.af-dropzone {
    flex: 0 0 15rem;
    border: 2px dashed var(--border-color);
    border-radius: 0.5rem;
    background-color: var(--bg-secondary);
    transition: border-color 0.15s ease-in-out, background-color 0.15s ease-in-out;
}

.af-dropzone:hover {
    border-color: var(--primary-color);
    background-color: var(--bg-tertiary);
}

.af-dropzone-dragover {
    border-color: var(--action-accent);
    background-color: var(--dialog-panel-active-bg);
}

.af-dropzone-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    width: 100%;
    height: 100%;
    min-height: 11rem;
    padding: 1.5rem 1rem;
    margin: 0;
    cursor: pointer;
    text-align: center;
}

.af-dropzone-icon {
    font-size: 3rem;
    line-height: 1;
    color: var(--primary-color);
}

.af-dropzone-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
}

.af-dropzone-hint {
    font-size: 0.8125rem;
    color: var(--text-muted);
}

.af-dropzone-limits {
    margin-top: 0.35rem;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.af-staging {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    background-color: var(--bg-primary);
}

.af-staging-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 11rem;
    padding: 1.5rem;
    text-align: center;
    color: var(--text-muted);
}

.af-staging-empty i {
    font-size: 2rem;
    opacity: 0.5;
}

.af-staging-list {
    flex: 1 1 auto;
    max-height: 16rem;
    overflow-y: auto;
    padding: 0.5rem;
}

.af-staging-item {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem;
    border-bottom: 1px solid var(--border-light);
}

.af-staging-item:last-child {
    border-bottom: none;
}

.af-staging-item-file {
    flex: 0 0 14rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
}

.af-staging-item-icon {
    font-size: 1.5rem;
    color: var(--text-secondary);
    flex: 0 0 auto;
}

.af-staging-item-meta {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.af-staging-item-name {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.af-staging-item-size {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.af-staging-item-fields {
    flex: 1 1 auto;
    display: grid;
    grid-template-columns: 1fr 1fr 10rem;
    gap: 0.5rem;
    min-width: 0;
}

.af-staging-item-actions {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
}

/* Phosphor glyphs carry their own line-height, which pushes the ✕ off centre. */
.af-staging-item-actions .btn-theme-icon,
.af-staging-item-actions .btn-theme-icon i {
    line-height: 1;
}

.af-staging-item-actions .btn-theme-icon i {
    display: block;
    font-size: 1rem;
}

.af-staging-item-error {
    flex: 1 0 100%;
    font-size: 0.75rem;
    color: var(--bs-danger);
}

.af-staging-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-top: 1px solid var(--border-color);
    background-color: var(--bg-tertiary);
    border-bottom-left-radius: 0.5rem;
    border-bottom-right-radius: 0.5rem;
}

.af-staging-count {
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.af-staging-footer-actions {
    display: flex;
    gap: 0.5rem;
}

/* ---------- Toolbar ---------- */

.af-toolbar {
    align-items: center;
    gap: 0.75rem;
}

.af-toolbar .grid-toolbar-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.af-search {
    width: 18rem;
}

/* Bootstrap's focus ring reads as a stray shadow here; the border colour still shifts
   on focus, so the field stays visibly active. */
.af-search .form-control:focus {
    box-shadow: none;
}

/* The inline clear button needs Bootstrap's .btn for input-group geometry, so the
   pointer-focus suppression has to cover it too. */
.attached-files-module .btn:focus:not(:focus-visible) {
    box-shadow: none;
    outline: none;
}

.af-view-toggle {
    display: inline-flex;
    gap: 0.25rem;
}

/* ---------- List view ---------- */

.af-col-icon {
    width: 2.5rem;
    text-align: center;
}

/* .sortable-column is only defined in History's scoped CSS, so the module needs its own. */
.attached-files-module .sortable-column {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.af-col-size {
    width: 6rem;
    text-align: right;
}

.af-col-actions {
    width: 1%;
    white-space: nowrap;
    text-align: right;
}

.af-cell-filename {
    max-width: 18rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---------- Card view ---------- */

.af-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr));
    gap: 1rem;
    padding: 0.25rem;
}

.af-card {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    background-color: var(--bg-primary);
    overflow: hidden;
    transition: box-shadow 0.15s ease-in-out, border-color 0.15s ease-in-out;
}

.af-card:hover {
    border-color: var(--primary-color);
    box-shadow: var(--shadow-sm);
}

.af-card-thumb {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 9rem;
    background-color: var(--bg-tertiary);
    overflow: hidden;
}

.af-card-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.af-card-thumb-icon {
    font-size: 3.5rem;
    color: var(--text-secondary);
}

.af-card-title {
    padding: 0.5rem;
    font-size: 0.8125rem;
    color: var(--text-primary);
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---------- Attachment details modal ---------- */

.af-attachment-modal-backdrop {
    z-index: 1040;
}

.af-attachment-modal {
    z-index: 1050;
}

.af-attachment-modal-dialog {
    width: min(980px, calc(100vw - 2rem));
    max-width: none;
}

.af-attachment-modal .modal-content {
    min-height: min(38rem, calc(100vh - 3.5rem));
}

.af-attachment-modal-body {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(18rem, 0.85fr);
    gap: 1.25rem;
    min-height: 0;
    padding: 1.25rem;
    background-color: var(--bg-secondary);
}

.af-attachment-preview-panel,
.af-attachment-info-panel {
    min-width: 0;
}

.af-attachment-preview-panel {
    display: flex;
    min-height: 28rem;
}

.af-attachment-preview-surface {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 28rem;
    padding: 1.5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--bs-border-radius);
    background-color: var(--bg-primary);
    box-shadow: var(--shadow-sm);
}

/* Rendered previews fill the surface edge-to-edge instead of sitting in the padded centre. */
.af-attachment-preview-surface.af-preview-has-content {
    padding: 0;
    overflow: hidden;
}

.af-preview-image {
    max-width: 100%;
    max-height: min(34rem, 70vh);
    object-fit: contain;
}

.af-preview-frame {
    width: 100%;
    height: min(34rem, 70vh);
    border: none;
    background-color: var(--bg-primary);
}

.af-preview-placeholder,
.af-preview-unavailable-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    max-width: 20rem;
    text-align: center;
    color: var(--text-muted);
}

/* Direct child only: the download button's own icon must keep button sizing. */
.af-preview-placeholder > i,
.af-preview-unavailable-inner > i {
    font-size: 3.5rem;
    line-height: 1;
    color: var(--text-secondary);
}

.af-preview-placeholder span,
.af-preview-unavailable-inner p {
    margin: 0;
}

.af-preview-unavailable {
    background-color: var(--bg-tertiary);
}

.af-preview-unavailable-inner > i {
    color: var(--bs-warning);
}

.af-attachment-download {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.af-attachment-download i {
    font-size: 1rem;
    line-height: 1;
}

.af-attachment-download-warning {
    font-size: 0.8125rem;
    color: var(--bs-warning);
}

.af-attachment-info-panel {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    padding: 0.25rem;
}

.af-attachment-field {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.af-attachment-field label {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.af-attachment-value {
    min-height: 2.25rem;
    padding: 0.55rem 0;
    color: var(--text-primary);
    overflow-wrap: anywhere;
}

.af-attachment-value-locked {
    padding: 0.55rem 0.7rem;
    border: 1px solid var(--border-color);
    border-radius: var(--bs-border-radius-sm);
    background-color: var(--bg-tertiary);
    color: var(--text-secondary);
}

.af-attachment-value-multiline {
    min-height: 5rem;
    white-space: pre-wrap;
}

.af-attachment-field .form-control,
.af-attachment-field .form-select {
    min-height: 2.25rem;
}

.af-attachment-modal-footer {
    justify-content: space-between;
    gap: 0.5rem;
    background-color: var(--bg-primary);
}

.af-attachment-footer-download,
.af-attachment-footer-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}

@media (max-width: 768px) {
    .af-attachment-modal-dialog {
        width: calc(100vw - 1rem);
    }

    .af-attachment-modal-body {
        grid-template-columns: 1fr;
        gap: 1rem;
        padding: 1rem;
    }

    .af-attachment-preview-panel,
    .af-attachment-preview-surface {
        min-height: 15rem;
    }
}

/* ---------- Narrow screens ---------- */

@media (max-width: 992px) {
    .af-header {
        flex-direction: column;
    }

    .af-dropzone {
        flex: 1 1 auto;
    }

    .af-dropzone-label {
        min-height: 8rem;
    }

    .af-staging-item-fields {
        grid-template-columns: 1fr;
    }
}
