[data-history-card] { position: relative; cursor: pointer; }
#overview-page .metric[data-history-card]:not(.gas-card) .metric-label,
#overview-page [data-device-status][data-history-card] h3 { padding-inline-end: 1.25rem; }
button.history-trigger {
  position: absolute;
  inset: .55rem .5rem auto auto;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 1.8rem;
  height: 1.8rem;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: .45rem;
  box-shadow: none;
  background: transparent;
  color: #285f90;
}
button.history-trigger:hover, button.history-trigger:focus-visible { background: #e1effc; color: #064a83; }
.history-trigger svg { width: 1.15rem; height: 1.15rem; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#telemetry-history {
  box-sizing: border-box;
  width: min(46rem, calc(100% - 2rem));
  max-width: none;
  max-height: 90vh;
  max-height: 90dvh;
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid #bcd4eb;
  border-radius: 1.25rem;
  padding: clamp(.9rem, 3vw, 1.7rem);
  background: #f7fbff;
  color: #142c49;
  box-shadow: 0 16px 64px #11284038;
}
#telemetry-history::backdrop { background: #0c274772; }
#telemetry-history [hidden] { display: none; }
.history-header, .history-controls { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .55rem; margin-bottom: .75rem; }
#telemetry-history .history-header { min-height: 0; height: auto; border: 0; }
#history-title { margin: 0; font-size: clamp(1.15rem, 4.5vw, 1.65rem); }
.history-header button, .history-period button { min-height: 2.65rem; padding: .4rem .65rem; font-size: .92rem; }
.history-period { display: flex; gap: .25rem; padding: .22rem; border-radius: .8rem; background: #e2edf9; }
.history-period button[aria-pressed="false"] { background: transparent; color: #134d81; border-color: transparent; box-shadow: none; }
.history-controls label { margin: 0; }
.history-bottle select, .history-unit select { display: block; max-width: 100%; min-height: 2.5rem; }
.history-status:not(:empty) { margin: .75rem 0; }
.history-status:empty { display: none; }
.history-legend { display: flex; flex-wrap: wrap; gap: .25rem 1rem; padding: 0; margin: .75rem 0; list-style: none; font-size: .9rem; }
.history-legend li::before { content: ''; display: inline-block; width: .75rem; height: .65rem; margin-right: .35rem; border-radius: .2rem; background: var(--series-color); }
.history-data canvas { display: block; width: 100%; max-width: 100%; height: 232px; touch-action: pan-y; cursor: crosshair; }
.history-lanes { display: grid; gap: .35rem; margin: .6rem 0 0; }
.history-lane { display: grid; gap: .15rem; align-items: center; font-size: .84rem; }
.history-track { position: relative; display: block; height: .75rem; border-radius: .26rem; background: #e7eef6; overflow: hidden; }
.history-segments, .history-cursor { position: absolute; inset: 0 auto 0 0; background: var(--segment-color); }
.history-cursor { background: #163957; width: 2px; }
.history-time { display: grid; gap: .15rem; margin-top: 1rem; font-size: .85rem; }
.history-time input { width: 100%; min-height: 1.65rem; padding: 0; margin: 0; accent-color: #0b5cb0; }
.history-details { display: block; min-height: 3.2rem; border-radius: .7rem; margin-top: .35rem; padding: .5rem .7rem; background: #eaf3fb; line-height: 1.5; }
.history-details span { display: block; }
.history-note { margin: .55rem 0 0; color: #405b75; font-size: .84rem; }
@media (max-width: 650px) {
  #telemetry-history { inset: auto 0 0; margin: 0 auto; width: 100%; padding-bottom: max(.9rem, env(safe-area-inset-bottom)); border-radius: 1.1rem 1.1rem 0 0; }
  #overview-page .metric[data-history-card]:not(.gas-card) .metric-label { padding-inline-end: .75rem; overflow-wrap: anywhere; }
  button.history-trigger { inset: .24rem .24rem auto auto; width: 1.55rem; height: 1.55rem; }
  .history-data canvas { height: 175px; }
}

.history-period { flex-wrap: wrap; }
.history-year select { display: block; max-width: 100%; min-height: 2.5rem; }
.history-comparison { margin-top: 1rem; border-top: 1px solid #cbddeb; padding-top: .8rem; }
.history-comparison h3 { margin: 0; font-size: 1rem; }
.history-comparison p { margin: .35rem 0 .6rem; }
.history-comparison table { width: 100%; }
.history-comparison :is(th,td) { padding-inline: .3rem; }
.history-comparison tr[aria-current="true"] { background: #eaf3fb; }

.history-legend li.history-legend-gap::before {
  width: 1rem;
  height: 0;
  border-radius: 0;
  border-top: 2px dashed currentColor;
  vertical-align: middle;
}

/* RC22: unified typography and portal-styled period and measurement selectors. */
#telemetry-history {font-family:inherit;}
#telemetry-history :is(button,select,option,input){font-family:inherit;font-size:inherit;}
#telemetry-history .history-period{width:100%;display:grid;grid-template-columns:repeat(5,minmax(0,1fr));gap:.2rem;padding:.25rem;box-sizing:border-box;}
#telemetry-history .history-period button{
  appearance:none;-webkit-appearance:none;min-width:0;min-height:40px;margin:0;padding:.45rem .35rem;
  border:0;border-radius:9px;box-shadow:none;background:transparent;color:#134d81;
  text-align:center;
  font-family:inherit;font-size:clamp(11px,1.1vw,14px);font-weight:600;line-height:1.35;
}
#telemetry-history .history-period button[aria-pressed=true]{color:white;background:var(--blue,#075ba8);}
#telemetry-history .history-period button:focus-visible,#telemetry-history .history-select-toggle:focus-visible,#telemetry-history .history-select-option:focus-visible{outline:2px solid #2878bc;outline-offset:2px;}
#telemetry-history .history-filter{min-width:0;flex:1 1 12rem;max-width:100%;font-size:14px;}
#telemetry-history .history-filter label{display:block;margin:0 0 .3rem;font-weight:600;}
#telemetry-history .history-filter select{width:100%;box-sizing:border-box;border:1px solid var(--line,#c3d8ec);border-radius:10px;background:white;font:inherit;padding:.6rem;}
#telemetry-history [hidden]{display:none!important;}
#telemetry-history .history-select{position:relative;min-width:0;}
#telemetry-history .history-select-toggle{
  appearance:none;-webkit-appearance:none;display:flex;position:relative;align-items:center;width:100%;box-sizing:border-box;
  min-height:44px;padding:10px 32px 10px 12px;text-align:left;margin:0;border:1px solid var(--line,#c3d8ec);border-radius:10px;
  box-shadow:none;color:var(--ink,#142c49);background:#fff;font:inherit;font-weight:600;
}
#telemetry-history .history-select-toggle::after{content:'';position:absolute;right:13px;top:calc(50% - 6px);width:8px;height:8px;border-right:2px solid var(--blue,#075ba8);border-bottom:2px solid var(--blue,#075ba8);transform:rotate(45deg);}
#telemetry-history .history-select-options{position:absolute;z-index:4;inset:calc(100% + 4px) 0 auto;box-sizing:border-box;padding:5px;max-height:15rem;overflow:auto;background:#fff;border:1px solid var(--line,#c3d8ec);box-shadow:0 10px 24px #1b39531a;border-radius:10px;}
#telemetry-history .history-select-option{appearance:none;-webkit-appearance:none;display:block;width:100%;min-height:42px;margin:0;padding:8px 10px;text-align:left;border:0;border-radius:7px;background:transparent;color:var(--ink,#142c49);box-shadow:none;font:inherit;}
#telemetry-history .history-select-option[aria-selected=true],#telemetry-history .history-select-option:hover{background:#e9f4fe;color:#075eac;}
#telemetry-history .history-select-option[aria-selected=true]{font-weight:700;}
@media(max-width:420px){#telemetry-history .history-period button{padding:.35rem .12rem;line-height:1.2;}}
