/* ── Variables ─────────────────────────────────────────────────────────────── */
:root {
    --bg:           #f0f2f5;
    --card:         #ffffff;
    --header:       #0d1b2a;
    --accent:       #1d4ed8;
    --accent-light: #dbeafe;
    --positive:     #16a34a;
    --pos-light:    #dcfce7;
    --negative:     #dc2626;
    --neg-light:    #fee2e2;
    --neutral:      #6b7280;
    --neu-light:    #f3f4f6;
    --earnings:     #7c3aed;
    --ear-light:    #ede9fe;
    --insider-buy:  #059669;
    --insider-sell: #dc2626;
    --border:       #e5e7eb;
    --text:         #111827;
    --text2:        #6b7280;
    --shadow:       0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md:    0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
    --radius:       12px;
    --radius-sm:    8px;
    --font:         'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

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

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    font-size: 14px;
    line-height: 1.5;
}

a { color: inherit; text-decoration: none; }
a:hover { text-decoration: underline; }

button { cursor: pointer; border: none; background: none; font-family: var(--font); }

/* ── Header ────────────────────────────────────────────────────────────────── */
.site-header {
    background: var(--header);
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0,0,0,.3);
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    max-width: 1400px;
    margin: 0 auto;
    gap: 12px;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -.3px;
}

.header-brand i { color: #60a5fa; font-size: 20px; }

.header-meta {
    display: flex;
    align-items: center;
    gap: 12px;
}

.last-update {
    font-size: 12px;
    color: #94a3b8;
    white-space: nowrap;
}

.btn-refresh {
    color: #94a3b8;
    font-size: 15px;
    padding: 6px 8px;
    border-radius: 6px;
    transition: color .2s, background .2s;
}
.btn-refresh:hover { color: #fff; background: rgba(255,255,255,.1); }
.btn-refresh.spinning i { animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.lang-toggle {
    display: flex;
    border: 1.5px solid rgba(255,255,255,.2);
    border-radius: 6px;
    overflow: hidden;
}
.lang-btn {
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 600;
    color: #94a3b8;
    background: transparent;
    transition: all .15s;
    letter-spacing: .5px;
}
.lang-btn.active { background: rgba(255,255,255,.15); color: #fff; }
.lang-btn:hover:not(.active) { color: #e2e8f0; }

/* ── Filter bar ─────────────────────────────────────────────────────────────── */
.filter-bar {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 54px;
    z-index: 90;
    box-shadow: var(--shadow);
}

.filter-inner {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    max-width: 1400px;
    margin: 0 auto;
    overflow-x: auto;
    scrollbar-width: none;
}
.filter-inner::-webkit-scrollbar { display: none; }

.filter-chips {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.chip {
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    border: 1.5px solid var(--border);
    color: var(--text2);
    background: #fff;
    white-space: nowrap;
    transition: all .15s;
    display: flex;
    align-items: center;
    gap: 5px;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.chip-insider-buy.active  { background: var(--insider-buy);  border-color: var(--insider-buy); }
.chip-insider-sell.active { background: var(--insider-sell); border-color: var(--insider-sell); }
.chip-earnings.active     { background: var(--earnings);     border-color: var(--earnings); }
.chip-insider-buy:hover   { border-color: var(--insider-buy);  color: var(--insider-buy); }
.chip-insider-sell:hover  { border-color: var(--insider-sell); color: var(--insider-sell); }
.chip-earnings:hover      { border-color: var(--earnings);     color: var(--earnings); }

.filter-right {
    display: flex;
    gap: 8px;
    margin-left: auto;
    flex-shrink: 0;
}

.select-ticker, .select-days, .select-market {
    padding: 5px 10px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
    color: var(--text);
    background: #fff;
    cursor: pointer;
    font-family: var(--font);
    outline: none;
    transition: border-color .15s;
}
.select-ticker:focus, .select-days:focus, .select-market:focus { border-color: var(--accent); }
.select-ticker { max-width: 180px; }
.select-market { max-width: 160px; }

/* ── Main layout ────────────────────────────────────────────────────────────── */
.main-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px 16px 40px;
}

@media (min-width: 1024px) {
    .main-layout {
        grid-template-columns: 1fr 320px;
        align-items: start;
    }
}

/* ── Feed stats ─────────────────────────────────────────────────────────────── */
.feed-stats {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
    flex-wrap: wrap;
    gap: 8px;
}

#statsText { font-size: 13px; color: var(--text2); }

.btn-mark-all {
    font-size: 12px;
    color: var(--accent);
    font-weight: 500;
    padding: 4px 10px;
    border: 1.5px solid var(--accent-light);
    border-radius: 6px;
    background: var(--accent-light);
    display: flex;
    align-items: center;
    gap: 5px;
    transition: all .15s;
}
.btn-mark-all:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ── News grid ──────────────────────────────────────────────────────────────── */
.news-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}

@media (min-width: 640px) {
    .news-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 1200px) {
    .news-grid { grid-template-columns: repeat(3, 1fr); }
}

/* ── News card ──────────────────────────────────────────────────────────────── */
.news-card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border-left: 4px solid var(--neutral);
    overflow: hidden;
    transition: transform .15s, box-shadow .15s;
    cursor: pointer;
    position: relative;
    display: flex;
    flex-direction: column;
}
.news-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.news-card.sentiment-positive { border-left-color: var(--positive); }
.news-card.sentiment-negative { border-left-color: var(--negative); }
.news-card.sentiment-neutral  { border-left-color: var(--neutral); }

.news-card.unread { background: #fafbff; }
.news-card.unread::before {
    content: '';
    position: absolute;
    top: 10px;
    right: 10px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent);
}

.card-image {
    width: 100%;
    height: 140px;
    object-fit: cover;
    display: block;
}

.card-body {
    padding: 14px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.card-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    flex-wrap: wrap;
}

.ticker-badge {
    font-size: 11px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 4px;
    background: var(--header);
    color: #fff;
    letter-spacing: .5px;
}

.event-badge {
    font-size: 10px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: .5px;
    white-space: nowrap;
}
.badge-news         { background: var(--accent-light); color: var(--accent); }
.badge-insider_buy  { background: var(--pos-light);    color: var(--positive); }
.badge-insider_sell { background: var(--neg-light);    color: var(--negative); }
.badge-earnings     { background: var(--ear-light);    color: var(--earnings); }
.badge-dividend     { background: #fef9c3;             color: #854d0e; }

.lang-badge {
    font-size: 9px;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 3px;
    background: #e2e8f0;
    color: #64748b;
    letter-spacing: .5px;
}

.card-title {
    font-size: 14px;
    font-weight: 600;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.card-title a { color: var(--text); }
.card-title a:hover { color: var(--accent); text-decoration: none; }

.card-summary {
    font-size: 12px;
    color: var(--text2);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    flex: 1;
}

.card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 4px;
}

.card-source {
    font-size: 11px;
    color: var(--text2);
    display: flex;
    align-items: center;
    gap: 4px;
}

.source-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    display: inline-block;
}
.dot-marketaux    { background: #6366f1; }
.dot-yahoo_rss    { background: #8b5cf6; }
.dot-sec_edgar    { background: #dc2626; }
.dot-alphavantage { background: #059669; }
.dot-cnmv         { background: #b45309; }

.card-time {
    font-size: 11px;
    color: var(--text2);
    white-space: nowrap;
}

/* ── Insider card special ──────────────────────────────────────────────────── */
.news-card.type-insider_buy  { border-left-color: var(--insider-buy); }
.news-card.type-insider_sell { border-left-color: var(--insider-sell); }
.news-card.type-earnings     { border-left-color: var(--earnings); }

/* ── Skeleton ────────────────────────────────────────────────────────────────── */
.skeleton-card {
    background: var(--card);
    border-radius: var(--radius);
    height: 200px;
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
}
.skeleton-card::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,.6) 50%, transparent 100%);
    animation: shimmer 1.4s infinite;
    background-size: 200% 100%;
}
@keyframes shimmer {
    0%   { background-position: -200% 0; }
    100% { background-position:  200% 0; }
}

/* ── Empty state ────────────────────────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text2);
}
.empty-state i { font-size: 40px; margin-bottom: 12px; opacity: .4; display: block; }

/* ── Pagination ─────────────────────────────────────────────────────────────── */
.pagination {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-top: 20px;
    flex-wrap: wrap;
}
.page-btn {
    padding: 6px 14px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    background: #fff;
    color: var(--text);
    transition: all .15s;
}
.page-btn:hover, .page-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}
.page-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ── Sidebar ────────────────────────────────────────────────────────────────── */
.sidebar {
    display: none;
}
@media (min-width: 1024px) {
    .sidebar {
        display: flex;
        flex-direction: column;
        gap: 16px;
        position: sticky;
        top: 120px;
    }
}

.widget {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.widget-title {
    font-size: 13px;
    font-weight: 600;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
}
.widget-title i { color: var(--accent); }

.widget-loading {
    padding: 20px;
    text-align: center;
    color: var(--text2);
}

.widget-item {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.widget-item:last-child { border-bottom: none; }

.wi-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.wi-ticker {
    font-size: 11px;
    font-weight: 700;
    background: var(--header);
    color: #fff;
    padding: 1px 6px;
    border-radius: 3px;
}

.wi-date {
    font-size: 11px;
    color: var(--text2);
}

.wi-text {
    font-size: 12px;
    color: var(--text);
    font-weight: 500;
}

.wi-sub {
    font-size: 11px;
    color: var(--text2);
}

.wi-buy  { color: var(--positive); font-weight: 600; }
.wi-sell { color: var(--negative); font-weight: 600; }

.log-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 7px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 12px;
}
.log-row:last-child { border-bottom: none; }
.log-source { color: var(--text); font-weight: 500; }
.log-status { font-size: 10px; padding: 1px 6px; border-radius: 4px; }
.status-success { background: var(--pos-light); color: var(--positive); }
.status-error   { background: var(--neg-light); color: var(--negative); }
.status-partial { background: #fef9c3;           color: #854d0e; }
.log-time { color: var(--text2); font-size: 11px; }

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

.toast {
    background: var(--header);
    color: #fff;
    padding: 10px 16px;
    border-radius: 10px;
    font-size: 13px;
    box-shadow: 0 4px 12px rgba(0,0,0,.2);
    animation: slideIn .2s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: 300px;
}
.toast.toast-success { border-left: 3px solid var(--positive); }
.toast.toast-error   { border-left: 3px solid var(--negative); }
@keyframes slideIn {
    from { transform: translateX(120%); opacity: 0; }
    to   { transform: translateX(0);    opacity: 1; }
}
@keyframes slideOut {
    from { transform: translateX(0);    opacity: 1; }
    to   { transform: translateX(120%); opacity: 0; }
}

/* ── Responsive tweaks ──────────────────────────────────────────────────────── */
@media (max-width: 480px) {
    .header-brand span { font-size: 15px; }
    .main-layout { padding: 12px 10px 30px; }
    .filter-inner { padding: 8px 10px; }
    .chip { padding: 4px 9px; font-size: 12px; }
}
