/* =============================================================================
   China's Rise in Key Technologies — what only this tool uses
   -----------------------------------------------------------------------------
   On top of tools/tool.css (tokens and the shared components) and the shell
   (projects/_tool_base.html); design direction docs/unga-design.md. Plain CSS,
   linked with {% static_v %}.

   Colour: the accent is China (the Chinese companies, together or one by
   one), nothing else. Every other band is one of two neutrals, alternating
   inside a home so that neighbours part; what a source does not break down
   is the palest. Flat fills, no legend: bands carry their names, the side
   panel and the tooltip carry the numbers.
   ============================================================================= */

/* 1. Data colours ------------------------------------------------------------ */
.ts {
    --cn: var(--accent-fill);
    /* a lighter step of the accent in both themes, so its labels keep the dark on-accent ink */
    --cn-2: color-mix(in srgb, var(--accent-fill) 58%, rgb(var(--pe-on-chrome)));
    --nb-a: color-mix(in srgb, var(--text) 30%, var(--surface));
    --nb-b: color-mix(in srgb, var(--text) 18%, var(--surface));
    --nb-rest: color-mix(in srgb, var(--text) 7%, var(--surface));
}

/* 2. Layout ------------------------------------------------------------------ */
.ts-bar .ts-tabs { flex: none; }
.ts-sources-btn span { display: none; }
@media (min-width: 1280px) { .ts-sources-btn span { display: inline; } }

.ts-overview, .ts-market { display: flex; flex-direction: column; gap: 16px; padding: 24px; }
.ts-overview[hidden], .ts-market[hidden] { display: none; }
.ts-ov-head { flex: none; display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap; }
.ts-ov-head p { margin: 0; }

.ts-cards { flex: 1; min-height: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); grid-auto-rows: minmax(0, 1fr); gap: 16px; }
.ts-card {
    display: grid; grid-template-rows: auto auto auto minmax(0, 1fr) auto auto; gap: 6px; min-height: 0; min-width: 0;
    padding: 14px 16px 12px; text-align: left; font: inherit; color: inherit; cursor: pointer;
    background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
    transition: border-color .15s;
}
.ts-card:hover { border-color: var(--text-3); }
.ts-card-kicker { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.ts-card-rank { font-size: var(--fs-xs); font-weight: 700; color: var(--text-3); font-variant-numeric: tabular-nums; }
.ts-card-kicker .u-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* the market's size in US dollars: a bar to scale with the largest, and the figure */
.ts-card-size { display: flex; align-items: center; gap: 10px; min-width: 0; }
.ts-card-size .t { margin-left: auto; font-size: var(--fs-xs); line-height: 16px; color: var(--text-2); white-space: nowrap; font-variant-numeric: tabular-nums; }
/* one track width on every card, so the bars share one scale */
.ts-card-bar { display: block; flex: 0 0 30%; height: 4px; border-radius: 999px; background: var(--surface-2); }
.ts-card-bar span { display: block; height: 4px; border-radius: 999px; background: var(--nb-a); }
.ts-card-title { font-size: var(--fs-sm); line-height: 18px; font-weight: 700; color: var(--text); }
.ts-card-figs { display: flex; align-items: baseline; gap: 8px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ts-card-figs .from { font-size: var(--fs-md); color: var(--text-3); }
.ts-card-figs .arrow { color: var(--text-3); font-size: var(--fs-sm); }
.ts-card-figs .to { font-size: var(--fs-xl); line-height: 28px; font-weight: 700; color: var(--accent); }
.ts-card-figs .yr { font-size: var(--fs-xs); color: var(--text-3); }
.ts-card-chart { position: relative; min-height: 0; }
.ts-card-chart svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.ts-card-foot { font-size: var(--fs-xs); line-height: 16px; color: var(--text-2); }

.ts-options { flex: none; display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; }
.ts-options .u-seg:empty { display: none; }
.ts-pick { display: inline-flex; align-items: center; gap: 8px; }
.ts-pick .u-select { min-width: 200px; }
.ts-events-toggle { margin-left: auto; }
.ts-main { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) clamp(300px, 25vw, 390px); gap: 16px; }
.ts-chart-panel { min-height: 0; overflow: hidden; }
.ts-chart { position: relative; flex: 1; min-height: 0; outline-offset: -2px; }
.ts-chart svg { display: block; position: absolute; inset: 0; }
.ts-basis { flex: none; margin: 0; padding: 2px 16px 12px; }
.ts-side { padding: 16px; gap: 12px; }

/* 3. Chart marks ------------------------------------------------------------- */
.ts-band { stroke: var(--surface); stroke-width: 1; stroke-linejoin: round; }
.ts-band.cn { fill: var(--cn); }
.ts-band.cn-2 { fill: var(--cn-2); }
.ts-band.nb-a { fill: var(--nb-a); }
.ts-band.nb-b { fill: var(--nb-b); }
.ts-band.nb-rest { fill: var(--nb-rest); }
.ts-band.is-on { stroke: var(--text); stroke-width: 1.5; }
.ts-group-edge { fill: none; stroke: var(--surface); stroke-width: 2.5; pointer-events: none; }
.ts-label { font-family: var(--font); font-size: 11px; fill: var(--text); pointer-events: none; font-variant-numeric: tabular-nums; }
.ts-label.on-cn { fill: var(--on-accent); font-weight: 700; }
.ts-label tspan.v { opacity: .75; }
.ts-measure .ts-label { font-family: var(--pe-font); }
.ts-nodata { font-family: var(--font); font-size: 11px; fill: var(--text-3); }
.ts-nodata-wash { fill: var(--text); opacity: .035; }
.ts-cross { stroke: var(--text); stroke-width: 1; opacity: .55; pointer-events: none; }
.ts-yeardot { fill: var(--text-3); }
.ts-yeardot.is-on { fill: var(--text); }
.ts-event { stroke: var(--text-3); stroke-dasharray: 2 3; opacity: .7; pointer-events: none; }
.ts-event-mark { fill: var(--text-3); cursor: help; }
.ts-event-mark:hover, .ts-event-mark.is-on { fill: var(--text); }
.ts-hit { fill: transparent; cursor: crosshair; }
/* Overview cards: China's share on a fixed 0-100% scale */
.ts-mini-area { fill: var(--cn); opacity: .22; }
.ts-mini-line { fill: none; stroke: var(--cn); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.ts-mini-line.is-gap { stroke-width: 1.5; stroke-dasharray: 2 4; }
.ts-mini-dot { fill: var(--surface); stroke: var(--cn); stroke-width: 1.5; }
.ts-mini-grid { stroke: var(--border); }
.ts-mini-axis { font-family: var(--font); font-size: 11px; fill: var(--text-3); }

/* 4. Side panel -------------------------------------------------------------- */
.ts-side-head .u-2xl { margin-top: 2px; font-variant-numeric: tabular-nums; }
.ts-side-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.ts-side-nav .years { display: inline-flex; gap: 4px; }
.ts-cn-fig { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 2px 12px; align-items: baseline;
             padding: 12px; border-radius: 10px; background: var(--accent-soft); }
.ts-cn-fig .v { font-size: var(--fs-2xl); line-height: 36px; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.ts-cn-fig .k { font-size: var(--fs-sm); font-weight: 700; color: var(--text); }
.ts-cn-fig .m { grid-column: 1 / -1; font-size: var(--fs-xs); line-height: 16px; color: var(--text-2); }
.ts-rank { margin: 0; padding: 0; list-style: none; }
.ts-rank li { display: grid; grid-template-columns: 18px minmax(0, 1fr) 64px 48px; align-items: center; gap: 8px; padding: 5px 0;
              border-top: 1px solid var(--border); font-size: var(--fs-sm); }
.ts-rank li:first-child { border-top: 0; }
.ts-rank .nm { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ts-rank .v { text-align: right; font-variant-numeric: tabular-nums; }
.ts-rank li.is-cn .nm, .ts-rank li.is-cn .v { font-weight: 700; }
.ts-rank li.is-rest { color: var(--text-3); }
.ts-rank li.is-on { background: var(--surface-2); }
.ts-rank .u-bar-fill { background: var(--bar); }
.ts-rank li.is-cn .u-bar-fill { background: var(--cn); }
.ts-rank li.is-rest .u-bar-fill { background: var(--nb-a); }
.ts-flag, .ts-dot { width: 14px; height: 14px; border-radius: 999px; flex: none; }
.ts-dot { display: inline-block; background: var(--nb-a); }
.ts-dot.cn { background: var(--cn); }
.ts-side-src { font-size: var(--fs-xs); line-height: 16px; color: var(--text-3); }
.ts-side-src a { color: var(--text-2); }
.ts-side-note { font-size: var(--fs-xs); line-height: 16px; color: var(--text-3); margin-top: auto; }

/* 5. Drawer ------------------------------------------------------------------ */
.ts-src-markets > .u-label { margin-bottom: 6px; }
.ts-src-list { margin: 8px 0 0; padding-left: 18px; font-size: var(--fs-xs); line-height: 16px; color: var(--text-2); }
.ts-src-list li + li { margin-top: 6px; }
.ts-table summary { cursor: pointer; }
.ts-table__wrap { margin-top: 14px; overflow-x: auto; }
.ts-table table { border-collapse: collapse; font-size: var(--fs-xs); line-height: 16px; font-variant-numeric: tabular-nums; }
.ts-table caption { text-align: left; font-weight: 700; color: var(--text); padding-bottom: 4px; white-space: nowrap; }
.ts-table th, .ts-table td { padding: 2px 6px; border-bottom: 1px solid var(--border); white-space: nowrap; text-align: right; color: var(--text-2); }
.ts-table tbody th { text-align: left; font-weight: 400; color: var(--text); position: sticky; left: 0; background: var(--surface); }
.ts-table tr.is-cn th, .ts-table tr.is-cn td { color: var(--accent); font-weight: 700; }

/* 6. Below 1024 px: the views stack and the page scrolls --------------------- */
@media (max-width: 1023px) {
    .ts-bar .ts-tabs { order: 3; max-width: 100%; overflow-x: auto; scrollbar-width: none; }
    .ts-bar .ts-tabs::-webkit-scrollbar { display: none; }
    .ts .u-view { position: static; }
    .ts .u-stage { min-height: 0; }
    .ts-overview, .ts-market { padding: 16px; }
    .ts-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-auto-rows: 236px; }
    .ts-main { grid-template-columns: minmax(0, 1fr); }
    .ts-chart { height: 440px; flex: none; }
    .ts-events-toggle { margin-left: 0; }
}
@media (max-width: 639px) {
    .ts-cards { grid-template-columns: minmax(0, 1fr); grid-auto-rows: 226px; }
    .ts-pick, .ts-pick .u-select { width: 100%; min-width: 0; }
    .ts-chart { height: 380px; }
    .ts-options .u-seg { max-width: 100%; overflow-x: auto; }
}
@media (min-width: 1024px) and (max-height: 820px) {
    .ts-overview, .ts-market { padding: 16px 24px; gap: 12px; }
    .ts-cards { gap: 12px; }
    .ts-card { padding: 10px 14px 10px; gap: 4px; grid-template-rows: auto auto minmax(0, 1fr) auto auto; }
    .ts-card-title { display: none; }
    .ts-card-figs .to { font-size: var(--fs-lg); line-height: 22px; }
}

/* Drawer: what each market and each count of it measures */
.ts-src-market + .ts-src-market { margin-top: 14px; }
.ts-src-lenses { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 12px; margin: 6px 0 0; }
.ts-src-lenses dt { color: var(--text); font-weight: 700; }
.ts-src-lenses dd { margin: 0; }

/* Companies: one line per company, broken where the source did not size it */
.ts-series .ts-line { fill: none; stroke: color-mix(in srgb, var(--text) 42%, var(--surface)); stroke-width: 1.75; stroke-linejoin: round; stroke-linecap: round; }
.ts-series .ts-pt { fill: var(--surface); stroke: color-mix(in srgb, var(--text) 42%, var(--surface)); stroke-width: 1.5; }
.ts-series.cn .ts-line { stroke: var(--cn); stroke-width: 2.5; }
.ts-series.cn .ts-pt { stroke: var(--cn); }
.ts-series.is-on .ts-line { stroke: var(--text); stroke-width: 3; }
.ts-series.cn.is-on .ts-line { stroke: var(--cn); stroke-width: 4; }
.ts-series.is-on .ts-pt { stroke: var(--text); }
.ts-line-label.cn { font-weight: 700; fill: var(--accent); }
.ts-line-tick { stroke: var(--text-3); stroke-width: 1; }

/* Draft marks: banner, partial years, breaks */
.ts-preview { flex: none; margin: 0; padding: 6px 16px; font-size: 12px; font-weight: 700; color: rgb(var(--pe-ink)); background: rgb(var(--pe-sunken)); border-bottom: 1px solid rgb(var(--pe-line) / .25); }
.ts-partial-wash { fill: var(--text); opacity: .06; pointer-events: none; }
.ts-series .ts-line.ts-break { stroke-dasharray: 5 4; }
.ts-break-mark { stroke: var(--text-3); stroke-width: 1; stroke-dasharray: 2 3; pointer-events: none; }
/* derived values (computed from official figures, not published): solid dots instead of hollow */
.ts-series .ts-pt.ts-derived { fill: color-mix(in srgb, var(--text) 42%, var(--surface)); }
.ts-series.cn .ts-pt.ts-derived { fill: var(--cn); }
.ts-tip-flag { opacity: .75; }

/* Draft: evidence panel and audit page */
.ts-preview a { color: rgb(var(--pe-accent-text)); text-decoration: underline; }
.ts-ev { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border); font-size: 12px; }
.ts-ev-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.ts-ev-block h3 { margin: 12px 0 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); }
.ts-ev dl { margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: 3px 10px; }
.ts-ev dt { color: var(--text-3); }
.ts-ev dd { margin: 0; overflow-wrap: anywhere; }
.ts-ev a, .ts-audit a { color: rgb(var(--pe-accent-text)); text-decoration: underline; }
.ts-ev q { quotes: none; font-style: italic; }
.ts-ev-status { font-weight: 700; padding: 0 6px; border: 1px solid var(--border); border-radius: 3px; }
.ts-ev-status.is-derived { border-color: var(--text-3); }
.ts-ev-status.is-uncertain, .ts-ev-status.is-missing { color: rgb(var(--pe-down)); border-color: rgb(var(--pe-down)); }
.ts-audit-stage { padding: 16px; display: flex; flex-direction: column; gap: 28px; overflow: auto; }
.ts-audit-filters { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; margin: 8px 0 12px; font-size: 12px; }
.ts-audit-filters select { font: inherit; background: var(--surface-2); color: var(--text); border: 1px solid var(--border); padding: 3px 6px; }
.ts-audit-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.ts-audit-table th, .ts-audit-table td { padding: 5px 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.ts-audit-table th[data-sort] { cursor: pointer; }
.ts-audit-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.ts-audit-table .note { max-width: 56ch; color: var(--text-2); }
.ts-audit-table tr.is-out td { opacity: .6; background: var(--surface-2); }
.ts-audit-table tr.is-big td { background: color-mix(in srgb, rgb(var(--pe-accent)) 14%, transparent); font-weight: 700; }
.ts-audit-table tr[hidden] { display: none; }
.ts-preview-link { font-weight: 700; padding: 1px 8px; border: 1px solid currentColor; border-radius: 3px; text-decoration: none !important; }
