/* RSS Reader Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-blue: #3d52a0;
    --primary-blue-light: #6c7ec5;
    --primary-blue-dark: #375a82;
    --aquamarine: #06b6d4;
    --aquamarine-dark: #0891b2;
    --background-light: #f0f0f0;
    --text-light: #333;
    --surface-light: #fff;
    --border-light: rgba(0,0,0,0.1);
}

body.dark-mode {
    --bg-primary: #0f1a2a;
    --bg-secondary: #192534;
    --bg-tertiary: #1e2d3e;
    --bg-surface: #2a3b53;
    --text-primary: #e6f0ff;
    --text-secondary: rgba(230,240,255,0.8);
    --text-muted: rgba(230,240,255,0.6);
    --blue-300: #93c5fd;
    --blue-500: #3b82f6;
    --blue-600: #2563eb;
    --blue-700: #1d4ed8;
    --teal-500: #14b8a6;
    --teal-600: #0d9488;
    --button-primary: #375a8247;
    --button-primary-hover: #4b6d94;
    --button-secondary: #2a3b53;
    --button-secondary-hover: #3a4d69;
    --border-subtle: rgba(70,90,126,0.2);
    --border-default: rgba(70,90,126,0.3);
    --border-emphasis: rgba(70,90,126,0.5);
    --success: #1a5a45;
    --success-hover: #27ae60;
    --warning: #d97706;
    --error: #dc2626;
    --info: #2980b9;
    --info-hover: #3498db;
    --shadow-light: rgba(0,0,0,0.1);
    --shadow-medium: rgba(0,0,0,0.25);
    --shadow-heavy: rgba(0,0,0,0.4);
    --overlay-light: rgba(15,26,42,0.8);
    --overlay-heavy: rgba(15,26,42,0.95);
}

body:not(.dark-mode) {
    --bg-primary: #f0f0f0;
    --bg-secondary: #fff;
    --bg-tertiary: #fafafa;
    --bg-surface: #fff;
    --text-primary: #333;
    --text-secondary: #666;
    --text-muted: #999;
    --button-primary: #3d52a0;
    --button-primary-hover: #2c3e75;
    --button-secondary: #6c7ec5;
    --button-secondary-hover: #5a6cb3;
    --border-subtle: rgba(0,0,0,0.1);
    --border-default: rgba(0,0,0,0.2);
    --border-emphasis: rgba(0,0,0,0.3);
    --success: #27ae60;
    --success-hover: #219a52;
    --warning: #f39c12;
    --error: #e74c3c;
    --info: #3498db;
    --info-hover: #2980b9;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
}

.container {
    max-width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

header {
    background: var(--bg-secondary);
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-default);
}

header h1 {
    font-size: 1.5rem;
    cursor: pointer;
    user-select: none;
    margin-right: auto;
}

.header-title {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
}

.btn-theme {
    padding: 0.4rem 0.6rem;
}

.header-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    width: 100%;
    flex-wrap: wrap;
}

/* Desktop: push buttons to the right after h1 */
@media (min-width: 769px) {
    .header-actions {
        flex-wrap: nowrap;
    }
    
    .header-actions h1 {
        margin-right: auto;
    }
}

/* Mobile drawer: hidden on desktop */
.mobile-only { display: none; }
.sidebar-backdrop { display: none; }

.btn.has-errors {
    background: var(--warning);
    color: var(--text-primary);
}

.feed-item.has-errors {
    border-left: 3px solid var(--warning);
}

.feed-item.disabled {
    opacity: 0.6;
}

.feed-item.disabled .feed-title {
    font-style: italic;
}

.category-header.has-errors {
    border-left: 3px solid var(--warning);
}

.error-icon,
.error-badge {
    cursor: help;
}

.error-badge {
    margin-left: auto;
    margin-right: 0.25rem;
}

.btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.2s;
}

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

.btn-primary:hover {
    background: var(--button-primary-hover);
}

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

.btn-secondary:hover {
    background: var(--button-secondary-hover);
}

.icon {
    font-size: 1.1rem;
}

.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.sidebar {
    width: 300px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-default);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.filter-buttons {
    display: flex;
    padding: 0.5rem;
    gap: 0.5rem;
    border-bottom: 1px solid var(--border-default);
}

.filter-btn {
    flex: 1;
    padding: 0.5rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-default);
    border-radius: 4px;
    cursor: pointer;
    color: var(--text-primary);
    font-size: 0.85rem;
    transition: all 0.2s;
}

.filter-btn.active {
    background: var(--button-primary);
    border-color: var(--button-primary);
}

.filter-btn:hover:not(.active) {
    background: var(--bg-surface);
}

.feed-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.category-item {
    margin-bottom: 0.5rem;
}

.category-header {
    padding: 0.75rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-default);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 500;
}

.category-header:hover {
    background: var(--bg-surface);
    border-color: var(--border-emphasis);
}

.category-header.active {
    background: var(--button-primary);
    border-color: var(--button-primary);
}

.category-header .expand-icon {
    font-size: 0.7rem;
    flex-shrink: 0;
    transition: transform 0.2s;
}

.category-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.category-feeds {
    display: none;
    padding-left: 1rem;
    margin-top: 0.5rem;
}

.category-feeds.expanded {
    display: block;
}

.category-feeds .feed-item {
    margin-bottom: 0.5rem;
}

.feed-item {
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-default);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.feed-item:hover {
    background: var(--bg-surface);
    border-color: var(--border-emphasis);
}

.feed-item.active {
    background: var(--button-primary);
    border-color: var(--button-primary);
}

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

.feed-title {
    font-weight: 500;
    margin-bottom: 0.25rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.feed-meta {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.unread-badge {
    background: var(--aquamarine);
    color: var(--bg-primary);
    padding: 0.125rem 0.5rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

.feed-actions {
    display: flex;
    gap: 0.25rem;
    margin-left: 0.5rem;
}

.btn-icon {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0.25rem;
    color: var(--text-muted);
    font-size: 0.9rem;
    transition: color 0.2s;
}

.btn-icon:hover {
    color: var(--error);
}

.content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.content-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-default);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.content-header h2 {
    font-size: 1.2rem;
}

.content-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.sort-select {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-default);
    border-radius: 4px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 0.9rem;
    cursor: pointer;
}

.sort-select:focus {
    outline: none;
    border-color: var(--aquamarine);
}

.item-list {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.item {
    background: var(--bg-secondary);
    border: 1px solid var(--border-default);
    border-radius: 4px;
    padding: 1rem;
    margin-bottom: 1rem;
    transition: all 0.2s;
}

.item.unread {
    border-left: 4px solid var(--aquamarine);
}

.item-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.5rem;
    gap: 1rem;
}

.item-title {
    flex: 1;
    cursor: pointer;
    font-weight: 500;
    font-size: 1.1rem;
    color: var(--text-primary);
    text-decoration: none;
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
}

.item-title:hover {
    color: var(--aquamarine);
}

.expand-icon {
    font-size: 0.8rem;
    transition: transform 0.2s;
    flex-shrink: 0;
    margin-top: 0.25rem;
}

.item.expanded .expand-icon {
    transform: rotate(90deg);
}

.item-meta {
    display: flex;
    gap: 1rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    flex-wrap: nowrap;          /* was wrap — keep meta + link on one row */
    align-items: center;
    justify-content: space-between;
}

.meta-info {
    display: block;             /* was flex+wrap — single text run */
    flex: 1;
    min-width: 0;               /* allow it to shrink so ellipsis kicks in */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    align-items: center;
}

/* keep the link/buttons at full size on the right, never wrapping */
.item-meta > .item-link,
.item-meta > .item-link-buttons {
    flex-shrink: 0;
    white-space: nowrap;
}

.meta-link {
    color: var(--text-muted);
    text-decoration: none;
    transition: color 0.2s;
}

.meta-link:hover {
    color: var(--aquamarine);
    text-decoration: underline;
}

.meta-uncategorized {
    color: var(--text-muted);
    font-style: italic;
}

.item-description {
    display: none;
    color: var(--text-secondary);
    font-size: 0.95rem;
    line-height: 1.6;
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border-subtle);
    overflow-x: auto;
}

.item-description img {
    max-width: 100%;
    height: auto;
    display: block;
}

.item.expanded .item-description {
    display: block;
}

.item-actions {
    display: flex;
    gap: 0.5rem;
}

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

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}

.empty-state .icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--overlay-light);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: 8px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 4px 20px var(--shadow-heavy);
}

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

.modal-header h2 {
    font-size: 1.3rem;
}

.close-modal {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-modal:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 1.5rem;
}

.modal-description {
    color: var(--text-secondary);
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.input-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.input-label input[type="checkbox"] {
    margin-right: 0.5rem;
}

.input-field {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-default);
    border-radius: 4px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 1rem;
    margin-bottom: 1rem;
}

.input-field:focus {
    outline: none;
    border-color: var(--aquamarine);
}

.textarea-field {
    min-height: 100px;
    resize: vertical;
    font-family: monospace;
}

/* Advanced Options in Add Feed Modal */
.advanced-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    padding: 0.5rem 0;
    color: var(--text-secondary);
    font-size: 0.9rem;
    user-select: none;
}

.advanced-toggle:hover {
    color: var(--text-primary);
}

.advanced-toggle .expand-icon {
    font-size: 0.7rem;
    transition: transform 0.2s;
}

.advanced-options {
    display: none;
    padding-top: 0.5rem;
}

.advanced-options.expanded {
    display: block;
}

/* Proxy status indicator */
.proxy-status {
    font-size: 0.8rem;
    margin-left: 0.25rem;
}

.proxy-status.configured {
    color: var(--success-hover);
}

.proxy-status.not-configured {
    color: var(--text-muted);
}

/* Proxy icon in feed list */
.proxy-icon {
    font-size: 0.85rem;
    margin-right: 0.25rem;
}

/* Proxy test button and results */
.btn-full {
    width: 100%;
    margin-bottom: 1rem;
}

.proxy-test-results {
    min-height: 1rem;
    margin-bottom: 1rem;
}

.test-loading {
    color: var(--text-muted);
    font-style: italic;
}

.test-results-grid {
    background: var(--bg-tertiary);
    border-radius: 4px;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
}

.test-result-row {
    display: flex;
    justify-content: space-between;
    padding: 0.25rem 0;
}

.test-label {
    color: var(--text-secondary);
}

.test-value {
    font-family: monospace;
    color: var(--text-primary);
}

.test-error-inline {
    color: var(--error);
    font-size: 0.9rem;
}

.test-success {
    color: var(--success-hover);
    padding: 0.5rem;
    background: rgba(39, 174, 96, 0.1);
    border-radius: 4px;
    text-align: center;
}

.test-warning {
    color: var(--warning);
    padding: 0.5rem;
    background: rgba(217, 119, 6, 0.1);
    border-radius: 4px;
    text-align: center;
}

.test-error {
    color: var(--error);
    padding: 0.5rem;
    background: rgba(220, 38, 38, 0.1);
    border-radius: 4px;
    text-align: center;
}

.test-location {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.test-ok {
    color: var(--success-hover);
}

.test-warn {
    color: var(--warning);
}

.test-success + .test-success {
    margin-top: 0.25rem;
}

/* Bottom Mark All Read button */
.mark-all-read-container {
    display: flex;
    justify-content: center;
    padding: 1.5rem 1rem;
    margin-top: 0.5rem;
    border-top: 1px solid var(--border-subtle);
    height: 25%;
}

.mark-all-read-btn {
    padding: 0.75rem 2rem;
    font-size: 1rem;
    width: 100%;
    justify-content: center;
}

.youtube-embed {
    width: 100%;
    max-width: 533px;
    aspect-ratio: 16 / 9;
    margin-bottom: 1rem;
    background: #000;
    position: relative;
}

.youtube-embed iframe {
    width: 100%;
    height: 100%;
}

.youtube-thumbnail {
    width: 100%;
    height: 100%;
    cursor: pointer;
    position: relative;
}

.youtube-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.youtube-play-btn {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 68px;
    height: 48px;
    background: rgba(0, 0, 0, 0.8);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: #fff;
    transition: background 0.2s;
}

.youtube-thumbnail:hover .youtube-play-btn {
    background: #c00;
}

.file-input {
    padding: 0.5rem;
}

.file-input::file-selector-button {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 4px;
    background: var(--button-secondary);
    color: var(--text-primary);
    cursor: pointer;
    margin-right: 1rem;
    transition: background 0.2s;
}

.file-input::file-selector-button:hover {
    background: var(--button-secondary-hover);
}

.import-status {
    min-height: 1.5rem;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.status-loading {
    color: var(--aquamarine);
}

.status-success {
    color: var(--success-hover);
}

.status-error {
    color: var(--error);
}

.modal-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
}

/* Filter badge (for saved/favorites counts) */
.filter-badge {
    background: var(--aquamarine);
    color: var(--bg-primary);
    padding: 0.1rem 0.4rem;
    border-radius: 8px;
    font-size: 0.7rem;
    font-weight: 600;
    margin-left: 0.25rem;
}

/* Item indicators (star/bookmark next to title) */
.item-indicators {
    display: inline-flex;
    gap: 0.25rem;
    margin-right: 0.25rem;
}

.indicator-star {
    color: var(--aquamarine);
}

.indicator-saved {
    color: var(--aquamarine);
    font-size: 0.9rem;
}

/* Item state styling */
.item.favorite {
    border-top: 2px solid var(--aquamarine);
}

.item.saved:not(.favorite) {
    border-top: 2px solid var(--aquamarine);
}

/* Action button active states */
.item-actions .btn-icon.active {
    color: var(--aquamarine);
}

.item-actions .btn-icon:first-child.active {
    color: var(--blue-300, #93c5fd);
}

.item-actions .btn-icon:hover {
    color: var(--text-primary);
}

/* Copy URL button styling */
.item-link-buttons {
    display: flex;
    gap: 0.25rem;
    align-items: center;
    margin-left: auto;
}

.btn-copy-link {
    background: transparent;
    border: 1px solid var(--border-default);
    border-radius: 4px;
    padding: 0.25rem 0.5rem;
    color: var(--text-secondary);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-copy-link:hover {
    background: var(--bg-surface);
    color: var(--text-primary);
    border-color: var(--border-emphasis);
}

.btn-copy-link.copied {
    background: var(--success);
    color: var(--text-primary);
    border-color: var(--success);
}

.btn-copy-link:disabled {
    opacity: 0.6;
    cursor: wait;
}

.btn-magnet {
    margin-left: 0.25rem;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .desktop-only {
        display: none !important;
    }
    .main-content {
        flex-direction: column;
    }
    
    /* Show the drawer toggle */
    .mobile-only {
        display: inline-flex;
    }

    /* Sidebar becomes an off-canvas drawer */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 85%;
        max-width: 320px;
        max-height: none;
        z-index: 950;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        border-right: 1px solid var(--border-default);
        border-bottom: none;
        box-shadow: 2px 0 12px var(--shadow-heavy);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    /* Dimmed backdrop behind the open drawer */
    .sidebar-backdrop.show {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 940;
        background: var(--overlay-light);
    }
    
    header {
        padding: 0.75rem 1rem;
    }

    .category-header {
        margin-bottom: 0.3rem;
    }

    .item {
        margin-bottom: .3rem;
    }
    
    header h1 {
        font-size: 1.2rem;
    }
    
    .header-actions {
        flex-wrap: wrap;
    }
    
    .btn {
        padding: 0.4rem 0.8rem;
        font-size: 0.85rem;
    }
    
    /* Hide button text on mobile, show only icons */
    .btn-text {
        display: none;
    }
    
    .header-actions .btn {
        padding: 0.4rem 0.6rem;
    }
    
    .item-list {
        padding: 0.5rem;
    }
    
    .content-header {
        flex-direction: row;
        align-items: center;
        flex-wrap: nowrap;
        gap: 0.5rem;
    }
    
    .content-header h2 {
        flex: 1;
        min-width: 0;        /* let it shrink so the buttons keep their space */
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .content-actions {
        width: auto;
        flex-shrink: 0;      /* sort select + button stay put, never wrap */
    }
    
    /* Mobile: single-line truncated item titles */
    .item-title span:last-child {
        display: block;
        max-width: 65vw;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    /* Show full title when expanded */
    .item.expanded .item-title span:last-child {
        max-width: none;
        white-space: normal;
        overflow: visible;
        text-overflow: unset;
    }
    
    /* Hide categories in unread mode on mobile */
/*    .sidebar.unread-mode .category-header {
        display: none;
    }
    
    .sidebar.unread-mode .category-feeds {
        display: block !important;
        padding-left: 0;
        margin-top: 0;
    }*/
    
    .sidebar.unread-mode .category-item {
        margin-bottom: 0;
    }
    
    /* Indicators redundant with action buttons on mobile */
    .item-indicators {
        display: none;
    }
    
    /* Filter buttons wrap on mobile */
    .filter-buttons {
        flex-wrap: wrap;
    }
    
    .filter-btn {
        min-width: calc(25% - 0.5rem);
    }

/* Feed rows: title + unread badge on one line, badge before actions */
    .feed-info {
        display: flex;
        align-items: center;
        gap: 0.5rem;
    }

    .feed-info .feed-title {
        flex: 1;
        min-width: 0;      /* allow ellipsis instead of pushing badge off */
        margin-bottom: 0;  /* was 0.25rem — kills the vertical offset */
    }

    .feed-info .feed-meta {
        flex-shrink: 0;    /* badge keeps its size, never wraps */
    }
}

/* ===== Search box ===== */
.search-box {
    display: flex;
    gap: 4px;
    margin-bottom: 12px;
    align-items: center;
}
.search-box input[type="search"] {
    flex: 1;
    margin: 0;
}
.search-box .btn-icon {
    flex-shrink: 0;
}

/* FTS5 snippet highlighting (for future use in renderItems) */
.item-snippet mark,
.item-description mark {
    background: var(--aquamarine);
    color: var(--bg-primary);
    padding: 0 2px;
    border-radius: 2px;
}
