:root {
    --bg: #0d1117;
    --surface: #161b22;
    --border: #30363d;
    --text: #e6edf3;
    --text-secondary: #8b949e;
    --green: #3fb950;
    --red: #f85149;
    --blue: #58a6ff;
    --yellow: #d29922;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 12px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

header h1 {
    font-size: 1.25rem;
    font-weight: 600;
}

header h1 a {
    color: var(--text);
    text-decoration: none;
}

.status-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--yellow);
    display: inline-block;
}

.status-dot.connected { background: var(--green); }
.status-dot.disconnected { background: var(--red); }

.separator { color: var(--border); }

/* --- Dashboard Layout (70/30 split) --- */
.dashboard-layout {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.dashboard-main {
    flex: 7;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.news-sidebar {
    flex: 3;
    min-width: 280px;
    max-width: 450px;
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.news-sidebar-panel {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    border: none;
    border-radius: 0;
}

.sentiment-scoreboard-panel {
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    max-height: 280px;
    border: none;
    border-radius: 0;
    border-top: 1px solid var(--border);
}

.sentiment-scoreboard-panel h2 {
    padding: 12px 16px 8px;
    flex-shrink: 0;
}

.news-sidebar-panel h2 {
    padding: 16px 16px 12px;
    flex-shrink: 0;
}

/* --- Tabs --- */
.tab-bar {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0;
    flex-shrink: 0;
}

.tab-btn {
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 600;
    padding: 8px 16px;
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s;
}

.tab-btn:hover {
    color: var(--text);
}

.tab-btn.active {
    color: var(--green);
    border-bottom-color: var(--green);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.empty-state {
    color: var(--text-secondary);
    font-size: 0.875rem;
    padding: 24px 0;
    text-align: center;
}

/* --- Panels --- */
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
}

.panel h2 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* --- Tables --- */
.table-container {
    overflow-x: auto;
    max-height: 400px;
    overflow-y: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

thead {
    position: sticky;
    top: 0;
    background: var(--surface);
    z-index: 1;
}

th {
    text-align: left;
    padding: 8px 12px;
    border-bottom: 2px solid var(--border);
    color: var(--text-secondary);
    font-weight: 600;
    white-space: nowrap;
}

td {
    padding: 6px 12px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

tr:hover { background: rgba(88, 166, 255, 0.05); }

.positive { color: var(--green); }
.negative { color: var(--red); }
.side-buy { color: var(--green); font-weight: 600; }
.side-sell { color: var(--red); font-weight: 600; }
.mono { font-family: 'SFMono-Regular', Consolas, monospace; font-size: 0.8125rem; }

/* New trade highlight animation */
@keyframes highlight {
    from { background: rgba(63, 185, 80, 0.2); }
    to { background: transparent; }
}
.new-trade { animation: highlight 2s ease-out; }

/* --- Chart --- */
.chart-container {
    height: 300px;
    position: relative;
}

/* --- Stats grid --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
}

.stats-grid-half {
    grid-template-columns: 1fr 1fr;
}

.stats-grid-thirds {
    grid-template-columns: 1fr 1fr 1fr;
}

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

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--blue);
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* --- Controls --- */
.table-controls {
    display: flex;
    gap: 12px;
    margin-bottom: 12px;
}

.filter-input, .filter-select {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 12px;
    color: var(--text);
    font-size: 0.875rem;
}

.filter-input:focus, .filter-select:focus {
    outline: none;
    border-color: var(--blue);
}

.full-width {
    max-width: 100%;
}

/* --- News Feed --- */
.news-feed {
    flex: 1;
    overflow-y: auto;
    padding: 0 12px 12px;
}

.news-feed::-webkit-scrollbar {
    width: 6px;
}

.news-feed::-webkit-scrollbar-track {
    background: transparent;
}

.news-feed::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.news-feed::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

.news-item {
    background: var(--bg);
    border: 1px solid var(--border);
    border-left: 3px solid var(--text-secondary);
    border-radius: 6px;
    padding: 10px 12px;
    margin-bottom: 8px;
    transition: border-color 0.2s;
}

.news-item:hover {
    border-color: var(--blue);
    border-left-color: inherit;
}

.news-item-positive {
    border-left-color: var(--green);
}

.news-item-negative {
    border-left-color: var(--red);
}

.news-item-neutral {
    border-left-color: var(--text-secondary);
}

/* Slide-in animation for new items */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.news-item-new {
    animation: slideIn 0.3s ease-out;
}

.news-tickers {
    display: flex;
    flex-wrap: nowrap;
    gap: 4px;
    margin-bottom: 6px;
    overflow: hidden;
}

.ticker-more {
    font-size: 0.625rem;
    color: var(--text-secondary);
    white-space: nowrap;
    align-self: center;
    flex-shrink: 0;
}

.ticker-badge {
    font-family: 'SFMono-Regular', Consolas, monospace;
    font-size: 0.6875rem;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
    background: rgba(139, 148, 158, 0.15);
    color: var(--text-secondary);
    white-space: nowrap;
}

.ticker-positive {
    background: rgba(63, 185, 80, 0.15);
    color: var(--green);
}

.ticker-negative {
    background: rgba(248, 81, 73, 0.15);
    color: var(--red);
}

.ticker-neutral {
    background: rgba(139, 148, 158, 0.15);
    color: var(--text-secondary);
}

.ticker-link:hover {
    text-decoration: underline;
}

.news-headline {
    font-size: 0.8125rem;
    line-height: 1.4;
    color: var(--text);
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: 4px;
}

.news-meta {
    font-size: 0.6875rem;
    color: var(--text-secondary);
}

.source-tag {
    font-size: 0.625rem;
    font-weight: 600;
    padding: 1px 5px;
    border-radius: 3px;
    background: rgba(139, 148, 158, 0.2);
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

/* Processed (green) — all sources after full text + Haiku analysis */
.source-processed {
    background: rgba(63, 185, 80, 0.2);
    color: var(--green);
}

/* Pending source colors */
.source-bloomberg {
    background: rgba(248, 81, 73, 0.2);
    color: var(--red);
}

.source-nyt {
    background: rgba(210, 153, 34, 0.2);
    color: var(--yellow);
}

.source-finnhub,
.source-alpaca {
    background: rgba(139, 148, 158, 0.2);
    color: var(--text-secondary);
}

.source-marketwatch {
    background: rgba(63, 185, 80, 0.12);
    color: #6fdd8b;
}

.source-cnbc {
    background: rgba(88, 166, 255, 0.12);
    color: #79c0ff;
}

.source-yahoo {
    background: rgba(188, 140, 255, 0.12);
    color: #d2a8ff;
}

.feed-updated-bar {
    font-size: 0.6875rem;
    color: var(--text-secondary);
    padding: 4px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

/* --- Source Stats (under Articles Collected) --- */
.collection-table {
    width: 100%;
    font-size: 0.8rem;
}

.collection-table th {
    text-align: left;
    padding: 6px 10px;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border);
}

.collection-table th:not(:first-child) {
    text-align: right;
}

.collection-table td {
    padding: 5px 10px;
    border-bottom: 1px solid var(--border);
}

.collection-table td:not(:first-child) {
    text-align: right;
    font-family: 'SFMono-Regular', Consolas, monospace;
}

.collection-table tfoot td {
    border-bottom: none;
    border-top: 2px solid var(--border);
}

.row-mismatch {
    background: rgba(248, 81, 73, 0.15);
}

/* --- Sentiment Scoreboard --- */
.sentiment-scoreboard {
    flex: 1;
    overflow-y: auto;
    padding: 0 12px 12px;
}

.sentiment-scoreboard::-webkit-scrollbar {
    width: 4px;
}

.sentiment-scoreboard::-webkit-scrollbar-track {
    background: transparent;
}

.sentiment-scoreboard::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

.sentiment-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 8px;
    font-size: 0.8125rem;
    border-radius: 4px;
}

.sentiment-row-odd {
    background: rgba(255, 255, 255, 0.02);
}

.sentiment-row-even {
    background: rgba(255, 255, 255, 0.05);
}

.sentiment-company {
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 120px;
    flex-shrink: 1;
}

.sentiment-symbol {
    font-family: 'SFMono-Regular', Consolas, monospace;
    font-size: 0.6875rem;
    color: var(--text-secondary);
    white-space: nowrap;
    flex-shrink: 0;
}

.sentiment-price {
    font-family: 'SFMono-Regular', Consolas, monospace;
    font-size: 0.6875rem;
    color: var(--blue);
    min-width: 58px;
    text-align: right;
    flex-shrink: 0;
    margin-left: auto;
}

.sentiment-name {
    font-size: 0.6875rem;
    color: var(--text-secondary);
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sentiment-counts {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.sentiment-count {
    font-family: 'SFMono-Regular', Consolas, monospace;
    font-size: 0.6875rem;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 4px;
    min-width: 28px;
    text-align: center;
}

.sentiment-pos {
    background: rgba(63, 185, 80, 0.15);
    color: var(--green);
}

.sentiment-neu {
    background: rgba(210, 153, 34, 0.15);
    color: var(--yellow);
}

.sentiment-neg {
    background: rgba(248, 81, 73, 0.15);
    color: var(--red);
}

.sentiment-empty {
    color: var(--text-secondary);
    font-size: 0.8125rem;
    padding: 8px 0;
    text-align: center;
}

/* --- Details Tab --- */
.details-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 12px;
}

.details-symbol-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.details-company-name {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--text);
}

.details-price {
    font-family: 'SFMono-Regular', Consolas, monospace;
    font-size: 1rem;
    font-weight: 600;
    color: var(--blue);
}

.details-search-wrap {
    position: relative;
    margin-left: auto;
}

.details-search {
    width: 260px;
}

.details-autocomplete {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 6px 6px;
    max-height: 280px;
    overflow-y: auto;
    z-index: 10;
}

.details-ac-item {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 0.875rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.details-ac-item:hover,
.details-ac-item.active {
    background: rgba(88, 166, 255, 0.1);
}

.details-ac-symbol {
    font-family: 'SFMono-Regular', Consolas, monospace;
    font-weight: 600;
    color: var(--text);
    margin-right: 8px;
}

.details-ac-name {
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.details-table td.title-cell {
    white-space: normal;
    word-break: break-word;
    min-width: 250px;
    max-width: 500px;
    line-height: 1.4;
}

.details-table .reason-col {
    white-space: normal;
    min-width: 200px;
    max-width: 400px;
}

.details-table td.reason-cell {
    white-space: normal;
    font-size: 0.8125rem;
    line-height: 1.4;
    color: var(--text-secondary);
}

/* --- Log Filters --- */
.log-filters {
    display: flex;
    gap: 20px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.filter-group-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-right: 2px;
}

.filter-chip {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 14px;
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 600;
    padding: 3px 12px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.filter-chip:hover {
    border-color: var(--blue);
    color: var(--text);
}

.filter-chip.active {
    background: rgba(88, 166, 255, 0.15);
    border-color: var(--blue);
    color: var(--blue);
}

/* --- Log Level Badges --- */
.log-level {
    font-size: 0.6875rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    white-space: nowrap;
}

.log-level-info {
    background: rgba(63, 185, 80, 0.15);
    color: var(--green);
}

.log-level-warning {
    background: rgba(210, 153, 34, 0.15);
    color: var(--yellow);
}

.log-level-error {
    background: rgba(248, 81, 73, 0.15);
    color: var(--red);
}

/* --- Resources Tab --- */
.resource-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.resource-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 20px;
    text-align: center;
}

.resource-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    margin-bottom: 8px;
}

.resource-pct {
    font-size: 2rem;
    font-weight: 700;
    color: var(--green);
    margin-bottom: 12px;
}

.resource-pct.resource-warning {
    color: var(--yellow);
}

.resource-pct.resource-critical {
    color: var(--red);
}

.resource-bar {
    height: 8px;
    background: rgba(139, 148, 158, 0.15);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 10px;
}

.resource-bar-fill {
    height: 100%;
    background: var(--green);
    border-radius: 4px;
    transition: width 0.5s ease, background 0.3s;
    width: 0;
}

.resource-bar-fill.resource-warning {
    background: var(--yellow);
}

.resource-bar-fill.resource-critical {
    background: var(--red);
}

.resource-detail {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    font-family: 'SFMono-Regular', Consolas, monospace;
}

/* Tab alert state — red bold overrides all tab states */
.tab-btn.tab-btn-alert {
    color: var(--red);
    font-weight: 800;
}

.tab-btn.tab-btn-alert:hover {
    color: var(--red);
}

.tab-btn.tab-btn-alert.active {
    color: var(--red);
    border-bottom-color: var(--red);
}

/* --- Responsive --- */
@media (max-width: 1024px) {
    .dashboard-layout {
        flex-direction: column;
    }

    .news-sidebar {
        max-width: none;
        min-width: 0;
        border-left: none;
        border-top: 1px solid var(--border);
        max-height: 400px;
    }
}

@media (max-width: 768px) {
    header { flex-direction: column; gap: 8px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .stats-grid-half { grid-template-columns: 1fr; }
    .stats-grid-thirds { grid-template-columns: 1fr; }
    .resource-grid { grid-template-columns: 1fr; }
}
