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

/* ── Dark theme (default) ── */
:root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --border: #2a2d3e;
    --accent: #6366f1;
    --accent-hover: #4f46e5;
    --text: #e2e8f0;
    --muted: #64748b;
    --green: #22c55e;
    --green-bg: #052e16;
    --red: #ef4444;
    --red-bg: #2d0a0a;
    --sidebar-w: 280px;
    --loader-bg: rgba(15, 17, 23, 0.88);
    --card-hover: #3a3d4e;
    --disclaimer-bg: #1a1200;
    --disclaimer-border: #3d2e00;
    --disclaimer-text: #a08040;
    --disclaimer-strong: #c8a020;
}

/* ── Warm Cream theme ── */
.light {
    --bg: #faf7f2;
    --surface: #f0ebe0;
    --border: #d6cdb8;
    --accent: #b45309;
    --accent-hover: #92400e;
    --text: #1c1008;
    --muted: #78604a;
    --green: #15803d;
    --green-bg: #dcfce7;
    --red: #b91c1c;
    --red-bg: #fee2e2;
    --loader-bg: rgba(250, 247, 242, 0.92);
    --card-hover: #c8b89a;
    --disclaimer-bg: #fef3c7;
    --disclaimer-border: #d97706;
    --disclaimer-text: #78350f;
    --disclaimer-strong: #92400e;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    font-size: 14px;
    line-height: 1.5;
    transition: background 0.2s, color 0.2s;
}

/* ── Loading overlay ── */
.loader {
    position: fixed; inset: 0;
    background: var(--loader-bg);
    backdrop-filter: blur(4px);
    display: flex; align-items: center; justify-content: center;
    z-index: 100;
}
.loader.hidden { display: none; }
.loader-box {
    text-align: center;
    color: var(--muted);
    font-size: 0.95rem;
}
.loader-box p { margin-top: 1rem; }
.spinner {
    width: 40px; height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Layout ── */
.page {
    display: flex;
    min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
    width: var(--sidebar-w);
    min-height: 100vh;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 1.75rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.brand-icon {
    font-size: 1.1rem;
    color: var(--accent);
}
.brand-name {
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: -0.3px;
    color: var(--text);
}
.brand-formerly {
    display: block;
    font-size: 0.62rem;
    color: var(--muted);
    font-weight: 500;
    opacity: 0.7;
    margin-top: 1px;
}
.sidebar-demo {
    width: 100%; border-radius: 10px;
    margin-top: 1rem;
    border: 1px solid var(--border);
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
}
.brand-desc {
    font-size: 0.8rem;
    color: var(--muted);
    line-height: 1.5;
    margin-top: -0.75rem;
}

/* ── Theme toggle ── */
.theme-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    color: var(--muted);
    background: none;
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 0.3rem 0.75rem;
    cursor: pointer;
    width: fit-content;
    transition: border-color 0.15s, color 0.15s;
}
.theme-toggle:hover { border-color: var(--accent); color: var(--text); }

/* ── Search row ── */
.search-row {
    display: flex;
    gap: 0.3rem;
}
.search-row input { flex: 1; }
.btn-search {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 0.7rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}
.btn-search:hover { background: var(--accent-hover); }

/* ── Form ── */
.form-group { display: flex; flex-direction: column; gap: 0.3rem; }
.form-group label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.form-group input {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.5rem 0.7rem;
    color: var(--text);
    font-size: 0.88rem;
    outline: none;
    transition: border-color 0.15s;
    width: 100%;
}
.form-group input::placeholder { color: var(--muted); }
.form-group input:focus { border-color: var(--accent); }
.hint { font-size: 0.73rem; color: var(--muted); }

.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    width: 100%;
    padding: 0.6rem 1rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
    margin-top: 0.25rem;
}
.btn:hover { background: var(--accent-hover); }
.btn-secondary {
    background: var(--bg);
    color: var(--muted);
    border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--border); color: var(--text); }
.btn-icon { font-size: 0.7rem; }

/* ── Meta box ── */
.meta-box {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}
.meta-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
}
.meta-label { color: var(--muted); }
.meta-val { color: var(--text); font-weight: 500; }

/* ── Section labels ── */
.section-label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--muted);
    margin-bottom: 0.5rem;
}

/* ── Custom sources ── */
.source-list { list-style: none; display: flex; flex-direction: column; gap: 0.25rem; }
.source-list a {
    font-size: 0.78rem;
    color: var(--accent);
    text-decoration: none;
    word-break: break-all;
}
.source-list a:hover { text-decoration: underline; }

/* ── Main content ── */
.content {
    flex: 1;
    padding: 1.5rem 2rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-width: 0;
}

/* ── Search result card ── */
.search-result-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
}
.sr-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    gap: 1rem;
    flex-wrap: wrap;
    border-bottom: 1px solid var(--border);
}
.sr-title-group { display: flex; align-items: baseline; gap: 0.6rem; }
.sr-name { font-size: 0.85rem; color: var(--muted); }
.sr-price-group { display: flex; align-items: center; gap: 0.5rem; }
.sr-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.25rem;
    border-bottom: 1px solid var(--border);
}
.sr-reasons { display: flex; flex-direction: column; }
.sr-no-news {
    padding: 1rem 1.25rem;
    font-size: 0.82rem;
    color: var(--muted);
}

/* ── Tab bar ── */
.tabs {
    display: flex;
    gap: 0.3rem;
    overflow-x: auto;
    padding-bottom: 0.25rem;
    scrollbar-width: none;
    flex-shrink: 0;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
    flex-shrink: 0;
    font-size: 0.78rem;
    font-weight: 600;
    padding: 0.35rem 0.8rem;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--muted);
    text-decoration: none;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.tab:hover { background: var(--border); color: var(--text); }
.tab.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.content-header h1 {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: -0.5px;
    color: var(--text);
}
.content-sub {
    font-size: 0.82rem;
    color: var(--muted);
    margin-top: 0.25rem;
}

/* ── Toolbar: sort + perf ── */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.sort-pills { display: flex; gap: 0.25rem; flex-wrap: wrap; }
.sort-pill {
    font-size: 0.74rem;
    font-weight: 600;
    padding: 0.25rem 0.65rem;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--muted);
    text-decoration: none;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.sort-pill:hover { background: var(--border); color: var(--text); }
.sort-pill.active {
    background: var(--bg);
    border-color: var(--accent);
    color: var(--accent);
}

.perf-bar {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.78rem;
    font-weight: 600;
}
.perf-up   { color: var(--green); }
.perf-down { color: var(--red); }
.perf-flat { color: var(--muted); }
.perf-sep  { color: var(--border); }

/* ── Results grid ── */
.results {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 0.65rem;
}

.stock-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    transition: border-color 0.15s;
    display: flex;
    flex-direction: column;
}
.stock-card:hover { border-color: var(--card-hover); }

.card-top {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    padding: 0.75rem 1rem;
}
.card-row1 {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}
.ticker-group { display: flex; align-items: baseline; gap: 0.45rem; }
.ticker {
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: var(--text);
}
.sentiment-score {
    font-size: 0.68rem;
    color: var(--muted);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 0.1rem 0.4rem;
}
.card-row2 {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    flex-wrap: wrap;
}
.price {
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--text);
}
.change {
    font-size: 0.72rem;
    font-weight: 600;
    padding: 0.1rem 0.4rem;
    border-radius: 20px;
}
.change.up   { background: var(--green-bg); color: var(--green); }
.change.down { background: var(--red-bg);   color: var(--red); }
.mentions-badge {
    font-size: 0.68rem;
    color: var(--muted);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 0.1rem 0.4rem;
    margin-left: auto;
}

/* ── Source articles / reasons ── */
.articles { border-top: 1px solid var(--border); }
.articles summary {
    font-size: 0.78rem;
    color: var(--muted);
    padding: 0.6rem 1.25rem;
    cursor: pointer;
    user-select: none;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    transition: color 0.15s;
}
.articles summary::-webkit-details-marker { display: none; }
.articles summary::before { content: "▶"; font-size: 0.6rem; }
details[open] summary::before { content: "▼"; }
.articles summary:hover { color: var(--text); }

.reasons { display: flex; flex-direction: column; gap: 0; }
.reason-group { padding: 0.6rem 1.25rem 0.85rem; }
.reason-group + .reason-group { border-top: 1px solid var(--border); }
.reason-label {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: 0.5rem;
}
.reason-up .reason-label   { color: var(--green); }
.reason-down .reason-label { color: var(--red); }

.article-list { list-style: none; display: flex; flex-direction: column; gap: 0.5rem; }
.article-list li {
    font-size: 0.8rem;
    color: var(--muted);
    line-height: 1.45;
    padding-left: 0.75rem;
}
.reason-up .article-list li   { border-left: 2px solid var(--green-bg); }
.reason-down .article-list li { border-left: 2px solid var(--red-bg); }
.article-list a { color: var(--text); text-decoration: none; }
.article-list a:hover { color: var(--accent); text-decoration: underline; }
.src-tag {
    display: inline-block;
    font-size: 0.62rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--muted);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.05rem 0.35rem;
    margin-right: 0.35rem;
    vertical-align: middle;
}

/* ── Empty / Welcome states ── */
.empty-state, .welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 4rem 2rem;
    color: var(--muted);
    gap: 0.75rem;
}
.empty-icon, .welcome-icon { font-size: 2.5rem; }
.empty-state p, .welcome p { max-width: 400px; line-height: 1.6; }
.empty-hint { font-size: 0.82rem; }

/* ── Disclaimer ── */
.disclaimer {
    margin-top: auto;
    padding: 1rem 1.25rem;
    background: var(--disclaimer-bg);
    border: 1px solid var(--disclaimer-border);
    border-radius: 10px;
    font-size: 0.78rem;
    color: var(--disclaimer-text);
    line-height: 1.6;
}
.disclaimer strong { color: var(--disclaimer-strong); }

/* ── Responsive ── */
@media (max-width: 700px) {
    .page { flex-direction: column; }
    .sidebar {
        width: 100%;
        min-height: unset;
        height: auto;
        position: static;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    .content { padding: 1rem; }
    .results { grid-template-columns: 1fr 1fr; }
    .tabs { gap: 0.25rem; }
    .tab { font-size: 0.72rem; padding: 0.3rem 0.6rem; }
}

/* -- Site intro / quick tour -- */
.site-intro {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 1rem;
}
.site-intro summary {
    cursor: pointer;
    padding: 0.75rem 1rem;
    font-weight: 600;
    font-size: 0.88rem;
    color: var(--text);
    list-style: none;
    user-select: none;
}
.site-intro summary::-webkit-details-marker { display: none; }
.site-intro summary::after {
    content: '\25BE';
    float: right;
    color: var(--muted);
    transition: transform 0.15s;
}
.site-intro[open] summary::after { transform: rotate(180deg); }
.intro-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem 1.25rem;
    padding: 0.25rem 1rem 1rem;
}
@media (max-width: 720px) { .intro-grid { grid-template-columns: 1fr; } }
.intro-item { display: flex; gap: 0.65rem; align-items: flex-start; }
.intro-emo { font-size: 1.1rem; line-height: 1.5; }
.intro-item strong { display: block; font-size: 0.83rem; color: var(--text); margin-bottom: 2px; }
.intro-item p { font-size: 0.78rem; color: var(--muted); line-height: 1.5; }
.intro-item em { font-style: normal; color: var(--accent); }

/* ── Account area ── */
.signin-link {
    width: 100%; padding: 0.65rem 1rem;
    background: #0ea5e9; color: #fff;
    border: 2px solid #38bdf8;
    border-radius: 10px;
    font-size: 0.88rem; font-weight: 700;
    cursor: pointer; letter-spacing: 0.2px;
    box-shadow: 0 4px 14px rgba(14,165,233,0.35);
    transition: background 0.15s, transform 0.15s, box-shadow 0.15s;
}
.signin-link:hover {
    background: #0284c7;
    border-color: #0ea5e9;
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(14,165,233,0.45);
}

.account-combo { position: relative; }
.account-trigger {
    display: flex; align-items: center; gap: 0.4rem; width: 100%;
    padding: 0.4rem 0.6rem; background: var(--bg);
    border: 1px solid var(--border); border-radius: 8px;
    cursor: pointer; color: var(--text); font-size: 0.8rem;
    transition: border-color 0.15s;
}
.account-trigger:hover { border-color: var(--accent); }
.account-avatar {
    width: 22px; height: 22px; background: var(--accent); color: #fff;
    border-radius: 50%; display: flex; align-items: center; justify-content: center;
    font-size: 0.68rem; font-weight: 700; flex-shrink: 0;
}
.account-email {
    flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    font-size: 0.74rem; color: var(--muted); text-align: left;
}
.account-drop {
    position: absolute; top: calc(100% + 5px); left: 0; right: 0;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 8px; overflow: hidden; z-index: 50;
}
.ad-item {
    display: block; width: 100%; padding: 0.5rem 0.85rem;
    font-size: 0.8rem; color: var(--text); background: none;
    border: none; text-align: left; cursor: pointer; transition: background 0.12s;
}
.ad-item:hover { background: var(--border); }
.ad-label { color: var(--muted); font-size: 0.71rem; cursor: default; }
.ad-label:hover { background: none; }

/* ── Watch button ── */
.watch-btn {
    flex-shrink: 0; background: none;
    border: 1px solid var(--border); border-radius: 6px;
    color: var(--muted); font-size: 0.78rem;
    padding: 0.1rem 0.4rem; cursor: pointer; line-height: 1.4;
    transition: border-color 0.12s, color 0.12s;
}
.watch-btn:hover { border-color: var(--accent); color: var(--accent); }
.watch-btn.on { border-color: #f59e0b; color: #f59e0b; }

/* ── Auth modal ── */
.auth-modal {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.65); z-index: 200;
    align-items: center; justify-content: center;
}
.auth-modal.open { display: flex; }
.auth-sheet {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 14px; width: min(400px, 92vw); padding: 1.5rem;
    position: relative;
}
.auth-modal-head {
    display: flex; align-items: center;
    justify-content: space-between; margin-bottom: 0.9rem;
}
.auth-modal-head h2 { font-size: 1.05rem; font-weight: 700; color: var(--text); }
.auth-close {
    background: none; border: 1px solid var(--border); border-radius: 6px;
    color: var(--muted); width: 26px; height: 26px; cursor: pointer;
    font-size: 0.78rem; display: flex; align-items: center; justify-content: center;
}
.auth-close:hover { color: var(--text); border-color: var(--text); }
.auth-sub { font-size: 0.78rem; color: var(--muted); margin-bottom: 0.9rem; line-height: 1.5; }
.auth-tabs {
    display: flex; gap: 0.25rem; margin-bottom: 0.9rem;
    background: var(--bg); border-radius: 8px; padding: 3px;
}
.auth-tab {
    flex: 1; padding: 0.38rem; border: none; border-radius: 6px;
    background: none; color: var(--muted); font-size: 0.81rem;
    font-weight: 600; cursor: pointer; transition: background 0.12s, color 0.12s;
}
.auth-tab.on { background: var(--surface); color: var(--text); }
.google-btn {
    display: flex; align-items: center; justify-content: center; gap: 0.5rem;
    width: 100%; padding: 0.55rem 1rem; background: var(--bg);
    border: 1px solid var(--border); border-radius: 8px; color: var(--text);
    font-size: 0.85rem; font-weight: 500; cursor: pointer; margin-bottom: 0.7rem;
    transition: border-color 0.15s, background 0.15s;
}
.google-btn:hover { border-color: var(--accent); background: var(--border); }
.or-divider {
    text-align: center; color: var(--muted); font-size: 0.73rem;
    margin: 0.6rem 0; position: relative;
}
.or-divider::before, .or-divider::after {
    content: ''; position: absolute; top: 50%;
    width: 38%; border-top: 1px solid var(--border);
}
.or-divider::before { left: 0; }
.or-divider::after  { right: 0; }
.auth-field {
    display: block; width: 100%; background: var(--bg);
    border: 1px solid var(--border); border-radius: 8px;
    padding: 0.52rem 0.75rem; color: var(--text); font-size: 0.85rem;
    outline: none; margin-bottom: 0.55rem; transition: border-color 0.15s;
}
.auth-field::placeholder { color: var(--muted); }
.auth-field:focus { border-color: var(--accent); }
.auth-submit {
    width: 100%; padding: 0.58rem 1rem; background: var(--accent);
    color: #fff; border: none; border-radius: 8px;
    font-size: 0.88rem; font-weight: 600; cursor: pointer;
    margin-top: 0.2rem; transition: background 0.15s;
}
.auth-submit:hover { background: var(--accent-hover); }
.auth-submit:disabled { opacity: 0.6; cursor: not-allowed; }
.auth-error { margin-top: 0.55rem; font-size: 0.78rem; color: var(--red); }
.auth-ok    { margin-top: 0.55rem; font-size: 0.78rem; color: var(--green); }

/* ── Saved sources remove button ── */
.rm-src {
    background: none; border: none; color: var(--muted);
    cursor: pointer; font-size: 0.68rem; padding: 0 0.2rem;
    vertical-align: middle;
}
.rm-src:hover { color: var(--red); }
