/* charts.css -- the interactive layer added by charts.js, plus the static
   pieces viz.py emits that base.css does not cover (axis titles, line legend,
   viz_config tables).  Colours are tokens only, so dark mode and the admin's
   theme editor apply without a rebuild of this file. */

/* ---------------------------------------------------------- static bits --- */
.svg-line .axis-title { fill: var(--ink-muted); font-size: 10.5px; font-family: var(--font-sans); }
.line-legend { list-style: none; margin: .5rem 0 0; padding: 0; display: flex;
               flex-wrap: wrap; gap: .3rem .9rem; font-size: .78rem; color: var(--ink-muted); }
.line-legend li { display: inline-flex; align-items: center; gap: .35rem; min-width: 0; }
.line-legend .key, .cx-key { width: 18px; height: 4px; flex: none; overflow: visible; }
.line-legend .key line, .cx-key line { stroke-width: 2.5; stroke-linecap: round; }
.line-note { margin: .4rem 0 0; }

.table-scroll { overflow-x: auto; max-width: 100%; border: 1px solid var(--border);
                border-radius: var(--radius); }
.table-scroll:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.data-table { width: 100%; border-collapse: collapse; font-size: .82rem; }
.data-table th { text-align: left; font-weight: 600; font-size: .72rem; color: var(--ink-muted);
                 text-transform: uppercase; letter-spacing: .04em; padding: .45rem .7rem;
                 border-bottom: 1px solid var(--border-strong); background: var(--bg-subtle);
                 white-space: nowrap; }
.data-table td { padding: .4rem .7rem; border-bottom: 1px solid var(--border); color: var(--ink); }
.data-table tr:last-child td { border-bottom: 0; }
.data-table td.num { font-family: var(--font-mono); font-size: .78rem; text-align: right;
                     white-space: nowrap; }

/* -------------------------------------------------------------- controls --- */
.cx-bar { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem .6rem;
          margin: 0 0 .7rem; font-size: .78rem; }
.cx-meta { color: var(--ink-subtle); font-family: var(--font-mono); font-size: .72rem; }
.cx-cloud .cx-meta { margin-left: auto; }
.cx-lbl { color: var(--ink-subtle); font-size: .74rem; }
.cx-seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius);
          overflow: hidden; }
.cx-seg .cx-btn { border: 0; border-radius: 0; }
.cx-seg .cx-btn + .cx-btn { border-left: 1px solid var(--border-strong); }
.cx-btn { font: inherit; font-size: .76rem; line-height: 1.2; padding: .32rem .7rem; min-height: 30px;
          color: var(--ink-muted); background: var(--bg); border: 1px solid var(--border-strong);
          border-radius: var(--radius); cursor: pointer; }
.cx-btn:hover:not(:disabled) { color: var(--ink); background: var(--bg-subtle); }
.cx-btn[aria-pressed="true"] { color: var(--bg); background: var(--ink); }
.cx-btn:disabled { opacity: .4; cursor: not-allowed; }
.cx-btn:focus-visible, .cx-chip:focus-visible, .cx-opt:focus-visible, .cx-link:focus-visible,
.topic-toggle:focus-visible, .cx-search:focus-visible, .cx-range:focus-visible,
.cx-plot:focus-visible, .cx-cloud .cw:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px; }
.cx-topics .cx-seg { margin-left: auto; }
.cx-back { margin-left: auto; }
.cx-back + .cx-seg { margin-left: 0; }

/* Shared floating readout (hover and keyboard focus). */
.cx-host { position: relative; }
.cx-tip { position: absolute; z-index: 5; pointer-events: none; max-width: min(280px, 90%);
          background: var(--bg); color: var(--ink); border: 1px solid var(--border-strong);
          border-radius: var(--radius); padding: .35rem .55rem; font-size: .76rem; line-height: 1.35;
          box-shadow: 0 4px 14px rgb(0 0 0 / .14); white-space: nowrap; }
.cx-tip strong { font-family: var(--font-mono); font-weight: 700; }
.cx-tip-l { color: var(--ink-muted); overflow: hidden; text-overflow: ellipsis; }
.cx-tip-s { color: var(--ink-subtle); }
.cx-tip-h { font-weight: 600; color: var(--ink-muted); margin-bottom: .15rem; font-family: var(--font-mono);
            font-size: .72rem; }
.cx-tip-row { display: grid; grid-template-columns: 18px auto minmax(0, 1fr); align-items: center;
              gap: .4rem; }

/* ------------------------------------------------------------ word cloud --- */
.cx-cloud .cw { border-radius: 3px; padding: 0 .1rem; outline-offset: 1px; }
.cx-cloud .cw:hover, .cx-cloud .cw:focus { background: var(--bg-muted); }

/* -------------------------------------------------------- topic clusters --- */
.cx-topics .topic-card h4 { margin-bottom: .45rem; text-transform: none; letter-spacing: 0; }
.topic-toggle { all: unset; box-sizing: border-box; width: 100%; display: flex; align-items: center;
                gap: .5rem; cursor: pointer; font-size: .76rem; font-weight: 600;
                text-transform: uppercase; letter-spacing: .05em; color: var(--ink-muted);
                border-radius: 3px; min-height: 24px; }
.topic-toggle:hover { color: var(--ink); }
.topic-n { margin-left: auto; font-weight: 400; text-transform: none; letter-spacing: 0;
           font-family: var(--font-mono); font-size: .68rem; color: var(--ink-subtle); }
.topic-chev { font-size: .6rem; color: var(--ink-subtle); }
.cx-topics .topic-card { cursor: default; transition: border-color .15s; }
.cx-topics .topic-card:hover { border-color: var(--border-strong); }
.cx-topics .topic-card.is-open { border-color: var(--border-strong); background: var(--bg); }
.topic-grid.is-drill { grid-template-columns: 1fr; }
.topic-card.is-open .bar-row.mini.with-v { grid-template-columns: minmax(80px, 160px) 1fr 3.6em;
                                           font-size: .8rem; }
.topic-card.is-open .bar-track { height: 10px; }
.topic-chips { display: flex; flex-wrap: wrap; gap: .3rem; }
.topic-chip { font-family: var(--font-mono); color: var(--ink); background: var(--bg);
              border: 1px solid; border-left-width: 3px; border-radius: 3px; padding: .05rem .4rem;
              line-height: 1.6; }
.topic-more { margin: .45rem 0 0; font-size: .7rem; color: var(--ink-subtle); font-family: var(--font-mono); }
.topic-shared { margin-top: .8rem; font-size: .8rem; color: var(--ink-muted); }
.topic-shared h5 { font-size: .74rem; margin: 0 0 .3rem; color: var(--ink-muted); font-weight: 600; }
.topic-shared ul { margin: 0; padding-left: 1.1rem; display: grid; gap: .15rem; }
.topic-shared strong { color: var(--ink); font-weight: 600; }
.cx-link { all: unset; cursor: pointer; color: var(--accent); text-decoration: underline;
           text-underline-offset: 2px; border-radius: 2px; }
.cx-link:hover { color: var(--accent-hover); }

/* ------------------------------------------------------------ line chart --- */
.cx-chips { display: flex; flex-wrap: wrap; gap: .3rem; }
.cx-chip { font: inherit; font-size: .76rem; display: inline-flex; align-items: center; gap: .4rem;
           padding: .25rem .55rem; min-height: 28px; border-radius: 999px; cursor: pointer;
           color: var(--ink-subtle); background: transparent; border: 1px dashed var(--border-strong);
           max-width: 100%; }
.cx-chip > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cx-chip[aria-pressed="false"] .cx-key { opacity: .35; }
.cx-chip[aria-pressed="true"] { color: var(--ink); background: var(--bg-subtle);
                                border: 1px solid var(--border-strong); }
.cx-chip:hover { border-color: var(--ink-subtle); }
.cx-bulk { display: inline-flex; gap: .3rem; }
.cx-x { color: var(--ink-subtle); margin-left: .1rem; }
ul.line-legend li .cx-chip { font-size: .74rem; }

.cx-picker { position: relative; }
.cx-picker-btn { min-width: 11rem; text-align: left; }
.cx-panel { position: absolute; z-index: 20; top: calc(100% + 4px); left: 0;
            width: min(320px, calc(100vw - 32px)); background: var(--bg);
            border: 1px solid var(--border-strong); border-radius: var(--radius);
            box-shadow: 0 8px 24px rgb(0 0 0 / .16); padding: .5rem; display: grid; gap: .45rem; }
.cx-panel[hidden] { display: none; }
.cx-search { font: inherit; font-size: .8rem; width: 100%; box-sizing: border-box; padding: .4rem .55rem;
             color: var(--ink); background: var(--bg-subtle); border: 1px solid var(--border-strong);
             border-radius: var(--radius); }
.cx-list { max-height: 260px; overflow-y: auto; display: grid; gap: 1px; overscroll-behavior: contain; }
.cx-opt { font: inherit; font-size: .8rem; text-align: left; display: flex; align-items: center; gap: .5rem;
          padding: .3rem .4rem; min-height: 28px; border: 0; border-radius: 4px; background: transparent;
          color: var(--ink-muted); cursor: pointer; }
.cx-opt[hidden] { display: none; }
.cx-opt:hover { background: var(--bg-subtle); color: var(--ink); }
.cx-opt[aria-pressed="true"] { color: var(--ink); font-weight: 600; }
.cx-check { width: 22px; height: 14px; flex: none; display: inline-flex; align-items: center;
            justify-content: center; border: 1px solid var(--border-strong); border-radius: 3px; }
.cx-opt[aria-pressed="true"] .cx-check { border-color: transparent; }
.cx-check .cx-key { width: 18px; }
.cx-empty { margin: 0; }

.cx-plot { width: 100%; touch-action: pan-y; border-radius: 4px; }
.cx-plot .cx-svg { display: block; width: 100%; height: auto; }
.cx-plot .cx-cross { stroke: var(--ink-subtle); stroke-width: 1; stroke-dasharray: 3 3; }
.cx-plot .cx-hdot { stroke: var(--bg); stroke-width: 2; }
.cx-line .cx-tip { white-space: normal; min-width: 9rem; }
.cx-line .cx-tip-l { white-space: nowrap; }
.cx-empty-plot { padding: 2rem 0; text-align: center; border: 1px dashed var(--border);
                 border-radius: var(--radius); }

/* ---------------------------------------------------- per-year bar/donut --- */
.cx-yearbar { gap: .5rem .8rem; }
.cx-range-wrap { display: inline-flex; align-items: center; gap: .4rem; flex: 1 1 240px; min-width: 0; }
.cx-range-wrap .cx-btn { padding: .2rem .55rem; font-size: .9rem; }
.cx-range { flex: 1; min-width: 80px; accent-color: var(--accent); cursor: pointer; }
.cx-range.is-idle { opacity: .5; }
.cx-range-end { font-family: var(--font-mono); font-size: .7rem; color: var(--ink-subtle); }
.cx-year { font-family: var(--font-mono); font-weight: 700; font-size: .85rem; color: var(--ink);
           min-width: 4.5em; }

@media (max-width: 620px) {
  .cx-cloud .cx-meta { margin-left: 0; flex-basis: 100%; }
  .cx-range-end { display: none; }
  .cx-picker-btn { min-width: 0; }
}
@media print {
  .cx-bar, .cx-tip, .cx-panel { display: none !important; }
}

/* ------------------------------------- content metrics (viz.field_stats) --- */
.chart-fields figcaption { font-size: .95rem; color: var(--ink); }
.fm-meta { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem .6rem; margin: 0 0 .9rem; }
.fm-legend { display: inline-flex; flex-wrap: wrap; align-items: center; gap: .3rem .45rem; }
.fm-lg-w, .fm-lg-b, .fm-lg-m { display: inline-block; flex: none; }
.fm-lg-w { width: 22px; height: 10px; border-left: 2px solid var(--ink-subtle); border-right: 2px solid var(--ink-subtle);
           background: linear-gradient(var(--ink-subtle), var(--ink-subtle)) center / 100% 2px no-repeat; }
.fm-lg-b { width: 18px; height: 12px; margin-left: .5rem; border: 2px solid var(--viz-seq-6);
           background: color-mix(in srgb, var(--viz-seq-4) 30%, transparent); border-radius: 3px; }
.fm-lg-m { width: 4px; height: 14px; margin-left: .5rem; background: var(--accent); border-radius: 2px; }
.fm-grid { display: grid; gap: .9rem; grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr)); }
.fm-card { border: 1px solid var(--border); border-radius: calc(var(--radius) + 2px); background: var(--bg);
           padding: .85rem 1rem .8rem; box-shadow: var(--shadow-sm, none); min-width: 0; }
.fm-head { display: flex; justify-content: space-between; align-items: baseline; gap: .6rem; margin-bottom: .7rem; }
.fm-name { font-size: .76rem; font-weight: 650; text-transform: uppercase; letter-spacing: .07em;
           color: var(--ink-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.fm-val { font-family: var(--font-mono); font-size: .9rem; font-weight: 700; color: var(--accent); white-space: nowrap; }
.fm-sd { font-weight: 450; font-size: .76rem; color: var(--ink-subtle); }
/* The box plot: whisker line with end caps, box, mean bar. */
.fm-plot { position: relative; height: 30px; margin: 0 4px .35rem; }
.fm-whisker { position: absolute; left: 0; right: 0; top: 50%; height: 2px; margin-top: -1px; background: var(--border-strong); }
.fm-cap { position: absolute; top: 6px; bottom: 6px; width: 2px; margin-left: -1px; background: var(--ink-subtle); border-radius: 1px; }
.fm-box { position: absolute; top: 3px; bottom: 3px; border: 2px solid var(--viz-seq-6); border-radius: 4px;
          background: color-mix(in srgb, var(--viz-seq-4) 28%, var(--bg)); }
.fm-mean { position: absolute; top: -1px; bottom: -1px; width: 4px; margin-left: -2px; border-radius: 2px;
           background: var(--accent); box-shadow: 0 0 0 2px var(--bg), 0 0 8px color-mix(in srgb, var(--accent) 55%, transparent); }
.fm-ends { display: flex; justify-content: space-between; gap: .5rem; font-family: var(--font-mono);
           font-size: .74rem; color: var(--ink-subtle); }
.fm-split { display: flex; height: 14px; border-radius: 7px; overflow: hidden; gap: 2px; margin-bottom: .4rem;
            background: var(--bg-muted); }
.fm-split span { display: block; height: 100%; }
.fm-dist { height: 9px; margin-top: .75rem; }
.fm-keys { display: flex; flex-wrap: wrap; gap: .2rem .8rem; font-family: var(--font-mono); font-size: .72rem; color: var(--ink-muted); }
.fm-keys i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: .3rem; vertical-align: -1px; }
.fm-rating { position: relative; height: 16px; border-radius: 8px; background: var(--bg-muted); overflow: hidden; margin-bottom: .4rem; }
.fm-rating span { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 8px;
                  background: linear-gradient(90deg, var(--viz-seq-3), var(--viz-seq-6)); }
