/* Dark, projection-friendly dashboard. Colours have fixed roles; shapes/labels back them up. */
:root {
  --bg: #0d1218; --panel: #151c24; --panel2: #1d2630; --line: #2c3742; --fg: #eef2f5; --muted: #9aa8b4;
  --canvas: #0a0f14;
  --gps: #4dd0e1; --rsrp: #5fd38d; --rsrq: #c39bff; --snr: #f2c94c; --http: #4fb3ff;
  --change: #ffb347; --serving: #5fd38d; --bad: #ff6b6b; --warn: #f2c94c; --plan: #b0bec5; --memo: #ff8ad8;
  --shade: rgba(13, 18, 24, .5); --overlay: rgba(13, 18, 24, .85); --overlay-soft: rgba(21, 28, 36, .55); --near: #b39ddb;
  color-scheme: dark;
}
/* Light theme (header switch): same roles, darker strokes so lines stay readable on white. Map tiles are not recoloured. */
:root[data-theme="light"] {
  --bg: #f3f6f9; --panel: #ffffff; --panel2: #eaf0f5; --line: #c9d3dc; --fg: #14202b; --muted: #53616d;
  --canvas: #f8fafc;
  --gps: #00838f; --rsrp: #2e7d32; --rsrq: #6a3fbf; --snr: #9a6b00; --http: #1565c0;
  --change: #c75f00; --serving: #2e7d32; --bad: #c62828; --warn: #9a6b00; --plan: #546e7a; --memo: #ad1457;
  --shade: rgba(243, 246, 249, .65); --overlay: rgba(255, 255, 255, .92); --overlay-soft: rgba(255, 255, 255, .7); --near: #5e35b1;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); }
body { font: 15px/1.5 system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif; }
a { color: var(--http); }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 8px; }
h3 { font-size: 13px; margin: 10px 0 4px; color: var(--muted); font-weight: 600; }
.sub { color: var(--muted); font-size: 13px; margin: 2px 0 0; }
.small { font-size: 12px; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
header.top { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 16px; align-items: center;
  padding: 12px 16px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--bg); z-index: 5; }
.status { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.dashboard-switch { display: inline-flex; gap: 2px; padding: 2px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel); }
.dashboard-switch button { padding: 2px 9px; border-color: transparent; font-size: 12px; }
.dashboard-switch button.active { background: var(--panel2); border-color: var(--serving); color: var(--serving); }
.badge { border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; font-size: 13px; background: var(--panel2); }
.badge.csv { border-color: var(--http); }
.badge.ble, .badge.ok { border-color: var(--serving); color: var(--serving); }
.badge.warn { border-color: var(--warn); color: var(--warn); }
.badge.demo-badge { border-color: var(--change); color: var(--change); }
.clock { font-variant-numeric: tabular-nums; font-size: 18px; font-weight: 700; }
.pagelink { font-size: 13px; }
main { padding: 12px 16px 32px; display: grid; gap: 12px; max-width: 1600px; margin: 0 auto; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px; min-width: 0; }
.loadrow { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; }
.filebtn { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 5px 12px; cursor: pointer; }
.filebtn input { display: none; }
.drop { border: 1px dashed var(--line); border-radius: 6px; padding: 5px 12px; color: var(--muted); }
.drop.over { border-color: var(--http); color: var(--fg); }
button { background: var(--panel2); color: var(--fg); border: 1px solid var(--line); border-radius: 6px; padding: 5px 12px; font: inherit; cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--http); }
button:disabled { opacity: .45; cursor: default; }
button.active { border-color: var(--serving); color: var(--serving); }
.viewswitch { display: inline-flex; gap: 6px; margin-left: auto; }
.msg { margin: 8px 0 0; padding: 6px 10px; border-radius: 6px; background: var(--panel2); border-left: 4px solid var(--http); }
.msg.warn { border-left-color: var(--warn); }
.msg.bad { border-left-color: var(--bad); }
.privacy { margin-top: 8px; color: var(--muted); font-size: 13px; }
.privacy summary { cursor: pointer; }
.tag { font-size: 12px; font-weight: 500; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 6px; margin-left: 6px; }
.grid { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(300px, 1fr); gap: 12px; }
@media (max-width: 980px) { .grid { grid-template-columns: 1fr; } }
.side { display: grid; gap: 12px; align-content: start; min-width: 0; }
.toolbar { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; margin-bottom: 8px; font-size: 13px; color: var(--muted); }
.toolbar label { display: inline-flex; gap: 5px; align-items: center; }
canvas { display: block; width: 100%; border-radius: 6px; background: var(--canvas); }
.mapwrap { position: relative; }
#map { height: 540px; touch-action: none; cursor: grab; }
@media (max-width: 600px) { #map { height: 360px; } }
.attribution { position: absolute; right: 6px; bottom: 6px; background: rgba(255,255,255,.9); color: #222; font-size: 11px; padding: 1px 6px; border-radius: 3px; }
.attribution a { color: #1565c0; }
.maperror { position: absolute; left: 50%; top: 8px; transform: translateX(-50%); background: rgba(13,18,24,.9); color: #fff; font-size: 12px; padding: 3px 10px; border-radius: 4px; }
.legend { font-size: 12px; color: var(--muted); margin: 6px 0 0; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-width: 0; }
.card.wide { grid-column: 1 / -1; }
.card b { display: block; font-size: 12px; color: var(--muted); font-weight: 600; }
.card span { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.card.dim span { color: var(--muted); }
.nodata { color: var(--muted); font-size: 15px !important; font-weight: 500 !important; }
.stale { color: var(--bad); }
.history { max-height: 280px; overflow: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 4px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; position: sticky; top: 0; background: var(--panel); }
tr.clickable { cursor: pointer; }
tr.clickable:hover, tr.selected { background: var(--panel2); }
.chip { display: inline-block; padding: 0 6px; border-radius: 3px; font-size: 12px; border: 1px solid currentColor; }
.chip.switched { color: var(--change); }
.chip.baseline { color: var(--serving); }
.chip.indeterminate { color: var(--muted); }
.charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 16px; }
@media (max-width: 900px) { .charts { grid-template-columns: 1fr; } }
.chart { height: 180px; cursor: crosshair; }
.chart.lane { height: 90px; }
.route-canvas { height: 120px; margin-top: 4px; }
.routenote { font-size: 12px; color: var(--muted); margin-top: 6px; }
.markerrow { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; margin-top: 8px; font-size: 13px; }
select { background: var(--panel2); color: var(--fg); border: 1px solid var(--line); border-radius: 5px; padding: 3px 6px; font: inherit; }
dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 0; }
dt { color: var(--muted); }
dd { margin: 0; }
.character { display: flex; gap: 12px; align-items: center; }
.sprite { width: 96px; height: 96px; flex: none; image-rendering: pixelated; background: transparent; }
/* Plain-language explanation under each radio metric (always visible). */
.help { font-size: 12px; color: var(--muted); margin-top: 2px; line-height: 1.35; }
.card-note { grid-column: 1 / -1; font-size: 12px; color: var(--muted); margin: 0; }
.routehead { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; }
.routehead h2 { margin: 0; }
.routestatus { font-size: 13px !important; padding: 1px 8px; color: var(--muted); }
.routestatus.off { color: var(--warn); }
.routestatus.near { color: var(--serving); }
/* Tunnel hint: purple = near a reference section (GPS), orange = "かも？" (estimate from several signs). */
.tunnelstatus { font-size: 13px !important; padding: 1px 8px; color: var(--muted); border-style: dashed; cursor: help; }
.tunnelstatus.near { color: var(--near); }
.tunnelstatus.maybe { color: var(--change); }
#tunnelReasons { margin: 4px 0 0; }
#tunnelInfo ul { margin: 4px 0; padding-left: 18px; }
#tunnelInfo li { margin-bottom: 4px; }
.routehead .markerrow { margin-top: 0; margin-left: auto; }
/* Route legend: amber circle = timetable plan, cyan-edged square = GPS estimate (projected fix). */
.routelegend { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 2px 6px; color: var(--muted); }
.routelegend i { display: inline-block; width: 11px; height: 11px; margin-left: 4px; }
.routelegend .lg-plan { border-radius: 50%; background: #ffb347; outline: 2px dashed var(--muted); outline-offset: 1px; }
.routelegend .lg-gps { border: 2px solid #26c6a8; background: var(--panel); }
.routelegend #routeGps { font-size: 12px !important; }
.route { position: relative; }
.routewrap { position: relative; }
.pinlegend i { display: inline-block; width: 10px; height: 10px; margin-left: 6px; }
.lg-passed { width: 16px !important; height: 4px !important; background: #7d8a96; border-radius: 2px; vertical-align: middle; }
.pin-lowacc { width: 0 !important; height: 0 !important; border-left: 6px solid transparent; border-right: 6px solid transparent; border-bottom: 10px solid #f2c94c; }
.pin-gap { border: 2.5px solid #9aa7b2; border-radius: 50%; }
.pin-near { background: #b39ddb; transform: rotate(45deg) scale(.85); }
.pin-hint { background: #ffb347; }
:root[data-theme="light"] .pin-lowacc { border-bottom-color: #b38600; }
:root[data-theme="light"] .pin-gap { border-color: #5f6b75; }
:root[data-theme="light"] .pin-near { background: #5e35b1; }
:root[data-theme="light"] .pin-hint { background: #d9730d; }
.pinpop { position: absolute; z-index: 30; width: min(300px, calc(100% - 8px)); padding: 6px 26px 6px 10px; font-size: 12px; line-height: 1.45;
  background: var(--panel); color: var(--fg); border: 1px solid var(--http); border-radius: 6px; box-shadow: 0 4px 14px rgba(0,0,0,.35); }
.pinpop p { margin: 0 0 4px; }
.pinpop button { position: absolute; top: 3px; right: 3px; padding: 0 6px; font-size: 13px; }
.pinlist { margin: 4px 0; padding-left: 20px; max-height: 180px; overflow: auto; }
.linkish { padding: 0 4px; font-size: 12px; font-variant-numeric: tabular-nums; }
.themetoggle { font-size: 12px; padding: 2px 10px; }
.track3d { height: 360px; touch-action: none; cursor: grab; }
@media (max-width: 600px) { .track3d { height: 280px; } }
.routenote { font-size: 12px; color: var(--muted); }
.routenote summary { cursor: pointer; }

/* The overview is a true viewport dashboard on desktop. Small screens keep natural scrolling. */
@media (min-width: 1000px) and (min-height: 760px) {
  body.dashboard-overview { height: 100vh; overflow: hidden; }
  body.dashboard-overview main {
    height: calc(100vh - var(--topbar-height, 76px)); max-width: none; padding: 8px 12px; gap: 8px; overflow: hidden;
    grid-template-rows: auto minmax(0, .82fr) minmax(0, 1.18fr);
  }
  body.dashboard-overview.has-route main { grid-template-rows: auto auto minmax(0, .72fr) minmax(0, 1fr); }
  body.dashboard-overview .panel { padding: 8px 10px; }
  body.dashboard-overview .loader .msg { margin-top: 4px; padding: 3px 8px; }
  body.dashboard-overview .privacy { margin-top: 4px; }
  body.dashboard-overview .grid { min-height: 0; grid-template-columns: minmax(0, 1.45fr) minmax(400px, 1fr); }
  body.dashboard-overview .mappanel { display: flex; flex-direction: column; min-height: 0; }
  body.dashboard-overview .mappanel .toolbar { margin-bottom: 4px; }
  body.dashboard-overview .mapwrap { flex: 1; min-height: 0; }
  body.dashboard-overview #map { height: 100%; }
  body.dashboard-overview .legend { display: none; }
  body.dashboard-overview .side { min-height: 0; overflow: hidden; align-content: stretch; grid-template-rows: auto auto minmax(0, 1fr); gap: 6px; }
  body.dashboard-overview .character { padding: 4px 8px; gap: 8px; min-height: 48px; }
  body.dashboard-overview .sprite { width: 42px; height: 42px; }
  body.dashboard-overview .character .small.muted:last-child { display: none; }
  body.dashboard-overview .cards { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; }
  body.dashboard-overview .card { padding: 4px 6px; border-radius: 6px; }
  body.dashboard-overview .card b { font-size: 10px; line-height: 1.2; }
  body.dashboard-overview .card span { font-size: 16px; line-height: 1.25; }
  body.dashboard-overview .card .help, body.dashboard-overview .card .small.muted,
  body.dashboard-overview .card-note { display: none; }
  body.dashboard-overview .card.distance { display: none; }
  body.dashboard-overview .history-panel { display: flex; flex-direction: column; min-height: 0; padding: 5px 8px; overflow: hidden; }
  body.dashboard-overview .history-panel h2 { margin: 0 0 2px; font-size: 13px; }
  body.dashboard-overview .history-panel .help { display: none; }
  body.dashboard-overview .history-panel #cellDiag { margin: 0 0 2px; font-size: 10px; line-height: 1.2; }
  body.dashboard-overview .history { flex: 1; min-height: 0; max-height: none; overflow: auto; scrollbar-gutter: stable; }
  body.dashboard-overview .history table { font-size: 10px; line-height: 1.15; }
  body.dashboard-overview .history th, body.dashboard-overview .history td { padding: 2px 4px; }
  body.dashboard-overview .side > .panel.small { display: none; }
  body.dashboard-overview .route { padding: 5px 8px; }
  body.dashboard-overview .route .routehead h2 { font-size: 13px; }
  body.dashboard-overview .route .route-canvas { height: 62px; margin: 0; }
  body.dashboard-overview .route .routenote { display: none; }
  body.dashboard-overview .pinlegend { font-size: 10px; }
  body.dashboard-overview .pinlegend .muted { display: none; }
  body.dashboard-overview .timeseries { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
  body.dashboard-overview .timeseries > h2 { flex: none; margin: 0 0 2px; }
  body.dashboard-overview .timeseries .toolbar { flex: none; margin: 2px 0 4px; gap: 4px 8px; }
  body.dashboard-overview .timeseries .replay .small { display: none; }
  body.dashboard-overview .charts { flex: 1; min-height: 0; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0 8px; }
  body.dashboard-overview .charts > div { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; }
  body.dashboard-overview .charts h3 { flex: none; margin: 1px 0; font-size: 11px; line-height: 1.15; }
  body.dashboard-overview .chart { flex: 1; height: auto; min-height: 68px; }
  body.dashboard-overview .chart.lane { flex: none; height: 40px; min-height: 40px; }
  body.dashboard-overview .timeseries > h3 { flex: none; margin: 2px 0 0; }
  body.dashboard-overview .timeseries > .small { flex: none; margin: 1px 0 0; font-size: 10px; }
  body.dashboard-overview #selectionPanel, body.dashboard-overview #sensorsPanel { display: none; }
  /* The one-screen overview keeps its existing cards and charts; altitude is shown in the detail view. */
  body.dashboard-overview #altitudePanel, body.dashboard-overview .card.altitude, body.dashboard-overview #track3dPanel { display: none; }
}
body:not(.dashboard-overview) .dashboard-switch button[aria-pressed="false"] { color: var(--muted); }
.sensors summary { cursor: pointer; list-style: revert; }
.sensors summary h2 { display: inline; }
/* CSV replay controls: the cursor slider takes the remaining width and wraps on narrow screens. */
.replay #cursor { flex: 1 1 200px; min-width: 160px; }
.replay #cursorLabel { font-variant-numeric: tabular-nums; color: var(--fg); }
tr.future { opacity: .45; }

/* Floating character: above every panel, dragged by the user, never auto-moving or blinking. */
.floatchar { position: fixed; z-index: 40; width: 150px; display: flex; flex-direction: column; align-items: center;
  touch-action: none; user-select: none; -webkit-user-select: none; cursor: grab; border-radius: 10px; outline: none;
  padding-bottom: 24px; /* room for the resize grip under the caption */ }
.floatchar:hover, .floatchar:focus-visible, .floatchar.dragging { background: var(--overlay-soft); box-shadow: 0 0 0 1px var(--line); }
.floatchar:focus-visible { box-shadow: 0 0 0 2px var(--serving); }
.floatchar.dragging { cursor: grabbing; }
.floatbar { align-self: stretch; display: flex; justify-content: space-between; align-items: center; height: 22px; padding: 0 2px 0 6px; }
.floatbar .grip { color: var(--muted); font-size: 12px; letter-spacing: -2px; }
.floatbar button { padding: 0 7px; line-height: 18px; font-size: 14px; background: var(--panel2); }
.floatsprite { width: 120px; height: 120px; image-rendering: pixelated; pointer-events: none; }
.floatcap { max-width: 150px; text-align: center; font-size: 12px; line-height: 1.35; padding: 3px 6px; border-radius: 6px;
  background: var(--overlay); border: 1px solid var(--line); }
.floatcap b { display: block; font-size: 13px; }
.floatcap span { display: block; }
.floatcap .floatnote { color: var(--muted); font-size: 10.5px; }
/* User-sized window (lower-left grip): the sprite takes the free height; text keeps its size and stays readable. */
.floatchar.sized { justify-content: flex-start; }
.floatchar.sized, .floatchar.sized:hover { background: var(--overlay-soft); box-shadow: 0 0 0 1px var(--line); }
.floatchar.sized .floatsprite { flex: 1 1 0; width: 100%; height: auto; min-height: 48px; }
.floatchar.sized .floatcap { flex: none; max-width: 100%; align-self: stretch; margin: 0 4px; }
.floatchar.sized .floatcap .floatnote { display: block; }
.floatchar.resizing { cursor: nesw-resize; }
.floatgrip { position: absolute; left: 0; bottom: 0; width: 22px; height: 22px; cursor: nesw-resize; touch-action: none; border-radius: 0 6px 0 10px;
  background: linear-gradient(45deg, transparent 0 30%, var(--muted) 30% 38%, transparent 38% 52%, var(--muted) 52% 60%, transparent 60% 74%, var(--muted) 74% 82%, transparent 82%) var(--panel2);
  border: 1px solid var(--line); opacity: .9; }
.floatgrip:hover, .floatgrip:focus-visible, .floatchar.resizing .floatgrip { opacity: 1; border-color: var(--http); outline: none; box-shadow: 0 0 0 2px var(--http); }
.floatshow { position: fixed; z-index: 40; right: 12px; bottom: 12px; font-size: 12px; padding: 4px 10px; opacity: .9; }
@media (max-width: 600px) {
  .floatchar { width: 104px; }
  .floatsprite { width: 76px; height: 76px; }
  .floatcap { max-width: 104px; font-size: 11px; }
  .floatcap .floatnote { display: none; }
}
