/**
 * Pro Gallery Lightbox - Comments panel
 *
 * Opens exactly like the statistics panel: a second layer on top of the
 * lightbox, same box, same distance from the top, one close button (header).
 * Everything is scoped to .pgl-cm-panel so the theme cannot leak into it.
 */

/* ---------- Panel shell ---------- */
.pgl-cm-panel {
    --cm-accent: #ffc809;
    --cm-head: #f5f5f5;
    --cm-head-line: #ddd;
    --cm-bg: #fff;
    --cm-tile: #f7f7f7;
    --cm-line: #ececec;
    --cm-line-strong: #d6d6d6;
    --cm-field: #d6d6d6;
    --cm-fg: #1f1f1f;
    --cm-mut: #737373;
    --cm-hatch: rgba(0, 0, 0, .03);
    --cm-avatar-bg: #efefef;
    --cm-avatar-fg: #555;
    --cm-ease: cubic-bezier(.22, 1, .36, 1);
    /* Fallback only: JS sets the real value (header bottom + a small gap). */
    --cm-top: 108px;
    position: fixed;
    inset: 0;
    z-index: 100010;
    visibility: hidden;
    pointer-events: none;
    transition: visibility 0s linear .55s;
}
[data-theme='dark'] .pgl-cm-panel {
    --cm-head: #2a2a2a;
    --cm-head-line: #484848;
    --cm-bg: #333;
    --cm-tile: #2c2c2c;
    --cm-line: #444;
    --cm-line-strong: #5a5a5a;
    --cm-field: #5a5a5a;
    --cm-fg: #ebebeb;
    --cm-mut: #b0b0b0;
    --cm-hatch: rgba(255, 255, 255, .04);
    --cm-avatar-bg: #404040;
    --cm-avatar-fg: #d0d0d0;
}
.pgl-cm-panel.is-open {
    visibility: visible;
    pointer-events: auto;
    transition-delay: 0s;
}
.pgl-cm-panel.is-instant,
.pgl-cm-panel.is-instant * {
    transition-duration: 0s !important;
    transition-delay: 0s !important;
}
.pgl-cm-panel *,
.pgl-cm-panel *::before,
.pgl-cm-panel *::after {
    box-sizing: border-box;
}
.pgl-cm-panel h2,
.pgl-cm-panel h3,
.pgl-cm-panel p,
.pgl-cm-panel ul {
    margin: 0;
    padding: 0;
    letter-spacing: normal;
    text-transform: none;
}
.pgl-cm-panel i,
.pgl-cm-panel em,
.pgl-cm-panel cite {
    font-style: normal;
}
.pgl-cm-panel button {
    font: inherit;
    margin: 0;
    box-shadow: none;
    text-transform: none;
}

.pgl-cm-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, .4);
    opacity: 0;
    transition: opacity .45s ease;
}
.pgl-cm-panel.is-open .pgl-cm-backdrop {
    opacity: 1;
}

/* Same horizontal box as the lightbox (JS copies the exact left/width of the
   lightbox header; these values are the fallback). */
.pgl-cm-sheet {
    position: absolute;
    top: var(--cm-top);
    bottom: 0;
    left: 65px;
    width: calc(100% - 130px);
    display: flex;
    flex-direction: column;
    background: var(--cm-bg);
    color: var(--cm-fg);
    border-radius: 12px 12px 0 0;
    box-shadow: 0 -10px 36px rgba(0, 0, 0, .35);
    transform: translateY(105%);
    transition: transform .55s var(--cm-ease);
    will-change: transform;
    overflow: hidden;
}
.pgl-cm-panel.is-open .pgl-cm-sheet {
    transform: translateY(0);
}

/* Dim the lightbox underneath; no scaling so both boxes keep the same size. */
.pgl-lightbox.pgl-cm-open .pgl-lightbox-modal {
    filter: brightness(.7);
    overflow: hidden;
    transition: filter .5s ease;
}

/* ---------- Header (same as the lightbox header) ---------- */
.pgl-cm-header {
    flex: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 3px 15px;
    background: var(--cm-head);
    border-bottom: 1px solid var(--cm-head-line);
    border-radius: 12px 12px 0 0;
    touch-action: none;
}
.pgl-cm-headline {
    display: flex;
    align-items: baseline;
    gap: 8px;
    min-width: 0;
    flex: 1 1 auto;
    font-size: 1em;
    color: var(--cm-fg);
}
.pgl-cm-headline h3 {
    margin: 0;
    font-size: 1em;
    font-weight: 600;
    line-height: 1.4;
    color: var(--cm-fg);
    background: none;
    height: auto;
    cursor: default;
}
/* .pgl-close-btn already carries the lightbox close button look. */
.pgl-cm-close {
    flex: none;
    border: 0;
    border-radius: 0;
}
.pgl-cm-close:focus-visible {
    outline: 2px solid var(--cm-fg);
    outline-offset: 2px;
}
@media (max-width: 768px) {
    .pgl-cm-headline { font-size: .9em; }
}

/* ---------- Scroll area ---------- */
.pgl-cm-scroll {
    position: relative;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 0 20px 40px;
    scrollbar-width: thin;
}
.pgl-cm-body {
    max-width: 640px;
    margin: 0 auto;
    padding-top: 22px;
    color: var(--cm-fg);
    font-size: 14px;
    line-height: 1.5;
}

/* Loader */
.pgl-cm-loader {
    display: none;
    position: absolute;
    left: 50%;
    top: 90px;
    transform: translateX(-50%);
    z-index: 3;
}
.pgl-cm-loader.is-active {
    display: block;
}
.pgl-cm-spin {
    display: block;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 3px solid var(--cm-line);
    border-top-color: var(--cm-accent);
    animation: pglCmSpin .8s linear infinite;
}

/* ---------- Theme isolation ---------- */
.pgl-cm-panel .pgl-cm-body,
.pgl-cm-panel .pgl-cm-body * {
    letter-spacing: normal;
    text-shadow: none;
}
.pgl-cm-panel .pgl-cm-body *::before,
.pgl-cm-panel .pgl-cm-body *::after {
    content: none !important;
}
.pgl-cm-panel .pgl-cm-head,
.pgl-cm-panel cite.fn {
    background: none !important;
    padding-inline-start: 0 !important;
    text-indent: 0 !important;
}

/* ---------- Summary / empty ---------- */
.pgl-cm-panel .comments-title {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 2px 10px;
    margin: 0 0 6px !important;
    padding: 0 !important;
    max-width: none !important;
    border: 0 !important;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.4;
    color: var(--cm-fg);
}
.pgl-cm-pending-count {
    font-size: 12px;
    font-weight: 500;
    color: var(--cm-mut);
}
.pgl-cm-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 36px 0 4px;
    text-align: center;
    color: var(--cm-mut);
}
.pgl-cm-empty svg {
    margin-bottom: 8px;
    opacity: .6;
}
.pgl-cm-panel p.no-comments {
    margin: 0;
    padding: 0 !important;
    font-size: 14px;
    font-weight: 600;
    color: var(--cm-fg);
}
.pgl-cm-empty span {
    font-size: 13px;
}

/* ---------- Comment list ---------- */
.pgl-cm-panel .pgl-cm-list > .comment + .comment {
    border-top: 1px solid var(--cm-line);
}
.pgl-cm-panel .comment {
    margin: 0 !important;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: none;
    box-shadow: none;
    animation: pglCmRise .45s var(--cm-ease) both;
}
.pgl-cm-row {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 18px 0;
}
.pgl-cm-main {
    flex: 1;
    min-width: 0;
}
.pgl-cm-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 3px 10px;
    margin: 0;
    padding: 0;
    border: 0;
    line-height: 1.35;
}
.pgl-cm-panel cite.fn {
    font-size: 13.5px;
    font-weight: 600;
    color: var(--cm-fg);
}
.pgl-cm-badge {
    padding: 0 6px;
    border: 1px solid var(--cm-line-strong);
    border-radius: 4px;
    color: var(--cm-mut);
    font-size: 10px;
    font-weight: 600;
    line-height: 1.7;
    letter-spacing: .06em !important;
    text-transform: uppercase;
}
.pgl-cm-panel .comment-meta {
    margin: 0;
    padding: 0;
    font-size: 12px;
    color: var(--cm-mut);
}
.pgl-cm-panel .comment-meta time {
    color: inherit;
    font-size: inherit;
}
.pgl-cm-panel .comment-content {
    margin-top: 5px;
    font-size: 14px;
    line-height: 1.65;
    color: var(--cm-fg);
    overflow-wrap: anywhere;
}
.pgl-cm-panel .comment-content p {
    margin: 0 0 .6em;
}
.pgl-cm-panel .comment-content p:last-child {
    margin-bottom: 0;
}
.pgl-cm-panel .comment-content a {
    color: inherit;
    text-decoration: underline;
    text-decoration-color: var(--cm-accent);
    text-underline-offset: 2px;
}

/* Reply link: plain text action (resets the global yellow pill) */
.pgl-cm-panel .reply {
    margin-top: 6px;
    min-height: 0;
}
.pgl-cm-panel .reply-button,
.pgl-cm-panel .reply-button:hover {
    display: inline-block !important;
    position: static !important;
    max-width: none;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0 !important;
    background: none !important;
    box-shadow: none !important;
    transform: none !important;
    line-height: 1.4;
}
.pgl-cm-panel .reply-button a,
.pgl-cm-panel a.pgl-custom-reply-link {
    display: inline-block;
    padding: 2px 0 !important;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--cm-mut);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: color .2s ease, border-color .2s ease;
}
.pgl-cm-panel .reply-button a:hover,
.pgl-cm-panel .reply-button a:focus-visible {
    color: var(--cm-fg);
    border-bottom-color: var(--cm-fg);
    outline: none;
}

/* Replies: hairline guide, smaller avatar */
.pgl-cm-panel .children {
    margin: 0 0 4px;
    margin-inline: 17px 0;
    padding: 0;
    padding-inline: 20px 0;
    border: 0;
    border-inline-start: 1px solid var(--cm-line);
}
.pgl-cm-panel .children .pgl-cm-row {
    padding: 14px 0;
}
.pgl-cm-panel .children .pgl-cm-avatar {
    width: 28px;
    height: 28px;
    font-size: 12px;
}

/* ---------- Avatar: neutral initial circle, Gravatar fades in on top ---------- */
.pgl-cm-avatar {
    position: relative;
    flex: none;
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    overflow: hidden;
    background: var(--cm-avatar-bg);
    color: var(--cm-avatar-fg);
    font-size: 14px;
    font-weight: 600;
    line-height: 1;
    user-select: none;
}
.pgl-cm-avatar b {
    font-weight: 600;
}
.pgl-cm-panel .pgl-cm-avatar .pgl-cm-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 50%;
    object-fit: cover;
    opacity: 0;
    transition: opacity .3s ease;
}
.pgl-cm-panel .pgl-cm-avatar .pgl-cm-img.is-loaded {
    opacity: 1;
}

/* ---------- Pending (visible only to its author) ---------- */
.pgl-cm-panel .comment.is-pending > .pgl-cm-row {
    margin-inline: -12px;
    padding-inline: 12px;
    border-radius: 10px;
    background-image: repeating-linear-gradient(135deg, var(--cm-hatch) 0 6px, transparent 6px 12px);
}
.pgl-cm-panel .comment.is-pending > .pgl-cm-row .pgl-cm-avatar,
.pgl-cm-panel .comment.is-pending > .pgl-cm-row cite.fn,
.pgl-cm-panel .comment.is-pending > .pgl-cm-row .comment-meta,
.pgl-cm-panel .comment.is-pending > .pgl-cm-row .comment-content {
    opacity: .5;
}
.pgl-cm-pending {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 20px;
    padding: 0 8px;
    border: 1px dashed var(--cm-line-strong);
    border-radius: 99px;
    color: var(--cm-mut);
    font-size: 11px;
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
}
.pgl-cm-pending svg {
    flex: none;
}
.pgl-cm-panel .pgl-cm-pending-note {
    margin: 6px 0 0;
    font-size: 12px;
    line-height: 1.5;
    color: var(--cm-mut);
}

/* ---------- Notice ---------- */
.pgl-cm-notice {
    margin: 0 0 16px;
    padding: 10px 14px;
    border: 1px solid var(--cm-line-strong);
    border-radius: 8px;
    background: var(--cm-tile);
    color: var(--cm-fg);
    font-size: 13px;
    line-height: 1.5;
    animation: pglCmRise .35s var(--cm-ease) both;
}
.pgl-cm-notice.is-error {
    border-color: rgba(214, 48, 48, .45);
    background: rgba(214, 48, 48, .07);
}

/* ---------- Form ---------- */
.pgl-cm-panel .pgl-cm-respond {
    margin: 28px 0 0;
    padding: 20px;
    border: 1px solid var(--cm-line);
    border-radius: 12px;
    background: var(--cm-tile);
}
.pgl-cm-panel .comment-reply-title {
    margin: 0 0 14px;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.3;
    color: var(--cm-fg);
}
.pgl-cm-panel form.comment-form {
    display: block !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0;
    border-radius: 0;
    background: none !important;
    box-shadow: none;
}
.pgl-cm-panel .comment-form p {
    margin: 0 0 12px;
}
.pgl-cm-panel .pgl-cm-fields {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0 12px;
}
.pgl-cm-panel .pgl-cm-fields p {
    width: auto !important;
    min-width: 0;
}
.pgl-cm-panel .comment-form label {
    display: block !important;
    margin: 0 0 6px;
    font-size: 12px;
    font-weight: 600;
    color: var(--cm-mut);
}
.pgl-cm-panel .comment-form .required {
    color: inherit;
    opacity: .7;
}
.pgl-cm-panel .comment-form input[type='text'],
.pgl-cm-panel .comment-form input[type='email'],
.pgl-cm-panel .comment-form textarea {
    display: block;
    width: 100% !important;
    min-width: 0;
    max-width: none !important;
    margin: 0;
    padding: 0 12px;
    height: 40px;
    border: 1px solid var(--cm-field);
    border-radius: 8px;
    background: var(--cm-bg);
    box-shadow: none;
    font: inherit;
    font-size: 14px;
    color: var(--cm-fg);
    outline: none;
    transition: border-color .2s ease, box-shadow .2s ease;
}
.pgl-cm-panel .comment-form textarea {
    height: auto;
    min-height: 104px;
    padding: 10px 12px;
    line-height: 1.55;
    resize: vertical;
}
.pgl-cm-panel .comment-form input[type='text']:focus,
.pgl-cm-panel .comment-form input[type='email']:focus,
.pgl-cm-panel .comment-form textarea:focus {
    border-color: var(--cm-fg);
    box-shadow: 0 0 0 3px rgba(255, 200, 9, .35);
}
.pgl-cm-panel .comment-form .logged-in-as {
    font-size: 13px;
    color: var(--cm-mut);
}
.pgl-cm-panel .comment-form .logged-in-as a {
    color: var(--cm-fg);
    text-decoration: underline;
    text-decoration-color: var(--cm-accent);
    text-underline-offset: 2px;
}
.pgl-cm-panel .comment-form .form-submit {
    margin: 4px 0 0;
    text-align: end;
}
.pgl-cm-panel .comment-form .submit {
    position: relative;
    display: inline-block;
    width: auto;
    height: 40px;
    padding: 0 24px;
    border: 0;
    border-radius: 8px;
    background: var(--cm-accent);
    box-shadow: none;
    color: #141414;
    font: inherit;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    transition: filter .2s ease, transform .15s ease, opacity .2s ease;
}
.pgl-cm-panel .comment-form .submit:hover {
    filter: brightness(.95);
}
.pgl-cm-panel .comment-form .submit:active {
    transform: translateY(1px);
}
.pgl-cm-panel .comment-form .submit:focus-visible {
    outline: 2px solid var(--cm-fg);
    outline-offset: 2px;
}
.pgl-cm-panel .comment-form .submit:disabled {
    opacity: .55;
    cursor: progress;
    filter: none;
    transform: none;
}
.pgl-cm-submit-spin {
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    width: 16px;
    height: 16px;
    margin: -8px 0 0 -8px;
    border: 2px solid rgba(20, 20, 20, .25);
    border-top-color: #141414;
    border-radius: 50%;
    animation: pglCmSpin .7s linear infinite;
}
.pgl-cm-panel .comment-form .submit.is-loading:disabled {
    opacity: 1;
}
.pgl-cm-panel .comment-form .submit.is-loading .pgl-cm-submit-label {
    visibility: hidden;
}
.pgl-cm-panel .comment-form .submit.is-loading .pgl-cm-submit-spin {
    display: block;
}
/* Reply form (cloned under a comment) */
.pgl-cm-panel .children > .comment-form {
    margin: 4px 0 14px !important;
    padding: 14px !important;
    border: 1px solid var(--cm-line);
    border-radius: 10px;
    background: var(--cm-tile) !important;
    animation: pglCmRise .35s var(--cm-ease) both;
}

@media (max-width: 768px) {
    .pgl-cm-panel { --cm-top: 78px; }
    .pgl-cm-sheet {
        left: 0;
        width: 100%;
    }
    .pgl-cm-scroll { padding: 0 14px 28px; }
    .pgl-cm-body { padding-top: 16px; }
    .pgl-cm-panel .pgl-cm-respond { padding: 16px; border-radius: 10px; }
    .pgl-cm-panel .pgl-cm-fields { grid-template-columns: minmax(0, 1fr); }
    .pgl-cm-panel .comment-form .form-submit { text-align: center; }
    .pgl-cm-panel .comment-form .submit { width: 100%; }
    .pgl-cm-panel .children { margin-inline-start: 14px; padding-inline-start: 14px; }
    .pgl-cm-panel .comment.is-pending > .pgl-cm-row { margin-inline: -8px; padding-inline: 8px; }
}

/* freshly posted comment: soft yellow flash */
.pgl-cm-panel .comment.is-new > .pgl-cm-row {
    animation: pglCmFlash 1.8s ease-out both;
}

/* ---------- Keyframes ---------- */
@keyframes pglCmFlash {
    from { background-color: rgba(255, 200, 9, .22); box-shadow: 0 0 0 8px rgba(255, 200, 9, .22); }
    to { background-color: rgba(255, 200, 9, 0); box-shadow: 0 0 0 8px rgba(255, 200, 9, 0); }
}
@keyframes pglCmRise {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes pglCmSpin {
    to { transform: rotate(360deg); }
}
@media (prefers-reduced-motion: reduce) {
    .pgl-cm-panel *,
    .pgl-cm-panel *::before,
    .pgl-cm-panel *::after {
        animation: none !important;
        transition-duration: .01s !important;
    }
}
