/* =====================================================
   StockNewsAI — Premium Dark Dashboard Theme
   ===================================================== */

/* ---------- CSS Custom Properties ---------- */
:root {
    /* Colors (Light Blue Theme) */
    --bg-primary: #f0f8ff;
    --bg-secondary: #e0f2fe;
    --bg-card: rgba(255, 255, 255, 0.6);
    --bg-card-hover: rgba(255, 255, 255, 0.85);
    --bg-sidebar: #e8f4fc;
    --border: rgba(0, 0, 0, 0.08);
    --border-hover: rgba(0, 0, 0, 0.15);

    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;

    --accent: #6366f1;
    --accent-glow: rgba(99, 102, 241, 0.3);
    --bullish: #22c55e;
    --bullish-bg: rgba(34, 197, 94, 0.1);
    --bearish: #ef4444;
    --bearish-bg: rgba(239, 68, 68, 0.1);
    --neutral: #8b8fa3;
    --neutral-bg: rgba(139, 143, 163, 0.1);
    --warning: #f59e0b;
    --warning-bg: rgba(245, 158, 11, 0.1);
    --high: #f97316;
    --high-bg: rgba(249, 115, 22, 0.08);

    /* Spacing */
    --sidebar-width: 220px;
    --topbar-height: 64px;
    --radius: 12px;
    --radius-sm: 8px;

    /* Fonts */
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

    /* Transitions */
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 14px; }

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    overflow: hidden;
    height: 100vh;
}

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

/* ---------- Layout ---------- */
#app {
    display: flex;
    flex-direction: row;
    height: 100vh;
    overflow: hidden;
}

#main-wrapper {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    position: relative;
}

#main-content {
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    flex: 1;
    background:
        radial-gradient(ellipse at 20% 0%, rgba(99, 102, 241, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 100%, rgba(139, 92, 246, 0.05) 0%, transparent 50%),
        var(--bg-primary);
}

/* ---------- Sidebar ---------- */
.collapsible-sidebar {
    width: 260px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
}
.collapsible-sidebar.collapsed {
    transform: translateX(-100%);
    margin-left: -260px;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px;
    border-bottom: 1px solid var(--border);
}

.logo-icon { font-size: 28px; }
.logo-text {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, #1e3a8a, #4338ca);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}
.logo-ai {
    background: linear-gradient(135deg, #6366f1, #a78bfa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: 800;
}

.sidebar-nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 16px 12px;
    gap: 4px;
}

.sidebar-nav .nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 14px;
    transition: var(--transition);
    text-decoration: none !important;
}
.sidebar-nav .nav-item:hover {
    background: rgba(0, 0, 0, 0.04);
    color: var(--text-primary);
}
.sidebar-nav .nav-item.active {
    background: rgba(99, 102, 241, 0.1);
    color: var(--text-primary);
}
.sidebar-nav .nav-icon { font-size: 18px; width: 24px; text-align: center; }

/* ---------- Sidebar Categories ---------- */
.sidebar-categories {
    margin-top: 24px;
    padding: 0 16px;
}
.sidebar-categories h3 {
    font-size: 11px;
    text-transform: uppercase;
    font-weight: 700;
    color: var(--text-muted);
    margin-bottom: 10px;
    padding-left: 8px;
    letter-spacing: 0.5px;
}
.category-list {
    list-style: none;
    padding: 0;
    margin: 0;
}
.category-item {
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}
.category-item:hover {
    background: rgba(0, 0, 0, 0.04);
    color: var(--text-primary);
}
.category-item.active {
    background: rgba(99, 102, 241, 0.1);
    color: var(--text-primary);
}

/* ---------- Top Header ---------- */
.glass-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    height: 72px;
    background: rgba(255, 255, 255, 0.6);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
}

.btn-toggle {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}
.btn-toggle:hover {
    background: rgba(0,0,0,0.05);
    color: var(--text-primary);
}

/* ---------- Search Module ---------- */
.header-center {
    flex: 1;
    display: flex;
    justify-content: center;
    padding: 0 40px;
}
.search-module form {
    position: relative;
    width: 100%;
    max-width: 480px;
}
.search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 16px;
    color: var(--text-muted);
}
#global-search-input {
    width: 100%;
    padding: 10px 16px 10px 42px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: rgba(255,255,255,0.7);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 14px;
    transition: var(--transition);
    outline: none;
}
#global-search-input:focus {
    border-color: var(--accent);
    background: white;
    box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ---------- Topbar Actions ---------- */
.header-right {
    display: flex;
    align-items: center;
    gap: 24px;
}

.topbar-actions {
    display: flex;
    gap: 8px;
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 13px;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: var(--transition);
}

.btn-primary {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: white;
    box-shadow: 0 2px 12px var(--accent-glow);
}
.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 20px var(--accent-glow);
}

.btn-ghost {
    background: var(--bg-card);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.btn-ghost:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
    border-color: var(--border-hover);
}

.btn-danger {
    background: rgba(239, 68, 68, 0.1);
    color: var(--bearish);
    border: 1px solid rgba(239, 68, 68, 0.2);
}
.btn-danger:hover { background: rgba(239, 68, 68, 0.2); }

.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ---------- Pages ---------- */
.page {
    display: none;
    padding: 24px 28px;
    overflow-y: auto;
    flex: 1;
}
.page.active { display: block; }

.page::-webkit-scrollbar { width: 6px; }
.page::-webkit-scrollbar-track { background: transparent; }
.page::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.2);
    border-radius: 3px;
}

/* ---------- Stats Cards ---------- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    transition: var(--transition);
    backdrop-filter: blur(12px);
}
.stat-card:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-hover);
    transform: translateY(-2px);
}

.stat-icon { font-size: 24px; margin-bottom: 4px; }
.stat-value {
    font-size: 32px;
    font-weight: 800;
    letter-spacing: -1px;
    line-height: 1;
}
.stat-label {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-bullish .stat-value { color: var(--bullish); }
.stat-bearish .stat-value { color: var(--bearish); }
.stat-high .stat-value { color: var(--warning); }

/* ---------- Cards ---------- */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    backdrop-filter: blur(12px);
    transition: var(--transition);
}
.card:hover { border-color: var(--border-hover); }

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.card-header h2 {
    font-size: 14px;
    font-weight: 600;
    letter-spacing: -0.2px;
}
.card-body { padding: 16px 20px; }

.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

/* ---------- Badges ---------- */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.3px;
}

.badge-bullish { background: var(--bullish-bg); color: var(--bullish); }
.badge-bearish { background: var(--bearish-bg); color: var(--bearish); }
.badge-neutral { background: var(--neutral-bg); color: var(--neutral); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-high { background: var(--high-bg); color: var(--high); border: 1px solid rgba(249,115,22,0.2); }
.badge-level { background: rgba(99,102,241,0.1); color: var(--text-primary); }

.badge-cat-general { background: #e2e8f0; color: #475569; }
.badge-cat-clinical { background: #dcfce7; color: #166534; }
.badge-cat-fda { background: #dbeafe; color: #1e40af; }
.badge-cat-regulatory { background: #fef08a; color: #854d0e; }
.badge-cat-breaking { background: #fee2e2; color: #991b1b; }

.detail-block-focus {
    background: rgba(99, 102, 241, 0.1);
    border-left: 3px solid var(--accent);
    padding: 12px;
    border-radius: 4px;
    margin-bottom: 12px;
}
.detail-block-focus h4 {
    color: var(--accent);
    font-size: 13px;
    margin-bottom: 6px;
    text-transform: uppercase;
    font-weight: 700;
}
.detail-block-focus p {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

/* ---------- Filter Bar ---------- */
.filter-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.filter-select, .form-input {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    padding: 8px 12px;
    font-family: var(--font);
    font-size: 13px;
    outline: none;
    transition: var(--transition);
}
.filter-select:focus, .form-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
}
.filter-select option { background: var(--bg-secondary); }

/* ---------- News List ---------- */
.news-list, .analysis-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.news-item {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 16px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: var(--transition);
    cursor: default;
}
.news-item:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-hover);
}

.news-sentiment {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}
.news-sentiment.bullish { background: var(--bullish-bg); }
.news-sentiment.bearish { background: var(--bearish-bg); }
.news-sentiment.neutral { background: var(--neutral-bg); }
.news-sentiment.unknown { background: var(--neutral-bg); }

.news-content { flex: 1; min-width: 0; }

.news-title {
    font-size: 14px;
    font-weight: 600;
    line-height: 1.4;
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.news-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 11px;
    color: var(--text-muted);
}

.news-ticker {
    font-weight: 700;
    color: var(--accent);
    font-size: 12px;
}

.news-summary {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 6px;
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ---------- Analysis Items ---------- */
.analysis-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: var(--transition);
}
.analysis-item:hover { border-color: var(--border-hover); }

.analysis-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    cursor: pointer;
}
.analysis-header:hover { background: var(--bg-card-hover); }

.analysis-summary-row {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}
.analysis-title {
    font-size: 18px;
    font-weight: 700;
    line-height: 1.4;
    flex: 1;
    min-width: 0;
    color: var(--text-primary);
}

.analysis-badges {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    align-items: center;
}

/* ---------- Categories Page ---------- */
.category-main-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 20px;
    padding: 10px 0;
}
.category-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 20px;
    cursor: pointer;
    transition: var(--transition);
}
.category-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.05);
    border-color: rgba(99, 102, 241, 0.4);
}
.category-icon {
    font-size: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.5);
    box-shadow: inset 0 2px 4px rgba(255, 255, 255, 0.8);
}
.category-info h3 {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 6px;
    color: var(--text-primary);
}
.category-count {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 500;
}

.analysis-detail {
    display: none;
    padding: 0 20px 20px;
    border-top: 1px solid var(--border);
}
.analysis-detail.open { display: block; padding-top: 16px; }

.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.detail-block {
    background: rgba(0, 0, 0, 0.03);
    border-radius: var(--radius-sm);
    padding: 14px;
}
.detail-block h4 {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 6px;
}
.detail-block p {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.6;
}

.confidence-bar {
    height: 4px;
    background: rgba(0,0,0,0.1);
    border-radius: 2px;
    margin-top: 6px;
    overflow: hidden;
}
.confidence-fill {
    height: 100%;
    border-radius: 2px;
    background: linear-gradient(90deg, var(--accent), #a78bfa);
    transition: width 0.6s ease;
}

.related-tickers {
    display: flex;
    gap: 6px;
    margin-top: 8px;
    flex-wrap: wrap;
}
.ticker-tag {
    padding: 3px 8px;
    background: rgba(99,102,241,0.1);
    color: #a5b4fc;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
}

/* ---------- Watchlist ---------- */
.add-company-card {
    margin-bottom: 20px;
    padding: 20px;
}
.add-company-card h2 {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 12px;
}

.form-row {
    display: flex;
    gap: 8px;
    align-items: center;
}
.form-row .form-input { flex: 1; }

.watchlist-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
}

.company-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    transition: var(--transition);
    position: relative;
}
.company-card:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-hover);
}

.company-ticker {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.5px;
    color: var(--accent);
    margin-bottom: 4px;
}
.company-name {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 12px;
}
.company-meta {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}
.company-actions {
    display: flex;
    gap: 6px;
}

/* ---------- System Page ---------- */
.system-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.health-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}
.health-row:last-child { border-bottom: none; }

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 6px;
}
.status-dot.ok { background: var(--bullish); box-shadow: 0 0 6px var(--bullish); }
.status-dot.error { background: var(--bearish); box-shadow: 0 0 6px var(--bearish); }

.job-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}
.job-card:last-child { border-bottom: none; }

.job-info { flex: 1; }
.job-name { font-size: 13px; font-weight: 600; }
.job-next {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ---------- Toast ---------- */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    color: white;
    animation: slideIn 0.3s ease, fadeOut 0.3s ease 2.7s;
    backdrop-filter: blur(12px);
}
.toast-success { background: rgba(34, 197, 94, 0.85); }
.toast-error { background: rgba(239, 68, 68, 0.85); }
.toast-info { background: rgba(99, 102, 241, 0.85); }

@keyframes slideIn {
    from { transform: translateX(100px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}
@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* ---------- Loading ---------- */
.loading-placeholder {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
    font-size: 13px;
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}
.empty-state .empty-icon {
    font-size: 48px;
    margin-bottom: 12px;
    opacity: 0.5;
}
.empty-state p { font-size: 14px; }

/* ---------- Responsive ---------- */
@media (max-width: 1024px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .dashboard-grid { grid-template-columns: 1fr; }
    .system-grid { grid-template-columns: 1fr; }
    .detail-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    #app { grid-template-columns: 60px 1fr; }
    .logo-text, .nav-label { display: none; }
    .sidebar-logo { justify-content: center; padding: 0 8px 24px; }
    .nav-item { justify-content: center; padding: 10px; }
    .nav-icon { width: auto; }
    .sidebar-footer { display: none; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .form-row { flex-wrap: wrap; }
    .watchlist-grid { grid-template-columns: 1fr; }
}
