/* CSS Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Light Theme (Default) */
:root {
    /* Threads Colors */
    --primary-color: #000000;
    --primary-hover: #333333;
    --success-color: #10b981;
    --danger-color: #ff3040;
    --warning-color: #f59e0b;
    
    /* Background colors */
    --bg-body: #f7f8fa;
    --bg-primary: #ffffff;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f3f5f7;
    --bg-hover: #fafafa;
    
    /* Text colors */
    --text-primary: #000000;
    --text-secondary: #999999;
    --text-tertiary: #bbbbbb;
    --text-muted: #cccccc;
    
    /* Border colors */
    --border-primary: #f0f0f0;
    --border-secondary: #e5e5e5;
    
    /* Component specific */
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.05);
    --code-bg: #f3f5f7;
    --code-text: #000000;
    --blockquote-border: #e5e5e5;
    --link-hover: #000000;
    
    /* Status colors */
    --status-error-bg: #fff5f5;
    --status-error-border: #ffe0e0;
    --status-info-bg: #f0f7ff;
    --status-info-text: #0070f3;
    
    /* Tag colors */
    --tag-bg: #f3f5f7;
    --tag-text: #000000;
    --tag-border: #e5e5e5;
    --bg-danger: #fff5f5;
}

/* Dark Theme */
:root.dark-theme,
html.dark-theme {
    --primary-color: #ffffff;
    --primary-hover: #f3f5f7;
    --success-color: #10b981;
    --danger-color: #ff3040;
    --warning-color: #fbbf24;
    
    /* Background colors */
    --bg-body: #050505;
    --bg-primary: #101010;
    --bg-secondary: #101010;
    --bg-tertiary: #1e1e1e;
    --bg-hover: #1a1a1a;
    
    /* Text colors */
    --text-primary: #f3f5f7;
    --text-secondary: #777777;
    --text-tertiary: #444444;
    --text-muted: #333333;
    
    /* Border colors */
    --border-primary: #262626;
    --border-secondary: #333333;
    
    /* Component specific */
    --shadow-sm: none;
    --shadow-md: none;
    --code-bg: #1e1e1e;
    --code-text: #f3f5f7;
    --blockquote-border: #333333;
    --link-hover: #ffffff;
    
    /* Status colors */
    --status-error-bg: rgba(255, 48, 64, 0.1);
    --status-error-border: rgba(255, 48, 64, 0.2);
    --status-info-bg: rgba(0, 112, 243, 0.1);
    --status-info-text: #3b82f6;
    
    /* Tag colors */
    --tag-bg: #1e1e1e;
    --tag-text: #f3f5f7;
    --tag-border: #333333;
}

/* AI Summary Styling */
.ai-summary {
    background-color: var(--bg-tertiary);
    border-radius: 12px;
    padding: 1rem;
    margin: 0.75rem 0;
    position: relative;
    border-left: 3px solid var(--success-color);
}

.ai-badge {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--success-color);
    margin-bottom: 0.4rem;
    letter-spacing: 0.05em;
}

.ai-summary p {
    margin: 0;
    font-size: 0.9375rem;
    line-height: 1.5;
    color: var(--text-primary);
}

/* Base Styles */
html {
    /* Ensure CSS variables cascade properly in Safari */
    color-scheme: light;
}

html.dark-theme {
    color-scheme: dark;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    line-height: 1.5;
    color: var(--text-primary);
    background-color: var(--bg-body);
    transition: background-color 0.2s ease, color 0.2s ease;
    -webkit-font-smoothing: antialiased;
    /* iOS Safari boosts the font size of short text it heuristically classifies
       as primary content, so a feed name like "Claude" renders ~2x larger than
       a long one like "Hacker News (100+ pts)" even when the CSS font-size is
       identical. Pinning to 100% disables the heuristic so all .feed-name (and
       any other short snippet) renders at the declared size. */
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    display: flex;
    justify-content: center;
    min-height: 100vh;
    overflow-x: hidden;
    position: relative; /* For fixed positioning context */
}

/* Layout */
.layout-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    margin: 0 1rem;
    margin-left: calc(1rem + 72px);
    min-height: 100vh;
    max-width: 640px;
    position: relative;
    padding-top: 60px; /* Make space for fixed header */
}

@media (min-width: 1200px) {
    .layout-main {
        max-width: 680px;
    }
}

@media (max-width: 1200px) {
    .layout-main {
        margin-left: 1rem;
    }
}

.container {
    max-width: 100%;
    margin: 0;
    padding: 0 1.5rem;
    width: 100%;
}

.content-frame main.container {
    padding: 1.5rem;
}

/* Page Header and Titles */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0;
    height: 60px;
    flex-shrink: 0;
    position: fixed;
    top: 0;
    width: 100%;
    max-width: 640px;
    z-index: 100;
    background-color: var(--bg-body);
}

@media (min-width: 1200px) {
    .page-header {
        max-width: 680px;
    }
}

.page-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
    text-align: center;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    max-width: calc(100% - 96px);
    overflow: hidden;
    white-space: nowrap;
    flex: 1;
}

/* allow dropdown menu to overflow when page-title hosts the grouping switcher */
.page-title:has(.grouping-switcher) {
    overflow: visible;
    white-space: normal;
}

.title-text {
    display: inline-block;
    white-space: nowrap;
}

.title-text.marquee-active {
    animation: title-marquee 9s linear infinite;
}

@keyframes title-marquee {
    0%   { transform: translateX(0); }
    10%  { transform: translateX(0); }
    70%  { transform: translateX(var(--marquee-offset, -60px)); }
    85%  { transform: translateX(var(--marquee-offset, -60px)); }
    86%  { transform: translateX(0); }
    100% { transform: translateX(0); }
}

.header-left, .header-right {
    width: 48px;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.back-button {
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    border-radius: 50%;
    transition: background-color 0.2s;
    text-decoration: none;
    background: none;
    border: none;
    cursor: pointer;
}

.back-button:hover {
    background-color: var(--bg-tertiary);
}

/* Content Frame (Threads Style) */
.content-frame {
    flex: 1;
    background-color: transparent;
    border: none;
    box-shadow: none;
    border-radius: 0;
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 10;
}

/* Pseudo-element for the fixed borders and rounded corners */
.content-frame::before {
    content: '';
    position: fixed;
    top: 60px; /* same as layout padding */
    bottom: 0;
    left: calc(50% - 320px + 72px / 2); /* center minus half max-width plus sidebar compensation */
    width: 640px; /* max-width of layout-main */
    background-color: var(--bg-primary);
    border: 1px solid var(--border-primary);
    border-bottom: none;
    border-radius: 24px 24px 0 0;
    box-shadow: var(--shadow-md);
    z-index: -1;
    pointer-events: none;
}

@media (min-width: 1200px) {
    .content-frame::before {
        width: 680px;
        left: calc(50% - 340px + 72px / 2);
    }
}

@media (max-width: 1200px) {
    .content-frame::before {
        left: calc(50% - 320px);
    }
}

@media (max-width: 768px) {
    .content-frame::before {
        top: 50px; /* matches mobile sticky header height */
        bottom: calc(60px + env(safe-area-inset-bottom)); /* clear the bottom nav */
        left: 0;
        right: 0;
        width: auto;
    }

    .content-frame {
        background-color: transparent;
        border: none;
        border-radius: 0;
        box-shadow: none;
    }
}

/* We need to remove the background and border from the actual content frame 
   so the pseudo-element shows through and stays fixed while content scrolls */
.content-frame {
    background-color: transparent;
    border: none;
    box-shadow: none;
    border-radius: 0;
}

.content-frame main.container {
    padding: 0 !important; /* Allow edge-to-edge content */
}

/* Base style for the content that should look like it's inside the frame */
.settings-page,
.feeds-page,
.rss-help-page,
.rsshub-page {
    background-color: transparent;
    min-height: 100%;
}

/* Ensure padding is applied to all container inside content-frame */
.content-frame .container {
    padding: 0 !important;
}

.content-frame main {
    flex: 1;
    position: relative;
    z-index: 10;
}

footer {
    display: none;
}

/* Sidebar Navigation */
.sidebar {
    width: 72px;
    height: 100vh;
    position: fixed;
    left: calc(50% - 320px - 72px - 2rem);
    top: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0;
    border-right: none;
    background-color: transparent;
    z-index: 1000;
}

@media (max-width: 1200px) {
    .sidebar {
        left: 0;
        background-color: var(--bg-body);
        border-right: 1px solid var(--border-primary);
    }
}

.sidebar-top {
    height: 60px;
    width: 100%;
    position: absolute;
    top: 0;
    left: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.logo-link {
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

.logo {
    width: 32px;
    height: 32px;
}

.sidebar-nav {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    align-items: center;
    margin: 0;
}

.sidebar-nav > a,
.search-toggle,
.filter-toggle,
.sidebar-liked-toggle,
.more-toggle {
    color: var(--text-tertiary);
    text-decoration: none;
    transition: color 0.2s, transform 0.1s;
    background: none;
    border: none;
    padding: 0.75rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
}

.sidebar-nav > a:hover,
.search-toggle:hover,
.filter-toggle:hover,
.sidebar-liked-toggle:hover,
.more-toggle:hover {
    color: var(--text-primary);
    background-color: var(--bg-tertiary);
}

.sidebar-nav > a.active {
    color: var(--text-primary);
}

.sidebar-bottom {
    margin-top: auto;
    width: 100%;
    display: flex;
    justify-content: center;
    padding-bottom: 0.5rem;
}

/* More Menu */
.more-menu-container {
    position: relative;
}

.more-menu {
    position: absolute;
    bottom: 0;
    left: 100%;
    margin-left: 0.5rem;
    background-color: var(--bg-primary);
    border: 1px solid var(--border-primary);
    border-radius: 16px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
    padding: 0.5rem;
    width: 180px;
    display: none;
    flex-direction: column;
    z-index: 1100;
}

.more-menu.active {
    display: flex;
}

.more-menu-item,
.theme-toggle-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 0.9375rem;
    font-weight: 500;
    border-radius: 12px;
    transition: background-color 0.2s;
    background: none;
    border: none;
    width: 100%;
    cursor: pointer;
    text-align: left;
}

.more-menu-item:hover,
.theme-toggle-item:hover {
    background-color: var(--bg-tertiary);
}

.theme-icon-container {
    position: relative;
    width: 18px;
    height: 18px;
}

.theme-icon-container svg {
    position: absolute;
    top: 0;
    left: 0;
    transition: opacity 0.3s;
}

.sun-icon { opacity: 1; }
.moon-icon { opacity: 0; }

html.dark-theme .sun-icon { opacity: 0; }
html.dark-theme .moon-icon { opacity: 1; }

/* Filter Panel Styles */
.filter-panel {
    position: absolute;
    left: 80px;
    top: 50%;
    transform: translateY(-50%);
    width: 280px;
    background-color: var(--bg-primary);
    border: 1px solid var(--border-primary);
    border-radius: 16px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.filter-panel.active {
    opacity: 1;
    visibility: visible;
}

.filter-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-primary);
}

.filter-panel-header h3 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
}

.filter-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

.filter-close:hover {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

.filter-panel-content {
    padding: 1.25rem;
}

.filters-vertical {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.filter-group label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.filter-select {
    width: 100%;
    height: 36px;
    padding: 0 0.75rem;
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-secondary);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.875rem;
    cursor: pointer;
    outline: none;
}

.filter-group.toggle-group {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
}

.filter-group.toggle-group label {
    margin: 0;
}

/* General Page Styles for non-article content */
.settings-page,
.feeds-page,
.rss-help-page {
    padding: 0;
}

/* Base style for the new RSSHub Explorer content structure */
.rsshub-page {
    background-color: transparent;
    min-height: 100%;
}

/* Page Headers (Settings, Feeds, RSS Help) */
.feeds-header, .rss-help-header, .settings-header {
    padding: 1.5rem 1.5rem 1rem;
    border-bottom: 1px solid var(--border-primary);
    background-color: var(--bg-primary);
    border-radius: 24px 24px 0 0;
}

.feeds-header h2, .rss-help-header h2, .settings-header h2 {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0;
    color: var(--text-primary);
}

.settings-header p, .rss-help-header p {
    margin-top: 0.25rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.feeds-header {
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Content Area for other pages */
.feeds-list, .rss-help-content, .settings-tab-content, .rsshub-page {
    padding: 1.5rem;
}

.rsshub-page {
    padding: 1.5rem;
}

.rsshub-content {
    margin: 0;
}

.rsshub-list {
    border-bottom: 1px solid var(--border-primary);
}

.rsshub-list-item {
    padding: 1rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    border-bottom: 1px solid var(--border-primary);
    cursor: pointer;
    transition: background-color 0.2s;
    text-align: left;
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
    width: 100%;
    color: var(--text-primary);
}

.rsshub-list-item:hover {
    background-color: var(--bg-hover);
}

.rsshub-list-item:last-child {
    border-bottom: none;
}

/* Settings Tabs */
.settings-tabs {
    display: flex;
    padding: 0 1.5rem;
    border-bottom: 1px solid var(--border-primary);
    gap: 1rem;
    background-color: var(--bg-primary);
}

.settings-tab {
    padding: 1rem 0;
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9375rem;
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.settings-tab[aria-selected="true"] {
    color: var(--text-primary);
}

.settings-tab[aria-selected="true"]::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    right: 0;
    height: 2px;
    background-color: var(--text-primary);
    border-radius: 2px 2px 0 0;
}

/* Settings Group and Grid Redesign — horizontal gutter comes from
   .settings-tab-content (1.5rem); the section itself only handles
   vertical rhythm. */
.settings-section {
    background-color: transparent;
    border-radius: 0;
    border: none;
    padding: 1.5rem 0;
    margin-bottom: 0;
    box-shadow: none;
    border-bottom: 1px solid var(--border-primary);
}

.section-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
}

.section-header i {
    color: var(--text-primary);
    font-size: 1.1rem;
}

.section-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0;
    color: var(--text-primary);
}

.settings-grid {
    display: flex;
    flex-direction: column;
    gap: 1px;
    background-color: transparent;
    border-radius: 0;
    border: none;
    overflow: visible;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center; /* keep center for simple items */
    padding: 1rem 0;
    background-color: transparent;
    gap: 1rem; /* prevent overlap */
    border-bottom: 1px solid var(--border-primary);
}

.setting-item:last-child {
    border-bottom: none;
}

/* Support multi-line descriptions inside settings without overlap.
   The leading padding mirrors the section-header's icon + gap so labels
   line up with the section heading text, not the heading icon. */
.setting-item-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0; /* allows text truncation */
    align-items: flex-start;
    text-align: left;
    padding-left: calc(1.1rem + 0.5rem);
}

.setting-item label {
    font-weight: 500;
    color: var(--text-primary);
    font-size: 0.9375rem;
    margin: 0;
    padding: 0;
}

.setting-item small {
    margin-top: 0.25rem;
    color: var(--text-secondary);
    font-size: 0.8125rem;
    line-height: 1.4;
}

.setting-value {
    color: var(--text-secondary);
    font-size: 0.9375rem;
    text-align: right;
    white-space: nowrap; /* keep value on one line */
    flex-shrink: 0; /* don't shrink the value */
}

.subsection-header {
    font-size: 1rem;
    font-weight: 600;
    margin: 1.5rem 0 1rem;
    color: var(--text-primary);
    padding-left: calc(1.1rem + 0.5rem);
}

/* subsection headers that already carry a leading icon (e.g. inside the
   topic-preferences container) line up with their own icon — no extra indent */
.topic-section .subsection-header {
    padding-left: 0;
}

/* Feeds Page Redesign — feed-card mirrors article-card */
.feed-card {
    /* inherits .article-card grid (48px avatar + 1fr main) */
    /* feed-specific tweaks below */
}

.feed-card .card-head {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.feed-card .feed-name {
    color: var(--text-primary);
    font-weight: 700;
    font-size: 0.9375rem;
    text-decoration: none;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.feed-card .feed-name:hover {
    text-decoration: underline;
}

.feed-card .feed-status-pill {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.1rem 0.5rem;
    border-radius: 8px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-left: auto;
    flex-shrink: 0;
}

.feed-card .feed-status-pill.disabled {
    color: var(--text-secondary);
    background: var(--bg-tertiary);
}

.feed-card .feed-status-pill.error {
    color: var(--danger-color);
    background: rgba(255, 48, 64, 0.1);
}

.feed-card .feed-url-line a {
    color: var(--text-secondary);
    text-decoration: none;
    /* wrap long urls onto multiple lines so the user can read what is actually
       subscribed (long rsshub:// urls have no natural break opportunities, so
       break-all is needed; overflow-wrap: anywhere is the modern complement). */
    word-break: break-all;
    overflow-wrap: anywhere;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.8125rem;
}

.feed-card .feed-url-line a:hover {
    text-decoration: underline;
}

.feed-card .feed-description-line p {
    color: var(--text-primary);
    font-size: 0.9375rem;
}

.feed-card .feed-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.feed-card .feed-error {
    background-color: rgba(255, 48, 64, 0.1);
    color: var(--danger-color);
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    font-size: 0.8125rem;
    margin-bottom: 0.5rem;
}

.feed-card .feed-edit-form {
    background-color: var(--bg-tertiary);
    border-radius: 12px;
    padding: 1rem;
    margin: 0.5rem 0;
}

.feed-card .card-actions {
    gap: 0.5rem;
}

.feed-card .card-actions .action {
    padding: 0.4rem;
    border-radius: 8px;
    color: var(--text-secondary);
    transition: background-color 0.15s ease, color 0.15s ease, opacity 0.2s;
}

.feed-card .card-actions .action:hover {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
    opacity: 1;
}

.feed-card .card-actions .action-delete:hover {
    background-color: rgba(255, 48, 64, 0.1);
    color: var(--danger-color);
}

/* spin the refresh icon while the fetch request is in flight */
.feed-card .action-fetch.htmx-request .icon {
    animation: feed-fetch-spin 0.9s linear infinite;
}

@keyframes feed-fetch-spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

@media (max-width: 768px) {
    .feed-card {
        padding: 1rem;
    }
}

/* legacy classes kept for any non-feed-card consumers */
.status-badge {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.25rem 0.5rem;
    border-radius: 8px;
    text-transform: uppercase;
}

.status-enabled { color: var(--success-color); background: rgba(16, 185, 129, 0.1); }
.status-disabled { color: var(--text-secondary); background: var(--bg-tertiary); }
.status-error { color: var(--danger-color); background: rgba(255, 48, 64, 0.1); }

.feed-url {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin: 0;
    word-break: break-all;
}

.feed-description {
    font-size: 0.9375rem;
    color: var(--text-primary);
    margin: 0;
}

.feed-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin-top: 0.5rem;
}

.feed-error {
    background-color: rgba(255, 48, 64, 0.1);
    color: var(--danger-color);
    padding: 0.75rem;
    border-radius: 8px;
    font-size: 0.875rem;
    margin-top: 0.5rem;
}

.feed-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 0.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-primary);
}

.feed-actions button,
.form-actions button,
.btn-primary,
.btn-secondary,
.btn-danger {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    border: none;
    transition: background-color 0.2s, opacity 0.2s;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-primary {
    background-color: var(--primary-color);
    color: var(--bg-primary);
}

.btn-primary:hover {
    opacity: 0.9;
}

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

.btn-secondary:hover {
    background-color: var(--border-primary);
}

.btn-danger {
    background-color: rgba(255, 48, 64, 0.1);
    color: var(--danger-color);
}

.btn-danger:hover {
    background-color: rgba(255, 48, 64, 0.2);
}

/* Add Feed Form */
.feed-form {
    background-color: var(--bg-tertiary);
    border-radius: 16px;
    padding: 1.5rem;
    margin: 0 1.5rem 1.5rem;
}

.feed-form h3 {
    margin: 0 0 1rem 0;
    font-size: 1.1rem;
    color: var(--text-primary);
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.form-group label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
}

.form-group input[type="text"],
.form-group input[type="url"],
.form-group input[type="number"],
.form-control,
.topic-select {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    border: 1px solid var(--border-secondary);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.9375rem;
    outline: none;
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-control:focus {
    border-color: var(--primary-color);
}

.form-group small {
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

/* Ensure article list doesn't have extra horizontal padding */
#articles-list {
    width: 100%;
}

.search-page-container {
    padding: 1.5rem 1.5rem 0.5rem;
    width: 100%;
}

.search-page-form {
    width: 100%;
}

.search-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: 12px;
    padding: 0 1rem;
    transition: background-color 0.2s, border-color 0.2s;
    height: 44px;
}

.search-input-wrapper:focus-within {
    background-color: var(--bg-primary);
    border-color: var(--border-secondary);
}

.search-icon {
    color: var(--text-secondary);
    margin-right: 0.75rem;
    width: 18px;
    height: 18px;
}

.search-page-input {
    flex: 1;
    height: 100%;
    border: none;
    background: none;
    font-size: 0.95rem;
    color: var(--text-primary);
    outline: none;
}

.search-page-input::placeholder {
    color: var(--text-tertiary);
}

.search-filter-dropdown-container {
    position: relative;
    display: flex;
    align-items: center;
}

.search-filter-toggle {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0.35rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, color 0.2s;
    margin-left: 0.5rem;
}

.search-filter-toggle:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}

.search-filter-menu {
    display: none;
    position: absolute;
    top: calc(100% + 0.5rem);
    right: 0;
    background-color: var(--bg-primary);
    border: 1px solid var(--border-secondary);
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
    min-width: 200px;
    z-index: 100;
    padding: 0.5rem;
    flex-direction: column;
}

.search-filter-menu.show {
    display: flex;
}

.search-filter-menu label.dropdown-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 0.75rem;
    cursor: pointer;
    border-radius: 8px;
    transition: background-color 0.2s;
    font-size: 0.9375rem;
    color: var(--text-primary);
    margin: 0;
}

.search-filter-menu label.dropdown-item:hover {
    background-color: var(--bg-hover);
}

.search-filter-menu input[type="radio"] {
    display: none;
}

.search-filter-menu input[type="radio"]:checked + span {
    font-weight: 600;
}

.search-filter-menu svg {
    color: var(--text-secondary);
}

/* RSS Help Page Redesign */
.rss-section {
    background-color: var(--bg-primary);
    border-radius: 16px;
    border: 1px solid var(--border-primary);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-sm);
}

.rss-section h3 {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0 0 1.25rem 0;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.rss-feed-list {
    display: flex;
    flex-direction: column;
    gap: 1px;
    background-color: var(--border-primary);
    border-radius: 12px;
    border: 1px solid var(--border-primary);
    overflow: hidden;
}

.rss-feed-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    background-color: var(--bg-primary);
}

.rss-feed-info h4 {
    margin: 0 0 0.25rem;
    font-size: 0.9375rem;
    color: var(--text-primary);
}

.rss-feed-info p {
    margin: 0 0 0.5rem;
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.rss-url {
    background-color: var(--bg-tertiary);
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.btn-copy {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.25rem;
    padding: 0.5rem;
    border-radius: 50%;
    transition: background-color 0.2s;
}

.btn-copy:hover {
    background-color: var(--bg-tertiary);
}

/* Ensure article cards don't get double padding and look consistent */
.no-articles {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-secondary);
    font-size: 0.9375rem;
}

/* Source Page */
.source-page-container {
    padding: 0;
    width: 100%;
}
.source-section-title {
    font-size: 0.9375rem;
    font-weight: 700;
    color: var(--text-secondary);
    padding: 1.5rem 1.5rem 0.5rem;
    margin: 0;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.source-separator {
    height: 12px;
    background-color: var(--bg-tertiary);
    border-top: 1px solid var(--border-primary);
    border-bottom: 1px solid var(--border-primary);
    margin: 1rem 0;
}

.article-card {
    display: grid;
    grid-template-columns: 48px 1fr;
    gap: 0.75rem;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-primary);
    background-color: transparent;
    transition: transform 0.15s ease, opacity 0.2s ease;
    touch-action: pan-y;
    position: relative;
    z-index: 1;
}

.article-card:last-child {
    border-bottom: none;
}

.card-avatar {
    grid-column: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    position: relative;
    z-index: 3;
}

.avatar-img {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background-color: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.875rem;
    color: var(--text-secondary);
    overflow: hidden;
    flex-shrink: 0;
}

.avatar-img.favicon-img {
    background-color: var(--bg-primary);
    object-fit: contain;
    border: 1px solid var(--border-primary);
}

/* iMessage-style brand badge sitting at the bottom-right of a post avatar.
   Anchored against .card-avatar (position: relative) so it overhangs the
   36x36 avatar by ~4px on right and bottom. The white border separates the
   badge visually from the avatar underneath. */
.avatar-badge {
    position: absolute;
    top: 22px;
    left: 22px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 2px solid var(--bg-primary);
    object-fit: cover;
    background: var(--bg-primary);
    z-index: 4;
    pointer-events: none;
}

.thread-line {
    flex: 1;
    width: 2px;
    background-color: var(--border-primary);
    border-radius: 1px;
}

.card-main {
    grid-column: 2;
    position: relative;
}

.card-head {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-bottom: 0.2rem;
    flex-wrap: wrap;
    position: relative;
    z-index: 2;
}

.card-head .feed-name {
    font-weight: 700;
    color: var(--text-primary);
    font-size: 0.9375rem;
    text-decoration: none;
}

.card-head .card-head-sep {
    color: var(--text-muted);
    font-size: 0.75rem;
}

.card-head .card-topic {
    color: var(--text-secondary);
    font-size: 0.875rem;
    text-decoration: none;
    background-color: var(--bg-tertiary);
    padding: 0.1rem 0.5rem;
    border-radius: 8px;
}

.card-head .card-time {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-left: 0.25rem;
}

.score-badge-mini {
    margin-left: auto;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.1rem 0.4rem;
    border-radius: 8px;
}

.score-badge-mini.score-low { color: var(--text-tertiary); background: var(--bg-tertiary); }
.score-badge-mini.score-medium { color: var(--warning-color); background: rgba(245, 158, 11, 0.1); }
.score-badge-mini.score-high { color: var(--success-color); background: rgba(16, 185, 129, 0.1); }

.card-title {
    font-size: 0.9375rem;
    font-weight: 400;
    margin-bottom: 0.5rem;
    line-height: 1.4;
    position: relative;
    z-index: 2;
}

.card-title a {
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 400; /* Like the replying-to text */
}

.card-summary {
    font-size: 0.9375rem;
    color: var(--text-primary);
    margin-bottom: 0.75rem;
    position: relative;
    z-index: 2;
}

.card-summary p {
    margin: 0;
    line-height: 1.5;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.card-summary p.card-summary-fallback {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    color: var(--text-primary);
    font-size: 0.9375rem;
    margin-bottom: 0.5rem;
    word-break: break-word;
    overflow-wrap: anywhere;
}

/* Remove AI Badge styling as it's now just normal text */
.ai-summary {
    /* Removed background, padding, border */
}

.ai-badge {
    display: none; /* Hide the AI Summary text */
}

.replying-to {
    color: var(--text-secondary);
    font-weight: 400;
    margin-right: 0.25rem;
}

.card-post-image {
    margin: 0.5rem 0 0.75rem;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--border-secondary);
    position: relative;
    z-index: 2;
}

.card-post-image img {
    width: 100%;
    max-height: 400px;
    object-fit: cover;
    display: block;
}

.card-actions {
    display: flex;
    gap: 1.25rem;
    margin-top: 0.5rem;
    z-index: 2;
    position: relative;
}

.card-actions .action {
    color: var(--text-primary);
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    transition: opacity 0.2s, transform 0.1s;
}

.card-actions .action:hover {
    opacity: 0.6;
}

.card-actions .action:active {
    transform: scale(0.9);
}

.card-actions .action .icon {
    width: 20px;
    height: 20px;
}

.card-actions .action.active {
    color: var(--danger-color);
}

.card-actions .action.action-done.active {
    color: var(--success-color);
}

.action-label {
    font-size: 0.75rem;
    font-weight: 500;
    margin-bottom: 0.25rem; /* Space below label instead of above */
    display: block;
    color: var(--text-secondary);
}

.action {
    display: flex;
    flex-direction: column; /* Label is first in HTML, so it will be on top */
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
}

/* Card Extras (Score, Topics, Explanation) */
.card-extras {
    display: none; /* Hide extras container since we moved everything else */
}

.classification {
    display: none; /* Hide score as it's shown in header */
}

.score-bar {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.5rem;
    border-radius: 8px;
    font-size: 0.8125rem;
    font-weight: 600;
    width: auto !important; /* Override inline width for a cleaner badge look */
}

.score-bar.score-low { color: var(--text-tertiary); background: var(--bg-tertiary); }
.score-bar.score-medium { color: var(--warning-color); background: rgba(245, 158, 11, 0.1); }
.score-bar.score-high { color: var(--success-color); background: rgba(16, 185, 129, 0.1); }

.explanation-bubble {
    background-color: var(--bg-tertiary);
    border-radius: 12px 18px 18px 12px; /* Smooth corners */
    position: relative;
    padding: 0.75rem 1rem;
    flex: 1; /* take up remaining space */
}

.explanation {
    font-size: 0.875rem;
    line-height: 1.5;
    color: var(--text-primary);
    margin: 0;
    position: relative;
    z-index: 2; /* Ensure text is above the tail */
}

/* Chat bubble tail */
.explanation-bubble::before {
    content: '';
    position: absolute;
    top: 10px; /* change to top left */
    left: -4px;
    width: 12px;
    height: 12px;
    background-color: var(--bg-tertiary);
    border-radius: 2px;
    z-index: 0;
    transform: rotate(45deg);
}

.explanation-bubble::after {
    display: none; /* remove second tail part */
}

.card-explanation {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    align-items: flex-start; /* changed to start to align with top of bubble */
    position: relative;
    z-index: 2;
}

.explanation-avatar {
    width: 32px; /* bit larger for avatar */
    height: 32px;
    border-radius: 50%;
    background-color: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 2px;
}

.explanation-avatar svg {
    width: 16px;
    height: 16px;
    color: var(--text-secondary);
}

.topics {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    position: relative;
    z-index: 2;
    margin-bottom: 0.5rem;
}

.topic-tag {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
    background-color: transparent;
    padding: 0.1rem 0.25rem;
    border-radius: 4px;
    text-decoration: none;
    transition: background-color 0.2s, color 0.2s;
}

.topic-tag::before {
    content: '#';
    color: var(--text-tertiary);
}

.topic-tag:hover {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

.topic-chip-big {
    background: var(--accent-blue, #3b82f6);
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.8125rem;
    text-decoration: none;
    font-weight: 500;
}
.topic-chip-big:hover { opacity: 0.85; }

.card-head .card-topic.topic-chip-big {
    background: var(--accent-blue, #3b82f6);
    color: white;
}

.content-actions {
    display: none; /* Hide content and extract buttons completely */
}

.btn-extract, .btn-content {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-primary);
    background-color: var(--bg-tertiary);
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn-extract:hover, .btn-content:hover {
    background-color: var(--border-primary);
}

/* Toast notifications */
#toast-host {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}

.toast {
    background: var(--text-primary);
    color: var(--bg-primary);
    padding: 0.6rem 1rem;
    border-radius: 9999px;
    font-size: 0.875rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.visible {
    opacity: 0.95;
    transform: translateY(0);
}

.toast.toast-error {
    background: var(--danger-color);
    color: white;
}

/* Preference Summary Styles */
.preference-summary-container {
    background: var(--bg-primary);
    border: 1px solid var(--border-primary);
    border-radius: 8px;
    padding: 1.5rem;
}

.preference-summary-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.5rem;
}

.preference-summary-header .subsection-header {
    margin: 0;
    font-size: 1.1rem;
    color: var(--text-primary);
    border-top: none;
    padding-top: 0;
}

.preference-summary-meta {
    display: flex;
    gap: 1.5rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.meta-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.meta-item i {
    color: var(--text-muted);
}

.preference-summary-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    gap: 1rem;
    flex-wrap: wrap;
    border-bottom: none;
}

.preference-summary-controls::after,
.preference-summary-controls::before {
    display: none;
}

.toggle-switch {
    display: flex;
    align-items: center;
    cursor: pointer;
    user-select: none;
}

.toggle-switch input[type="checkbox"] {
    display: none;
}

.toggle-slider {
    width: 48px;
    height: 24px;
    background-color: var(--text-muted);
    border-radius: 24px;
    margin-right: 0.75rem;
    position: relative;
    transition: background-color 0.2s;
}

.toggle-slider::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    background-color: white;
    border-radius: 50%;
    top: 2px;
    left: 2px;
    transition: transform 0.2s;
}

.toggle-switch input[type="checkbox"]:checked + .toggle-slider {
    background-color: var(--primary-color);
}

.toggle-switch input[type="checkbox"]:checked + .toggle-slider::after {
    transform: translateX(24px);
}

.toggle-label {
    font-size: 0.875rem;
    color: var(--text-primary);
}

.button-group {
    display: flex;
    gap: 0.5rem;
}

.preference-summary-content {
    margin-top: 1rem;
    border-top: none;
    border: none;
}

#preference-form {
    border: none;
    border-top: none;
}

.preference-summary-textarea {
    width: 100%;
    min-height: 200px;
    padding: 1rem;
    border: 1px solid var(--border-primary);
    border-radius: 4px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.875rem;
    line-height: 1.6;
    resize: vertical;
    transition: border-color 0.2s, background-color 0.2s;
}

.preference-summary-textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

.preference-summary-textarea[readonly] {
    background: var(--bg-tertiary);
    cursor: default;
}

.preference-summary-textarea.editable {
    background: var(--bg-primary);
}

.preference-summary-help {
    margin-top: 1rem;
    display: flex;
    align-items: start;
    gap: 0.5rem;
    font-size: 0.813rem;
    color: var(--text-secondary);
}

.preference-summary-help i {
    color: var(--text-muted);
    margin-top: 0.125rem;
    flex-shrink: 0;
}

.preference-summary-help p {
    margin: 0;
    line-height: 1.5;
}

.loading {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
}

.loading i {
    margin-right: 0.5rem;
}

/* Mobile adjustments */
@media (max-width: 768px) {
    body {
        flex-direction: column;
    }

    .container {
        padding: 0 1rem;
    }

    .sidebar {
        width: 100%;
        height: calc(60px + env(safe-area-inset-bottom));
        position: fixed;
        left: 0;
        bottom: 0;
        top: auto;
        flex-direction: row;
        border-right: none;
        border-top: 1px solid var(--border-primary);
        padding: 0 1rem env(safe-area-inset-bottom) 1rem;
        justify-content: space-around;
        background-color: var(--bg-primary);
    }
    
    .sidebar-top, .sidebar-bottom {
        display: none;
    }
    
    .sidebar-nav {
        flex-direction: row;
        width: 100%;
        justify-content: space-around;
        margin: 0;
    }

    /* full-screen scroll shell on mobile.
       body is fixed at the dynamic viewport height with no scroll of its
       own; .layout-main is the only thing that scrolls. iOS Safari only
       collapses / shows the URL bar when the document/window scrolls, so
       moving scroll into an inner element keeps the layout viewport
       constant — the bottom sidebar stays anchored instead of being
       dragged off-screen during the URL-bar transition that the user
       reported on non-PWA Safari. PWA standalone has no URL bar so it
       was already stable; this brings the in-browser experience to
       match. dvh (vs vh) handles the rare cases when the dynamic
       viewport changes for reasons other than scroll (e.g. keyboard). */
    body {
        height: 100dvh;
        overflow: hidden;
    }
    .layout-main {
        margin: 0;
        padding-top: 0;
        padding-bottom: calc(60px + env(safe-area-inset-bottom));
        max-width: 100%;
        border-right: none;
        border-radius: 0;
        height: 100%;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }

    .content-frame {
        border-radius: 0;
        border: none;
        box-shadow: none;
        height: auto;
    }
    
    .content-frame main.container,
    .content-frame .container {
        padding: 0 !important;
    }

    .page-header {
        position: sticky;
        top: 0;
        background-color: var(--bg-body);
        z-index: 100;
        padding: 0.5rem 1rem;
        height: 50px;
    }

    .page-title {
        font-size: 14px;
    }

    .article-card {
        padding: 1rem;
    }

    .feeds-header, .rss-help-header, .settings-header {
        padding: 1rem 1rem 0.75rem;
    }

    .feeds-list, .rss-help-content, .settings-tab-content {
        padding: 1rem;
    }

    .settings-tabs {
        padding: 0 1rem;
    }

    .feed-form {
        margin: 0 1rem 1rem;
        padding: 1.25rem;
    }

    .search-page-container {
        padding: 1rem 1rem 0.5rem;
    }

    .filter-panel {
        left: 10px;
        right: 10px;
        width: calc(100% - 20px);
        bottom: calc(70px + env(safe-area-inset-bottom));
        top: auto;
        transform: none;
    }

    .more-menu {
        bottom: calc(100% + 10px);
        left: auto;
        right: 0;
        margin-left: 0;
        width: 200px;
        box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.15);
    }

    .preference-summary-header {
        flex-direction: column;
        gap: 1rem;
    }
    
    .preference-summary-meta {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .preference-summary-controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    .button-group {
        justify-content: center;
    }
}

/* Source Data Modal */
.source-modal {
    border: none;
    border-radius: 16px;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    box-shadow: 0 4px 24px rgba(0,0,0,0.15);
    width: 90vw;
    max-width: 800px;
    max-height: 90vh;
    padding: 0;
    margin: auto;
}

.source-modal::backdrop {
    background: rgba(0, 0, 0, 0.5);
}

.source-modal .modal-content {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-height: 90vh;
}

.source-modal .modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-primary);
    flex-shrink: 0;
}

.source-modal .modal-header h3 {
    margin: 0;
    font-size: 1.1rem;
}

.source-modal .btn-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
}

.source-modal .modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    font-size: 0.875rem;
    flex: 1;
}

.source-modal .modal-body h4 {
    margin: 1.5rem 0 0.5rem 0;
    color: var(--text-secondary);
}

.source-modal .modal-body h4:first-child {
    margin-top: 0;
}

.source-modal pre {
    background-color: var(--bg-tertiary);
    padding: 1rem;
    border-radius: 8px;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-all;
    margin: 0;
}

.spinner {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    100% { transform: rotate(360deg); }
}

/* Beats UI */
.beats-header {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.beat-detail {
    padding: 1.5rem;
}

.beat-header {
    margin-bottom: 2rem;
}

.avatar-stack {
    position: relative;
    width: 40px;
    height: 40px;
}

.avatar-stack .avatar-img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
}

.avatar-stack .avatar-overflow {
    position: absolute;
    right: -4px;
    bottom: -4px;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 11px;
    background: var(--text-primary);
    color: var(--bg-primary);
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--bg-primary);
}

.beats-header-title {
    display: flex;
    width: 100%;
    justify-content: space-between;
    align-items: center;
}

/* grouping switcher dropdown in beats header */
.grouping-switcher {
    position: relative;
}

.grouping-switcher summary {
    list-style: none;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    cursor: pointer;
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-primary);
    padding: 0.35rem 0.5rem;
    border-radius: 8px;
    user-select: none;
}

.grouping-switcher summary::-webkit-details-marker { display: none; }

.grouping-switcher summary:hover {
    background: var(--bg-secondary);
}

.grouping-switcher-count {
    font-weight: 400;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.grouping-switcher-chevron {
    color: var(--text-secondary);
    transition: transform 0.15s ease;
}

.grouping-switcher[open] .grouping-switcher-chevron {
    transform: rotate(180deg);
}

.grouping-menu {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    min-width: 220px;
    background: var(--bg-primary);
    border: 1px solid var(--border-primary);
    border-radius: 10px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    list-style: none;
    padding: 0.4rem 0;
    margin: 0;
    z-index: 100;
}

.grouping-menu-item a {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 1rem;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 0.9rem;
    gap: 0.5rem;
}

.grouping-menu-item a:hover {
    background: var(--bg-secondary);
}

.grouping-menu-active a {
    color: var(--accent-primary, #0070f3);
    font-weight: 600;
}

.grouping-menu-count {
    color: var(--text-secondary);
    font-weight: 400;
    font-size: 0.82rem;
}

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

.grouping-unread-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent-danger, #ef4444);
    vertical-align: middle;
    margin: 0 3px 1px;
    animation: grouping-dot-pulse 2s ease-in-out infinite;
}

.grouping-menu-separator {
    height: 1px;
    background: var(--border-primary);
    margin: 0.35rem 0;
}

.grouping-menu-meta a {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.beats-search-container {
    width: 100%;
}

/* comment-button badge showing member count on multi-member beat cards */
.action-comment {
    position: relative;
}

.action-badge {
    position: absolute;
    top: -4px;
    right: -6px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 8px;
    background: var(--accent, #1d9bf0);
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    line-height: 16px;
    text-align: center;
}

/* container for members expanded under a beat card via the comment button */
.beat-members-expand:empty {
    display: none;
}

.beat-members-expand {
    margin-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.beat-members-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* @view-transition { navigation: auto; } */

main.container {
  view-transition-name: main-content;
}

::view-transition-old(main-content) { animation: slide-out-left 0.25s ease-out; }
::view-transition-new(main-content) { animation: slide-in-right 0.25s ease-out; }
@keyframes slide-in-right { from { transform: translateX(100%); } to { transform: translateX(0); } }
@keyframes slide-out-left { from { transform: translateX(0); } to { transform: translateX(-30%); opacity: 0.3; } }
@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(main-content), ::view-transition-new(main-content) { animation: none; }
}

/* Pull-to-refresh indicator for /beats */
.ptr-indicator {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translate(-50%, -100%);
  padding: 0.5rem 1rem;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color, rgba(0,0,0,0.1));
  border-radius: 999px;
  font-size: 0.85rem;
  color: var(--text-primary, #333);
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  z-index: 1000;
  opacity: 0;
  transition: transform 200ms ease, opacity 200ms ease;
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.ptr-indicator.pulling {
  transform: translate(-50%, 16px);
  opacity: 1;
}
.ptr-arrow {
  display: inline-block;
  transition: transform 180ms ease;
}
.ptr-indicator.ready .ptr-arrow {
  transform: rotate(180deg);
}
.ptr-indicator.loading .ptr-arrow {
  animation: ptr-spin 0.9s linear infinite;
}
@keyframes ptr-spin {
  to { transform: rotate(360deg); }
}
@media (prefers-reduced-motion: reduce) {
  .ptr-indicator, .ptr-arrow { transition: none; }
  .ptr-indicator.loading .ptr-arrow { animation: none; }
}

/* ── Settings sub-pages nav ─────────────────────────────────────── */
.settings-subpages {
    margin: 0 0 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.settings-subpage-link {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.875rem 1rem;
    border-radius: 10px;
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
    text-decoration: none;
    font-size: 0.9375rem;
    font-weight: 500;
    transition: background-color 0.15s;
}

.settings-subpage-link:hover {
    background-color: var(--border-primary);
}

.settings-subpage-link .chevron {
    margin-left: auto;
    color: var(--text-secondary);
}

/* ── Groupings page ─────────────────────────────────────────────── */
.groupings-page {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.groupings-header {
    padding: 1.5rem 1.5rem 1rem;
    border-bottom: 1px solid var(--border-primary);
    background-color: var(--bg-primary);
    border-radius: 24px 24px 0 0;
}

.groupings-header h2 {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0;
    color: var(--text-primary);
}

.groupings-header p {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-top: 0.25rem;
    margin-bottom: 0;
}

.groupings-body {
    display: flex;
    flex-direction: column;
    gap: 2rem;
    padding: 0 1.5rem 1.5rem;
}

@media (max-width: 768px) {
    .groupings-body {
        gap: 1.5rem;
    }
}

.groupings-list-section h3,
.grouping-form-section h3 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0 0 0.75rem;
    color: var(--text-primary);
}

/* ── Groupings list ─────────────────────────────────────────────── */
.groupings-list {
    display: flex;
    flex-direction: column;
    gap: 0;
    border: 1px solid var(--border-primary);
    border-radius: 12px;
    overflow: hidden;
    background-color: var(--bg-primary);
}

.grouping-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    border-bottom: 1px solid var(--border-primary);
    cursor: default;
    transition: background-color 0.1s;
}

.grouping-row:last-child {
    border-bottom: none;
}

.grouping-row:hover {
    background-color: var(--bg-hover);
}

.grouping-row.dragging {
    opacity: 0.5;
    background-color: var(--bg-tertiary);
}

.grouping-drag-handle {
    flex-shrink: 0;
    cursor: grab;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    padding: 4px;
    border-radius: 4px;
}

.grouping-drag-handle:hover {
    color: var(--text-primary);
    background-color: var(--bg-tertiary);
}

.grouping-drag-handle:active {
    cursor: grabbing;
}

.grouping-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 0;
}

.grouping-name {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-primary);
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: block;
}

.grouping-slug {
    font-size: 0.8125rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    color: var(--text-secondary);
    background-color: var(--bg-tertiary);
    padding: 1px 5px;
    border-radius: 4px;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: inline-block;
}

.grouping-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 2px;
}

.tag-chip {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 500;
    background-color: var(--tag-bg);
    color: var(--tag-text);
    border: 1px solid var(--tag-border);
}

.grouping-actions {
    flex-shrink: 0;
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.no-groupings {
    padding: 2rem 1.5rem;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.9375rem;
}

/* ── btn-sm modifier ────────────────────────────────────────────── */
.btn-sm {
    padding: 0.3rem 0.65rem;
    font-size: 0.8125rem;
    border-radius: 6px;
}

/* ── Grouping create / edit form ────────────────────────────────── */
.grouping-form-section form {
    background-color: var(--bg-tertiary);
    border-radius: 12px;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0;
}

.grouping-form-section form h3 {
    margin-bottom: 1rem;
}

/* beat timeline */
.beat-timeline {
    padding: 1.5rem 0;
}

.timeline-heading {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-secondary, #6b7280);
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.timeline-segment {
    position: relative;
    padding-left: 0.5rem;
    padding-bottom: 1.5rem;
    border-left: 2px solid var(--border-secondary);
}

.timeline-segment.current .revision-title {
    font-weight: 700;
}

.timeline-node {
    margin-bottom: 0.5rem;
}

.timeline-node time {
    font-size: 0.78rem;
    color: var(--text-secondary, #6b7280);
    display: block;
    margin-bottom: 0.2rem;
}

.revision-title {
    font-size: 0.95rem;
    font-weight: 600;
    margin: 0;
    color: var(--text, #111827);
}

.badge-current {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 500;
    padding: 0.1rem 0.4rem;
    border-radius: 9999px;
    background: var(--accent, #6366f1);
    color: #fff;
    vertical-align: middle;
    margin-left: 0.4rem;
    text-transform: none;
    letter-spacing: 0;
}

.timeline-members {
    padding-left: 0;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.timeline-member {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    font-size: 0.88rem;
    line-height: 1.4;
}

.timeline-member time {
    flex-shrink: 0;
    font-size: 0.78rem;
    color: var(--text-secondary, #6b7280);
    min-width: 2.8rem;
}

.timeline-member .feed-name {
    flex-shrink: 0;
    font-size: 0.78rem;
    color: var(--text-secondary, #6b7280);
}

.timeline-member a {
    color: var(--text, #111827);
    text-decoration: none;
}

.timeline-member a:hover {
    text-decoration: underline;
}

/* timeline member expand/collapse via <details> */
.timeline-member-details {
    border-radius: 4px;
    min-width: 0;
    overflow: hidden;
}

.timeline-member-summary {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    font-size: 0.88rem;
    line-height: 1.4;
    cursor: pointer;
    list-style: none;
    padding: 0.15rem 0;
    min-width: 0;
    overflow: hidden;
}

.timeline-member-summary::-webkit-details-marker {
    display: none;
}

.timeline-member-summary time {
    flex-shrink: 0;
    font-size: 0.78rem;
    color: var(--text-secondary, #6b7280);
    min-width: 2.8rem;
}

.timeline-member-summary .feed-name {
    flex-shrink: 0;
    font-size: 0.78rem;
    color: var(--text-secondary, #6b7280);
}

.timeline-member-summary .member-title {
    color: var(--text, #111827);
    text-decoration: none;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.timeline-member-summary .member-title:hover {
    text-decoration: underline;
}


.expand-chevron {
    flex-shrink: 0;
    font-size: 0.7rem;
    color: var(--text-secondary, #6b7280);
    transition: transform 0.15s ease;
    margin-left: auto;
}

details[open] .expand-chevron {
    transform: rotate(180deg);
}

.timeline-member-expanded {
    padding: 0.5rem 0 0.25rem 0.25rem;
    border-top: 1px solid var(--border, #e5e7eb);
    margin-top: 0.25rem;
}
