/* CSS Reset & Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #0a0a0a;
    --bg-secondary: #141414;
    --bg-tertiary: #1e1e1e;
    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
    --text-tertiary: #666666;
    --accent-color: #ff6b35;
    --accent-secondary: #ff8c5a;
    --border-color: #2a2a2a;
    --danger-color: #ff4757;
    --success-color: #2ed573;
    --card-bg: #161616;
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 480px;
    margin: 0 auto;
    position: relative;
    overflow: hidden;
    background: var(--bg-primary);
}

/* Top Bar */
.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
}

.logo {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, #2d5a27, #4a9c3f);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: white;
}

.page-title {
    font-size: 18px;
    font-weight: 600;
}

.top-actions {
    display: flex;
    gap: 8px;
}

.icon-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: all 0.2s ease;
}

.icon-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.icon-btn:active {
    transform: scale(0.95);
}

/* Category Tabs */
.category-tabs-wrapper {
    position: relative;
    background: var(--bg-primary);
    overflow: hidden;
}

.category-tabs-wrapper::after {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 30px;
    background: linear-gradient(to right, transparent, var(--bg-primary));
    pointer-events: none;
    z-index: 1;
}

.category-tabs {
    display: flex;
    padding: 8px 16px;
    gap: 8px;
    background: var(--bg-primary);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    scroll-snap-type: x mandatory;
}

.category-tabs::-webkit-scrollbar {
    display: none;
}

.tab-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: 25px;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s ease;
    scroll-snap-align: start;
    flex-shrink: 0;
}

.tab-btn.active {
    background: var(--accent-color);
    color: white;
}

.tab-btn .badge {
    color: inherit;
    font-size: 12px;
    background: rgba(255, 255, 255, 0.2);
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
}

.tab-btn .badge:empty {
    display: none;
}

/* Filter Button Active State */
.filter-btn.active {
    color: var(--accent-color);
}

.filter-btn.active i::before {
    content: "\f058";
    font-weight: 900;
}

/* Main Content */
.main-content {
    flex: 1;
    overflow-y: auto;
    padding-bottom: calc(70px + var(--safe-area-bottom));
    -webkit-overflow-scrolling: touch;
}

.page {
    display: none;
    padding: 16px;
    min-height: 100%;
}

.page.active {
    display: block;
}

/* Article List */
.article-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.article-card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid var(--border-color);
    position: relative;
}

.article-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 60%;
    background: var(--accent-color);
    border-radius: 0 4px 4px 0;
    opacity: 1;
    transition: opacity 0.2s ease;
}

.article-card.read {
    opacity: 0.6;
}

.article-card.read::before {
    opacity: 0;
}

.article-card.read .article-title {
    color: var(--text-secondary);
}

.article-card:hover {
    background: var(--bg-tertiary);
    transform: translateY(-2px);
}

.article-card:active {
    transform: scale(0.98);
}

.article-source {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

.source-icon {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: var(--accent-color);
}

.source-name {
    font-size: 13px;
    color: var(--text-secondary);
}

.article-time {
    font-size: 12px;
    color: var(--text-tertiary);
    margin-left: auto;
}

.article-title {
    font-size: 16px;
    font-weight: 600;
    line-height: 1.4;
    margin-bottom: 8px;
    color: var(--text-primary);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.article-title.highlight {
    color: var(--accent-color);
}

.article-summary {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.article-image {
    width: 100%;
    height: 180px;
    object-fit: cover;
    border-radius: 8px;
    margin-top: 12px;
}

/* Loading State */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: var(--text-secondary);
    gap: 12px;
}

.loading i {
    font-size: 24px;
    color: var(--accent-color);
}

.loading.hidden {
    display: none;
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--text-tertiary);
    text-align: center;
}

.empty-state i {
    font-size: 48px;
    margin-bottom: 16px;
    color: var(--text-tertiary);
}

.empty-state p {
    font-size: 14px;
}

/* Subscription Page */
.subscription-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.subscription-header h2 {
    font-size: 20px;
    font-weight: 600;
}

.add-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 20px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.add-btn:hover {
    background: var(--accent-secondary);
}

.subscription-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.subscription-item {
    display: flex;
    align-items: center;
    padding: 16px;
    background: var(--card-bg);
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

.subscription-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--accent-color), var(--accent-secondary));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: white;
    margin-right: 12px;
}

.subscription-info {
    flex: 1;
}

.subscription-name {
    font-size: 15px;
    font-weight: 500;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.subscription-type-tag {
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 4px;
    background: var(--bg-tertiary);
    color: var(--text-tertiary);
}

.subscription-type-tag.article { color: var(--accent-color); }
.subscription-type-tag.podcast { color: #9b59b6; }
.subscription-type-tag.image { color: #3498db; }
.subscription-type-tag.video { color: #e74c3c; }

.subscription-url {
    font-size: 12px;
    color: var(--text-tertiary);
    word-break: break-all;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.subscription-actions {
    display: flex;
    gap: 8px;
}

.delete-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: rgba(255, 71, 87, 0.1);
    color: var(--danger-color);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: all 0.2s ease;
}

.delete-btn:hover {
    background: rgba(255, 71, 87, 0.2);
}

/* Discover Page */
.discover-header {
    margin-bottom: 20px;
}

.discover-header h2 {
    font-size: 20px;
    font-weight: 600;
}

.discover-section {
    margin-bottom: 24px;
}

.discover-section h3 {
    font-size: 16px;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.popular-feeds {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.feed-item {
    display: flex;
    align-items: center;
    padding: 14px;
    background: var(--card-bg);
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

.feed-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: var(--accent-color);
    margin-right: 12px;
}

.feed-info {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.feed-name {
    font-size: 14px;
    font-weight: 500;
}

.feed-desc {
    font-size: 12px;
    color: var(--text-tertiary);
    margin-top: 2px;
}

.subscribe-btn {
    width: 32px;
    height: 32px;
    border: 1px solid var(--accent-color);
    background: transparent;
    color: var(--accent-color);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    transition: all 0.2s ease;
}

.subscribe-btn:hover {
    background: var(--accent-color);
    color: white;
}

.subscribe-btn.subscribed {
    background: var(--success-color);
    border-color: var(--success-color);
    color: white;
}

.subscribe-btn.subscribed i::before {
    content: "\f00c";
}

/* Settings Page */
.settings-header {
    margin-bottom: 20px;
}

.settings-header h2 {
    font-size: 20px;
    font-weight: 600;
}

.settings-list {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.settings-group h3 {
    font-size: 13px;
    color: var(--text-tertiary);
    text-transform: uppercase;
    margin-bottom: 12px;
    letter-spacing: 0.5px;
}

.settings-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: var(--card-bg);
    border-radius: 10px;
    margin-bottom: 8px;
}

.settings-item span {
    font-size: 14px;
}

.settings-value {
    color: var(--text-tertiary);
}

.settings-item select,
.settings-item input[type="text"] {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
}

.settings-item input[type="text"] {
    width: 180px;
    text-align: right;
}

.danger-btn {
    padding: 8px 16px;
    background: rgba(255, 71, 87, 0.1);
    color: var(--danger-color);
    border: none;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.danger-btn:hover {
    background: rgba(255, 71, 87, 0.2);
}

.normal-btn {
    padding: 8px 16px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: none;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.normal-btn:hover {
    background: var(--border-color);
}

/* Bottom Navigation */
.bottom-nav {
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 10px 0;
    padding-bottom: calc(10px + var(--safe-area-bottom));
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-width: 480px;
    margin: 0 auto;
    z-index: 100;
}

.nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 16px;
    border: none;
    background: transparent;
    color: var(--text-tertiary);
    font-size: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.nav-btn i {
    font-size: 20px;
}

.nav-btn.active {
    color: var(--accent-color);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 20px;
}

.modal.show {
    display: flex;
}

.modal-content {
    width: 100%;
    max-width: 360px;
    background: var(--bg-secondary);
    border-radius: 16px;
    overflow: hidden;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    font-size: 17px;
    font-weight: 600;
}

.close-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-body {
    padding: 20px;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.form-group input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 15px;
    outline: none;
    transition: border-color 0.2s ease;
}

.form-group input:focus {
    border-color: var(--accent-color);
}

/* Type Selector */
.type-selector {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.type-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    flex: 1;
    min-width: 70px;
}

.type-btn i {
    font-size: 18px;
}

.type-btn.active {
    border-color: var(--accent-color);
    background: rgba(255, 107, 53, 0.1);
    color: var(--accent-color);
}

.type-btn:hover {
    border-color: var(--accent-color);
}

.hint {
    font-size: 12px;
    color: var(--text-tertiary);
}

.modal-footer {
    display: flex;
    gap: 12px;
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
}

.cancel-btn,
.confirm-btn {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.cancel-btn {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.confirm-btn {
    background: var(--accent-color);
    color: white;
}

.confirm-btn:hover {
    background: var(--accent-secondary);
}

/* Article Detail Modal */
.article-detail-modal {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-primary);
    z-index: 999;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: hidden;
}

.article-detail-modal.show {
    transform: translateX(0);
    pointer-events: auto;
}

.detail-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    position: relative;
    z-index: 1000;
}

.back-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    color: var(--text-primary);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.detail-actions {
    display: flex;
    gap: 8px;
}

.detail-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    -webkit-overflow-scrolling: touch;
    background: var(--bg-primary);
    width: 100%;
}

.detail-content h1 {
    font-size: 22px;
    font-weight: 700;
    line-height: 1.4;
    margin-bottom: 16px;
}

.detail-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.detail-source {
    font-size: 14px;
    color: var(--accent-color);
}

.detail-time {
    font-size: 14px;
    color: var(--text-tertiary);
}

.detail-body {
    font-size: 16px;
    line-height: 1.8;
    color: var(--text-secondary);
}

.detail-body p {
    margin-bottom: 16px;
}

.detail-body img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 16px 0;
}

.detail-body a {
    color: var(--accent-color);
    text-decoration: none;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    padding: 12px 24px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-radius: 25px;
    font-size: 14px;
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 400;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Animations */
@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

.fa-spin {
    animation: spin 1s linear infinite;
}

/* Responsive */
@media (min-width: 481px) {
    .app-container {
        border-left: 1px solid var(--border-color);
        border-right: 1px solid var(--border-color);
    }
}

/* Font Size Settings */
body.font-small {
    --article-title-size: 14px;
    --article-summary-size: 12px;
    --detail-title-size: 18px;
    --detail-body-size: 14px;
}

body.font-medium {
    --article-title-size: 16px;
    --article-summary-size: 14px;
    --detail-title-size: 22px;
    --detail-body-size: 16px;
}

body.font-large {
    --article-title-size: 18px;
    --article-summary-size: 16px;
    --detail-title-size: 26px;
    --detail-body-size: 18px;
}

body.font-small .article-title,
body.font-medium .article-title,
body.font-large .article-title {
    font-size: var(--article-title-size);
}

body.font-small .article-summary,
body.font-medium .article-summary,
body.font-large .article-summary {
    font-size: var(--article-summary-size);
}

body.font-small .detail-content h1,
body.font-medium .detail-content h1,
body.font-large .detail-content h1 {
    font-size: var(--detail-title-size);
}

body.font-small .detail-body,
body.font-medium .detail-body,
body.font-large .detail-body {
    font-size: var(--detail-body-size);
}

/* Pull to refresh indicator */
.pull-indicator {
    text-align: center;
    padding: 20px;
    color: var(--text-tertiary);
    font-size: 14px;
}

/* AI Toolbar */
.ai-toolbar {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.ai-toolbar::-webkit-scrollbar {
    display: none;
}

.ai-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.ai-btn i {
    font-size: 14px;
}

.ai-btn:hover {
    border-color: var(--accent-color);
    color: var(--accent-color);
}

.ai-btn:active {
    transform: scale(0.95);
}

.ai-btn.loading {
    pointer-events: none;
    opacity: 0.7;
}

.ai-btn.loading i {
    animation: spin 1s linear infinite;
}

.ai-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* AI Result Panel */
.ai-result-panel {
    display: none;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    max-height: 300px;
    overflow: hidden;
}

.ai-result-panel.show {
    display: block;
}

.ai-result-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-tertiary);
}

.ai-result-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--accent-color);
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-result-title::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    background: var(--accent-color);
    border-radius: 50%;
}

.close-ai-btn {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--text-tertiary);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

.close-ai-btn:hover {
    background: var(--bg-primary);
    color: var(--text-primary);
}

.ai-result-content {
    padding: 16px;
    overflow-y: auto;
    max-height: 240px;
    font-size: 14px;
    line-height: 1.7;
    color: var(--text-secondary);
}

.ai-result-content p {
    margin-bottom: 12px;
}

.ai-result-content p:last-child {
    margin-bottom: 0;
}

.ai-result-content .loading-text {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-tertiary);
}

.ai-result-content .loading-text i {
    color: var(--accent-color);
}

.ai-result-content .error-text {
    color: var(--danger-color);
}

.ai-result-content .stock-impact {
    padding: 12px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    border-left: 3px solid var(--accent-color);
}

.ai-result-content .stock-positive {
    border-left-color: var(--success-color);
}

.ai-result-content .stock-negative {
    border-left-color: var(--danger-color);
}

.ai-result-content .stock-neutral {
    border-left-color: var(--text-tertiary);
}

/* AI Settings */
.ai-key-item input {
    width: 160px;
    text-align: right;
}

.settings-item select {
    min-width: 140px;
}
