/* ─── Shared post-viewer modal ─────────────────────────────────
 *
 * Used by:
 *   - Explore › Posts chip → tile click
 *   - Home feed → "N Comments" link
 *   - any surface that calls window.devalayPostViewer.open(id)
 *
 * Markup is auto-injected by static/js/post-viewer.js so any page
 * that loads this CSS + JS gets the modal for free. The internal
 * `.post-viewer__*` namespace keeps the styles self-contained.
 */

.dvl-post-viewer-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}
.dvl-post-viewer-modal[hidden] {
    display: none;
}
body.dvl-post-viewer-open {
    overflow: hidden;
}
.dvl-post-viewer-modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(2px);
}
.dvl-post-viewer-modal__panel {
    position: relative;
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    /* Instagram-style sizing: panel commits to a substantial height
       so the image column always feels like the hero, even when the
       comments column is short. min(...) clamps prevent the modal
       from getting awkwardly large on huge desktops. */
    width: min(1100px, 95vw);
    height: min(840px, 90vh);
    overflow: hidden;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.30);
    display: flex;
    flex-direction: column;
}
.dvl-post-viewer-modal__close {
    position: absolute;
    top: var(--s-3);
    right: var(--s-3);
    z-index: 3;
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.92);
    color: var(--text-primary);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}
.dvl-post-viewer-modal__close:hover { background: #fff; }
.dvl-post-viewer-modal__body {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Inner viewer (header + media + text + actions + stats + comments + composer) */
.post-viewer {
    display: flex;
    flex: 1 1 auto;
    min-height: 0;
    background: var(--bg-primary);
}
.post-viewer__loading,
.post-viewer__error {
    padding: var(--s-8) var(--s-5);
    text-align: center;
    color: var(--text-tertiary);
    font-family: var(--font-primary);
}
.post-viewer--with-media .post-viewer__media-wrap {
    flex: 1 1 auto;
    min-width: 0;
    background: #0a0a0a;
    display: flex;
    align-items: center;
    justify-content: center;
}
.post-viewer__media {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}
.post-viewer__side {
    /* Right column — comments stack, action row, composer. */
    flex: 0 0 440px;
    max-width: 100%;
    display: flex;
    flex-direction: column;
    min-height: 0;
    border-left: 1px solid var(--border-subtle, rgba(0,0,0,0.06));
}
.post-viewer--text-only .post-viewer__side {
    flex: 1 1 auto;
    border-left: 0;
}

.post-viewer__header {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    padding: var(--s-3) var(--s-4);
    border-bottom: 1px solid var(--border-subtle, rgba(0,0,0,0.06));
    flex-shrink: 0;
}
.post-viewer__avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}
.post-viewer__avatar--empty {
    background: var(--border-subtle, #ddd);
}
.post-viewer__author { min-width: 0; }
.post-viewer__name {
    font-family: var(--font-primary);
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.2;
}
.post-viewer__meta {
    display: flex;
    gap: var(--s-2);
    font-size: var(--t-body-sm);
    color: var(--text-tertiary);
    margin-top: 2px;
}
.post-viewer__loc::before { content: "·"; margin-right: var(--s-1); }

.post-viewer__text {
    padding: var(--s-3) var(--s-4) 0;
    color: var(--text-primary);
    font-family: var(--font-primary);
    font-size: var(--t-body-md);
    line-height: 1.55;
    flex-shrink: 0;
}
.post-viewer__text * { max-width: 100%; }

/* Action row */
.post-viewer__actions {
    display: flex;
    align-items: center;
    gap: var(--s-1);
    padding: var(--s-2) var(--s-3);
    border-top: 1px solid var(--border-subtle, rgba(0,0,0,0.06));
    flex-shrink: 0;
}
.post-viewer__actions-spacer { flex: 1 1 auto; }
.post-viewer__action {
    appearance: none;
    background: transparent;
    border: 0;
    padding: var(--s-2);
    border-radius: 50%;
    cursor: pointer;
    color: var(--text-primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background var(--duration-fast) ease,
                color var(--duration-fast) ease,
                transform var(--duration-fast) ease;
}
.post-viewer__action:hover { background: var(--bg-light, #FFF8F0); }
.post-viewer__action:active { transform: scale(0.92); }
.post-viewer__action svg {
    width: 24px; height: 24px; display: block;
    fill: none; stroke: currentColor; stroke-width: 1.8;
    stroke-linecap: round; stroke-linejoin: round;
}
.post-viewer__action.is-active {
    color: var(--brand-primary, #FF7A1A);
}
.post-viewer__action--like.is-active svg { fill: #ed4956; stroke: #ed4956; }
.post-viewer__action--save.is-active svg { fill: currentColor; }

.post-viewer__stats {
    display: flex;
    gap: var(--s-3);
    padding: var(--s-1) var(--s-4) var(--s-2);
    color: var(--text-primary);
    font-family: var(--font-primary);
    font-size: var(--t-body-sm);
    font-weight: 600;
    flex-shrink: 0;
}
.post-viewer__stats-time {
    color: var(--text-tertiary);
    font-weight: 400;
    font-size: var(--t-body-xs, 12px);
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

/* Comments */
.post-viewer__comments {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: var(--s-2) var(--s-4) var(--s-3);
}
.post-viewer__comments-loading,
.post-viewer__comments-empty {
    padding: var(--s-5) var(--s-3);
    color: var(--text-tertiary);
    text-align: center;
    font-family: var(--font-primary);
    font-size: var(--t-body-sm);
}
.post-viewer__comment {
    display: flex;
    gap: var(--s-3);
    padding: var(--s-2) 0;
    align-items: flex-start;
}
.post-viewer__comment-like {
    appearance: none;
    background: transparent;
    border: 0;
    padding: var(--s-1);
    cursor: pointer;
    color: var(--text-tertiary);
    align-self: flex-start;
    margin-top: 2px;
    transition: color var(--duration-fast) ease,
                transform var(--duration-fast) ease;
    flex-shrink: 0;
}
.post-viewer__comment-like:hover { color: var(--text-primary); }
.post-viewer__comment-like:active { transform: scale(0.85); }
.post-viewer__comment-like svg {
    width: 14px; height: 14px;
    fill: none; stroke: currentColor; stroke-width: 2;
}
.post-viewer__comment-like.is-active { color: #ed4956; }
.post-viewer__comment-like.is-active svg { fill: #ed4956; stroke: #ed4956; }
.post-viewer__comment-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}
.post-viewer__comment-avatar--empty {
    background: var(--border-subtle, #ddd);
}
.post-viewer__comment-body { min-width: 0; flex: 1 1 auto; }
.post-viewer__comment-head {
    display: flex;
    gap: var(--s-2);
    align-items: baseline;
}
.post-viewer__comment-name {
    font-family: var(--font-primary);
    font-weight: 600;
    font-size: var(--t-body-sm);
    color: var(--text-primary);
}
.post-viewer__comment-time {
    font-size: var(--t-body-xs, 12px);
    color: var(--text-tertiary);
}
.post-viewer__comment-text {
    margin-top: 2px;
    color: var(--text-primary);
    font-family: var(--font-primary);
    font-size: var(--t-body-sm);
    line-height: 1.45;
    white-space: pre-wrap;
    word-break: break-word;
}

/* Composer */
.post-viewer__composer {
    display: flex;
    gap: var(--s-2);
    padding: var(--s-2) var(--s-3);
    border-top: 1px solid var(--border-subtle, rgba(0,0,0,0.08));
    background: var(--bg-primary);
    flex-shrink: 0;
}
.post-viewer__composer-input {
    flex: 1 1 auto;
    min-width: 0;
    padding: var(--s-2) var(--s-3);
    border: 1px solid var(--border-subtle, rgba(0,0,0,0.12));
    border-radius: var(--radius-pill, 999px);
    font: inherit;
    font-size: var(--t-body-md);
    color: var(--text-primary);
    background: var(--bg-light, #fbf7f2);
    transition: border-color var(--duration-fast) ease,
                box-shadow var(--duration-fast) ease;
}
.post-viewer__composer-input:focus {
    outline: none;
    border-color: var(--brand-primary, #FF7A1A);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-primary, #FF7A1A) 18%, transparent);
    background: var(--bg-primary);
}
.post-viewer__composer-submit {
    appearance: none;
    border: 0;
    padding: 0 var(--s-4);
    border-radius: var(--radius-pill, 999px);
    background: var(--brand-primary, #FF7A1A);
    color: #fff;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--duration-fast) ease, opacity var(--duration-fast) ease;
}
.post-viewer__composer-submit:hover { background: var(--brand-primary-dark, #E66B0F); }
.post-viewer__composer-submit:disabled { opacity: 0.6; cursor: progress; }

@media (max-width: 720px) {
    .dvl-post-viewer-modal__panel {
        width: 100vw;
        height: 100vh;
        border-radius: 0;
    }
    .post-viewer { flex-direction: column; }
    .post-viewer--with-media .post-viewer__media-wrap {
        max-width: none;
        max-height: 50vh;
    }
    .post-viewer__side {
        flex: 1 1 auto;
        border-left: 0;
        border-top: 1px solid var(--border-subtle, rgba(0,0,0,0.06));
    }
}
