/* === Reset & Base === */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #2b5a8f;
    --primary-dark: #1e4270;
    --primary-light: #3d6fa3;
    --accent: #e8f2fc;
    --bg: #f8f9fb;
    --white: #ffffff;
    --text: #1a1f2e;
    --text-light: #5a6475;
    --border: #d4dbe6;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
    --radius: 12px;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* === Layout === */
.live-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* === Header (matches main site) === */
.live-header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: var(--white);
    flex-shrink: 0;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
}

.header-content {
    max-width: 900px;
    margin: 0 auto;
    padding: 18px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-title {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar {
    font-size: 2rem;
    line-height: 1;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

.title-text h1 {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.title-text .subtitle {
    font-size: 0.875rem;
    opacity: 0.9;
    margin-top: 2px;
    font-weight: 400;
}

.header-nav {
    display: flex;
    gap: 12px;
    align-items: center;
}

.nav-link {
    background: rgba(255, 255, 255, 0.15);
    color: var(--white);
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.35);
}

/* === Live Indicator === */
.live-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    opacity: 0.9;
}

.live-indicator.disconnected {
    opacity: 0.5;
}

.live-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4ade80;
    animation: pulse-dot 2s ease-in-out infinite;
}

.live-indicator.disconnected .live-dot {
    background: #94a3b8;
    animation: none;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(0.85); }
}

/* === Feed === */
.feed-container {
    flex: 1;
    padding: 24px 16px;
    max-width: 900px;
    width: 100%;
    margin: 0 auto;
}

.feed-items {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.feed-empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-light);
    font-size: 1.1rem;
}

.feed-empty a {
    color: var(--primary);
    text-decoration: underline;
}

/* === Feed Item === */
.feed-item {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: box-shadow 0.2s ease, border-color 0.2s ease;
    overflow: hidden;
}

.feed-item:hover {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
    border-color: var(--primary-light);
}

.feed-item-summary {
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.feed-item-question {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text);
    line-height: 1.4;
}

.feed-item-meta {
    display: flex;
    align-items: baseline;
    gap: 12px;
    font-size: 0.82rem;
    color: var(--text-light);
}

.feed-item-time {
    flex-shrink: 0;
}

.feed-item-preview {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* === Feed Item Expanded === */
.feed-item-detail {
    display: none;
    padding: 0 20px 20px;
    border-top: 1px solid var(--border);
}

.feed-item.open .feed-item-detail {
    display: block;
}

.feed-item.open .feed-item-preview {
    display: none;
}

.feed-item-answer {
    font-size: 0.95rem;
    line-height: 1.7;
    color: var(--text);
}

/* Markdown content inside answers */
.feed-item-answer p { margin-bottom: 10px; }
.feed-item-answer p:last-child { margin-bottom: 0; }
.feed-item-answer ul, .feed-item-answer ol { margin: 10px 0; padding-left: 24px; }
.feed-item-answer li { margin-bottom: 6px; }
.feed-item-answer strong { font-weight: 600; }
.feed-item-answer a { color: var(--primary); text-decoration: underline; }
.feed-item-answer h1, .feed-item-answer h2, .feed-item-answer h3 {
    margin: 14px 0 8px;
    font-weight: 700;
    line-height: 1.3;
}
.feed-item-answer h1 { font-size: 1.2rem; }
.feed-item-answer h2 { font-size: 1.1rem; }
.feed-item-answer h3 { font-size: 1rem; }
.feed-item-answer code {
    background: rgba(0, 0, 0, 0.06);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.9em;
}
.feed-item-answer pre {
    background: #f2f4f6;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 14px;
    overflow-x: auto;
    margin: 10px 0;
    font-size: 0.875rem;
}
.feed-item-answer pre code { background: none; padding: 0; }
.feed-item-answer blockquote {
    border-left: 4px solid var(--primary);
    padding: 6px 14px;
    margin: 10px 0;
    background: var(--accent);
    border-radius: 0 6px 6px 0;
}
.feed-item-answer table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 0.875rem;
}
.feed-item-answer th, .feed-item-answer td {
    padding: 8px 12px;
    border: 1px solid var(--border);
    text-align: left;
}
.feed-item-answer th {
    background: var(--accent);
    font-weight: 600;
}

/* Sources in expanded view */
.feed-item-sources {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.feed-item-sources summary {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--primary);
    cursor: pointer;
    padding: 6px 0;
}

.feed-item-sources ul {
    list-style: none;
    padding: 8px 0 0 0;
    margin: 0;
    font-size: 0.82rem;
    color: var(--text-light);
}

.feed-item-sources li {
    padding: 3px 0;
}

.feed-item-sources a {
    color: var(--primary);
    text-decoration: underline;
}

/* === New item animation === */
@keyframes slide-in {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.feed-item.new {
    animation: slide-in 0.3s ease-out;
}

/* === Mobile === */
@media (max-width: 768px) {
    .header-content {
        padding: 14px 16px;
    }

    .avatar {
        font-size: 1.5rem;
    }

    .title-text h1 {
        font-size: 1.35rem;
    }

    .title-text .subtitle {
        font-size: 0.8rem;
    }

    .nav-link {
        padding: 6px 14px;
        font-size: 0.8rem;
    }

    .feed-container {
        padding: 16px 12px;
    }

    .feed-item-summary {
        padding: 14px 16px;
    }

    .feed-item-detail {
        padding: 0 16px 16px;
    }

    .feed-item-meta {
        flex-direction: column;
        gap: 2px;
    }

    .feed-item-preview {
        white-space: normal;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
    }
}

.feed-item-admin-hide {
  margin-top: 6px;
  background: none;
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 6px;
  padding: 2px 10px;
  font-size: 0.75rem;
  color: #b91c1c;
  cursor: pointer;
}
.feed-item-admin-hide:hover { background: #fef2f2; border-color: #b91c1c; }

.feed-item-user {
  font-size: 0.75rem;
  color: var(--primary, #2b5a8f);
  background: rgba(43, 90, 143, 0.08);
  border-radius: 4px;
  padding: 1px 6px;
  margin-right: 6px;
}

.feed-item-great { font-size: 0.8rem; margin-right: 6px; }

/* "Continue this thread" button in the personal history view. */
.feed-item-continue {
  margin-top: 6px;
  align-self: flex-start;
  background: var(--accent, #e8f2fc);
  border: 1px solid var(--primary, #2b5a8f);
  border-radius: 6px;
  padding: 3px 12px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--primary, #2b5a8f);
  cursor: pointer;
  transition: all 0.2s ease;
}
.feed-item-continue:hover { background: var(--primary, #2b5a8f); color: #fff; }

/* === Thread groups === */
.feed-group {
    border-left: 3px solid var(--primary, #2b5a8f);
    border-radius: var(--radius);
    background: rgba(43, 90, 143, 0.04);
    padding: 4px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.thread-toggle {
    align-self: flex-start;
    margin: 0 4px 4px;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 4px 12px;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--primary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.thread-toggle:hover {
    background: var(--accent);
    border-color: var(--primary);
}

.thread-followups {
    display: none;
    flex-direction: column;
    gap: 8px;
    padding: 0 4px 4px;
}

.thread-followups.open {
    display: flex;
}

/* Follow-up entries sit indented beneath the thread's first question. */
.feed-item.followup {
    margin-left: 18px;
    border-style: dashed;
    background: var(--white);
}

@media (max-width: 768px) {
    .feed-item.followup {
        margin-left: 8px;
    }
}
