/* topic_styles.css - Fixed Layout Version */
/* ✅ FIXED: Layout conflicts between header and main content */

/* Import Comment Styles */
@import url('topic_styles_comment.css');

/* ==================== CSS VARIABLES ==================== */
:root {
    --bg-primary:    #1a1f2e;
    --bg-secondary:  #2d3748;
    --bg-card:       #4a5568;
    --bg-hover:      #5a6578;

    --text-primary:   #ffffff;
    --text-secondary: #e2e8f0;
    --text-muted:     #a0aec0;
    --text-subtle:    #718096;

    --accent-main:   #68d391;
    --accent-second: #81e6d9;
    --accent-warm:   #f6e05e;
    --accent-danger: #fc8181;

    --border-primary:   #4a5568;
    --border-secondary: #5a6578;

    --gradient-main: linear-gradient(135deg, var(--accent-main), var(--accent-second));
    --gradient-warm: linear-gradient(135deg, var(--accent-warm), #fbb6ce);

    --shadow-sm: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 15px rgba(0,0,0,0.2);
    --shadow-lg: 0 8px 25px rgba(0,0,0,0.3);

    /* view-tier palette */
    --tier-hot:  #ff4757;
    --tier-warm: #ff7f50;
    --tier-mid:  #3d84f7;
    --tier-cool: #68d391;
}

/* ==================== BASE STYLES ==================== */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.4;
    margin: 0;
    padding: 0;
}

a {
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.3s ease;
}

a:hover {
    color: var(--text-primary);
}

/* ==================== HEADER LAYOUT (Fixed) ==================== */
.header {
    background: var(--bg-secondary);
    padding: 12px 20px;
    border-bottom: 1px solid var(--border-primary);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-content {
    max-width: 1200px; 
    margin: 0 auto; 
    padding: 12px 20px; 
    display: flex;
    justify-content: space-between; 
    align-items: center; 
    box-sizing: border-box;
    /* ✅ FIXED: Proper container constraints */
}

.header-left {
    flex: 0 0 auto;
}

.header-right {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 15px;
}

/* Logo Styles */
.logo-link { 
    display: flex; align-items: center; text-decoration: none; 
    transition: all 0.3s ease;
}
.logo-link:hover { transform: scale(1.02); }
.logo-container { display: flex; flex-direction: column; align-items: flex-start; }
.logo-main { display: flex; align-items: center; gap: 8px; margin-bottom: 2px; }
.logo-icon {
    font-size: 28px; background: linear-gradient(135deg, var(--accent-main), var(--accent-second));
    -webkit-background-clip: text; -webkit-text-fill-color: transparent; animation: pulse 2s infinite;
}
.logo-text {
    font-size: 22px; background: linear-gradient(135deg, var(--accent-main), var(--accent-second));
    -webkit-background-clip: text; -webkit-text-fill-color: transparent; font-weight: 600; margin: 0;
}
.logo-tagline {
    font-size: 11px; color: var(--text-muted); margin: 0; font-weight: 400;
    opacity: 0.8; transition: all 0.3s ease;
}
.logo-link:hover .logo-tagline { opacity: 1; color: var(--accent-main); }

/* Navigation Controls */
.nav-controls { display: flex; align-items: center; gap: 8px; }

.back-btn {
    display: flex; align-items: center; gap: 6px; padding: 8px 16px;
    background: rgba(104, 211, 145, 0.08); border: 1px solid rgba(104, 211, 145, 0.15);
    border-radius: 8px; color: var(--accent-main); text-decoration: none;
    font-size: 14px; font-weight: 500; transition: all 0.3s ease;
}
.back-btn:hover {
    background: rgba(104, 211, 145, 0.12); border-color: rgba(104, 211, 145, 0.25);
    transform: translateY(-1px); box-shadow: 0 4px 15px rgba(104, 211, 145, 0.2);
}

/* Create Post Button */
.create-post-btn {
    width: 36px; height: 36px; border-radius: 8px;
    background: rgba(104, 211, 145, 0.08); border: 1px solid rgba(104, 211, 145, 0.15);
    color: var(--accent-main); cursor: pointer; transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex; align-items: center; justify-content: center; font-size: 14px;
}
.create-post-btn:hover {
    background: rgba(104, 211, 145, 0.12); border-color: rgba(104, 211, 145, 0.25);
    transform: translateY(-1px); box-shadow: 0 8px 25px rgba(104, 211, 145, 0.15);
}

/* Hamburger Menu */
.hamburger-menu {
    width: 36px; height: 36px; background: rgba(160, 174, 192, 0.05);
    border: 1px solid rgba(160, 174, 192, 0.12); border-radius: 8px; cursor: pointer;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1); display: flex; flex-direction: column;
    justify-content: center; align-items: center; gap: 4px; padding: 10px;
}
.hamburger-menu:hover {
    background: rgba(160, 174, 192, 0.08); border-color: rgba(104, 211, 145, 0.2);
    transform: translateY(-1px); box-shadow: 0 6px 20px rgba(0, 0, 0, 0.1);
}
.hamburger-menu span {
    width: 16px; height: 2px; background: var(--text-secondary);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); border-radius: 2px;
}
.hamburger-menu:hover span { background: var(--accent-main); }

/* Auth Section */
.auth-section { display: flex; align-items: center; gap: 10px; }
.user-info { display: flex; align-items: center; gap: 8px; color: var(--text-primary); font-size: 14px; }

/* ✅ FIXED: User Avatar - Proper sizing and overflow control */
.user-avatar {
    width: 32px; height: 32px; border-radius: 50%; background: var(--accent-main);
    display: flex; align-items: center; justify-content: center; font-size: 14px;
    font-weight: 600; color: white; overflow: hidden; flex-shrink: 0; position: relative;
}
.user-avatar img { 
    width: 100%; height: 100%; object-fit: cover; 
    max-width: 100%; max-height: 100%; position: absolute; top: 0; left: 0; border-radius: 50%;
}

/* Google Auth Button */
.google-auth-btn {
    background: white; border: 1px solid #dadce0; border-radius: 50%;
    width: 40px; height: 40px; display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: all 0.3s ease; box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.google-auth-btn:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.15); transform: translateY(-1px);
}
.google-logo { width: 16px; height: 16px; }

/* Breadcrumb Navigation */
.breadcrumb-nav {
    background: linear-gradient(135deg, rgba(45, 55, 72, 0.8), rgba(74, 85, 104, 0.6));
    border-bottom: 1px solid var(--border-primary); 
    /*top: 65px; /* ✅ FIXED: Adjust based on header height */
    z-index: 99; 
    backdrop-filter: blur(8px);
}
.breadcrumb-container {
    max-width: 1200px; margin: 0 auto; padding: 6px 20px; display: flex;
    align-items: center; gap: 4px; font-size: 11px; flex-wrap: wrap;
}
.breadcrumb-item {
    display: flex; align-items: center; gap: 4px; padding: 3px 6px;
    border-radius: 4px; color: var(--text-muted); text-decoration: none;
    transition: all 0.3s ease; white-space: nowrap;
}
.breadcrumb-item:hover { background: rgba(74, 85, 104, 0.2); color: var(--text-secondary); }
.breadcrumb-item.current {
    color: var(--text-secondary); background: rgba(74, 85, 104, 0.15);
    border: 1px solid rgba(74, 85, 104, 0.3);
}
.breadcrumb-separator { color: var(--text-muted); font-size: 8px; margin: 0 1px; opacity: 0.6; }

.debug-badge {
    background: linear-gradient(135deg, #ef4444, #dc2626); color: white;
    padding: 4px 8px; border-radius: 4px; font-size: 10px; font-weight: 600;
}

/* ==================== MAIN LAYOUT (Fixed) ==================== */
/* ✅ FIXED: Main container with proper spacing and constraints */
.main-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 20px;
    /* ✅ FIXED: Ensure it doesn't conflict with header */
    box-sizing: border-box;
    min-height: calc(100vh - 120px); /* Account for header + breadcrumb */
}

/* ==================== BUTTONS ==================== */
.btn, .btn-small {
    padding: 8px 16px;
    border: 1px solid var(--border-primary);
    border-radius: 8px;
    background: var(--bg-card);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-small {
    padding: 4px 8px;
    font-size: 11px;
}

.btn:hover, .btn-small:hover {
    background: var(--bg-hover);
    transform: translateY(-1px);
}

.btn.primary {
    background: var(--gradient-main);
    border-color: var(--accent-main);
    color: white;
}

.btn.danger {
    background: linear-gradient(135deg, var(--accent-danger), #f56565);
    border-color: var(--accent-danger);
    color: white;
}

/* ==================== TOPIC CARD ==================== */
.topic-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: var(--shadow-md);
    margin-bottom: 20px;
    /* ✅ FIXED: Ensure proper width constraints */
    width: 100%;
    box-sizing: border-box;
}

.topic-header {
    padding: 20px 20px 16px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-primary);
}

.topic-meta {
    display: flex;
    align-items: center;
    gap: 15px;
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.topic-meta i {
    color: var(--accent-main);
}

.verified-badge {
    background: var(--gradient-main);
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 10px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 4px;
}

.topic-title {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 15px;
    line-height: 1.3;
    /* ✅ FIXED: Prevent text overflow */
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.topic-stats {
    display: flex;
    gap: 20px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: rgba(104, 211, 145, 0.1);
    border: 1px solid rgba(104, 211, 145, 0.3);
    border-radius: 20px;
    font-size: 12px;
    color: var(--text-muted);
}

.stat-item i {
    color: var(--accent-main);
}

.topic-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.action-btn {
    padding: 8px 16px;
    border: 1px solid var(--border-primary);
    border-radius: 8px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
}

.action-btn:hover {
    background: rgba(104, 211, 145, 0.1);
    border-color: var(--accent-main);
    color: var(--accent-main);
    transform: translateY(-1px);
}

.action-btn.liked {
    background: rgba(236, 72, 153, 0.2);
    border-color: #ec4899;
    color: #ec4899;
}

/* ==================== TOPIC CONTENT ==================== */
.topic-content {
    padding: 20px 20px 10px;
    font-size: 16px;
    line-height: 1.7;
    color: var(--text-secondary);
    word-wrap: break-word;
    overflow-wrap: break-word;
    max-width: 100%;
}

/* ==================== COMPACT STATS INFOGRAPHIC (csi) ==================== */

.topic-stats, .topic-actions { display: none; }

.csi-block {
    padding: 10px 0 16px;
    margin-bottom: 18px;
    border-bottom: 1px solid rgba(74,85,104,0.45);
}

/* meta chips row */
.csi-meta-row {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-bottom: 10px;
}
.csi-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 20px;
    background: rgba(74,85,104,0.25);
    font-size: 10px;
    color: var(--text-muted);
    white-space: nowrap;
}
.csi-chip i { font-size: 9px; }
.csi-chip.csi-yt  { background: rgba(255,50,50,0.1); color: #fc8181; border: 1px solid rgba(255,80,80,0.2); }
.csi-chip.csi-fire{ background: rgba(246,173,85,0.1); color: #f6ad55; border: 1px solid rgba(246,173,85,0.2); }

/* bars */
.csi-bars-wrap { display: flex; flex-direction: column; gap: 5px; margin-bottom: 10px; }

.csi-bar-row {
    display: grid;
    grid-template-columns: 13px 1fr 36px;
    align-items: center;
    gap: 8px;
}
.csi-bar-row i { font-size: 10px; text-align: center; }
.csi-icon-views { color: #63b3ed; }
.csi-icon-likes { color: #68d391; }
.csi-icon-cmts  { color: #b794f4; }
.csi-icon-read  { color: #f6e05e; }

.csi-track {
    height: 5px;
    background: rgba(255,255,255,0.06);
    border-radius: 10px;
    overflow: hidden;
}
.csi-fill {
    height: 100%;
    border-radius: 10px;
    width: 0%;
    transition: width 1s cubic-bezier(.4,0,.2,1);
}
.csi-fill-views { background: linear-gradient(90deg,#3b82f6,#63b3ed); box-shadow: 0 0 6px rgba(99,179,237,.3); }
.csi-fill-likes { background: linear-gradient(90deg,#38a169,#68d391); box-shadow: 0 0 6px rgba(104,211,145,.3); }
.csi-fill-cmts  { background: linear-gradient(90deg,#805ad5,#b794f4); box-shadow: 0 0 6px rgba(183,148,244,.3); }

.csi-val {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
    text-align: right;
    white-space: nowrap;
}

/* action row */
.csi-action-row {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}
.csi-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 18px;
    border: 1px solid rgba(104,211,145,0.2);
    background: rgba(104,211,145,0.06);
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all .2s ease;
    line-height: 1;
}
.csi-btn i { font-size: 11px; color: var(--accent-main); }
.csi-btn:hover { background: rgba(104,211,145,0.13); color: var(--text-primary); transform: translateY(-1px); }
.csi-like i  { color: #f472b6; }
.csi-like.liked { background: rgba(244,114,182,0.12); border-color: #f472b6; color: #f472b6; }
.csi-share i { color: var(--accent-second); }
.csi-share  { padding: 4px 9px; }

.csi-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 9px;
    border-radius: 18px;
    background: rgba(74,85,104,0.2);
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1;
}
.csi-pill i { font-size: 10px; color: var(--text-subtle); }

@media (max-width: 480px) {
    .csi-bar-row { grid-template-columns: 12px 1fr 30px; gap: 6px; }
    .csi-btn  { font-size: 11px; padding: 4px 8px; }
    .csi-pill { font-size: 10px; padding: 3px 7px; }
}

/* ==================== MAGAZINE CONTENT STYLES ==================== */

/* ลบกรอบซ้อน — เนื้อหาอยู่โดยตรงใน topic-content */
.ai-content-section {
    width: 100%;
    box-sizing: border-box;
}

.ai-section-content {
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Magazine Drop Cap สำหรับย่อหน้าแรก */
.ai-summary > p:first-of-type::first-letter,
.ai-summary::first-letter {
    font-size: 3.8em;
    font-weight: 800;
    float: left;
    line-height: 0.8;
    margin: 4px 8px 0 0;
    color: var(--accent-main);
    font-family: Georgia, serif;
}

/* Magazine body text */
.ai-summary {
    font-size: 17px;
    line-height: 1.4;
    color: var(--text-secondary);
    letter-spacing: 0.01em;
    position: relative;
    padding: 0;
    margin: 0;
    background: none;
    border: none;
    font-style: normal;
}

.ai-summary::before { display: none; }

/* Reading progress bar ด้านบนเนื้อหา */
.reading-progress-bar {
    height: 3px;
    background: linear-gradient(90deg, var(--accent-main), var(--accent-second));
    border-radius: 2px;
    margin-bottom: 24px;
    transform-origin: left;
    transition: width 0.3s ease;
}

/* Pull quote / highlight box */
.pull-quote {
    border-left: 4px solid var(--accent-main);
    padding: 12px 20px;
    margin: 28px 0;
    background: rgba(104, 211, 145, 0.06);
    border-radius: 0 8px 8px 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--accent-main);
    line-height: 1.5;
}

/* Section divider magazine style */
.section-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 28px 0;
}
.section-divider::before,
.section-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--border-primary), transparent);
}
.section-divider-icon {
    color: var(--accent-main);
    font-size: 14px;
    opacity: 0.7;
}

/* Readability score badge */
.readability-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(104, 211, 145, 0.1);
    border: 1px solid rgba(104, 211, 145, 0.25);
    border-radius: 20px;
    padding: 4px 12px;
    font-size: 11px;
    color: var(--accent-main);
    margin-bottom: 16px;
}
.readability-stars {
    color: #f6e05e;
    font-size: 10px;
    letter-spacing: 1px;
}

/* Estimated reading time */
.reading-meta-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 10px 0 20px 0;
    border-bottom: 1px solid rgba(74, 85, 104, 0.4);
    margin-bottom: 24px;
    font-size: 12px;
    color: var(--text-muted);
    flex-wrap: wrap;
}
.reading-meta-bar i { color: var(--accent-main); margin-right: 4px; }

/* Key points highlight */
.key-points-box {
    background: linear-gradient(135deg, rgba(104, 211, 145, 0.08), rgba(129, 230, 217, 0.05));
    border: 1px solid rgba(104, 211, 145, 0.2);
    border-radius: 12px;
    padding: 16px 20px;
    margin: 24px 0;
}
.key-points-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--accent-main);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.key-points-list {
    list-style: none;
    padding: 0;
    margin: 0;
}
.key-points-list li {
    padding: 4px 0 4px 20px;
    position: relative;
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.6;
}
.key-points-list li::before {
    content: '▸';
    position: absolute;
    left: 0;
    color: var(--accent-main);
}

/* detail2 content — magazine style continuation */
.detail2-content {
    font-size: 16px;
    line-height: 1.85;
    color: var(--text-secondary);
    margin-top: 20px;
    letter-spacing: 0.01em;
}

/* Footer brand stamp */
.brand-stamp {
    text-align: center;
    padding: 16px 0 8px;
}
.brand-stamp-inner {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: linear-gradient(135deg, rgba(104,211,145,0.1), rgba(129,230,217,0.08));
    border: 1px solid rgba(104,211,145,0.2);
    border-radius: 30px;
    padding: 6px 20px;
    font-size: 13px;
    font-weight: 600;
    color: var(--accent-main);
}

.ai-title {
    font-size: 20px;
    font-weight: 600;
    background: var(--gradient-main);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 15px;
}

.detail-title {
    color: var(--accent-main);
    margin: 20px 0 10px 0;
}

.detail-title.secondary {
    color: var(--accent-second);
}

/* ==================== MOBILE MAGAZINE OPTIMIZATIONS ==================== */
@media (max-width: 768px) {
    .ai-summary {
        font-size: 16px;
        line-height: 1.8;
    }
    .ai-summary::first-letter,
    .ai-summary > p:first-of-type::first-letter {
        font-size: 3.2em;
    }
    .pull-quote {
        font-size: 16px;
        padding: 10px 16px;
        margin: 20px 0;
    }
    .key-points-box {
        padding: 14px 16px;
    }
    .reading-meta-bar {
        gap: 12px;
    }
}

@media (max-width: 480px) {
    .ai-summary {
        font-size: 15px;
        line-height: 1.75;
    }
    .reading-meta-bar {
        font-size: 11px;
    }
}

.topic-tags {
    padding: 0 25px 25px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.topic-tags .tag {
    background: rgba(104, 211, 145, 0.1);
    color: var(--accent-main);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    border: 1px solid rgba(104, 211, 145, 0.3);
    cursor: pointer;
    transition: all 0.3s ease;
}

.topic-tags .tag:hover {
    background: rgba(104, 211, 145, 0.2);
    transform: translateY(-1px);
}

/* ==================== SIDEBAR ==================== */
.sidebar {
    display: flex;
    flex-direction: column;
    gap: 20px;
    /* ✅ FIXED: Ensure sidebar doesn't overflow */
    min-width: 0; /* Allow shrinking */
    max-width: 300px;
}

.sidebar-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: var(--shadow-md);
    /* ✅ FIXED: Proper width constraints */
    width: 100%;
    box-sizing: border-box;
}

.sidebar-header {
    background: var(--bg-card);
    padding: 15px 20px;
    border-bottom: 1px solid var(--border-primary);
}

.sidebar-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.sidebar-content {
    padding: 20px;
}

.video-preview {
    position: relative;
    margin-bottom: 15px;
    border-radius: 12px;
    overflow: hidden;
}

.video-thumbnail {
    width: 100%;
    height: 160px;
    object-fit: cover;
    cursor: pointer;
    transition: transform 0.3s ease;
}

.video-thumbnail:hover {
    transform: scale(1.05);
}

.play-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0,0,0,0.7);
    color: white;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.play-overlay:hover {
    background: var(--accent-main);
    transform: translate(-50%, -50%) scale(1.1);
}

.video-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
    line-height: 1.4;
}

.video-channel {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.video-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 15px;
}

.video-stat {
    background: var(--bg-primary);
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 11px;
    color: var(--text-muted);
    text-align: center;
    border: 1px solid var(--border-primary);
}

.video-stat i {
    color: var(--accent-main);
    margin-right: 4px;
}

.video-actions {
    display: flex;
    gap: 8px;
}

.video-btn {
    flex: 1;
    padding: 10px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    text-decoration: none;
}

.video-btn.primary {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white;
}

.video-btn.secondary {
    background: transparent;
    border: 1px solid var(--border-primary);
    color: var(--text-muted);
}

.video-btn:hover {
    filter: brightness(1.1);
    color: white;
}

.video-btn.secondary:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* Related Topics */
.related-topic {
    background: var(--bg-primary);
    border: 1px solid var(--border-primary);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    color: var(--text-secondary);
}

.related-topic:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--accent-main);
    transform: translateY(-1px);
}

.related-header {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 8px;
}

.related-title {
    font-size: 13px;
    font-weight: 500;
    color: inherit;
    line-height: 1.3;
    flex: 1;
}

.related-preview {
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 8px;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.related-meta {
    font-size: 10px;
    color: var(--text-muted);
    display: flex;
    gap: 10px;
}

.related-meta i {
    color: var(--accent-main);
}

/* Tag Container */
.tag-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.tag-container .tag {
    background: rgba(104, 211, 145, 0.1);
    color: var(--accent-main);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    border: 1px solid rgba(104, 211, 145, 0.3);
    cursor: pointer;
    transition: all 0.3s ease;
}

.tag-container .tag:hover {
    background: rgba(104, 211, 145, 0.2);
    transform: translateY(-1px);
}

/* ==================== NOTIFICATIONS ==================== */
.notification {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 12px 20px;
    border-radius: 8px;
    color: white;
    font-size: 14px;
    z-index: 10000;
    transform: translateX(400px);
    transition: transform 0.3s ease;
    box-shadow: var(--shadow-lg);
    max-width: 300px;
}

.notification.success { background: linear-gradient(135deg, #10b981, #059669); }
.notification.error { background: linear-gradient(135deg, #ef4444, #dc2626); }
.notification.warning { background: linear-gradient(135deg, #f59e0b, #d97706); }
.notification.info { background: linear-gradient(135deg, #3b82f6, #2563eb); }
.notification.show { transform: translateX(0); }

/* ==================== ANIMATIONS ==================== */
@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

/* ==================== MOBILE RESPONSIVE (Enhanced) ==================== */
@media (max-width: 768px) {
    /* Header Mobile Adjustments */
    .header-content { 
        padding: 12px 15px; 
    }
    
    .logo-icon { font-size: 24px; }
    .logo-text { font-size: 18px; }
    .logo-tagline { font-size: 9px; }
    .back-btn span { display: none; }
    .breadcrumb-nav { top: 55px; }
    .user-info span { display: none; }
    .user-avatar { width: 28px; height: 28px; font-size: 12px; flex-shrink: 0; }
    .create-post-btn, .hamburger-menu { width: 32px; height: 32px; font-size: 13px; }
    .google-auth-btn { width: 36px; height: 36px; }
    .google-logo { width: 14px; height: 14px; }
    
    /* Main Menu Mobile */
    .main-menu { width: 100%; max-width: 280px; }
    .quick-nav-grid { grid-template-columns: repeat(2, 1fr); }
    
    /* Main Container Mobile */
    .main-container {
        grid-template-columns: 1fr;
        padding: 15px;
        gap: 15px;
        min-height: calc(100vh - 100px);
    }
    
    .sidebar { 
        order: 2; 
        max-width: 100%;
    }
    
    .topic-header, 
    .topic-content {
        padding: 16px 14px;
    }
    
    .topic-title { 
        font-size: 20px; 
    }
    
    .topic-actions, 
    .topic-stats {
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .video-stats { 
        grid-template-columns: 1fr; 
    }
    
    .video-actions { 
        flex-direction: column; 
    }
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(30px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

@media (max-width: 480px) {
    .topic-header,
    .topic-content {
        padding: 14px 12px;
    }
    
    .topic-title {
        font-size: 18px;
    }
    
    .main-container {
        padding: 8px;
    }
}

/* ==================== LOADING AND ERROR STATES ==================== */
.loading {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
}

.loading i {
    animation: spin 1s linear infinite;
    font-size: 24px;
    color: var(--accent-main);
    margin-bottom: 10px;
}

.error-state {
    text-align: center;
    padding: 40px;
    color: var(--accent-danger);
    background: rgba(252, 129, 129, 0.1);
    border: 1px solid rgba(252, 129, 129, 0.3);
    border-radius: 12px;
    margin: 20px 0;
}

/* ==================== ACCESSIBILITY IMPROVEMENTS ==================== */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Focus indicators */
button:focus,
a:focus,
input:focus,
textarea:focus {
    outline: 2px solid var(--accent-main);
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --bg-primary: #000000;
        --bg-secondary: #1a1a1a;
        --text-primary: #ffffff;
        --border-primary: #666666;
    }
}

/* ==================== VIEW TIER CARDS ==================== */

.rt-card { background: rgba(45,55,72,0.8); border: 1px solid rgba(74,85,104,0.5); }

.rt-card.tier-hot {
    background: linear-gradient(135deg, rgba(255,71,87,.12) 0%, rgba(45,55,72,0.85) 60%);
    border-color: rgba(255,71,87,.25);
}
.rt-card.tier-warm {
    background: linear-gradient(135deg, rgba(255,127,80,.10) 0%, rgba(45,55,72,0.85) 60%);
    border-color: rgba(255,127,80,.22);
}
.rt-card.tier-mid {
    background: linear-gradient(135deg, rgba(61,132,247,.10) 0%, rgba(45,55,72,0.85) 60%);
    border-color: rgba(61,132,247,.2);
}

.rt-card .rt-accent-line { background: var(--tc, var(--accent-main)); }
.rt-card.tier-hot  { --tc: var(--tier-hot);  }
.rt-card.tier-warm { --tc: var(--tier-warm); }
.rt-card.tier-mid  { --tc: var(--tier-mid);  }
.rt-card.tier-cool { --tc: var(--tier-cool); }

.rt-tier-badge {
    position: absolute;
    top: 7px; right: 7px;
    font-size: 9px; font-weight: 700;
    letter-spacing: .6px;
    text-transform: uppercase;
    padding: 2px 6px;
    border-radius: 4px;
    color: #fff;
    background: var(--tc, var(--accent-main));
    opacity: .9;
}
.rt-card { position: relative; }

.rt-card.tier-hot .rt-accent-line {
    animation: flamePulse 1.8s ease-in-out infinite;
}
@keyframes flamePulse {
    0%,100% { opacity:.85; }
    50%      { opacity:1; box-shadow: 0 0 8px rgba(255,71,87,.5); }
}

.rt-card.tier-hot  .rt-icon-wrap { color: var(--tier-hot)  !important; }
.rt-card.tier-warm .rt-icon-wrap { color: var(--tier-warm) !important; }
.rt-card.tier-mid  .rt-icon-wrap { color: var(--tier-mid)  !important; }
.rt-card.tier-cool .rt-icon-wrap { color: var(--tier-cool) !important; }

/* ── Dark slate sidebar — distinct but easy on eyes ── */
.rt-sidebar-card {
    background: #1e2535;
    border-color: rgba(255,255,255,.07);
    box-shadow: 0 4px 20px rgba(0,0,0,.35);
}

.rt-sidebar-card .sidebar-content { background: transparent; padding: 10px 12px 12px; }

/* ── AIThai logo mark ── */
.rt-logo-mark {
    display: inline-flex;
    align-items: baseline;
    gap: 0;
    background: rgba(104,211,145,.12);
    border: 1px solid rgba(104,211,145,.2);
    border-radius: 5px;
    padding: 3px 6px 3px 5px;
    flex-shrink: 0;
    line-height: 1;
}
.rt-logo-mark-sm { padding: 2px 5px 2px 4px; }
.rt-logo-ai {
    font-size: 13px;
    font-weight: 900;
    letter-spacing: -0.5px;
    color: #68d391;
    font-family: -apple-system, 'Segoe UI', sans-serif;
}
.rt-logo-th {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1px;
    color: rgba(255,255,255,.45);
    font-family: -apple-system, 'Segoe UI', sans-serif;
}

/* header text */
.rt-sidebar-card .rt-sidebar-label { color: #c8d4e0; font-size: 12px; letter-spacing: 2px; }
.rt-sidebar-card .rt-sidebar-sub   { color: #566478; letter-spacing: 3px; }
.rt-sidebar-card .rt-sidebar-line  { background: linear-gradient(90deg, rgba(104,211,145,.18), transparent); }

/* cards inside */
.rt-sidebar-card .rt-card {
    background: rgba(255,255,255,.04);
    border-color: rgba(255,255,255,.07);
}
.rt-sidebar-card .rt-card:hover {
    background: rgba(255,255,255,.08);
    transform: translateX(3px);
    box-shadow: 0 2px 12px rgba(0,0,0,.25);
}
.rt-sidebar-card .rt-card.tier-hot {
    background: linear-gradient(135deg, rgba(255,71,87,.1) 0%, rgba(30,37,53,.9) 60%);
    border-color: rgba(255,71,87,.2);
}
.rt-sidebar-card .rt-card.tier-warm {
    background: linear-gradient(135deg, rgba(255,127,80,.09) 0%, rgba(30,37,53,.9) 60%);
    border-color: rgba(255,127,80,.18);
}
.rt-sidebar-card .rt-card.tier-mid {
    background: linear-gradient(135deg, rgba(61,132,247,.09) 0%, rgba(30,37,53,.9) 60%);
    border-color: rgba(61,132,247,.18);
}

/* text สีอ่อนบน dark */
.rt-sidebar-card .rt-title   { color: #dce6f0; font-size: 12.5px; }
.rt-sidebar-card .rt-preview { color: #7a90a8; opacity: 1; }
.rt-sidebar-card .rt-foot span { color: #566478; }
.rt-sidebar-card .rt-card .rt-stat-nerds { border-color: rgba(255,255,255,.07); }
.rt-sidebar-card .rt-sn-item { background: rgba(255,255,255,.06); color: #7a90a8; }
.rt-card .rt-stat-nerds {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 5px;
    padding-top: 5px;
    border-top: 1px solid rgba(0,0,0,.06);
    flex-wrap: wrap;
}
.rt-sidebar-card .rt-card .rt-stat-nerds { border-color: rgba(0,0,0,.08); }

.rt-sn-item {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 9.5px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    letter-spacing: .2px;
    padding: 2px 6px;
    border-radius: 3px;
    background: rgba(255,255,255,.12);
    color: var(--text-subtle);
}
.rt-sidebar-card .rt-sn-item { background: rgba(0,0,0,.05); color: #6a5e52; }

.rt-sn-item i { font-size: 8px; }
.rt-sn-item.sn-hot  { color: #e05050; background: rgba(224,80,80,.1); }
.rt-sn-item.sn-like { color: #e06070; background: rgba(224,96,112,.1); }
.rt-sn-item.sn-cmt  { color: #6a9fd8; background: rgba(106,159,216,.1); }

/* engagement rate badge */
.rt-engage-rate {
    margin-left: auto;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: .5px;
    padding: 2px 6px;
    border-radius: 3px;
    color: #fff;
}
.rt-engage-rate.eng-high { background: #e05050; }
.rt-engage-rate.eng-mid  { background: #d4a030; }
.rt-engage-rate.eng-low  { background: #5a8a6a; }

/* ── "อ่านต่อ" header ── */
.rt-sidebar-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 14px 0;
}
/* ── Tags card ── */
.jp-tags-card { overflow: visible; }

.jp-tags-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 14px 10px;
    border-bottom: 1px solid rgba(255,255,255,.06);
}
.jp-tags-title-wrap {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.jp-tags-label {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 1px;
    color: var(--text-secondary);
    line-height: 1;
}
.jp-tags-sub {
    font-size: 8px;
    letter-spacing: 2.5px;
    color: var(--text-subtle);
    text-transform: uppercase;
    line-height: 1;
}

/* tag pills — 5 Japanese colours cycling */
.jp-tag-container {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
}
.jp-tag {
    display: inline-flex;
    align-items: center;
    padding: 4px 11px;
    border-radius: 3px;           /* square-ish — Japanese label feel */
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .4px;
    cursor: pointer;
    transition: all .2s ease;
    border-left: 3px solid;
}
.jp-tag:hover { filter: brightness(1.15); transform: translateY(-1px); }

/* 1 — 朱 vermillion */
.jp-tag-1 {
    background: rgba(192,57,43,.12);
    color: #e07060;
    border-color: #c0392b;
}
/* 2 — 藍 indigo */
.jp-tag-2 {
    background: rgba(74,111,165,.13);
    color: #7eb8d4;
    border-color: #4a6fa5;
}
/* 3 — 萌黄 yellow-green */
.jp-tag-3 {
    background: rgba(107,153,63,.13);
    color: #a8cc6e;
    border-color: #6b993f;
}
/* 4 — 紫 purple */
.jp-tag-4 {
    background: rgba(120,80,160,.13);
    color: #b08fe0;
    border-color: #7850a0;
}
/* 5 — 黄土 ochre */
.jp-tag-5 {
    background: rgba(185,140,50,.13);
    color: #d4aa55;
    border-color: #b98c32;
}

/* ลบ sidebar-header เดิม — ใช้ rt-section-title แทน */
#relatedTopics { padding: 0; }

.sidebar-content { padding: 14px 14px 10px; }

.rt-card {
    display: flex;
    align-items: stretch;
    border-radius: 10px;
    overflow: hidden;
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.06);
    margin-bottom: 8px;
    cursor: pointer;
    transition: background .2s ease, transform .2s ease;
}
.rt-card:last-child { margin-bottom: 0; }
.rt-card:hover {
    background: rgba(255,255,255,0.07);
    transform: translateX(2px);
}

.rt-accent-line {
    width: 3px;
    flex-shrink: 0;
    border-radius: 10px 0 0 10px;
    opacity: .85;
}

.rt-body {
    display: flex;
    align-items: flex-start;
    gap: 9px;
    padding: 10px 10px 10px 9px;
    flex: 1;
    min-width: 0;
}

.rt-icon-wrap {
    font-size: 13px;
    margin-top: 1px;
    flex-shrink: 0;
    opacity: .85;
}

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

.rt-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    line-height: 1.4;
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.rt-preview {
    font-size: 10px;
    color: var(--text-muted);
    line-height: 1.4;
    margin-bottom: 5px;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
    opacity: .75;
}

.rt-foot {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.rt-foot span {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 10px;
    color: var(--text-subtle);
}
.rt-foot i { font-size: 9px; }
.rt-time { margin-left: auto; }

.rt-tag {
    font-size: 9px;
    padding: 1px 5px;
    border-radius: 4px;
    background: rgba(129,140,248,.15);
    color: #a5b4fc;
}

/* ==================== SCROLL TO TOP ==================== */
#scrollTopBtn {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    bottom: 24px;
    right: 18px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(30, 36, 54, 0.82);
    border: 1px solid rgba(104, 211, 145, 0.3);
    color: var(--accent-main);
    font-size: 13px;
    cursor: pointer;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 2px 12px rgba(0,0,0,0.4);
    transition: transform .2s ease, background .2s ease;
    z-index: 999;
}
#scrollTopBtn:hover {
    background: rgba(104, 211, 145, 0.18);
    transform: translateY(-2px);
}
#scrollTopBtn:active { transform: scale(0.92); }

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}