:root {
    color-scheme: dark;
    --ink: #e4eaf2; --muted: #98a8bd; --line: #293549;
    --surface: #151f2e; --canvas: #0d1420; --navy: #223b62;
    --blue: #8bb9ff; --red: #ff8c92; --green: #66d6ab;
    /* Web report typography; exported PNG sizes live in services/report_images.py. */
    --report-title-size: 48px;
    --report-body-size: 24px;
    --report-header-size: 21px;
    --report-row-height: 56px;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 58px; }
body { margin: 0; min-width: 320px; background: var(--canvas); color: var(--ink); font: 13px/1.45 "Noto Sans TC","Microsoft JhengHei",system-ui,sans-serif; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
button, select { font: inherit; }
button { cursor: pointer; border: 1px solid #3d5678; background: #254675; color: #edf4ff; padding: 7px 12px; min-height: 36px; border-radius: 5px; }
button:disabled { opacity: .5; cursor: wait; }
a:focus-visible, button:focus-visible, summary:focus-visible, .table-scroll:focus-visible { outline: 2px solid #8bb9ff; outline-offset: 2px; }
h1,h2,p { margin-top: 0; }
h1 { font-size: 21px; margin-bottom: 2px; }
h2 { font-size: 15px; margin-bottom: 0; }
h2 small { color: var(--muted); font-size: 11px; font-weight: 400; }
.page-shell { width: min(1420px,calc(100% - 24px)); margin: 0 auto 24px; }
.page-nav { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; position: sticky; top: 0; z-index: 10; padding: 7px 0; background: #0d1420f5; border-bottom: 1px solid var(--line); }
.page-nav form { margin: 0; }
.page-nav > span { margin-left: auto; color: var(--muted); font-size: 12px; }
.page-nav a { padding: 8px 14px; min-height: 36px; color: var(--muted); border-radius: 5px; font-weight: 700; }
.page-nav a[aria-current] { color: #fff; background: var(--navy); }
.hero { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 0 8px; }
.hero-copy, .table-hint { margin-bottom: 0; color: var(--muted); font-size: 11px; }
.source-status { padding: 5px 8px; border-radius: 4px; color: var(--muted); background: #1b283a; font-size: 11px; white-space: nowrap; }
.status-dot { display: none; }
.eyebrow { font-size: 11px; color: var(--muted); }
.filter-bar { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 8px; padding: 8px 10px; margin: 4px 0 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
.filter-bar label { display: grid; gap: 3px; min-width: 0; color: var(--muted); font-size: 11px; }
.filter-bar select { width: 100%; min-width: 0; min-height: 36px; padding: 4px 7px; color: var(--ink); background: #101927; border: 1px solid #344258; border-radius: 4px; font-size: 12px; }
.report-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 6px 0; font-size: 12px; }
.report-actions a { padding: 8px 3px; }
#copy-status { color: var(--muted); }
#navigation-status { color: #e9bd7b; font-size: 12px; margin: 5px 0; }
#navigation-status:empty { display: none; }
[data-report-filter][aria-busy="true"] { border-color: #8bb9ff; }
[data-report-filter] { grid-template-columns: repeat(3,minmax(0,1fr)) auto; align-items: end; }
[data-report-filter].viewer-filter { grid-template-columns: 170px minmax(0,1fr); align-items: end; }
.viewer-categories { display: grid; grid-template-columns: repeat(5,minmax(0,1fr)); gap: 5px; }
.viewer-categories button { min-height: 42px; padding: 7px 4px; background: #101927; color: var(--muted); white-space: nowrap; font-weight: 700; }
.viewer-categories button[aria-pressed="true"] { background: #254675; color: #fff; border-color: #8bb9ff; }
.viewer-categories button { min-width: 0; min-height: 44px; border-radius: 8px; }
.viewer-categories button[data-category="外資"] { border-bottom: 3px solid #8bb9ff; }
.viewer-categories button[data-category="投信"] { border-bottom: 3px solid #c8a3ff; }
.viewer-categories button[data-category="自營商"] { border-bottom: 3px solid #ffcc80; }
.viewer-categories button[data-category="三大法人"] { border-bottom: 3px solid #74dec9; }
.viewer-categories button[data-category="主力"] { border-bottom: 3px solid #ff98b0; }
@media(max-width:600px) {
    [data-report-filter].viewer-filter { grid-template-columns: minmax(0,1fr); }
    .viewer-categories button { font-size: 13px; }
}
.report-block { margin: 12px 0 20px; }
.section-heading { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 0 0 6px; }
.direction-3buy h2 { border-left: 3px solid var(--red); padding-left: 7px; }
.direction-3sell h2 { border-left: 3px solid var(--green); padding-left: 7px; }
.section-heading button { background: #1b2b42; border-color: #334862; font-size: 11px; }
.table-card { background: none; }
.table-scroll { overflow: auto; max-width: 100%; border: 1px solid var(--line); border-radius: 6px; scrollbar-color: #53657d #111a29; }
.report-block .section-heading h2 { font-size: var(--report-title-size); }
.report-block .section-heading h2 small { display: block; font-size: 12px; }
.report-block[data-category="外資"] .section-heading h2 { color: #8bb9ff; }
.report-block[data-category="投信"] .section-heading h2 { color: #c8a3ff; }
.report-block[data-category="自營商"] .section-heading h2 { color: #ffcc80; }
.report-block[data-category="三大法人"] .section-heading h2 { color: #74dec9; }
.report-block[data-category="主力"] .section-heading h2 { color: #ff98b0; }
.ranking-table { border-collapse: separate; border-spacing: 0; width: 100%; min-width: 1350px; table-layout: auto; font-variant-numeric: tabular-nums; font-size: var(--report-body-size); }
.ranking-table th, .ranking-table td { height: var(--report-row-height); padding: 6px 9px; white-space: nowrap; border-bottom: 1px solid #233044; vertical-align: middle; line-height: 24px; }
.ranking-table th { color: #b9c8da; background: #1c2b40; font-size: var(--report-header-size); text-align: left; font-weight: 600; }
.ranking-table tbody td { background: var(--surface); }
.ranking-table tbody tr:nth-child(even) td { background: #121d2c; }
.ranking-table tbody tr:hover td:not(.heat) { background: #223149; }
.ranking-table tbody tr:last-child td { border-bottom: 0; }
.ranking-table .numeric { text-align: right; }
.ranking-table th:first-child, .ranking-table td:first-child { width: 45px; min-width: 45px; max-width: 45px; text-align: center; position: sticky; left: 0; z-index: 2; }
.ranking-table th:nth-child(2), .ranking-table td:nth-child(2) { position: sticky; left: 45px; z-index: 2; border-right: 1px solid #35435a; min-width: 200px; }
.ranking-table .identity { display: table-cell; }
.identity a, .identity > span { display: inline; font-size: var(--report-body-size); vertical-align: middle; }
.identity a { font-weight: 700; margin-right: 7px; }
.identity > span { color: var(--ink); }
.identity .institution-tags { display: inline-flex; gap: 2px; margin-left: 5px; }
.institution-tag { font-size: 9px; line-height: 15px; padding: 0 3px; color: #c4d8ff; background: #263b60; border-radius: 3px; font-weight: 500; }
.rank-badge { font-size: 12px; background: none; }
.heat { font-weight: 600; }
.up { color: var(--red); }
.down { color: var(--green); }
.return-pill { padding: 0; background: none; font-size: 12px; }
.summary-grid { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); border: 1px solid var(--line); border-radius: 5px; background: var(--surface); margin: 6px 0; }
.metric-card { display: grid; min-height: 0; padding: 7px 10px; border-right: 1px solid var(--line); }
.metric-card:last-child { border: 0; }
.metric-label, .metric-card small { font-size: 10px; color: var(--muted); }
.metric-card strong { font-size: 14px; font-weight: 600; }
.method-note, .notice, .empty-panel { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 9px 12px; margin: 10px 0; font-size: 12px; color: var(--muted); }
summary { cursor: pointer; min-height: 30px; line-height: 30px; font-weight: 600; color: #c4d4e8; }
details p { margin: 7px 0; }
.empty-state { text-align: center; color: var(--muted); position: static !important; }
.empty-panel { padding: 24px; text-align: center; }
.progress-panel { padding: 10px 12px; margin: 10px 0; border: 1px solid var(--line); background: var(--surface); border-radius: 6px; }
.progress-panel p { margin: 6px 0; font-size: 12px; }
progress { width: 100%; height: 9px; accent-color: #76a7ec; display: block; margin: 8px 0; }
.progress-details { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 8px; margin: 8px 0 0; }
.progress-details dt { color: var(--muted); font-size: 10px; }
.progress-details dd { margin: 3px 0 0; font-size: 12px; overflow-wrap: anywhere; }
#notice, #warning { color: #e9bd7b; }
#notice:empty, #warning:empty { display: none; }
#message { overflow-wrap: anywhere; color: #c5d0df; }
.progress-reason { color: #ffd09b; }
.progress-reason:empty { display: none; }
.plan-scroll { overflow: auto; max-height: 36vh; }
.work-plan-table { width: 100%; border-collapse: collapse; font-size: 12px; min-width: 610px; }
.work-plan-table th, .work-plan-table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.work-plan-table th { background: #1c2b40; position: sticky; top: 0; }
.work-plan-table td:not(.pending-codes) { white-space: nowrap; }
.pending-codes a { display: inline-block; margin: 0 7px 2px 0; }
.log-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 7px; }
.log-heading label { font-size: 11px; min-height: 36px; display: flex; align-items: center; }
#event-log { max-height: 58vh; overflow: auto; background: #0b121e; color: #c9d8ea; border-radius: 5px; padding: 4px 9px; font-family: Consolas,"Microsoft JhengHei",monospace; overflow-wrap: anywhere; }
#event-log p { margin: 0; padding: 7px 0; border-bottom: 1px solid #263447; font-size: 12px; }
.help-panel h2 { font-size: 13px; margin-top: 8px; }
@media(max-width:600px) {
    .page-shell { width: calc(100% - 12px); }
    h1 { font-size: 19px; }
    .filter-bar { padding: 7px; gap: 6px; }
    .filter-bar select { font-size: 11px; padding: 3px; }
    .source-status { font-size: 10px; }
    .summary-grid, .progress-details { grid-template-columns: repeat(2,minmax(0,1fr)); }
    .metric-card { border-bottom: 1px solid var(--line); }
    .ranking-table th:nth-child(2), .ranking-table td:nth-child(2) { min-width: 170px; }
}
@media(prefers-reduced-motion:reduce) { html { scroll-behavior: auto; } }
.raw-json { white-space: pre-wrap; overflow-wrap: anywhere; background: #0b121e; padding: 12px; font-size: 12px; }
.activity-history p { white-space: pre-wrap; overflow-wrap: anywhere; font: 12px Consolas,"Microsoft JhengHei",monospace; padding: 6px 0; border-bottom: 1px solid #263447; }
.access-panel { max-width: 780px; margin: 12px 0; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.mobile-rankings { display: none; }
@media(max-width:700px) {
    .desktop-rankings { display: none; }
    .mobile-rankings { display: block; min-width: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
    .mobile-rank-head, .mobile-stock > summary { display: grid; grid-template-columns: minmax(0,1.3fr) minmax(0,1.05fr) minmax(0,1.1fr) minmax(0,.8fr); align-items: center; gap: 4px; padding: 8px 7px; }
    .mobile-rank-head { background: #1c2b40; color: var(--muted); font-size: 11px; text-align: right; }
    .mobile-rank-head > :first-child { text-align: left; }
    .mobile-stock { background: var(--surface); border-top: 1px solid #293549; }
    .mobile-stock:nth-child(odd) { background: #121d2c; }
    .mobile-stock > summary { list-style: none; min-height: 76px; line-height: 1.35; font-size: 12px; font-weight: 400; color: var(--ink); margin: 0; }
    .mobile-stock > summary::-webkit-details-marker { display: none; }
    .mobile-stock > summary > span { min-width: 0; }
    .mobile-stock > summary strong { font-size: 13px; font-weight: 650; }
    .mobile-stock > summary small { display: block; font-size: 10px; white-space: nowrap; }
    .mobile-stock-name > span { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 12px; }
    .mobile-stock-name strong { color: var(--blue); }
    .expand-cue { display: inline-block; font-style: normal; font-size: 12px; color: var(--muted); }
    .mobile-stock[open] .expand-cue { transform: rotate(180deg); }
    .mobile-price, .mobile-streak { text-align: right; display: grid; gap: 2px; }
    .mobile-streak > small:last-child { color: var(--muted); }
    .mobile-badges b { display: inline-block; margin: 3px 2px 0 0; padding: 0 3px; border-radius: 3px; background: #263b60; color: #c4d8ff; font-size: 9px; }
    .mobile-energy { text-align: right; padding: 9px 4px; border-radius: 5px; color: #edf4ff; font-size: 13px; font-weight: 700; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
    .mobile-stock-detail { padding: 10px; border-top: 1px solid #344258; background: #101927; }
    .mobile-stock-link { display: block; font-size: 13px; font-weight: 600; overflow-wrap: anywhere; padding: 4px 0 10px; }
    .mobile-stock-detail dl { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 6px; margin: 0; }
    .mobile-stock-detail dl > div { padding: 8px; background: #192536; border-radius: 5px; min-width: 0; }
    .mobile-stock-detail dt { font-size: 10px; color: #c3d0df; }
    .mobile-stock-detail dd { margin: 4px 0 0; font-size: 13px; font-weight: 600; overflow-wrap: anywhere; }
    .mobile-stock-detail p { font-size: 10px; color: var(--muted); line-height: 1.5; margin: 9px 0 0; }
}
.access-add { display: flex; align-items: end; gap: 10px; margin-bottom: 12px; }
.access-add label { flex: 1; display: grid; gap: 7px; min-width: 0; color: var(--muted); }
.access-add input[type=email] { width: 100%; min-width: 0; height: 44px; padding: 10px; font-size: 16px; border: 1px solid #344258; border-radius: 7px; color: var(--ink); background: var(--canvas); }
.access-panel button { min-height: 44px; }
.viewer-list { list-style: none; margin: 12px 0 0; padding: 0; }
.viewer-list li { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.viewer-list li:last-child { border-bottom: 0; }
.viewer-list li > span { flex: 1; min-width: 0; overflow-wrap: anywhere; font-size: 15px; }
.viewer-list form { margin: 0; flex-shrink: 0; }
.viewer-list button { background: #33212c; color: #ffadb2; border-color: #6b3e4b; }
@media(max-width:600px) {
    :root { --report-title-size: 28px; --report-body-size: 16px; --report-header-size: 13px; --report-row-height: 44px; }
    .page-shell { width: calc(100% - 20px); }
    .page-nav { position: static; gap: 6px; }
    .page-nav a { padding: 9px 8px; }
    .page-nav button { min-height: 44px; padding: 8px; }
    .hero { padding-top: 16px; }
    .viewer-filter { padding: 10px; gap: 10px; border-radius: 12px; }
    .viewer-filter select { min-height: 44px; font-size: 16px; }
    .viewer-categories { gap: 4px; }
    .viewer-categories button { font-size: 14px; padding: 6px 2px; }
    .section-heading { flex-wrap: wrap; }
    .report-block .section-heading h2 small { font-size: 11px; line-height: 1.6; }
    .ranking-table { min-width: 1150px; }
    .ranking-table th, .ranking-table td { padding: 6px; }
    .access-panel { padding: 12px; }
    .access-add { flex-direction: column; align-items: stretch; }
    .access-add button { width: 100%; }
}
.filter-bar input { background: #101a29; color: #e4eaf2; border: 1px solid #34445b; border-radius: 4px; padding: 5px; max-width: 150px; }
