/* Sessions: the list, the report and its charts, on top of ui.css. */

/* The categorical order and steps are the validated ramps, checked against each brand's own surfaces.
   IDAN Motor leads with its accent, so slot 7 is blue rather than a second violet. */
:root {
  --grid: var(--track);
  --axis: var(--line-2);
  --series-1: #743dbc;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #2a78d6;
  --series-8: #e34948;
  --seq-1: #86b6ef;
  --seq-2: #5598e7;
  --seq-3: #3987e5;
  --seq-4: #2a78d6;
  --seq-5: #256abf;
  --seq-6: #184f95;
  --seq-7: #0d366b;
  --div-1: #96261f;
  --div-2: #c8382f;
  --div-3: #e08a80;
  --div-4: #a8a7a1;
  --div-5: #86b6ef;
  --div-6: #3987e5;
  --div-7: #1c5cab;
}
:root[data-brand="energy"] {
  --series-1: #2a78d6;
  --series-7: #4a3aa7;
}
@media (prefers-color-scheme: dark) {
  :root {
    --series-1: #8f5bd6;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #3987e5;
    --series-8: #e66767;
    --seq-1: #184f95;
    --seq-2: #1c5cab;
    --seq-3: #256abf;
    --seq-4: #3987e5;
    --seq-5: #6da7ec;
    --seq-6: #9ec5f4;
    --seq-7: #cde2fb;
    --div-1: #f08a7e;
    --div-2: #e05a4a;
    --div-3: #a04a40;
    --div-4: #6b6b66;
    --div-5: #3d6fa8;
    --div-6: #4a92e8;
    --div-7: #8fc0f5;
  }
  :root[data-brand="energy"] {
    --series-1: #3987e5;
    --series-7: #9085e9;
  }
}

.view { display: flex; flex-direction: column; gap: 24px; min-width: 0; }
.grow { flex: 1; }
.badges { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.count-note { font: 400 13px/18px var(--f-body); color: var(--ink-2); white-space: nowrap; }
.status { font: 400 13px/18px var(--f-body); color: var(--ink-2); }
.status.bad { color: var(--bad-fg); }
.status.ok { color: var(--ok-fg); }
.gate .hint:empty { display: none; }
.actions .info, .tlabel .info, h2 .info, h3 .info { margin-left: 0; }
.actions > .info { margin-left: -4px; }
#btnSave.hide + .info, #btnStop.hide + .info { display: none; }

/* -- the list -- */

.livenow { align-items: center; }
.livenow > div { font: 400 14px/20px var(--f-body); }
.livenow > span > .ic { color: var(--link); display: block; }

.drop { cursor: pointer; }
.drop > span > .ic { width: 24px; height: 24px; color: var(--link); display: block; }
.drop b { display: flex; align-items: center; gap: 6px; }
.drop .hint { display: block; }
.drop.over { border-style: solid; }

.search > span > .ic { position: absolute; left: 12px; top: 10px; color: var(--muted); pointer-events: none; }
#sessionFilters .search { flex-basis: 280px; max-width: 300px; }
.dates {
  display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 4px 0 12px;
  border: 1px solid var(--field); border-radius: 4px; background: var(--bg);
  font: 500 14px/20px var(--f-body); color: var(--ink-2); white-space: nowrap;
}
.dates > span > .ic { display: block; }
.dates:focus-within { border-color: var(--accent); outline: 1px solid var(--accent); }
#sessionFilters .dates input[type="date"] {
  width: 132px; min-height: 36px; padding: 0 4px; border: 0; background: transparent; outline: 0;
}
#sourceFilter { flex-shrink: 0; }

.filterchips { display: flex; gap: 8px; flex-wrap: wrap; }
.filterchips:empty { display: none; }
.filterchips .badge { padding-right: 2px; text-transform: none; letter-spacing: 0; }
.filterchips .badge button {
  min-height: 0; height: 18px; width: 18px; padding: 0; border: 0; border-radius: 2px;
  background: transparent; color: inherit; font: inherit;
}
.filterchips .badge button:hover { background: var(--hover); }

.sessions th { vertical-align: middle; }
.sessions th, .sessions td { padding-left: 12px; padding-right: 12px; }
.sessions th:first-child, .sessions td:first-child { padding-left: 16px; }
.sessions td { vertical-align: middle; }
.sessions td.state { min-width: 204px; }
.sessions .vehicle .sub { font-family: var(--f-body); }
.sessions .when { white-space: nowrap; }
.sessions .when button.link { color: var(--ink); font: 600 14px/20px var(--f-body); text-align: left; }
.sessions .when button.link:hover { color: var(--link); }
.sessions .vehicle { font-family: var(--f-mono); font-size: 13px; }
.sessions th.acts, .sessions td.acts { width: 1%; text-align: right; }
#sessionRows .sessionname {
  width: 100%; min-width: 160px; min-height: 36px; padding: 0 8px;
  border-color: transparent; background: transparent; color: var(--ink);
}
#sessionRows .sessionname:hover { border-color: var(--line); }
#sessionRows .sessionname:focus { border-color: var(--accent); background: var(--bg); }
#sessionRows .sessionname::placeholder { color: var(--muted); font-style: italic; }
button.badge.sourcebtn {
  min-height: 22px; height: 22px; padding: 0 8px; cursor: pointer;
  font: var(--badge); letter-spacing: .06em;
}
button.badge.sourcebtn:hover { border-color: var(--field); background: var(--idle-bg); color: var(--idle-fg); }
button.badge.sourcebtn[aria-pressed="true"] { background: var(--tint); border-color: var(--accent); color: var(--link); }
.rowacts { display: flex; gap: 4px; justify-content: flex-end; align-items: center; }
.rowacts .iconbtn { width: 36px; height: 36px; min-height: 36px; }
.rowacts .iconbtn.danger { color: var(--bad-fg); border: 0; }
.rowacts .iconbtn.danger:hover { background: var(--bad-bg); }
.tfoot .pagesize { display: inline-flex; align-items: center; gap: 8px; }
.tfoot select.filter { min-height: 32px; padding: 0 8px; }

/* -- the report head and the live strip -- */

.menu > summary { list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu > summary .ic { margin-right: -2px; }
.menu .menupop { width: min(360px, calc(100vw - 32px)); }
.menu .menupop small { display: block; margin-top: 2px; font: 400 12px/16px var(--f-body); }
.menunote { padding: 8px 12px 6px; font: 400 12px/16px var(--f-body); color: var(--muted); border-top: 1px solid var(--line); margin-top: 4px; }

.linkbar {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--tile); color: var(--ink-2);
  font: 600 14px/20px var(--f-body);
}
.linkbar .dot { width: 10px; height: 10px; background: var(--muted); }
.linkbar[data-state="live"] { background: var(--tint); border-color: color-mix(in srgb, var(--accent) 35%, transparent); color: var(--link); }
.linkbar[data-state="live"] .dot { background: var(--accent); animation: pulse 1.6s ease-in-out infinite; }
.linkbar[data-state="connecting"] { background: var(--warn-bg); border-color: color-mix(in srgb, var(--warn) 45%, transparent); color: var(--warn-fg); }
.linkbar[data-state="connecting"] .dot { background: var(--warn); }
.linkbar[data-state="stalled"], .linkbar[data-state="failed"] { background: var(--bad-bg); border-color: var(--bad); color: var(--bad-fg); }
.linkbar[data-state="stalled"] .dot, .linkbar[data-state="failed"] .dot { background: var(--bad); }
@keyframes pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .linkbar .dot { animation: none; } }

.rangebar {
  position: sticky; top: 56px; z-index: 6; margin: -8px 0; padding: 8px 0;
  background: var(--bg); border-bottom: 1px solid transparent;
}
.rangebar .seg > button { min-height: 32px; padding: 0 12px; font-weight: 600; }

.kpis { grid-template-columns: repeat(5, minmax(0, 1fr)); align-items: stretch; }
.tile.warn { border-color: var(--warn); }
.tile.bad { border-color: var(--bad); }
.tile > .tvalue { overflow-wrap: anywhere; }

/* -- charts -- */

.chartgrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.chartgrid:empty, #leadChart:empty { display: none; }
.chartcard .cardhead { align-items: flex-start; flex-wrap: nowrap; }
.chartcard .cardhead > div:first-child { flex: 1; }
.chartcard h2 { display: flex; align-items: center; gap: 6px; }
.charttools { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; justify-content: flex-end; }
.tabletoggle[aria-pressed="true"] { background: var(--tint); border-color: var(--accent); color: var(--link); }
.plot { position: relative; }
.plot svg, .maparea svg { display: block; }
/* Charts let a direct label sit past the plot; the map must not let its edge tiles past the frame. */
.plot svg { overflow: visible; }
.plot .grid { stroke: var(--grid); stroke-width: 1; }
.plot .axis, .plot .zero { stroke: var(--axis); stroke-width: 1; }
.plot .marker { stroke-width: 1; opacity: .5; }
.plot .tick, .plot .axislabel { fill: var(--muted); font: 500 11px var(--f-data); font-feature-settings: 'tnum'; }
.plot .endlabel { fill: var(--ink); font: 600 11.5px var(--f-body); }
.plot .barvalue { fill: var(--ink); font: 500 11px var(--f-data); font-feature-settings: 'tnum'; }
.xlabel { margin-top: -4px; text-align: center; font: 400 12px/16px var(--f-body); color: var(--muted); }
.legend { display: flex; gap: 6px 16px; flex-wrap: wrap; margin-bottom: 8px; }
.legenditem { display: inline-flex; align-items: center; gap: 6px; font: 400 13px/18px var(--f-body); color: var(--ink-2); }
.legenditem svg { display: block; }

/* The crosshair finds the x; readers aim at a time, never at a 2px line. */
.crosshair { position: absolute; top: 0; width: 1px; background: var(--axis); pointer-events: none; display: none; }
.tooltip {
  position: absolute; z-index: 40; pointer-events: none; display: none; min-width: 140px;
  padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); box-shadow: var(--shadow); font: 400 12px/18px var(--f-body);
}
.tooltip .tt-x { color: var(--muted); margin-bottom: 4px; font-family: var(--f-data); }
.tooltip .tt-row { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.tooltip .tt-name { color: var(--ink-2); display: inline-flex; align-items: center; gap: 6px; }
.tooltip .tt-value { font: 600 12px/18px var(--f-data); font-feature-settings: 'tnum'; }

.datatable { max-height: 320px; overflow: auto; margin-top: 12px; }
.datatable .table th { position: sticky; top: 0; background: var(--bg); padding: 8px 12px; }
.datatable .table td { padding: 6px 12px; font: 500 13px/18px var(--f-data); font-feature-settings: 'tnum'; white-space: nowrap; }
.tablenote { margin-top: 6px; font: 400 12px/16px var(--f-body); color: var(--muted); }

/* -- packs and the arrangement -- */

.legendline { display: flex; gap: 16px; flex-wrap: wrap; font: 400 13px/18px var(--f-body); color: var(--ink-2); }
.packs { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); }
.pack {
  display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; padding: 16px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg); min-width: 0;
}
.pack .sum { flex: 0 0 168px; min-width: 168px; display: flex; flex-direction: column; gap: 6px; }
.pack .pkhead { flex: 1 1 100%; }
.pack .cellwrap { flex: 1 1 180px; min-width: 0; }
.pack .pkhead { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.pack .pkhead b { display: block; font: 600 15px/20px var(--f-head); overflow-wrap: anywhere; }
.pack .pkhead span { font: 400 12px/16px var(--f-body); color: var(--ink-2); }
.pack .soc { font: 700 28px/34px var(--f-data); font-feature-settings: var(--data-features); }
.pack .soc small { font: 400 13px/18px var(--f-body); color: var(--muted); margin-left: 2px; }
.pack .bar.wide { margin: 2px 0 4px; }
.pack .pkrow { display: flex; justify-content: space-between; gap: 6px; font: 500 13px/18px var(--f-data); font-feature-settings: 'tnum'; }
.pack .pkrow.big { font-weight: 600; font-size: 14px; }
.pack .pkrow.quiet { color: var(--ink-2); font-weight: 400; }
.pack .amps.neg { color: var(--bad-fg); }
.pack .badges { margin-top: 6px; }
.pack .badges .badge { height: 20px; padding: 0 6px; font-size: 11px; }

/* A chip per cell, carrying its own reading, as the bench console draws them. */
.cellhead { display: flex; justify-content: space-between; margin-bottom: 6px; font: 400 12px/16px var(--f-body); color: var(--ink-2); }
.cellgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(58px, 1fr)); gap: 4px; }
.cellchip {
  border: 1px solid transparent; border-radius: 4px; padding: 3px 5px 4px;
  background: var(--tile); line-height: 1.2;
}
.cellchip .cline { display: flex; justify-content: space-between; align-items: baseline; gap: 3px; }
.cellchip .ci { font: 500 9px/12px var(--f-body); color: var(--muted); }
.cellchip .cv { font: 600 11.5px/14px var(--f-data); font-feature-settings: 'tnum'; }
.cellchip.balancing { border-color: var(--warn); background: var(--warn-bg); }
.lvl { height: 3px; margin-top: 3px; background: var(--track); border-radius: 2px; overflow: hidden; }
.lvl > i { display: block; height: 100%; width: 0; background: var(--accent); }
.low .lvl > i { background: var(--bad); }
.high .lvl > i { background: var(--warn); }

.section { border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 12px; }
.sectionhead { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sectionhead h3 { display: flex; align-items: center; gap: 6px; }
.numfield, .inline { display: inline-flex; align-items: center; gap: 8px; font: 500 14px/20px var(--f-body); color: var(--ink-2); white-space: nowrap; }
#seriesCount, #parallelCount { width: 72px; }
#shockThreshold { width: 76px; min-height: 36px; }
.seriesjoin { color: var(--muted); font-size: 16px; }
.strings { display: flex; flex-direction: column; gap: 8px; }
.stringrow {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--tile);
}
.stringrow > .tag { min-width: 72px; font: var(--label); letter-spacing: var(--label-track); text-transform: uppercase; color: var(--ink-2); }
.stringrow select.posselect { width: auto; min-width: 150px; min-height: 36px; }
.stringsum { margin-left: auto; font: 500 13px/18px var(--f-data); font-feature-settings: 'tnum'; color: var(--ink-2); }
.parallelnote { padding-left: 4px; font: 400 13px/18px var(--f-body); color: var(--ink-2); }
.messages { display: flex; flex-direction: column; gap: 8px; }
.messages:empty { display: none; }
.messages .notice { padding: 10px 14px; font-size: 13px; line-height: 18px; }

/* -- the route and the events -- */

.mapctl { row-gap: 10px; }
.mapctl .check { color: var(--ink-2); font-weight: 500; }
.mapctl select.filter { min-height: 36px; }
.muted-off { opacity: .45; }
.maparea {
  position: relative; border: 1px solid var(--line); border-radius: 8px;
  overflow: hidden; line-height: 0; text-align: center; background: var(--tile);
}
/* Never wider than it was projected, so a tall route cannot outgrow the screen. */
.maparea > svg { display: inline-block; width: 100%; max-width: 900px; height: auto; }
.mapover {
  position: absolute; top: 8px; right: 8px; z-index: 2; max-width: min(20rem, 60%);
  padding: 6px 9px; border-radius: 6px; border: 1px solid var(--line); text-align: left;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  font: 400 12px/17px var(--f-body); color: var(--ink-2); pointer-events: none;
}
.mapover b { color: var(--ink); font-weight: 600; }
.maptip {
  position: absolute; z-index: 3; padding: 5px 8px; border-radius: 4px; pointer-events: none;
  background: var(--ink); color: var(--bg); font: 400 11px/15px var(--f-body);
  white-space: nowrap; transform: translate(-50%, -140%);
}
.mapover.hide, .maptip.hide { display: none; }
.ramp { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font: 400 13px/18px var(--f-body); color: var(--ink-2); }
.rampbar { display: block; border-radius: 3px; }
.maparea .maplabel { fill: var(--ink-2); font: 500 11px var(--f-body); }
/* The backdrop is context, not the subject: it sits back so the route reads. */
.maparea .maptile { opacity: .82; }
.maparea .tilewash { fill: var(--panel); opacity: .30; }
.maparea .attribution { fill: var(--muted); font: 400 10px var(--f-body); paint-order: stroke; stroke: var(--panel); stroke-width: 3px; stroke-linejoin: round; }
.maparea .tick { fill: var(--muted); font: 500 12px var(--f-body); }
@media (prefers-color-scheme: dark) {
  /* Raster tiles are drawn for a light page; this keeps them from glaring. */
  .maparea .maptile { filter: invert(1) hue-rotate(180deg) brightness(.86) contrast(.92); opacity: .72; }
}
.maparea .scalebar { stroke: var(--ink-2); stroke-width: 1.5; }
/* A 2px surface ring keeps a marker legible where the route crosses itself. */
.maparea .routeend { stroke: var(--panel); stroke-width: 2; }
.maparea .shockmark { stroke: var(--panel); stroke-width: 2; fill: var(--warn); }
.maparea .shockmark.shock-severe { fill: var(--bad); }
.maparea .shockmark.shock-heavy { fill: var(--warn); }
.maparea .shockmark.shock-moderate { fill: var(--muted); }

.eventscroll { max-height: 520px; overflow: auto; }
.eventscroll .table th { position: sticky; top: 0; background: var(--bg); }
.eventscroll .table th, .eventscroll .table td { padding: 8px 10px; }
.eventscroll .table th:first-child, .eventscroll .table td:first-child { padding-left: 20px; }
.eventscroll .table td { font-size: 13px; line-height: 18px; white-space: nowrap; }
.eventscroll .table td.at { font: 500 13px/18px var(--f-data); font-feature-settings: 'tnum'; color: var(--ink-2); }
#events .tablewrap { border: 0; border-radius: 0; margin: -16px -20px; }

@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .chartgrid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 900px) {
  .view { gap: 16px; }
  .rangebar { flex-wrap: nowrap; }
  .rangebar .eyebrow, .rangebar .grow, .rangebar #rangeLabel { display: none; }
  .rangebar .seg > button { padding: 0 10px; }
  .packs { grid-template-columns: minmax(0, 1fr); }
  .pack .sum { flex-basis: 100%; }
  .drop { flex-wrap: wrap; align-items: flex-start; }
  .drop > div { flex-basis: calc(100% - 40px); }
  .drop > button { margin-left: 40px; }
  #sessionFilters .search { max-width: none; }
  .dates { flex: 1 1 100%; }
  #sessionFilters .dates input[type="date"] { flex: 1; width: auto; min-width: 0; }
  #sourceFilter { flex: 1; }

  .sessions.cards tr { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; }
  .sessions.cards td, .sessions.cards td:first-child { width: auto; padding: 2px 0; }
  .sessions.cards td.when { flex: 1 1 auto; order: 0; }
  .sessions.cards td.acts { flex: none; order: 1; }
  .sessions.cards td.name { flex: 1 1 100%; order: 2; margin-left: -8px; }
  .sessions.cards td.tags { flex: none; order: 3; min-width: 0; }
  .sessions.cards td.tags::before { display: none; }
  .sessions.cards td.vehicle, .sessions.cards td.num { flex: none; order: 4; font-size: 13px; }
  .sessions.cards td[data-label]::before { min-width: 0; margin-right: 6px; font-size: 11px; color: var(--muted); }
  .sessions.cards .vehicle .main, .sessions.cards .vehicle .sub { display: inline; }
  .sessions.cards .vehicle .sub { margin-left: 4px; }
  #sessionRows .sessionname { min-width: 0; }
}
