/* === Variables === */
:root {
    --bg: #0a0a0f;
    --bg-card: #12121a;
    --bg-hover: #1a1a26;
    --border: #2a2a3a;
    --text: #e4e4ef;
    --text-dim: #8888a0;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --radius: 8px;
    --shadow: 0 4px 24px rgba(0,0,0,0.3);
}

/* === Reset === */
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* === Buttons === */
.btn {
    display: inline-block;
    padding: 10px 24px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: background 0.2s;
}
.btn:hover { background: var(--accent-hover); }
.btn-sm { padding: 6px 16px; font-size: 13px; }
.btn-lg { padding: 14px 40px; font-size: 16px; }
.btn-full { width: 100%; }
.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
}
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #dc2626; }
.btn-ghost { background: transparent; color: var(--text-dim); padding: 6px 12px; }
.btn-ghost:hover { color: var(--text); background: var(--bg-hover); }

/* === Forms === */
input, select, textarea {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 14px;
    margin-bottom: 12px;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
}
textarea { resize: vertical; min-height: 100px; }
label { display: block; margin-bottom: 4px; font-size: 13px; color: var(--text-dim); }

/* === Cards === */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}

/* === Landing === */
.landing-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 40px;
    max-width: 1200px;
    margin: 0 auto;
}
.logo {
    font-size: 24px;
    font-weight: 800;
    color: var(--text);
}
.logo span { color: var(--accent); }
.landing-header nav { display: flex; gap: 24px; align-items: center; }
.landing-header nav a { color: var(--text-dim); font-size: 14px; }

.hero {
    text-align: center;
    padding: 100px 20px 80px;
    max-width: 800px;
    margin: 0 auto;
}
.hero h1 { font-size: 48px; font-weight: 800; line-height: 1.2; margin-bottom: 20px; }
.hero .accent { color: var(--accent); }
.hero .subtitle { color: var(--text-dim); font-size: 18px; margin-bottom: 40px; }

.features {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 24px;
    max-width: 1000px;
    margin: 0 auto 80px;
    padding: 0 20px;
}
.feature-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px 24px;
    text-align: center;
}
.feature-icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 700;
    margin: 0 auto 16px;
}
.feature-card h3 { margin-bottom: 8px; }
.feature-card p { color: var(--text-dim); font-size: 14px; }

/* === Pricing === */
.pricing { text-align: center; padding: 80px 20px; }
.pricing h2 { font-size: 36px; margin-bottom: 40px; }
.pricing-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    max-width: 1100px;
    margin: 0 auto;
}
.price-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px 24px;
}
.price-card.featured { border-color: var(--accent); }
.price-card h3 { margin-bottom: 8px; }
.price { font-size: 36px; font-weight: 800; margin-bottom: 20px; }
.price span { font-size: 16px; color: var(--text-dim); font-weight: 400; }
.price-card ul { list-style: none; margin-bottom: 24px; }
.price-card li { padding: 6px 0; color: var(--text-dim); font-size: 14px; }

/* === Modal === */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 32px;
    width: auto;
    min-width: 500px;
    max-width: 90vw;
    max-height: 85vh;
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
}
@media (max-width: 768px) {
    .modal-content {
        min-width: 0;
        width: 95vw;
        padding: 20px;
        max-height: 90vh;
    }
}
.modal-close {
    position: absolute;
    top: 12px;
    right: 16px;
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 24px;
    cursor: pointer;
}
.modal-content h2 { margin-bottom: 20px; }
.form-switch { margin-top: 16px; font-size: 13px; color: var(--text-dim); text-align: center; }
.error-msg { color: var(--danger); font-size: 13px; margin-top: 12px; text-align: center; }

/* === App Layout === */
.app-layout {
    display: grid;
    grid-template-columns: 240px 1fr;
    min-height: 100vh;
}
.sidebar {
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    padding: 20px 0;
    display: flex;
    flex-direction: column;
}
.sidebar .logo {
    padding: 0 20px;
    margin-bottom: 32px;
}
.sidebar nav { flex: 1; }
.sidebar nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    color: var(--text-dim);
    font-size: 14px;
    transition: all 0.15s;
}
.sidebar nav a:hover, .sidebar nav a.active {
    background: var(--bg-hover);
    color: var(--text);
}
.sidebar nav a.active { border-right: 2px solid var(--accent); }
.sidebar .user-info {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    font-size: 13px;
    color: var(--text-dim);
}
.sidebar .user-info .name { color: var(--text); font-weight: 600; }
.sidebar .mobile-logout { display: none; }

.main-content {
    padding: 32px;
    overflow-y: auto;
    max-height: 100vh;
}
.main-content h1 { font-size: 24px; margin-bottom: 24px; }

/* === Dashboard === */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 32px;
}
.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}
.stat-card .label { font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; }
.stat-card .value { font-size: 28px; font-weight: 700; margin-top: 4px; }
.stat-card .value.accent { color: var(--accent); }

/* === Reports === */
.report-list { display: flex; flex-direction: column; gap: 12px; }
.report-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: border-color 0.15s;
}
.report-item:hover { border-color: var(--accent); }
.report-item .title { font-weight: 600; }
.report-item .meta { font-size: 12px; color: var(--text-dim); margin-top: 4px; }

/* Status badges */
.status {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}
.status-queued { background: var(--border); color: var(--text-dim); }
.status-researching { background: rgba(99,102,241,0.2); color: var(--accent); }
.status-synthesizing { background: rgba(245,158,11,0.2); color: var(--warning); }
.status-generating { background: rgba(245,158,11,0.2); color: var(--warning); }
.status-complete { background: rgba(34,197,94,0.2); color: var(--success); }
.status-error { background: rgba(239,68,68,0.2); color: var(--danger); }

/* === Report Viewer === */
.report-viewer { max-width: 900px; }
.report-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 16px;
}
.report-section h3 { margin-bottom: 12px; color: var(--accent); }
.report-section .content { white-space: pre-wrap; font-size: 14px; line-height: 1.7; }

/* === Knowledge === */
.doc-list { display: flex; flex-direction: column; gap: 8px; }
.doc-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.doc-item .name { font-weight: 500; }
.doc-item .details { font-size: 12px; color: var(--text-dim); }

/* === Content Library === */
.content-filters {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}
.filter-btn {
    padding: 6px 14px;
    border-radius: 16px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-dim);
    font-size: 13px;
    cursor: pointer;
}
.filter-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.content-report-group {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 12px;
    overflow: hidden;
}
.content-report-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px;
    cursor: pointer;
    transition: background 0.15s;
}
.content-report-header:hover { background: var(--bg-hover); }
.content-report-body {
    border-top: 1px solid var(--border);
    padding: 12px;
}
.content-item {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
}
.content-item .header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}
.content-item .body { font-size: 14px; white-space: pre-wrap; line-height: 1.6; }
.content-item .actions { display: flex; gap: 8px; margin-top: 12px; }

/* === SSE Progress === */
.progress-bar {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
}
.progress-bar .stage { font-weight: 600; margin-bottom: 8px; }
.progress-track {
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    transition: width 0.5s ease;
}

/* === Upload Area === */
.upload-area {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 40px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s;
    margin-bottom: 20px;
}
.upload-area:hover { border-color: var(--accent); }
.upload-area p { color: var(--text-dim); }

/* === Toast === */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 12px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    font-size: 14px;
    z-index: 2000;
    animation: slideIn 0.3s ease;
}
.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--danger); }
@keyframes slideIn { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* === Empty State === */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-dim);
}
.empty-state h3 { color: var(--text); margin-bottom: 8px; }


/* === Login button contrast fix (all themes) === */
.landing-header nav .btn {
    color: #fff;
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

/* === Responsive === */
@media (max-width: 768px) {
    .features, .pricing-grid { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .app-layout { grid-template-columns: 1fr; }
    .sidebar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        top: auto;
        border-right: none;
        border-top: 1px solid var(--border);
        padding: 0;
        display: flex;
        flex-direction: row;
        z-index: 800;
        height: auto;
        background: var(--bg-card);
    }
    .sidebar .logo { display: none; }
    .sidebar .user-info {
        display: none;
    }
    .sidebar .mobile-logout {
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 8px 4px;
        font-size: 10px;
        color: var(--text-dim);
        text-align: center;
        white-space: normal;
        word-break: break-word;
        min-height: 68px;
        cursor: pointer;
    }
    .sidebar .mobile-logout:hover {
        color: var(--text);
        background: var(--bg-hover);
    }
    .sidebar nav {
        display: flex;
        flex-direction: row;
        width: 100%;
        flex: none;
        min-height: 68px;
    }
    .sidebar nav a {
        flex: 1;
        text-align: center;
        padding: 8px 4px;
        font-size: 10px;
        line-height: 1.2;
        border-right: none;
        justify-content: center;
        align-items: center;
        white-space: normal;
        overflow: visible;
        text-overflow: clip;
        word-break: break-word;
        min-height: 68px;
    }
    .sidebar nav a.active {
        border-right: none;
        border-top: 2px solid var(--accent);
        background: var(--bg-hover);
    }
    .main-content {
        padding: 16px;
        padding-bottom: 168px;
        max-height: none;
        min-height: 100vh;
    }
    .hero h1 { font-size: 32px; }
    #errorFooter {
        bottom: 92px !important;
    }
    #themeSwitcher {
        padding: 2px 6px;
        gap: 4px;
        opacity: 0.9;
    }
    #themeSwitcher .theme-btn {
        padding: 3px 6px;
        font-size: 9px;
    }
}
