/* ═══════════════════════════════════════════════════
   TH Ai Biotic — Reddit-Style Dark Theme
   ═══════════════════════════════════════════════════ */

/* ── Base ──────────────────────────────────────── */
body {
    background: #030303;
    font-family: 'Noto Sans Thai', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

.gradient-orange {
    background: linear-gradient(135deg, #F58220 0%, #FF9A3C 100%);
}

/* ── Top Navbar ────────────────────────────────── */
.reddit-navbar {
    background: #1a1a1b;
    border-bottom: 1px solid #343536;
    position: sticky;
    top: 0;
    z-index: 50;
}

.search-input {
    background: #272729;
    border: 1px solid #343536;
    border-radius: 20px;
    transition: all 0.2s;
}

.search-input:focus {
    border-color: #F58220;
    background: #1a1a1b;
    box-shadow: 0 0 0 3px rgba(245, 130, 32, 0.15);
}

.search-input:hover {
    border-color: #484849;
    background: #222223;
}

/* ── Layout ────────────────────────────────────── */
.reddit-layout {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    gap: 24px;
    padding: 20px 16px;
    align-items: flex-start;
}

.reddit-feed {
    flex: 1;
    min-width: 0;
}

.reddit-sidebar-right {
    width: 312px;
    flex-shrink: 0;
    position: sticky;
    top: 64px;
}

/* ── Room Left Rail ────────────────────────────── */
.reddit-left-rail {
    width: 220px;
    flex-shrink: 0;
    position: sticky;
    top: 64px;
}

.room-nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
    color: #d7dadc;
    font-size: 14px;
}

.room-nav-item:hover {
    background: #2a2a2b;
}

.room-nav-item.active {
    background: #272729;
    color: #F58220;
    font-weight: 600;
}

/* ── Sort Tabs ─────────────────────────────────── */
.sort-tabs {
    display: flex;
    align-items: center;
    gap: 4px;
    background: #1a1a1b;
    border: 1px solid #343536;
    border-radius: 8px;
    padding: 4px;
    margin-bottom: 12px;
}

.sort-tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
    color: #818384;
    cursor: pointer;
    transition: all 0.15s;
    border: none;
    background: none;
}

.sort-tab:hover {
    background: #2a2a2b;
    color: #d7dadc;
}

.sort-tab.active {
    background: #272729;
    color: #F58220;
}

/* ── Thread Card (Reddit Post) ─────────────────── */
.reddit-post {
    background: #1a1a1b;
    border: 1px solid #343536;
    border-radius: 8px;
    margin-bottom: 10px;
    transition: border-color 0.15s;
    overflow: hidden;
    cursor: pointer;
}

.reddit-post:hover {
    border-color: #818384;
}

.reddit-post-inner {
    display: flex;
}

.vote-column {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px 4px;
    width: 40px;
    flex-shrink: 0;
    background: #161617;
    gap: 2px;
}

.vote-btn {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    border: none;
    background: none;
    cursor: pointer;
    color: #818384;
    transition: all 0.1s;
    padding: 0;
}

.vote-btn:hover {
    background: #2a2a2b;
    color: #F58220;
}

.vote-btn.upvoted {
    color: #FF4500;
}

.vote-btn.downvoted {
    color: #7193FF;
}

.vote-count {
    font-size: 12px;
    font-weight: 700;
    color: #d7dadc;
    line-height: 1;
}

.post-content {
    flex: 1;
    padding: 8px;
    min-width: 0;
}

.post-meta {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: #818384;
    flex-wrap: wrap;
}

.post-meta .room-badge {
    font-weight: 700;
    color: #d7dadc;
    cursor: pointer;
}

.post-meta .room-badge:hover {
    text-decoration: underline;
}

.post-title {
    font-size: 18px;
    font-weight: 500;
    color: #d7dadc;
    margin: 6px 0 4px;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.post-preview {
    font-size: 14px;
    color: #818384;
    margin-bottom: 6px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.5;
}

.post-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 4px 4px;
}

.post-action-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 700;
    color: #818384;
    cursor: pointer;
    transition: background 0.1s;
    border: none;
    background: none;
}

.post-action-btn:hover {
    background: #2a2a2b;
    color: #d7dadc;
}

/* ── Right Sidebar ─────────────────────────────── */
.sidebar-card {
    background: #1a1a1b;
    border: 1px solid #343536;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 16px;
}

.sidebar-card-header {
    background: linear-gradient(135deg, #F58220, #FF9A3C);
    padding: 12px 16px;
    font-size: 14px;
    font-weight: 700;
    color: white;
}

.sidebar-card-body {
    padding: 12px 16px;
}

.sidebar-stat {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid #343536;
}

.sidebar-stat:last-child {
    border-bottom: none;
}

.sidebar-stat-value {
    font-size: 16px;
    font-weight: 700;
    color: #d7dadc;
}

.sidebar-stat-label {
    font-size: 12px;
    color: #818384;
}

/* ── Agent Cards (Sidebar) ─────────────────────── */
.agent-mini-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
}

.agent-mini-card:hover {
    background: #272729;
}

/* ── Create Post Bar ───────────────────────────── */
.create-post-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #1a1a1b;
    border: 1px solid #343536;
    border-radius: 8px;
    padding: 8px 12px;
    margin-bottom: 12px;
    cursor: pointer;
    transition: border-color 0.15s;
}

.create-post-bar:hover {
    border-color: #d7dadc;
}

.create-post-input {
    flex: 1;
    background: #272729;
    border: 1px solid #343536;
    border-radius: 4px;
    padding: 8px 16px;
    color: #d7dadc;
    font-size: 14px;
    outline: none;
    transition: all 0.15s;
}

.create-post-input:hover {
    background: #2a2a2b;
    border-color: #484849;
}

.create-post-input:focus {
    border-color: #F58220;
    background: #1a1a1b;
}

/* ── Thread Detail View ────────────────────────── */
.thread-detail-card {
    background: #1a1a1b;
    border: 1px solid #343536;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 16px;
}

/* Thread action pills (like Reddit's action bar) */
.thread-action-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 20px;
    background: #272729;
    color: #818384;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    border: none;
}

.thread-action-pill:hover {
    background: #343536;
    color: #d7dadc;
}

/* Reddit-style comment action buttons */
.comment-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    border-radius: 16px;
    background: transparent;
    color: #818384;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    border: none;
}

.comment-action-btn:hover {
    background: #272729;
    color: #d7dadc;
}

.comment-action-btn.liked {
    color: #ff4500;
}

.comment-actions {
    border-top: none;
    padding-top: 0;
}

/* Expand replies button */
.expand-replies-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    margin-top: 4px;
    border-radius: 20px;
    background: transparent;
    color: #4a9eff;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    border: none;
}

.expand-replies-btn:hover {
    background: #272729;
}

.expand-replies-btn .expand-icon {
    font-size: 10px;
    transition: transform 0.2s;
}

/* Reply sort dropdown */
.reply-sort-option {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 14px;
    background: none;
    border: none;
    color: #818384;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s;
    text-align: left;
}

.reply-sort-option:hover {
    background: #272729;
    color: #d7dadc;
}

.reply-sort-option.active {
    color: #4a9eff;
    background: #272729;
}

/* Inline reply box (Reddit-style) */
.inline-reply-box-reddit {
    margin-top: 8px;
    border: 1px solid #343536;
    border-radius: 12px;
    background: #1a1a1b;
    overflow: hidden;
}

.inline-reply-textarea {
    width: 100%;
    min-height: 80px;
    padding: 14px 16px;
    background: transparent;
    border: none;
    color: #d7dadc;
    font-size: 14px;
    resize: none;
    outline: none;
    font-family: inherit;
}

.inline-reply-textarea::placeholder {
    color: #818384;
}

.inline-reply-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 8px 12px;
    border-top: 1px solid #343536;
}

.inline-reply-cancel {
    padding: 6px 16px;
    border-radius: 20px;
    background: transparent;
    color: #d7dadc;
    font-size: 13px;
    font-weight: 600;
    border: 1px solid #343536;
    cursor: pointer;
    transition: all 0.15s;
}

.inline-reply-cancel:hover {
    background: #272729;
}

.inline-reply-submit {
    padding: 6px 16px;
    border-radius: 20px;
    background: #F58220;
    color: white;
    font-size: 13px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all 0.15s;
}

.inline-reply-submit:hover {
    background: #FF9A3C;
    transform: scale(1.02);
}

/* Join Conversation Box */
.join-conversation-box {
    border: 1px solid #343536;
    border-radius: 24px;
    padding: 10px 16px;
    cursor: text;
    transition: border-color 0.15s;
}

.join-conversation-box:hover {
    border-color: #d7dadc;
}

.join-conversation-placeholder {
    color: #818384;
    font-size: 14px;
}

/* ── Message / Comment ─────────────────────────── */
.message-bubble {
    animation: fadeInUp 0.3s ease;
    background: #1a1a1b;
    border: 1px solid #343536;
    border-radius: 8px;
    padding: 12px 16px;
}

.message-bubble:hover {
    border-color: #484849;
}

/* ── Threaded Comments ────────────────────────── */
.comment-thread {
    display: flex;
    gap: 0;
    margin-top: 8px;
    position: relative;
}

.thread-line {
    width: 20px;
    flex-shrink: 0;
    position: relative;
    cursor: pointer;
}

.thread-line::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 10px;
    width: 1px;
    background: #3a3a3c;
    transition: background 0.15s;
}

/* Horizontal connector — L-shape to link to child */
.thread-line::after {
    content: '';
    position: absolute;
    top: 20px;
    left: 10px;
    width: 10px;
    height: 1px;
    background: #3a3a3c;
    transition: background 0.15s;
}

.thread-line:hover::before,
.thread-line:hover::after {
    background: #F58220;
}

.thread-content {
    flex: 1;
    min-width: 0;
}

.comment-thread .message-bubble {
    border: none;
    border-radius: 4px;
    padding: 8px 8px 8px 0;
    background: transparent;
}

#replyPageReplies .whitespace-pre-wrap {
    white-space: normal;
}

.comment-thread .message-bubble:hover {
    background: #1a1a1b;
    border-color: transparent;
}

.comment-thread .avatar-photo,
.comment-thread .avatar-emoji-fallback {
    width: 24px;
    height: 24px;
    font-size: 11px;
}

/* Collapsed thread */
.comment-thread.collapsed>.thread-content>*:not(.message-bubble:first-child) {
    display: none;
}

.comment-thread.collapsed>.thread-content>.message-bubble:first-child {
    opacity: 0.5;
}

.comment-thread.collapsed>.thread-line::before {
    background: #818384;
    height: 100%;
}

.comment-thread.collapsed>.thread-line::after {
    content: '+';
    position: absolute;
    top: 4px;
    left: 5px;
    width: 12px;
    height: 12px;
    background: #272729;
    border: 1px solid #818384;
    border-radius: 50%;
    font-size: 10px;
    line-height: 10px;
    text-align: center;
    color: #818384;
}

/* Message action buttons */
.msg-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 6px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    color: #818384;
    cursor: pointer;
    transition: all 0.1s;
    border: none;
    background: none;
}

.msg-action-btn:hover {
    background: #2a2a2b;
    color: #d7dadc;
}

/* ── Like button ───────────────────────────────── */
.like-btn {
    transition: all 0.2s;
}

.like-btn:hover {
    transform: scale(1.1);
}

.like-btn.liked {
    color: #ef4444;
}

/* ── Avatar ────────────────────────────────────── */
.avatar-photo {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid transparent;
}

.avatar-emoji-fallback {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    border: 2px solid transparent;
    flex-shrink: 0;
}

/* ── Animations ────────────────────────────────── */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes gradientShift {

    0%,
    100% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }
}

/* ── Thread stagger animation ──────────────────── */
.thread-stagger {
    animation: fadeInUp 0.3s ease backwards;
}

.thread-stagger:nth-child(1) {
    animation-delay: 0.02s;
}

.thread-stagger:nth-child(2) {
    animation-delay: 0.04s;
}

.thread-stagger:nth-child(3) {
    animation-delay: 0.06s;
}

.thread-stagger:nth-child(4) {
    animation-delay: 0.08s;
}

.thread-stagger:nth-child(5) {
    animation-delay: 0.10s;
}

/* ── Typing Indicator ──────────────────────────── */
.typing-dot {
    animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) {
    animation-delay: 0s;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingBounce {

    0%,
    60%,
    100% {
        transform: translateY(0);
    }

    30% {
        transform: translateY(-6px);
    }
}

/* ── Modal ─────────────────────────────────────── */
.modal-overlay {
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
}

/* ── Inline Reply Box ──────────────────────────── */
.inline-reply-box {
    animation: fadeInUp 0.2s ease;
    background: #272729;
    border: 1px solid rgba(245, 130, 32, 0.3);
    border-radius: 8px;
}

/* ── Toast Notification ────────────────────────── */
.toast {
    animation: slideInRight 0.3s ease;
    background: #1a1a1b;
    border: 1px solid #343536;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    color: #d7dadc;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.toast.success {
    border-color: #22c55e;
}

.toast.error {
    border-color: #ef4444;
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* ── Skeleton Loading ──────────────────────────── */
.skeleton {
    background: linear-gradient(90deg, #272729 25%, #343536 50%, #272729 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s ease infinite;
    border-radius: 4px;
}

@keyframes shimmer {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

.skeleton-text {
    height: 14px;
    margin-bottom: 8px;
}

.skeleton-text-sm {
    height: 10px;
    margin-bottom: 6px;
}

.skeleton-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
}

.skeleton-card {
    padding: 12px;
    border-radius: 8px;
    background: #1a1a1b;
    border: 1px solid #343536;
    margin-bottom: 10px;
}

/* ── Loading Stage ─────────────────────────────── */
.stage-complete {
    opacity: 0;
    transition: opacity 0.5s ease;
}

/* ── Scrollbar ─────────────────────────────────── */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: #030303;
}

::-webkit-scrollbar-thumb {
    background: #343536;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #484849;
}

/* ── Content Visibility (perf) ─────────────────── */
.message-bubble {
    content-visibility: auto;
    contain-intrinsic-size: auto 120px;
}

/* ── Responsive ────────────────────────────────── */
@media (max-width: 1024px) {
    .reddit-sidebar-right {
        display: none;
    }

    .reddit-layout {
        padding: 12px 8px;
    }
}

@media (max-width: 768px) {
    .reddit-left-rail {
        display: none;
    }

    .reddit-left-rail.show {
        display: block;
        position: fixed;
        top: 48px;
        left: 0;
        bottom: 0;
        width: 260px;
        z-index: 40;
        background: #1a1a1b;
        border-right: 1px solid #343536;
        padding: 12px;
        overflow-y: auto;
    }

    .reddit-layout {
        gap: 0;
        padding: 8px;
    }

    .post-title {
        font-size: 15px;
    }

    .vote-column {
        width: 32px;
        padding: 6px 2px;
    }

    .thread-line {
        width: 16px;
    }

    .thread-line::before {
        left: 8px;
    }
}

/* ── Reduced Motion ────────────────────────────── */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ── Print ─────────────────────────────────────── */
@media print {
    body {
        background: white;
        color: black;
    }

    .reddit-navbar,
    .reddit-left-rail,
    .reddit-sidebar-right,
    .vote-column,
    .post-actions {
        display: none !important;
    }
}