/* Modal / Iframe overlay */
.modal-overlay {
    display: flex;
    /* Kept as flex but initialized hidden via opacity/pointer-events */
    opacity: 0;
    pointer-events: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--modal-overlay);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 100;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* When activated by JS */
.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-container {
    width: 90%;
    height: 90%;
    max-width: 1400px;
    background: var(--modal-bg);
    border-radius: 12px;
    border: 1px solid var(--nav-border);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: scale(0.95);
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1), background-color 0.5s var(--apple-ease);
}

.modal-overlay.active .modal-container {
    transform: scale(1);
}

.modal-container:fullscreen,
.modal-container.pseudo-fullscreen {
    width: 100vw;
    height: 100vh;
    max-width: none;
    border-radius: 0;
    border: none;
    background: #000;
}

.modal-container:fullscreen .modal-header,
.modal-container.pseudo-fullscreen .modal-header {
    border-radius: 0;
}

.modal-header {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid var(--nav-border);
    background: var(--card-bg);
    /* Use matching sub-glass */
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.icon-btn:hover {
    background: var(--nav-border);
    color: var(--text-primary);
}

.modal-body {
    display: flex;
    flex-grow: 1;
    overflow: hidden;
    position: relative;
    /* Restores structure so iframe fills 100% height and isn't scrunched */
}

.iframe-wrapper {
    flex: 1;
    position: relative;
    background: #000;
    /* Deep black behind iframe */
}

iframe {
    width: 100%;
    height: 100%;
    border: none;
    background: transparent;
    opacity: 0;
    transition: opacity 0.5s ease;
}

iframe.loaded {
    opacity: 1;
}

/* === Global Left-Sidebar (Comments) === */
.global-sidebar {
    width: 350px;
    background: var(--card-bg);
    /* Use matching sub-glass */
    border-right: 1px solid var(--nav-border);
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    /* Slide in from the left */
    transform: translateX(-100%);
    transition: transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
    z-index: 100;
    /* Under modal, above main page */
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.2);
}

.global-sidebar.open {
    transform: translateX(0);
}

.sidebar-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--nav-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(0, 0, 0, 0.1);
}

.sidebar-header h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 250px;
}

.comments-feed {
    flex-grow: 1;
    padding: 1.5rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.comment-input-area {
    padding: 1.25rem 1.5rem;
    border-top: 1px solid var(--nav-border);
    background: rgba(0, 0, 0, 0.05);
}

.auth-prompt {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    text-align: center;
    padding: 1rem 0;
}

.auth-prompt.hidden {
    display: none;
}

.auth-prompt p {
    font-size: 0.95rem;
    color: var(--text-secondary);
}

#commentForm.hidden {
    display: none;
}

#commentForm textarea {
    width: 100%;
    background: var(--bg-color);
    border: 1px solid var(--nav-border);
    border-radius: 8px;
    padding: 0.75rem;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9rem;
    resize: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

#commentForm textarea:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 2px rgba(10, 132, 255, 0.2);
}

.comment-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.5rem;
}

.char-count {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* Individual Comments */
.comment-item {
    display: flex;
    gap: 12px;
    animation: fadeSlideUp 0.3s ease-out forwards;
}

@keyframes fadeSlideUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.comment-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.1);
    object-fit: cover;
    flex-shrink: 0;
}

.comment-content {
    /* Hardcoded transparent background to match card effects */
    background: rgba(43, 43, 43, 0.4);
    padding: 10px 14px;
    border-radius: 12px;
    border-top-left-radius: 2px;
    width: 100%;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

[data-theme="light"] .comment-content {
    background: rgba(255, 255, 255, 0.7);
}

.own-comment .comment-content {
    background: rgba(10, 132, 255, 0.15);
    border: 1px solid rgba(10, 132, 255, 0.2);
}

[data-theme="light"] .own-comment .comment-content {
    background: rgba(10, 132, 255, 0.08);
}

.comment-meta {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 4px;
}

.comment-author {
    font-weight: 600;
    font-size: 0.85rem;
}

.comment-date {
    font-size: 0.7rem;
    color: var(--text-secondary);
}

.comment-text {
    font-size: 0.9rem;
    line-height: 1.4;
    word-break: break-word;
    white-space: pre-wrap;
}

.empty-comments {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    opacity: 0.7;
}

/* === Custom Edit Simulation Modal UI === */

.upload-form-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

@media (min-width: 600px) {
    .upload-form-grid {
        grid-template-columns: 1fr 1fr;
    }
}

.upload-input-group {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
    width: 100%;
}

.upload-input-group label {
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
}

.upload-input-modern {
    width: 100%;
    padding: 0.875rem 1rem;
    border-radius: 12px;
    border: 1px solid var(--card-border);
    background: var(--bg-color);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 1rem;
    transition: all 0.3s var(--apple-ease);
    outline: none;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.02);
}

.upload-input-modern:focus {
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.15);
}

.upload-select-modern {
    padding: 0.4rem 0.75rem;
    border-radius: 6px;
    border: 1px solid var(--card-border);
    background: var(--bg-color);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.85rem;
    outline: none;
    cursor: pointer;
    transition: all 0.2s;
}

.upload-select-modern:focus {
    border-color: var(--accent-blue);
}

.ai-improve-modern {
    display: flex;
    align-items: center;
    background-color: var(--card-bg);
    border: 1px solid var(--accent-blue);
    border-radius: 9999px;
    padding: 0.5rem;
    box-shadow: inset 0 0 0 1px rgba(0, 113, 227, 0.2), 0 4px 10px rgba(0, 113, 227, 0.1);
    transition: all 0.3s var(--apple-ease);
    margin-bottom: 1rem;
    gap: 0.5rem;
}

.ai-improve-modern:focus-within {
    box-shadow: inset 0 0 0 1px var(--accent-blue), 0 4px 15px rgba(0, 113, 227, 0.2);
}

.ai-improve-icon {
    margin-left: 0.5rem;
    flex-shrink: 0;
}

.ai-improve-input {
    flex: 1;
    border: none;
    background: transparent !important;
    background-color: transparent !important;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 1rem;
    outline: none;
    padding: 0.5rem;
    color-scheme: dark;
}

/* Re-use hero submit styling for AI prompt here */
.upload-submit-modern {
    width: 100%;
    padding: 1rem;
    border-radius: 14px;
    font-size: 1.05rem;
    font-weight: 600;
    color: white;
    background: linear-gradient(135deg, var(--accent-blue), #00d2ff);
    border: none;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: transform 0.3s var(--apple-ease), box-shadow 0.3s var(--apple-ease);
    box-shadow: 0 4px 15px rgba(0, 113, 227, 0.3);
}

.upload-submit-modern:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0, 113, 227, 0.4);
}

.upload-submit-modern:active {
    transform: translateY(0) scale(0.98);
}

.hero-ai-submit-modal {
    background: linear-gradient(135deg, var(--accent-blue), #00d2ff);
    border: none;
    border-radius: 9999px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    box-shadow: 0 4px 15px rgba(0, 113, 227, 0.4);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}


@media (max-width: 768px) {
    .global-sidebar {
        width: 100%;
    }
}