/* BridgeInvestIQ Dashboard v1 — base theme, RTL-first with English (ltr) support. */
:root {
    --bg: #f4f6fa;
    --surface: #ffffff;
    --surface-2: #f0f2f7;
    --border: #e2e6ee;
    --text: #1b2330;
    --text-soft: #5b6473;
    --primary: #1f6feb;
    --primary-ink: #ffffff;
    --up: #1a8f4c;
    --down: #d23b3b;
    --flat: #8a93a3;
    --warn: #b6791e;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(20, 30, 50, .08), 0 1px 2px rgba(20, 30, 50, .06);
    font-family: Vazirmatn, "Segoe UI", Tahoma, system-ui, sans-serif;
}

body.theme-dark {
    --bg: #0e1320;
    --surface: #161d2e;
    --surface-2: #1d2538;
    --border: #2a3550;
    --text: #e6ebf5;
    --text-soft: #9aa6bd;
    --shadow: none;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

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

h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.1rem; }

/* Layout */
.app-shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
    display: flex; align-items: center; gap: 1rem;
    padding: .6rem 1.2rem; background: var(--surface);
    border-bottom: 1px solid var(--border); box-shadow: var(--shadow);
    position: sticky; top: 0; z-index: 10; flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 1.15rem; color: var(--text); }
.topbar-nav { display: flex; gap: .25rem; flex-wrap: wrap; }
.topbar-nav a { padding: .35rem .7rem; border-radius: 8px; color: var(--text-soft); }
.topbar-nav a:hover { background: var(--surface-2); text-decoration: none; }
.topbar-nav .nav-admin { color: var(--primary); font-weight: 600; }
.topbar-actions { margin-inline-start: auto; display: flex; align-items: center; gap: .6rem; }

.dashboard-body { display: flex; flex: 1; align-items: stretch; }
.sidebar {
    width: 230px; background: var(--surface); border-inline-end: 1px solid var(--border);
    padding: 1rem .75rem; flex-shrink: 0;
}
.nav-menu { display: flex; flex-direction: column; gap: .15rem; }
.nav-menu a { padding: .45rem .7rem; border-radius: 8px; color: var(--text-soft); }
.nav-menu a:hover { background: var(--surface-2); text-decoration: none; }
.nav-menu .nav-admin { color: var(--primary); font-weight: 600; }
.nav-group-label { font-size: .72rem; color: var(--text-soft); margin: .6rem .4rem .1rem; text-transform: uppercase; opacity: .7; }

.app-main { flex: 1; padding: 1.4rem; max-width: 1280px; width: 100%; margin: 0 auto; }
.app-footer {
    padding: .8rem 1.4rem; border-top: 1px solid var(--border);
    display: flex; justify-content: space-between; gap: 1rem; color: var(--text-soft); font-size: .85rem; flex-wrap: wrap;
}
.footer-disclaimer { color: var(--warn); }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.1rem; flex-wrap: wrap; }

/* Cards & grid */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem; box-shadow: var(--shadow); }
.card-title { margin: 0 0 .8rem; font-size: 1.02rem; }
.card-link { display: inline-block; margin-top: .8rem; font-size: .9rem; }
.dashboard-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.1rem; }
.span-2 { grid-column: span 2; }
.span-full { grid-column: 1 / -1; }

.market-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: .8rem; }
.stat { display: flex; flex-direction: column; background: var(--surface-2); border-radius: 10px; padding: .7rem .9rem; }
.stat-label { font-size: .78rem; color: var(--text-soft); }
.stat-value { font-size: 1.25rem; font-weight: 700; }
.text-up { color: var(--up); } .text-down { color: var(--down); }

.rank-list, .impact-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .5rem; }
.rank-list li, .impact-list li { display: flex; align-items: center; gap: .5rem; padding: .35rem 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.rank-symbol { font-weight: 700; }
.rank-name, .impact-title { color: var(--text-soft); font-size: .88rem; flex: 1; }

.chip-list { list-style: none; display: flex; flex-wrap: wrap; gap: .4rem; padding: 0; margin: 0; }
.chip { background: var(--surface-2); padding: .3rem .65rem; border-radius: 999px; font-weight: 600; }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: .25rem; padding: .12rem .5rem; border-radius: 999px; font-size: .8rem; font-weight: 600; white-space: nowrap; }
.badge-label { opacity: .8; font-weight: 500; }
.score-high { background: #def3e4; color: #14723c; }
.score-mid { background: #fdf1d6; color: #936416; }
.score-low { background: #fce3da; color: #9c4a25; }
.score-vlow { background: #fad6d6; color: #9c2525; }
.direction-positive, .impact-positive, .change-up, .signal-positive, .confidence-high { background: #def3e4; color: #14723c; }
.direction-negative, .impact-negative, .change-down, .signal-negative, .confidence-low { background: #fad6d6; color: #9c2525; }
.direction-neutral, .impact-neutral, .change-flat, .signal-neutral, .confidence-mid { background: var(--surface-2); color: var(--text-soft); }
.direction-mixed, .impact-mixed { background: #e7ddf6; color: #5b3b9c; }
.signal-pill, .status-pill, .plan-pill { padding: .12rem .5rem; border-radius: 999px; font-size: .75rem; font-weight: 600; background: var(--surface-2); color: var(--text-soft); }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: .35rem; padding: .5rem .9rem; border-radius: 9px; border: 1px solid transparent; cursor: pointer; font: inherit; font-weight: 600; }
.btn-sm { padding: .3rem .6rem; font-size: .85rem; }
.btn-primary { background: var(--primary); color: var(--primary-ink); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn:hover { text-decoration: none; opacity: .92; }

/* Tables */
.data-table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td { padding: .55rem .7rem; text-align: start; border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table thead th { font-size: .8rem; color: var(--text-soft); background: var(--surface-2); position: sticky; top: 0; }
.data-table tbody tr:hover { background: var(--surface-2); }

/* States */
.state-card { text-align: center; padding: 2rem 1.2rem; border: 1px dashed var(--border); border-radius: var(--radius); background: var(--surface); }
.state-icon { font-size: 2rem; }
.state-title { margin: .4rem 0; }
.state-message { color: var(--text-soft); margin: 0 auto .8rem; max-width: 460px; }
.upgrade-card { border-color: var(--primary); }
.usage-limit-card { border-color: var(--warn); }
.error-state { border-color: var(--down); }

.skeleton { display: flex; flex-direction: column; gap: .6rem; }
.skeleton-row { height: 14px; border-radius: 6px; background: linear-gradient(90deg, var(--surface-2), var(--border), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.3s infinite; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* Charts */
.chart { width: 100%; height: auto; }
.line-chart { height: 160px; }
.line-chart-line { fill: none; stroke: var(--primary); stroke-width: 2; vector-effect: non-scaling-stroke; }
.line-chart-area { fill: rgba(31,111,235,.12); stroke: none; }
.chart-caption { text-align: center; color: var(--text-soft); font-size: .82rem; margin-top: .3rem; }
.bar-chart { display: flex; flex-direction: column; gap: .45rem; }
.bar-row { display: grid; grid-template-columns: 120px 1fr 80px; align-items: center; gap: .5rem; font-size: .85rem; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { background: var(--surface-2); border-radius: 6px; height: 14px; overflow: hidden; }
.bar-fill { display: block; height: 100%; }
.bar-pos { background: var(--up); } .bar-neg { background: var(--down); }
.bar-value { text-align: end; color: var(--text-soft); }
.donut-wrap { display: flex; align-items: center; gap: 1.2rem; flex-wrap: wrap; }
.donut-chart { width: 150px; height: 150px; transform: rotate(-90deg); }
.donut-base { fill: none; stroke: var(--surface-2); stroke-width: 4; }
.donut-seg { fill: none; stroke-width: 4; }
.donut-seg-a, .donut-seg-positive { stroke: var(--up); }
.donut-seg-b, .donut-seg-negative { stroke: var(--down); }
.donut-seg-c, .donut-seg-neutral { stroke: var(--flat); }
.donut-seg-d, .donut-seg-mixed { stroke: var(--primary); }
.donut-legend { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .3rem; font-size: .85rem; }
.legend-swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-inline-end: .4rem; }
.donut-legend .donut-seg-a { background: var(--up); } .donut-legend .donut-seg-b { background: var(--down); }
.donut-legend .donut-seg-c { background: var(--flat); } .donut-legend .donut-seg-d { background: var(--primary); }

.timeline-chart { position: relative; padding: .6rem 0; }
.timeline-markers { list-style: none; display: flex; gap: 1rem; overflow-x: auto; padding: 0; margin: 0; }
.timeline-marker { display: flex; flex-direction: column; align-items: center; min-width: 90px; font-size: .8rem; text-align: center; }
.timeline-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--flat); }
.timeline-positive .timeline-dot { background: var(--up); }
.timeline-negative .timeline-dot { background: var(--down); }
.timeline-value { font-weight: 700; }
.timeline-label { color: var(--text-soft); max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Citations */
.citation-list { display: flex; flex-direction: column; gap: .6rem; padding-inline-start: 1.2rem; }
.citation-meta { display: flex; gap: .6rem; font-size: .78rem; color: var(--text-soft); }
.citation-quote { margin: .25rem 0; padding-inline-start: .7rem; border-inline-start: 3px solid var(--primary); color: var(--text); }
.citation-support { font-size: .8rem; color: var(--text-soft); }

/* Disclosures */
.disclosure-card { display: block; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem; box-shadow: var(--shadow); color: var(--text); }
.disclosure-card:hover { text-decoration: none; border-color: var(--primary); }
.disclosure-card-head { display: flex; justify-content: space-between; font-size: .8rem; color: var(--text-soft); }
.disclosure-symbol { font-weight: 700; color: var(--text); }
.disclosure-title { margin: .35rem 0; font-size: .98rem; }
.disclosure-card-meta { display: flex; gap: .5rem; font-size: .78rem; color: var(--text-soft); flex-wrap: wrap; align-items: center; }

/* Forms */
.filter-bar { display: flex; gap: .8rem; align-items: flex-end; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem; margin-bottom: 1.1rem; }
.field { display: flex; flex-direction: column; gap: .25rem; font-size: .82rem; color: var(--text-soft); }
.field input, .field select, .filter-bar input, .filter-bar select { padding: .4rem .55rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); font: inherit; }
.filter-actions { display: flex; gap: .5rem; }
.date-range { display: flex; gap: .8rem; }
.stock-search { display: flex; gap: .35rem; }
.stock-search input { padding: .4rem .6rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); }

/* Pagination */
.pagination { display: flex; gap: .3rem; align-items: center; margin-top: 1rem; flex-wrap: wrap; }
.page-link { padding: .35rem .65rem; border: 1px solid var(--border); border-radius: 8px; color: var(--text); }
.page-link.active { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.page-link.disabled { opacity: .4; pointer-events: none; }
.page-info { margin-inline-start: auto; color: var(--text-soft); font-size: .82rem; }

/* Breadcrumb */
.breadcrumb { display: flex; gap: .4rem; align-items: center; font-size: .85rem; color: var(--text-soft); }
.breadcrumb-current { color: var(--text); font-weight: 600; }

/* User menu */
.user-menu { display: flex; align-items: center; gap: .5rem; }
.user-id { font-size: .82rem; color: var(--text-soft); }
.signin-dropdown { position: relative; }
.signin-form, .signin-dropdown form { display: flex; gap: .35rem; padding: .5rem; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; position: absolute; inset-inline-end: 0; margin-top: .3rem; box-shadow: var(--shadow); z-index: 20; }
.signin-form input, .signin-form select { padding: .3rem .4rem; border: 1px solid var(--border); border-radius: 6px; }
.inline-form { display: inline; }

.disclaimer { background: #fff7e6; border: 1px solid #f0d9a8; color: #7a5b16; border-radius: var(--radius); padding: .8rem 1rem; font-size: .85rem; }
body.theme-dark .disclaimer { background: #2a2410; border-color: #4a3f1a; color: #d9c486; }
.disclaimer-warnings { margin: .4rem 0 0; padding-inline-start: 1.1rem; }
.last-updated { color: var(--text-soft); font-size: .8rem; text-align: end; }

.admin-denied { display: flex; flex-direction: column; align-items: center; gap: 1rem; padding: 3rem 1rem; }

@media (max-width: 900px) {
    .dashboard-grid { grid-template-columns: 1fr; }
    .span-2 { grid-column: span 1; }
    .sidebar { display: none; }
}

/* Stock detail */
.stock-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; }
.stock-meta { color: var(--text-soft); font-size: .85rem; }
.stock-head-actions { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.score-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: .5rem; }
.score-changes { display: flex; gap: 1rem; margin-top: .7rem; color: var(--text-soft); font-size: .85rem; flex-wrap: wrap; }
.kv-list { list-style: none; margin: 0; padding: 0; }
.kv-list li { display: flex; justify-content: space-between; padding: .35rem 0; border-bottom: 1px solid var(--border); }
.kv-list li span:first-child { color: var(--text-soft); }
.warn-list { margin: .6rem 0 0; padding-inline-start: 1.1rem; color: var(--warn); font-size: .82rem; }

/* Disclosures */
.disclosure-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.extracted-text { margin-top: .8rem; }
.extracted-text p { white-space: pre-wrap; color: var(--text-soft); font-size: .88rem; }
.summary-short { font-weight: 600; }
.cited-section { margin-top: 1rem; }
.cited-title { font-size: .95rem; margin: 0 0 .4rem; }
.cited-items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .8rem; }
.cited-text { margin: 0 0 .3rem; }
.impact-head { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .6rem; }
.impact-factor { border-top: 1px solid var(--border); padding-top: .7rem; margin-top: .7rem; }
.impact-factor-head { display: flex; gap: .5rem; align-items: center; }
.impact-contrib { font-weight: 700; }
.impact-reason { color: var(--text-soft); font-size: .88rem; margin: .3rem 0; }
.chunk-text { max-width: 360px; white-space: normal; }
.chunk-hash { font-family: monospace; font-size: .78rem; color: var(--text-soft); }

/* Billing */
.plan-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem; }
.plan-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; display: flex; flex-direction: column; gap: .6rem; background: var(--surface-2); }
.plan-card h3 { margin: 0; }
.plan-features { list-style: none; margin: 0; padding: 0; font-size: .85rem; color: var(--text-soft); display: flex; flex-direction: column; gap: .2rem; }
.plan-current { color: var(--text-soft); font-size: .85rem; }
.gateway-select { margin-inline-end: .4rem; }

/* Admin */
.admin-nav-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 1rem; margin-bottom: 1.2rem; }
.admin-nav-card { display: flex; flex-direction: column; align-items: center; gap: .5rem; text-align: center; color: var(--text); font-weight: 600; }
.admin-nav-card:hover { text-decoration: none; border-color: var(--primary); }
.admin-nav-icon { font-size: 1.8rem; }
.severity-error { background: #fad6d6; color: #9c2525; }
.severity-warning { background: #fdf1d6; color: #936416; }
