/* Application styles */

/* Live dashboard widgets (session_participants/_widgets). */
.widget-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: #e8e8e4;
  border: 1px solid #e8e8e4;
}
.widget-cell { background: #fff; padding: 0.75rem; min-width: 0; }
.widget-small { grid-column: span 1; min-height: 100px; }
.widget-large { grid-column: span 2; min-height: 200px; }
.widget-value-label {
  font-size: 0.65rem;
  color: #aaa;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 0.25rem;
}
.widget-value { font-size: 2.2rem; letter-spacing: -0.03em; }

/* Live connection dot: grey until connected, then a pulsing red. */
.live-indicator {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #ccc;
  margin-right: 0.4rem;
  vertical-align: middle;
}
.live-indicator.live { background: #c0392b; animation: live-pulse 1.5s ease-in-out infinite; }
@keyframes live-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.2; }
}

/* Session page: one card per participant. */
.participant-card { padding: 1rem; }
.participant-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

/* Time window sliders above a participant's widgets (TimeRangeControl). */
.time-range {
  margin: 0.75rem 0;
  padding: 0.5rem 0.75rem 0.75rem;
  border: 1px solid #e8e8e4;
  background: #fff;
  font-size: 0.8rem;
  color: #666;
}
.time-range-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.25rem; }
.time-range-head span { text-transform: uppercase; letter-spacing: 0.07em; font-size: 0.65rem; color: #aaa; }
.time-range button {
  font-size: 0.75rem;
  padding: 0.15rem 0.6rem;
  background: none;
  color: #333;
  border: 1px solid #ccc;
}
.time-range button:hover { background: #f5f5f0; }
.time-range button:disabled { opacity: 0.4; cursor: default; background: none; }
.time-range-rows { display: grid; gap: 0.25rem 1.5rem; }
/* Same columns on both rows so the two sliders line up. */
.time-range-rows label {
  display: grid;
  grid-template-columns: 2.5rem 7.5rem 1fr;
  align-items: center;
  font-variant-numeric: tabular-nums;
}
.time-range input[type="range"] { width: 100%; max-width: none; padding: 0; border: none; }
@media (min-width: 700px) {
  .time-range-rows { grid-template-columns: 1fr 1fr; }
}

/* Page header: breadcrumb trail and the page's actions (ApplicationHelper#breadcrumbs). */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.25rem 1rem;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid #e0e0db;
}
.page-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 0.25rem 1rem; flex: none; }
.page-actions form { display: inline; }
.breadcrumbs {
  display: flex;
  flex-wrap: wrap;
  /* center, not baseline: a crumb with overflow: hidden (cut short on phones)
     reports its baseline at its bottom edge, which pushed it up out of line. */
  align-items: center;
  min-width: 0;
  font-size: 0.9rem;
  line-height: 1.5;
  color: #888;
}
.breadcrumbs a { color: #666; }
.breadcrumbs strong { color: #111; font-weight: 600; }
.crumb + .crumb::before { content: "›"; margin: 0 0.4em; color: #aaa; }
.breadcrumbs-more {
  display: none;
  font: inherit;
  line-height: inherit;
  padding: 0 0.2em;
  background: none;
  color: #555;
  border: none;
  cursor: pointer;
}
.breadcrumbs-more:hover { background: none; color: #111; }
/* Phones: one line of "… › parent › current", the parent cut short if needed. */
@media (max-width: 700px) {
  .breadcrumbs:not(.expanded) { flex-wrap: nowrap; }
  .breadcrumbs:not(.expanded) .crumb { white-space: nowrap; }
  .breadcrumbs:not(.expanded) .breadcrumbs-more { display: inline; }
  .breadcrumbs:not(.expanded) .breadcrumbs-more + .crumb::before { content: "›"; margin: 0 0.4em; color: #aaa; }
  .breadcrumbs:not(.expanded) .crumb-early { display: none; }
  /* Long names are cut short, the parent first and the current page only if still needed. */
  .breadcrumbs:not(.expanded) .crumb-parent,
  .breadcrumbs:not(.expanded) .crumb-current { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  /* Never shrinks to nothing, but small enough not to pad out a short name. */
  .breadcrumbs:not(.expanded) .crumb-parent { flex: 0 1000 auto; min-width: 2.5em; }
  .breadcrumbs:not(.expanded) .crumb-current { flex: 0 1 auto; }
}

/* Participant live page: connection status and links. */
.live-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.25rem 1rem;
  font-size: 0.8rem;
  color: #888;
}
.live-header a { color: #555; }

/* A page's own heading and the one-line summary under it (e.g. an event). */
.page-title { margin-top: 0; margin-bottom: 0.25rem; }
.page-meta { display: flex; flex-wrap: wrap; gap: 0.25rem 0; color: #666; margin-top: 0; }
.page-meta > span + span::before { content: "·"; margin: 0 0.6em; color: #aaa; }
@media (max-width: 700px) {
  .page-meta { flex-direction: column; }
  .page-meta > span + span::before { content: none; }
}

/* A link styled as the app's primary button. */
a.button {
  display: inline-block;
  padding: 0.6rem 1.1rem;
  background: #111;
  color: #fff;
  text-decoration: none;
  font-size: 0.95rem;
}
a.button:hover { background: #333; }

/* Device page: live dashboard call to action, races beside setup. */
.device-live { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; margin: 1.25rem 0 0.5rem; }
.device-layout { display: grid; gap: 0 2.5rem; grid-template-columns: minmax(0, 2fr) minmax(16rem, 1fr); align-items: start; }
.device-layout h2 { margin-top: 1.5rem; }
.device-layout table { width: 100%; }
@media (max-width: 800px) {
  .device-layout { grid-template-columns: 1fr; }
}
.device-setup-note { margin: -0.5rem 0 0.75rem; }
.setup-card {
  display: block;
  padding: 0.75rem 1rem;
  margin-bottom: 0.5rem;
  background: #fff;
  border: 1px solid #e0e0db;
  color: inherit;
  text-decoration: none;
}
.setup-card:hover { border-color: #999; }
.setup-card strong { display: block; font-weight: 600; }
.setup-card span { font-size: 0.85rem; color: #666; }
.races-table.collapsed tr.older { display: none; }
.nowrap { white-space: nowrap; }
button.link-button { background: none; color: #333; padding: 0.25rem 0; text-decoration: underline; }
button.link-button:hover { background: none; color: #000; }
/* Show or hide content (e.g. table columns) by screen width. */
.narrow-only { display: none; }
@media (max-width: 700px) {
  .wide-only { display: none; }
  .narrow-only { display: block; }
}

/* Value widget warning colours (options warn_* / alarm_*). */
.widget-cell.value-warn { background: #fff4d6; }
.widget-cell.value-warn .widget-value { color: #9a6200; }
.widget-cell.value-alarm { background: #fde2e1; }
.widget-cell.value-alarm .widget-value { color: #b42318; }

/* --- Setup pages (setup/sensors, setup/dashboard) --- */
.page-intro { color: #555; margin-top: 0; }
.section-help { color: #777; font-size: 0.9rem; margin: -0.5rem 0 0.75rem; }
.field-help { color: #777; font-size: 0.85rem; margin: 0.25rem 0; }
.setup-editor section { margin-bottom: 2rem; }
.setup-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1.25rem; margin: 0.75rem 0 1rem; font-size: 0.9rem; color: #555; }
.setup-toolbar select { width: auto; margin-left: 0.4rem; }
.defaults-banner {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 0.5rem 1rem;
  padding: 0.6rem 0.9rem; margin: 0.75rem 0; background: #f2f7ef; border: 1px solid #cfe3c4; font-size: 0.9rem;
}
.defaults-banner.differs { background: #fff8e6; border-color: #f0dca8; }
.defaults-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.defaults-actions form { display: inline; }
.defaults-actions button { font-size: 0.8rem; padding: 0.3rem 0.7rem; background: #fff; color: #333; border: 1px solid #bbb; }
.defaults-actions button:hover { background: #f5f5f0; }
.unnamed-keys, .rename-notice { padding: 0.6rem 0.9rem; margin: 0.75rem 0; background: #eef4fb; border: 1px solid #c9dbef; font-size: 0.9rem; }
.unnamed-keys { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; }
.unnamed-keys[hidden], .rename-notice[hidden], .formula-suggestions[hidden] { display: none; }
.chip-button {
  font-size: 0.8rem; padding: 0.2rem 0.6rem; background: #fff; color: #333;
  border: 1px solid #bbb; border-radius: 999px; cursor: pointer;
}
.chip-button:hover { background: #f5f5f0; border-color: #888; }
button.link-button.danger { color: #b42318; }
.help-toggle {
  font-size: 0.75rem; width: 1.4rem; height: 1.4rem; padding: 0; margin-left: 0.4rem; vertical-align: middle;
  border-radius: 50%; background: #fff; color: #555; border: 1px solid #bbb;
}
.help-toggle:hover { background: #f5f5f0; }
.formula-help { font-size: 0.9rem; }

.setup-table { width: 100%; border-collapse: collapse; }
.setup-table th { font-size: 0.75rem; font-weight: normal; color: #888; text-align: left; padding: 0.25rem 0.4rem; }
.setup-table td { padding: 0.25rem 0.4rem; vertical-align: top; border: none; }
.setup-table input { max-width: none; width: 100%; padding: 0.3rem 0.45rem; font-size: 0.9rem; }
.setup-table input.short { width: 5.5rem; }
.setup-table input.mono, .mono { font-family: Consolas, Monaco, monospace; font-size: 0.85rem; }
.setup-table .grip { width: 1rem; color: #bbb; cursor: grab; touch-action: none; user-select: none; padding-top: 0.55rem; }
.setup-table .latest { color: #444; font-variant-numeric: tabular-nums; white-space: nowrap; padding-top: 0.55rem; }
.setup-table .formula-cell { width: 50%; }
.setup-table tr.dragging { opacity: 0.5; }
.remove-row { background: none; color: #bbb; padding: 0.3rem 0.4rem; font-size: 1.1rem; line-height: 1; }
.remove-row:hover { background: none; color: #b42318; }
.formula-check { font-size: 0.8rem; margin-top: 0.15rem; }
.formula-check.good { color: #2e7d32; }
.formula-check.bad { color: #b42318; }
.formula-suggestions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.3rem; margin: 0.4rem 0; font-size: 0.85rem; color: #666; }
@media (max-width: 700px) {
  /* Two fields per line rather than squeezing every column onto a phone. */
  .setup-table thead { display: none; }
  .setup-table tr { display: grid; grid-template-columns: 1.2rem 1fr 1fr auto; gap: 0.3rem; padding: 0.5rem 0; border-bottom: 1px solid #eee; }
  .setup-table td { display: block; padding: 0; border: none; }
  .setup-table td.grip { grid-column: 1; grid-row: 1 / span 3; }
  .setup-table td:last-child { grid-column: 4; grid-row: 1; }
  .setup-table input.short { width: 100%; }
  .setup-table .formula-cell { width: auto; }
  /* From the car: key | name, then unit | latest. Parameters: name | value, then unit | note. */
  [data-rows] td:nth-child(2), [data-parameters] td:nth-child(2) { grid-column: 2; grid-row: 1; }
  [data-rows] td:nth-child(3), [data-parameters] td:nth-child(3) { grid-column: 3; grid-row: 1; }
  [data-rows] td:nth-child(4), [data-parameters] td:nth-child(4) { grid-column: 2; grid-row: 2; }
  [data-rows] td:nth-child(5), [data-parameters] td:nth-child(5) { grid-column: 3; grid-row: 2; }
  /* Calculated: name, then the formula, then the unit. */
  [data-calculated] td:nth-child(2), [data-calculated] td:nth-child(3) { grid-column: 2 / span 2; }
  [data-calculated] td:nth-child(4) { grid-column: 2; }
}

.setup-save {
  position: sticky; bottom: 0; z-index: 5;
  padding: 0.75rem 0; margin-top: 1rem; background: #fffff8; border-top: 1px solid #e0e0db;
}

/* Dashboard editor: preview beside the widget panel. */
.dashboard-layout { display: grid; grid-template-columns: minmax(0, 1fr) 20rem; gap: 1.5rem; align-items: start; }
@media (max-width: 900px) { .dashboard-layout { grid-template-columns: 1fr; } }
.dashboard-preview .widget-cell { position: relative; }
.dashboard-preview .widget-cell.selected { outline: 2px solid #2563eb; outline-offset: -2px; z-index: 1; }
.dashboard-preview .widget-cell.dragging { opacity: 0.5; }
.cell-overlay { position: absolute; inset: 0; cursor: pointer; }
.cell-overlay:hover { background: rgba(37, 99, 235, 0.05); }
.cell-grip {
  position: absolute; top: 0.3rem; right: 0.4rem; z-index: 2; padding: 0.1rem 0.3rem;
  color: #999; background: rgba(255, 255, 255, 0.85); cursor: grab; touch-action: none; user-select: none;
}
.placeholder-cell span { color: #888; font-size: 0.85rem; }
.empty-preview { color: #888; padding: 2rem; text-align: center; border: 1px dashed #ccc; }
.add-widgets { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; margin-top: 0.75rem; font-size: 0.9rem; color: #555; }
.widget-panel { position: sticky; top: 1rem; padding: 1rem; background: #fff; border: 1px solid #e0e0db; }
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.5rem; }
.panel-head span { display: flex; gap: 0.75rem; }
.panel-field { display: grid; gap: 0.2rem; margin: 0.6rem 0; font-size: 0.85rem; color: #666; }
.panel-field input, .panel-field select { max-width: none; width: 100%; font-size: 0.9rem; }
.check-field { display: flex; align-items: center; gap: 0.5rem; margin: 0.6rem 0; font-size: 0.9rem; }
.check-field input { width: auto; margin: 0; }
.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.field-pair .panel-field { margin: 0.3rem 0; }
.sensor-chips { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-bottom: 0.4rem; }
.sensor-chip { display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.2rem 0.5rem; background: #111; color: #fff; font-size: 0.8rem; }
.sensor-chip select { width: auto; padding: 0 0.2rem; font-size: 0.75rem; background: #333; color: #fff; border: none; }
.sensor-chip button { background: none; color: #aaa; padding: 0; font-size: 0.95rem; line-height: 1; }
.sensor-chip button:hover { background: none; color: #fff; }

/* Flash messages (layouts/_flash), dismissed with their × button. */
.flash-messages { display: grid; gap: 0.5rem; margin: 0.75rem 0 1rem; }
.flash { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 0.6rem 0.75rem 0.6rem 1rem; border: 1px solid; }
.flash-notice { background: #f0f7ec; border-color: #c7e0b8; color: #275e19; }
.flash-alert { background: #fdf0ef; border-color: #f2c6c2; color: #8f1d14; }
.flash-dismiss { flex: none; background: none; color: inherit; padding: 0 0.3rem; font-size: 1.2rem; line-height: 1; opacity: 0.6; }
.flash-dismiss:hover { background: none; opacity: 1; }

/* Battery page: health measures (sparklines, dot strips) and readings grouped by discharge. */
.health-lede { margin: 1.25rem 0 0; }
.health { border-top: 1px solid #999; margin-top: 0.75rem; }
.health-measure { display: grid; grid-template-columns: minmax(14rem, 1fr) 2fr; gap: 0.75rem 3rem; align-items: center; padding: 1.1rem 0; border-bottom: 1px solid #ddd; }
.health-own h3 { margin: 0; font-size: 1rem; font-weight: 400; color: #555; }
.health-value { font-size: 1.9rem; letter-spacing: -0.02em; line-height: 1.2; font-variant-numeric: tabular-nums; }
.health-trend { font-size: 0.9rem; margin-top: 0.15rem; }
.health-trend svg { vertical-align: middle; margin-right: 0.3rem; overflow: visible; max-width: none; }
.health-compare p { margin: 0 0 0.6rem; font-size: 0.95rem; }
.dot-strip-line { position: relative; height: 12px; margin: 0 6px; }
.dot-strip-line::before { content: ""; position: absolute; left: 0; right: 0; top: 50%; border-top: 1px solid #ccc; }
.dot-strip .dot { position: absolute; top: 50%; width: 8px; height: 8px; border-radius: 50%; background: #bbb; transform: translate(-50%, -50%); }
.dot-strip .dot:hover { background: #666; }
.dot-strip .dot.current { width: 12px; height: 12px; background: #111; }
.dot-strip-scale { display: flex; justify-content: space-between; font-size: 0.8rem; color: #777; margin-top: 0.3rem; font-variant-numeric: tabular-nums; }
@media (max-width: 700px) {
  .health-measure { grid-template-columns: 1fr; }
}
.sparkline polyline { fill: none; stroke: #888; stroke-width: 1.25; }
.sparkline circle { fill: #111; }
.change-good { color: #2e7d32; }
.change-bad { color: #b42318; }
.table-scroll { overflow-x: auto; }
.readings-table th.num, .readings-table td.num { text-align: right; padding-right: 1.5rem; }
.readings-table tr.discharge-head th { padding-top: 1.25rem; color: #111; font-weight: 600; border-bottom-color: #ddd; }

/* Hours / minutes / seconds inputs (shared/_duration_fields). */
.duration-fields { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; }
.duration-fields label { display: flex; align-items: center; gap: 0.4rem; margin: 0; }
.duration-fields input { width: 5rem; }
.duration-fields span { color: #666; }

/* Battery analysis: period links, scatter, race pairs. */
.period-picker { display: flex; flex-wrap: wrap; gap: 0.25rem 1.25rem; margin: 1rem 0; }
.period-picker strong { font-weight: 600; }
.analysis-chart { position: relative; height: 26rem; max-height: 70vh; }
.pair-count { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.75rem; }
.pair-count label { margin: 0; }
.pair-count input[type="number"] { width: 5rem; }
.pair-count input[type="submit"] { width: auto; }
.pairs-table th.num, .pairs-table td.num { text-align: right; padding-right: 1.5rem; }
.all-pairs { margin: 1.5rem 0; }
.all-pairs summary { cursor: pointer; color: #555; }
.capacity-table td { vertical-align: middle; }
.capacity-table th.num, .capacity-table td.num { text-align: right; padding-right: 1.5rem; }
.capacity-table .track-col { width: 50%; min-width: 9rem; }
.track-scale { display: flex; justify-content: space-between; font-size: 0.8rem; color: #777; }
.capacity-track { position: relative; height: 12px; margin: 0 6px; }
.capacity-track::before { content: ""; position: absolute; left: 0; right: 0; top: 50%; border-top: 1px solid #e4e4e0; }
.capacity-track .track-change { position: absolute; top: 50%; border-top: 1px solid #aaa; }
.capacity-track .track-dot { position: absolute; top: 50%; width: 10px; height: 10px; border-radius: 50%; background: #111; transform: translate(-50%, -50%); }
.capacity-track .track-dot.previous { width: 7px; height: 7px; background: #fff; border: 1px solid #999; }

/* Uploaded models (prediction_models/show): one block per version. */
.model-version { border: 1px solid #ddd; padding: 0.75rem 1rem 1rem; margin-bottom: 1rem; scroll-margin-top: 1rem; }
.model-version:target { border-color: #111; }
.model-version h2 { margin: 0; font-size: 1.1rem; }
.model-facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 0.4rem 1rem; margin: 0.75rem 0; }
.model-facts dt { color: #666; }
.model-facts dd { margin: 0; min-width: 0; }
.model-facts dd p { margin: 0 0 0.4rem; }
.model-facts code { display: inline-block; margin: 0 0.25rem 0.25rem 0; }

/* Model sensors in the sensors editor (setup/sensors_editor.js). */
.model-cell select { max-width: 100%; }
.model-made-for { font-size: 0.8rem; color: #666; margin-top: 0.2rem; }
.model-made-for.elsewhere { color: #9a5b00; }
.model-inputs { display: grid; gap: 0.35rem; margin: 0.5rem 0 0.25rem; }
.model-input { display: grid; grid-template-columns: minmax(5rem, max-content) minmax(0, 1fr); align-items: center; gap: 0 0.6rem; margin: 0; color: inherit; }
.model-input span { font-size: 0.85rem; }
.model-input .formula-check { grid-column: 2; margin-top: 0; }
.model-input .formula-check:empty { display: none; }
.model-name-matches:empty { display: none; }
.model-name-matches { display: grid; gap: 0.3rem; margin: 0.5rem 0; padding: 0.5rem 0.6rem; background: #fff7e6; font-size: 0.85rem; }
.model-name-match { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; margin: 0; color: inherit; }
.model-name-match select { width: auto; max-width: 100%; }
