/**
 * Gym Fuel Toronto — threaded gym chat (Reddit-style)
 * All chat UI styles live here; logic is in js/chat-engine.js
 */

.gf-chat-root {
    --gf-chat-neon: #00bfff;
    --gf-chat-surface: rgba(15, 23, 42, 0.96);
    --gf-chat-border: rgba(59, 130, 246, 0.35);
    --gf-chat-muted: #94a3b8;
    --gf-chat-text: #f1f5f9;
    --gf-chat-indent: 1.15rem;
    --gf-discussion-footer-h: auto;
    font-family: system-ui, -apple-system, sans-serif;
    color: var(--gf-chat-text);
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    overflow: hidden;
}

/* Floating action button (mobile) */
.gf-chat-fab {
    display: none;
    position: fixed;
    right: 1rem;
    bottom: 1.25rem;
    z-index: 9000;
    width: 3.25rem;
    height: 3.25rem;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, #2563eb, #0ea5e9);
    color: #fff;
    box-shadow: 0 8px 28px rgba(37, 99, 235, 0.45);
    cursor: pointer;
    align-items: center;
    justify-content: center;
}

.gf-chat-fab svg {
    width: 1.35rem;
    height: 1.35rem;
}

/* Side panel (desktop) / bottom sheet (mobile) — 3-row grid: header | scroll | footer */
.gf-chat-panel,
.gf-discussion-container {
    position: fixed;
    z-index: 9001;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas:
        'discussion-header'
        'discussion-body'
        'discussion-footer';
    width: 100%;
    height: 100%;
    min-height: 0;
    max-height: 100%;
    background: var(--gf-chat-surface);
    border: 1px solid var(--gf-chat-border);
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(14px);
}

.gf-chat-panel.is-open {
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
}

.gf-chat-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9000;
    background: rgba(2, 6, 23, 0.55);
}

.gf-chat-backdrop.is-visible {
    display: block;
}

.gf-chat-header {
    grid-area: discussion-header;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 1rem 1.15rem;
    border-bottom: 1px solid var(--gf-chat-border);
    flex-shrink: 0;
    margin: 0;
}

.gf-chat-header-titles {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: flex-end;
    gap: 8px;
    min-width: 0;
    flex: 1 1 auto;
}

.gf-chat-title {
    margin: 0;
    font-size: 1.125rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.2;
    color: var(--gf-chat-text);
    flex-shrink: 0;
    white-space: nowrap;
}

.gf-chat-header-meta {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: flex-end;
    gap: 8px;
    min-width: 0;
}

.gf-chat-comment-counter {
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: rgba(148, 163, 184, 0.95);
    flex-shrink: 0;
    white-space: nowrap;
}

.gf-chat-clear-discussion {
    display: none;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    padding: 0.2rem 0.45rem;
    border: 1px solid rgba(248, 113, 113, 0.45);
    border-radius: 0.4rem;
    background: rgba(127, 29, 29, 0.35);
    color: #fca5a5;
    font-size: 0.65rem;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    white-space: nowrap;
}

.gf-chat-clear-discussion:hover:not(:disabled) {
    background: rgba(185, 28, 28, 0.5);
    color: #fecaca;
}

.gf-chat-clear-discussion:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.gf-chat-clear-discussion-label {
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

.gf-chat-discussion-full {
    margin: 0;
    flex: 1 1 auto;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #f87171;
}

.gf-chat-compose--full .gf-chat-submit:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.gf-discussion-scroll {
    grid-area: discussion-body;
    min-height: 0;
    max-height: 100%;
    flex: 1 1 auto;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: rgba(59, 130, 246, 0.4) transparent;
}

.gf-discussion-scroll::-webkit-scrollbar {
    width: 6px;
}

.gf-discussion-scroll::-webkit-scrollbar-track {
    background: transparent;
}

.gf-discussion-scroll::-webkit-scrollbar-thumb {
    background: rgba(59, 130, 246, 0.35);
    border-radius: 6px;
}

.gf-discussion-scroll::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 191, 255, 0.5);
}

.gf-discussion-container,
.gf-discussion-scroll {
    scrollbar-width: thin;
    scrollbar-color: rgba(59, 130, 246, 0.4) transparent;
}

.gf-chat-close {
    border: none;
    background: rgba(37, 99, 235, 0.2);
    color: var(--gf-chat-text);
    width: 2rem;
    height: 2rem;
    border-radius: 0.5rem;
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
}

.gf-chat-thread-list {
    box-sizing: border-box;
    padding: 0.85rem 1rem 1.25rem;
    margin: 0;
    overflow: visible;
    min-height: min-content;
}

.gf-chat-empty {
    text-align: center;
    color: var(--gf-chat-muted);
    font-size: 0.85rem;
    padding: 2rem 0.5rem;
}

.gf-chat-comment {
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    margin: 0 0 0.65rem;
    padding: 0.75rem 0.85rem 0.8rem;
    border-radius: 0.65rem;
    background: rgba(17, 24, 39, 0.85);
    border: 1px solid rgba(75, 85, 99, 0.35);
}

.gf-chat-comment:last-child {
    margin-bottom: 0;
}

.gf-chat-comment--reply {
    border-color: rgba(59, 130, 246, 0.2);
}

.gf-chat-indent-0 {
    margin-left: 0;
    width: 100%;
    max-width: 100%;
}

.gf-chat-indent-1 {
    margin-left: var(--gf-chat-indent);
    width: calc(100% - var(--gf-chat-indent));
    max-width: calc(100% - var(--gf-chat-indent));
}

.gf-chat-indent-2 {
    margin-left: calc(2 * var(--gf-chat-indent));
    width: calc(100% - (2 * var(--gf-chat-indent)));
    max-width: calc(100% - (2 * var(--gf-chat-indent)));
}

.gf-chat-comment--flattened {
    border-left: 2px solid rgba(0, 191, 255, 0.35);
    padding-left: 0.65rem;
}

.gf-chat-reply-to {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    margin: 0 0 0.4rem;
    font-size: 0.72rem;
    color: var(--gf-chat-muted);
}

.gf-chat-reply-to-bar {
    display: inline-block;
    width: 3px;
    height: 0.9rem;
    border-radius: 2px;
    background: var(--gf-chat-neon);
    opacity: 0.75;
    flex-shrink: 0;
}

.gf-chat-reply-to-user {
    color: var(--gf-chat-neon);
    font-weight: 700;
}

.gf-chat-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.35rem 0.5rem;
    margin-bottom: 0.35rem;
    font-size: 0.68rem;
}

.gf-chat-author {
    font-weight: 800;
    color: #f97316;
}

.gf-chat-time {
    color: var(--gf-chat-muted);
}

.gf-chat-body {
    margin: 0;
    font-size: 0.84rem;
    line-height: 1.45;
    white-space: pre-wrap;
    word-break: break-word;
}

.gf-chat-actions,
.gf-comment-actions {
    margin: 0.5rem 0 0;
    padding: 0;
}

.gf-chat-reply-btn {
    border: none;
    background: transparent;
    color: var(--gf-chat-neon);
    font-size: 0.72rem;
    font-weight: 700;
    cursor: pointer;
    padding: 0;
}

.gf-chat-reply-btn:hover {
    text-decoration: underline;
}

.gf-chat-action-btn {
    border: none;
    background: transparent;
    font-size: 0.72rem;
    font-weight: 700;
    cursor: pointer;
    padding: 0;
    margin-right: 0.65rem;
}

.gf-chat-action-btn:hover {
    text-decoration: underline;
}

.gf-chat-edit-btn {
    color: var(--gf-chat-neon);
}

.gf-chat-delete-btn {
    color: #f87171;
}

.gf-chat-edit-form {
    margin-top: 0.35rem;
}

.gf-chat-edit-input {
    width: 100%;
    min-height: 4rem;
    resize: vertical;
    border-radius: 0.55rem;
    border: 1px solid rgba(75, 85, 99, 0.5);
    background: rgba(15, 23, 42, 0.9);
    color: var(--gf-chat-text);
    padding: 0.55rem 0.65rem;
    font-size: 0.84rem;
    font-family: inherit;
    line-height: 1.45;
}

.gf-chat-edit-input:focus {
    outline: 2px solid rgba(59, 130, 246, 0.45);
    border-color: var(--gf-chat-neon);
}

.gf-chat-edit-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.gf-chat-save-btn {
    border: none;
    border-radius: 0.45rem;
    padding: 0.4rem 0.85rem;
    font-size: 0.72rem;
    font-weight: 800;
    color: #fff;
    background: linear-gradient(135deg, #2563eb, #0ea5e9);
    cursor: pointer;
}

.gf-chat-cancel-edit-btn {
    border: none;
    border-radius: 0.45rem;
    padding: 0.4rem 0.85rem;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--gf-chat-muted);
    background: rgba(75, 85, 99, 0.35);
    cursor: pointer;
}

.gf-chat-compose,
.gf-discussion-compose {
    grid-area: discussion-footer;
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
        "reply reply"
        "input actions"
        "status status";
    column-gap: 0.5rem;
    row-gap: 0.5rem;
    align-items: end;
    flex-shrink: 0;
    margin: 0;
    margin-top: auto;
    padding: 0.65rem 1rem 0.85rem;
    border-top: 1px solid var(--gf-chat-border);
    background: rgba(11, 15, 26, 0.98);
    border-radius: 0 0 14px 14px;
    z-index: 2;
    box-sizing: border-box;
}

.gf-chat-replying-to {
    grid-area: reply;
    display: none;
    font-size: 0.72rem;
    color: var(--gf-chat-muted);
    margin-bottom: 0;
}

.gf-chat-replying-to.is-active {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.gf-chat-cancel-reply {
    border: none;
    background: transparent;
    color: var(--gf-chat-neon);
    font-size: 0.72rem;
    cursor: pointer;
}

.gf-chat-input {
    grid-area: input;
    width: 100%;
    min-width: 0;
    min-height: 3.25rem;
    max-height: 8rem;
    resize: none;
    border-radius: 12px;
    border: 1px solid rgba(75, 85, 99, 0.5);
    background: rgba(15, 23, 42, 0.9);
    color: var(--gf-chat-text);
    padding: 0.6rem 0.75rem;
    font-size: 0.84rem;
    font-family: inherit;
    outline: none;
    box-shadow: none;
}

.gf-chat-input:focus {
    outline: none;
    border-color: var(--gf-chat-neon);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.35);
}

.gf-chat-compose-actions {
    grid-area: actions;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: flex-end;
    align-self: end;
    gap: 0.5rem;
    margin: 0;
    flex-shrink: 0;
    width: auto;
}

.gf-chat-submit {
    border: none;
    border-radius: 0.55rem;
    padding: 0.5rem 1rem;
    font-size: 0.78rem;
    font-weight: 800;
    color: #fff;
    background: linear-gradient(135deg, #2563eb, #0ea5e9);
    cursor: pointer;
}

.gf-chat-submit:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.gf-chat-status {
    grid-area: status;
    grid-column: 1 / -1;
    font-size: 0.72rem;
    color: var(--gf-chat-muted);
    margin: 0;
    padding: 0;
    min-height: 1.1rem;
    line-height: 1.35;
    flex-shrink: 0;
}

.gf-chat-status.is-error {
    color: #f87171;
}

.gf-chat-compose--guest .gf-chat-input {
    cursor: not-allowed;
    opacity: 0.9;
}

.gf-chat-compose--guest .gf-chat-input::placeholder {
    color: #94a3b8;
    opacity: 1;
}

.gf-chat-toast {
    display: none;
    margin-top: 0.5rem;
    padding: 0.55rem 0.75rem;
    border-radius: 0.5rem;
    font-size: 0.75rem;
    line-height: 1.4;
    color: #fef3c7;
    background: rgba(120, 53, 15, 0.55);
    border: 1px solid rgba(251, 191, 36, 0.5);
}

.gf-chat-toast.is-visible {
    display: block;
}

/* Tablet / small desktop: fixed right panel (unchanged below 1024px) */
@media (min-width: 768px) and (max-width: 1023px) {
    .gf-chat-fab,
    .gf-chat-backdrop {
        display: none !important;
    }

    .gf-chat-panel {
        top: 0;
        right: 0;
        width: min(22rem, 100vw);
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
        min-height: 0;
        overflow: hidden;
        transform: none;
        visibility: visible;
        opacity: 1;
        pointer-events: auto;
    }
}

/* Large desktop: in-flow wide discussion (gym detail layout) */
@media (min-width: 1024px) {
    .gf-detail-discussion .gf-chat-fab,
    .gf-detail-discussion .gf-chat-backdrop {
        display: none !important;
    }

    .gf-detail-discussion,
    #chat-container.gf-detail-discussion {
        min-height: calc(100vh - 2.5rem);
        height: calc(100vh - 2.5rem);
        max-height: calc(100vh - 2.5rem);
    }

    .gf-detail-discussion .gf-chat-root {
        position: relative;
        width: 100%;
        height: 100%;
        min-height: 0;
    }

    .gf-detail-discussion .gf-chat-panel,
    .gf-detail-discussion .gf-discussion-container {
        position: relative !important;
        top: auto !important;
        right: auto !important;
        left: auto !important;
        bottom: auto !important;
        width: 100% !important;
        height: 100% !important;
        max-height: 100% !important;
        border-radius: 14px;
        overflow: hidden;
        transform: none !important;
        visibility: visible;
        opacity: 1;
        pointer-events: auto;
    }

    .gf-detail-discussion .gf-chat-thread-list {
        padding: 1rem 1.25rem 1.35rem;
    }

    .gf-detail-discussion .gf-chat-compose,
    .gf-detail-discussion .gf-discussion-compose {
        padding: 0.9rem 1.25rem 1rem;
        border-radius: 0 0 14px 14px;
    }

    .gf-detail-discussion .gf-chat-close {
        display: none;
    }

    .gf-detail-discussion .gf-chat-comment {
        width: 100%;
        max-width: none;
        padding: 0.85rem 1.15rem;
    }

    .gf-detail-discussion .gf-chat-body {
        font-size: 0.95rem;
        line-height: 1.6;
        max-width: none;
    }

    .gf-detail-discussion .gf-chat-meta {
        font-size: 0.75rem;
    }

    .gf-detail-discussion .gf-chat-input {
        width: 100%;
        min-height: 3.5rem;
        max-height: 7rem;
        resize: none;
        border-radius: 12px;
        font-size: 0.9rem;
        padding: 0.65rem 0.85rem;
    }

    .gf-detail-discussion .gf-chat-actions,
    .gf-detail-discussion .gf-comment-actions {
        margin-bottom: 0.5rem;
    }

    .gf-detail-discussion .gf-chat-compose-actions {
        display: flex;
        flex-direction: column;
        justify-content: flex-end;
        align-items: flex-end;
        align-self: end;
        width: auto;
    }

    .gf-detail-discussion .gf-chat-header-titles {
        flex-wrap: nowrap;
        align-items: flex-end;
        gap: 8px;
    }

    .gf-detail-discussion .gf-chat-comment-counter {
        white-space: nowrap;
    }

    .gf-detail-discussion .gf-chat-submit {
        min-width: 7.5rem;
        padding: 0.6rem 1.75rem;
        font-size: 0.82rem;
    }

    .gf-detail-discussion .gf-chat-header {
        padding: 1.1rem 1.25rem;
    }

    .gf-detail-discussion .gf-chat-title {
        font-size: 1.2rem;
    }

    .gf-detail-discussion .gf-chat-indent-1 {
        margin-left: 1.25rem;
        width: calc(100% - 1.25rem);
        max-width: calc(100% - 1.25rem);
    }

    .gf-detail-discussion .gf-chat-indent-2 {
        margin-left: 2.5rem;
        width: calc(100% - 2.5rem);
        max-width: calc(100% - 2.5rem);
    }
}

/* Mobile: bottom sheet */
@media (max-width: 767px) {
    .gf-chat-header-titles {
        flex-wrap: nowrap;
        align-items: flex-end;
        gap: 8px;
    }

    .gf-chat-comment-counter {
        white-space: nowrap;
    }

    .gf-chat-compose,
    .gf-discussion-compose {
        column-gap: 0.5rem;
        row-gap: 0.5rem;
        align-items: end;
    }

    .gf-chat-fab {
        display: inline-flex;
    }

    .gf-chat-root {
        height: 100%;
        max-height: 78vh;
    }

    .gf-chat-panel {
        left: 0;
        right: 0;
        bottom: 0;
        top: auto;
        width: 100%;
        height: 78vh;
        max-height: 78vh;
        min-height: 0;
        overflow: hidden;
        border-radius: 1rem 1rem 0 0;
        transform: translateY(100%);
        visibility: hidden;
        opacity: 0;
        pointer-events: none;
        transition: transform 0.28s ease, opacity 0.2s ease, visibility 0.28s;
    }

    .gf-chat-panel.is-open {
        transform: translateY(0);
    }
}
