/* ============================================================
   MagReader - CSS
   Dark mode by default, magazine-style reading experience
   ============================================================ */

/* === CSS Variables (Dark Theme) === */
:root, [data-theme="dark"] {
    --bg-primary: #0f0f0f;
    --bg-secondary: #1a1a1a;
    --bg-card: #1e1e1e;
    --bg-hover: #2a2a2a;
    --text-primary: #e8e8e8;
    --text-secondary: #a0a0a0;
    --text-muted: #666;
    --accent: #4a9eff;
    --accent-hover: #3a8eef;
    --success: #4caf50;
    --danger: #ef5350;
    --warning: #ffa726;
    --border: #2a2a2a;
    --shadow: rgba(0,0,0,0.3);
    --reader-bg: #1a1a1a;
    --reader-text: #d4d4d4;
}

[data-theme="light"] {
    --bg-primary: #f5f5f5;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-hover: #f0f0f0;
    --text-primary: #1a1a1a;
    --text-secondary: #555;
    --text-muted: #999;
    --accent: #1a73e8;
    --accent-hover: #1557b0;
    --success: #2e7d32;
    --danger: #c62828;
    --warning: #ef6c00;
    --border: #e0e0e0;
    --shadow: rgba(0,0,0,0.1);
    --reader-bg: #fefefe;
    --reader-text: #2a2a2a;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* === Navigation === */
.navbar {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: 0 1rem;
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-container {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    height: 56px;
    gap: 1.5rem;
}

.nav-brand {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
}

.nav-links {
    display: flex;
    gap: 0.5rem;
    flex: 1;
}

.nav-link {
    color: var(--text-secondary);
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.nav-link:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

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

.hamburger {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
}

.mobile-menu {
    display: none;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: 0.5rem 1rem;
}

.mobile-menu a {
    display: block;
    padding: 0.75rem;
    color: var(--text-secondary);
    border-radius: 8px;
}

.mobile-menu.active { display: block; }

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); color: #fff; }
.btn-secondary { background: var(--bg-hover); color: var(--text-primary); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #388e3c; color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-disabled { background: var(--bg-hover); color: var(--text-muted); cursor: default; }
.btn-small { padding: 0.3rem 0.6rem; font-size: 0.8rem; }
.btn-full { width: 100%; justify-content: center; }
.btn-icon {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0.4rem;
    border-radius: 8px;
}
.btn-icon:hover { background: var(--bg-hover); }

/* === Layout === */
.main-content { padding: 1.5rem 1rem; }
.container { max-width: 1200px; margin: 0 auto; }

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

.page-header h1 { font-size: 1.75rem; font-weight: 700; }
.subtitle { color: var(--text-secondary); margin-top: 0.25rem; }
.header-actions { display: flex; gap: 0.5rem; }

.section { margin-top: 2rem; }
.section h2 { font-size: 1.25rem; margin-bottom: 1rem; }

/* === Stats Grid === */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.25rem;
    text-align: center;
}

.stat-number { font-size: 2rem; font-weight: 700; }
.stat-label { color: var(--text-secondary); font-size: 0.85rem; margin-top: 0.25rem; }
.stat-new .stat-number { color: var(--warning); }
.stat-ready .stat-number { color: var(--accent); }
.stat-reading .stat-number { color: var(--accent); }
.stat-translated .stat-number { color: var(--success); }

/* === Magazine Grid === */
.magazines-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1rem;
}

.magazine-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: all 0.2s;
    color: var(--text-primary);
}

.magazine-card:hover {
    background: var(--bg-hover);
    border-color: var(--accent);
    color: var(--text-primary);
}

.magazine-icon { font-size: 2.5rem; }
.magazine-info h3 { font-size: 1.1rem; }
.magazine-count { color: var(--text-secondary); font-size: 0.85rem; }

/* === Issues List === */
.issues-list { display: flex; flex-direction: column; gap: 0.5rem; }

.issue-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1rem 1.25rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.2s;
    color: var(--text-primary);
}

.issue-card:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.issue-info { display: flex; flex-direction: column; gap: 0.2rem; }
.issue-magazine { color: var(--accent); font-size: 0.85rem; font-weight: 500; }
.issue-title { font-weight: 500; }
.issue-date { color: var(--text-secondary); font-size: 0.85rem; }
.issue-pages { color: var(--text-muted); font-size: 0.8rem; }

/* === Status Badges === */
.status-badge {
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
}

.status-new { background: var(--warning); color: #000; }
.status-indexing { background: var(--accent); color: #fff; }
.status-indexed { background: #7c4dff; color: #fff; }
.status-translating_titles { background: #ff9800; color: #000; }
.status-titles_ready { background: var(--success); color: #fff; }
.status-translated { background: #00c853; color: #000; }
.status-queued { background: var(--text-muted); color: #fff; }
.status-translating { background: var(--warning); color: #000; }
.status-error { background: var(--danger); color: #fff; }
.status-index_failed { background: var(--danger); color: #fff; }

/* === Articles List === */
.articles-list { display: flex; flex-direction: column; gap: 1rem; }

.article-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.25rem;
    transition: all 0.2s;
}

.article-card:hover { border-color: var(--accent); }

.article-header {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.article-titles { flex: 1; }
.title-el { font-size: 1.1rem; font-weight: 600; margin-bottom: 0.25rem; }
.title-en { color: var(--text-secondary); font-size: 0.85rem; font-style: italic; }
.article-source { color: var(--text-muted); font-size: 0.8rem; margin-top: 0.25rem; }

.article-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.5rem;
}

.page-badge {
    background: var(--bg-hover);
    padding: 0.2rem 0.6rem;
    border-radius: 6px;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.tags { display: flex; gap: 0.3rem; flex-wrap: wrap; }
.tag {
    background: var(--bg-hover);
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    color: var(--accent);
}

.article-summary {
    margin: 0.75rem 0;
    padding: 0.75rem;
    background: var(--bg-primary);
    border-radius: 8px;
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.7;
}

.article-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

/* === Article Reader === */
.reader-container {
    max-width: 800px;
    margin: 0 auto;
}

.reader-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    gap: 1rem;
    flex-wrap: wrap;
}

.reader-meta {
    display: flex;
    gap: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.85rem;
    flex-wrap: wrap;
}

.reader-controls { display: flex; gap: 0.25rem; }

.reader-article {
    background: var(--reader-bg);
    color: var(--reader-text);
    padding: 2rem;
    border-radius: 16px;
    font-size: 18px;
    line-height: 1.8;
}

.reader-article h1.article-title {
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    line-height: 1.3;
}

.reader-article .article-meta {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.reader-article h2.article-subheading {
    font-size: 1.3rem;
    font-weight: 600;
    margin: 1.5rem 0 0.75rem;
    color: var(--accent);
}

.reader-article p {
    margin-bottom: 1rem;
}

.reader-article .article-figure {
    margin: 1.5rem 0;
    text-align: center;
}

.reader-article .article-figure img {
    max-width: 100%;
    border-radius: 8px;
    box-shadow: 0 2px 8px var(--shadow);
}

.reader-article .article-figure figcaption {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-top: 0.5rem;
    font-style: italic;
}

/* === Search === */
.search-form {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.search-input {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 1rem;
}

.search-input:focus {
    outline: none;
    border-color: var(--accent);
}

.search-results-count {
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

/* === Login === */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg-primary);
}

.login-container { width: 100%; max-width: 400px; padding: 1rem; }

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 2rem;
    text-align: center;
}

.login-card h1 { font-size: 2rem; margin-bottom: 0.25rem; }
.login-subtitle { color: var(--text-secondary); margin-bottom: 1.5rem; }

.form-group {
    text-align: left;
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 0.3rem;
    color: var(--text-secondary);
}

.form-group input {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 1rem;
}

.form-group input:focus {
    outline: none;
    border-color: var(--accent);
}

.alert { padding: 0.75rem; border-radius: 8px; margin-bottom: 1rem; }
.alert-error { background: rgba(239,83,80,0.15); color: var(--danger); }

/* === Empty States === */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-secondary);
}

.empty-state p { margin-bottom: 0.5rem; }

/* === Responsive === */
@media (max-width: 768px) {
    .nav-links { display: none; }
    .nav-actions { display: none; }
    .hamburger { display: block; margin-left: auto; }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .page-header h1 { font-size: 1.4rem; }
    .header-actions { flex-wrap: wrap; }

    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.5rem;
    }

    .stat-card { padding: 0.75rem; }
    .stat-number { font-size: 1.5rem; }

    .article-header { flex-direction: column; }
    .article-meta {
        flex-direction: row;
        align-items: center;
    }

    .reader-article {
        padding: 1rem;
        border-radius: 8px;
        font-size: 16px;
    }

    .reader-article h1.article-title { font-size: 1.4rem; }

    .search-form { flex-direction: column; }

    .magazines-grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
