/* Media Upload Styling */

.attach-btn {
    background: transparent;
    border: none;
    font-size: 20px;
    cursor: pointer;
    padding: 0;
    color: var(--text-color);
    /* Use text rendering for emoji to pick up color */
    -webkit-text-fill-color: var(--text-color);
    opacity: 0.7;
    transition: opacity 0.15s, transform 0.15s;
    border-radius: 4px;
}

.attach-btn:hover:not(:disabled) {
    opacity: 1;
    transform: scale(1.1);
}

.attach-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    transform: none;
    color: var(--light-text);
    -webkit-text-fill-color: var(--light-text);
}

/* Terminal theme: replace emoji with colorable text character */
[data-theme="terminal"] .attach-btn {
    font-size: 0; /* Hide emoji */
    filter: none;
}

[data-theme="terminal"] .attach-btn::after {
    content: "[+]";
    font-size: 14px;
    font-family: 'Courier New', monospace;
    color: var(--text-color);
    font-weight: bold;
    text-shadow: var(--terminal-glow-subtle);
    transition: text-shadow 0.15s;
}

[data-theme="terminal"] .attach-btn:hover:not(:disabled)::after {
    text-shadow: var(--terminal-glow);
}

[data-theme="terminal"] .attach-btn:disabled::after {
    color: var(--border-color);
    text-shadow: none;
}

.modal.hidden {
    display: none;
}

#upload-modal .modal-content {
    background: var(--modal-bg);
    padding: 24px;
    border-radius: 8px;
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}

#upload-modal h3 {
    margin-top: 0;
    margin-bottom: 16px;
    color: var(--text-color);
}

.progress-bar {
    width: 100%;
    height: 32px;
    background: var(--border-color);
    border-radius: 16px;
    overflow: hidden;
    margin: 16px 0;
    box-shadow: inset 0 2px 4px var(--shadow-color);
    position: relative;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--success-color), var(--primary-color));
    transition: width 0.3s ease;
    width: 0;
    position: relative;
    overflow: hidden;
}

.progress-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.3),
        transparent
    );
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% {
        transform: translateX(-100%);
    }
    100% {
        transform: translateX(100%);
    }
}

#progress-text {
    display: block;
    text-align: center;
    margin-top: 12px;
    color: var(--text-color);
    font-weight: 500;
    font-size: 14px;
}

#progress-details {
    display: block;
    text-align: center;
    margin-top: 8px;
    color: var(--light-text);
    font-size: 12px;
}

.preview-image {
    max-width: 100%;
    max-height: 400px;
    display: block;
    margin: 12px auto;
    border-radius: 4px;
}

#caption-input {
    width: 100%;
    padding: 8px;
    margin: 12px 0;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    box-sizing: border-box;
    background-color: var(--input-bg);
    color: var(--text-color);
}

#upload-complete {
    text-align: center;
}

#upload-complete button {
    margin: 8px 4px;
}

.drop-zone-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: color-mix(in srgb, var(--primary-color) 90%, transparent);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    font-weight: bold;
    z-index: 999;
    pointer-events: none;
}

.drop-zone-overlay.hidden {
    display: none;
}

.hidden {
    display: none;
}

/* File Attachment (non-embeddable files) */
.file-attachment {
    display: inline-flex;
    align-items: center;
    padding: 12px;
    margin: 8px 0;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--light-bg);
    max-width: 400px;
    white-space: normal; /* Override parent pre-wrap from .message-text */
}

.file-attachment .file-icon {
    font-size: 32px;
    margin-right: 12px;
    flex-shrink: 0;
}

.file-attachment .file-info {
    flex: 1;
    min-width: 0;
}

.file-attachment .file-name {
    font-weight: bold;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-color);
}

.file-attachment .file-size {
    color: var(--light-text);
    font-size: 0.9em;
}

.file-attachment .download-btn {
    padding: 8px 16px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 4px;
    white-space: nowrap;
    margin-left: 8px;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    line-height: normal;
    flex-shrink: 0;
}

.file-attachment .download-btn:hover {
    background: var(--primary-hover);
}

/* Terminal theme file attachment */
[data-theme="terminal"] .file-attachment {
    border-color: var(--primary-color);
    background: var(--dark-bg);
}

[data-theme="terminal"] .file-attachment .download-btn {
    background: var(--dark-bg);
    color: var(--text-color);
    border: 1px solid var(--primary-color);
}

[data-theme="terminal"] .file-attachment .download-btn:hover {
    background: var(--primary-color);
    color: var(--chat-bg);
}

/* Inline Media Rendering */
.inline-media-container {
    display: inline-block;
    max-width: 100%;
    white-space: normal; /* Override parent pre-wrap from .message-text */
}

.inline-media-image {
    display: block;
    margin: 10px 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain; /* Prevent cropping, maintain aspect ratio */
    cursor: pointer;
    /* Fade in animation when loaded */
    opacity: 0;
    transition: opacity 0.15s ease-in;
}

.inline-media-image.loaded {
    opacity: 1;
}

.inline-media-image.loaded:hover {
    filter: brightness(0.95);
}

.inline-media-video {
    display: block;
    margin: 10px 0;
    border-radius: 4px;
    max-width: 100%;
    height: auto;
}

.inline-media-audio {
    display: block;
    margin: 10px 0;
    max-width: 100%;
}

/* Message text with media */
.message-text a {
    color: var(--primary-color);
    text-decoration: none;
}

.message-text a:hover {
    text-decoration: underline;
}

/* Media Lightbox */
.media-lightbox {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.media-lightbox.show {
    opacity: 1;
}

.media-lightbox.hidden {
    display: none;
}

.media-lightbox-content {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 10px;
    box-sizing: border-box;
    transform: scale(0.95);
    transition: transform 0.3s ease;
}

.media-lightbox.show .media-lightbox-content {
    transform: scale(1);
}

.media-lightbox-media {
    max-width: 100%;
    max-height: calc(100vh - 60px);
    object-fit: contain;
    cursor: pointer;
}

.media-lightbox-url {
    background: rgba(255, 255, 255, 0.1);
    padding: 8px 16px;
    border-radius: 4px;
    color: #fff;
    text-decoration: none;
    font-size: 12px;
    transition: background 0.2s ease;
    cursor: pointer;
    word-break: break-all;
    max-width: 90%;
    text-align: center;
    flex-shrink: 0;
}

.media-lightbox-url:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

.media-lightbox-close-hint {
    position: absolute;
    top: 10px;
    right: 10px;
    color: rgba(255, 255, 255, 0.5);
    font-size: 12px;
    pointer-events: none;
}

/* Upload Toast Notifications */
.upload-toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column-reverse;
    gap: 10px;
    pointer-events: none;
}

.upload-toast {
    width: 320px;
    background: var(--darker-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 12px var(--shadow-heavy);
    padding: 12px;
    color: var(--text-color);
    pointer-events: auto;
    animation: toast-slide-in 0.3s ease-out;
}

.upload-toast.removing {
    animation: toast-slide-out 0.3s ease-in forwards;
}

@keyframes toast-slide-in {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes toast-slide-out {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(100%);
    }
}

.upload-toast-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.upload-toast-filename {
    font-weight: 500;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 250px;
}

.upload-toast-close {
    background: transparent;
    border: none;
    color: var(--light-text);
    font-size: 18px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

.upload-toast-close:hover {
    color: var(--text-color);
}

.upload-toast-progress {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 6px;
}

.upload-toast-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--success-color), var(--primary-color));
    transition: width 0.2s ease;
    width: 0;
    position: relative;
    overflow: hidden;
}

.upload-toast-progress-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.3),
        transparent
    );
    animation: shimmer 1.5s infinite;
}

.upload-toast-status {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: var(--light-text);
}

.upload-toast-percent {
    font-weight: 500;
}

/* Success state */
.upload-toast.success {
    background: var(--success-color);
    color: #fff;
}

.upload-toast.success .upload-toast-progress-fill {
    background: rgba(255, 255, 255, 0.3);
}

.upload-toast.success .upload-toast-progress-fill::after {
    animation: none;
}

/* Error state */
.upload-toast.error {
    background: var(--danger-color);
    color: #fff;
}

.upload-toast.error .upload-toast-progress-fill {
    background: rgba(255, 255, 255, 0.3);
}

.upload-toast.error .upload-toast-progress-fill::after {
    animation: none;
}

/* Attach Button Progress Ring */
.attach-btn-container {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.attach-btn-container .attach-btn {
    margin-right: 0;  /* Remove margin so ring centers properly */
}

.attach-btn-progress {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.attach-btn-progress.active {
    opacity: 1;
    pointer-events: auto;
    cursor: pointer;
}

.attach-btn-progress-ring {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    /* Default: green clockwise for upload */
    background: conic-gradient(
        from 0deg,
        var(--success-color) var(--progress, 0%),
        var(--border-color) var(--progress, 0%)
    );
    mask: radial-gradient(transparent 55%, black 56%);
    -webkit-mask: radial-gradient(transparent 55%, black 56%);
    transition: background 0.3s ease;
}

/* Digest phase: gray, counter-clockwise (100% to 0%) */
.attach-btn-progress.digest .attach-btn-progress-ring {
    /* Counter-clockwise: show gray from end, transparent fills from start */
    /* Use bright blue-gray to make digest phase clearly visible */
    background: conic-gradient(
        from 0deg,
        rgba(0, 0, 0, 0.1) calc(100% - var(--progress, 0%)),
        #5a9fd4 calc(100% - var(--progress, 0%))
    ) !important;
}

/* Upload phase: green clockwise (0% to 100%) */
.attach-btn-progress.upload .attach-btn-progress-ring {
    background: conic-gradient(
        from 0deg,
        var(--success-color) var(--progress, 0%),
        var(--border-color) var(--progress, 0%)
    );
}

.attach-btn-progress.success {
    opacity: 1;
}

.attach-btn-progress.success .attach-btn-progress-ring {
    background: var(--success-color);
    animation: progress-success-pulse 0.6s ease-out forwards;
}

.attach-btn-progress.error {
    opacity: 1;
}

.attach-btn-progress.error .attach-btn-progress-ring {
    background: var(--danger-color);
    animation: progress-error-pulse 0.6s ease-out forwards;
}

@keyframes progress-success-pulse {
    0% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.1);
        opacity: 0.8;
    }
    100% {
        transform: scale(1);
        opacity: 0;
    }
}

@keyframes progress-error-pulse {
    0% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.1);
        opacity: 0.8;
    }
    100% {
        transform: scale(1);
        opacity: 0;
    }
}

/* Terminal theme: progress ring colors */
[data-theme="terminal"] .attach-btn-progress-ring {
    background: conic-gradient(
        from 0deg,
        var(--success-color) var(--progress, 0%),
        var(--border-color) var(--progress, 0%)
    );
}

[data-theme="terminal"] .attach-btn-progress.digest .attach-btn-progress-ring {
    background: conic-gradient(
        from 0deg,
        var(--border-color) calc(100% - var(--progress, 0%)),
        var(--primary-color) calc(100% - var(--progress, 0%))
    ) !important;
}

[data-theme="terminal"] .attach-btn-progress.upload .attach-btn-progress-ring {
    background: conic-gradient(
        from 0deg,
        var(--text-color) var(--progress, 0%),
        var(--border-color) var(--progress, 0%)
    );
}

[data-theme="terminal"] .attach-btn-progress.success .attach-btn-progress-ring {
    background: var(--success-color);
}

[data-theme="terminal"] .attach-btn-progress.error .attach-btn-progress-ring {
    background: var(--danger-color);
}
