/* GTelemetry Dashboard Styles */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg:        #0d0f14;
  --surface:   #161920;
  --border:    #252830;
  --text:      #e2e6f0;
  --muted:     #6b7280;
  --accent:    #3b82f6;
  --green:     #22c55e;
  --red:       #ef4444;
  --orange:    #f97316;
  --yellow:    #eab308;

  /* Tire temp thresholds */
  --tire-cold:    #2563eb;  /* <60°C */
  --tire-warm:    #38bdf8;  /* <80°C */
  --tire-optimal: #22c55e;  /* <95°C */
  --tire-hot:     #f97316;  /* <110°C */
  --tire-danger:  #ef4444;  /* ≥110°C */

  --font-mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  --font-ui:   system-ui, -apple-system, sans-serif;
}

html {
  height: 100%;
}

body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.4;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: padding-right 0.15s ease;
}
/* Non-modal social drawer is PUSH-style: while open, the app content box shrinks by the
   drawer width (shared var) so nothing sits underneath it — the dashboard reflows to fit. */
body.social-open { padding-right: min(var(--social-drawer-w), 92vw); }

/* Scrollbars — themed to match the app rather than the OS default. A slim, rounded
   thumb in the border tone (floating on a transparent track via a transparent border +
   content-box clip, so it works over any surface) that brightens toward the muted tone
   on hover. WebKit/Blink use the pseudo-elements; Firefox uses scrollbar-color. */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 8px;
  border: 3px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--muted); background-clip: content-box; }
::-webkit-scrollbar-corner { background: transparent; }

/* ---- App shell + Session Manager panel ---- */
:root { --session-panel-w: 264px; }

#app-shell {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: row;
  overflow: hidden;
}

#app-main {
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#session-panel {
  position: relative;
  flex: 0 0 var(--session-panel-w);
  width: var(--session-panel-w);
  min-width: 200px;
  max-width: 20vw;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
body.session-collapsed #session-panel { display: none; }

#session-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 52px;
  flex-shrink: 0;
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
}
#session-panel-title {
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
}
#session-collapse-btn, #session-expand-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 6px;
  width: 26px; height: 26px;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
}
#session-collapse-btn:hover, #session-expand-btn:hover { color: var(--text); }

#session-expand-btn {
  display: none;
  position: fixed;
  left: 8px; top: 13px;
  z-index: 60;
  background: var(--surface);   /* solid, so the header label never shows through it */
}
body.session-collapsed #session-expand-btn { display: block; }
/* When the panel is collapsed the floating ‹›› button sits at the header's left edge —
   shift the header content right so the GTelemetry label doesn't draw over/under it. */
body.session-collapsed header { padding-left: 44px; }

#session-panel-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;          /* the list scrolls, not the whole body */
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Load / Record stay pinned at the top; only #session-list scrolls. */
#session-actions { display: flex; flex-direction: column; gap: 8px; flex-shrink: 0; }
#load-session-btn, #record-session-btn {
  width: 100%;
  padding: 9px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 13px;
}
#load-session-btn:hover { border-color: var(--accent); color: var(--accent); }
#record-session-btn:hover,
#record-session-btn.recording { border-color: var(--red); color: var(--red); }

#session-empty {
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  padding: 18px 6px;
  line-height: 1.6;
}

#session-list { display: flex; flex-direction: column; gap: 8px; flex: 1 1 auto; min-height: 0; overflow-y: auto; }

.session-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  cursor: grab;
  display: flex;
  gap: 8px;
  background: var(--bg);
}
.session-item:hover { border-color: var(--muted); }
.session-item.active { border-color: var(--accent); background: rgba(59, 130, 246, 0.08); }
/* Drag-to-reorder: the lifted card dims, and the cursor shows the grab. */
.session-item.dragging { opacity: 0.45; cursor: grabbing; border-color: var(--accent); }

/* Left column: thumbnail + the Active/Select pill directly beneath it. */
.session-thumb-col { display: flex; flex-direction: column; gap: 5px; flex-shrink: 0; width: 56px; }
.session-thumb {
  width: 56px; height: 56px;
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #0a0c10;
}
/* The Active/Select pill spans the thumbnail width. Active reads as an accent pill (kept fully
   opaque despite being disabled, so it's a status rather than a greyed-out button). */
.session-btn.select { width: 100%; text-align: center; padding: 3px 4px; }
.session-btn.select.active-pill { opacity: 1; color: var(--accent); border-color: var(--accent); cursor: default; }
.session-item.racebox .session-btn.select.active-pill { color: var(--red); border-color: var(--red); }
.session-info { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.session-track { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-meta { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-badges { display: flex; align-items: center; gap: 6px; margin-top: 2px; flex-wrap: wrap; }

.session-badge {
  font-size: 9px;
  letter-spacing: 0.06em;
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid var(--border);
  color: var(--muted);
}
.session-badge.saved      { color: var(--green);  border-color: var(--green); }
.session-badge.unsaved    { color: var(--orange); border-color: var(--orange); }
.session-badge.loaded     { color: var(--accent); border-color: var(--accent); }
.session-badge.building   { color: var(--accent); border-color: var(--accent); }
.session-badge.comparison { color: var(--yellow); border-color: var(--yellow); }

/* Load-progress bar shown while a session is building. */
.session-progress {
  height: 3px;
  margin-top: 5px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 2px;
  overflow: hidden;
}
.session-progress-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.15s;
}

/* RaceBox sessions use a red accent (thumbnail reddened in drawSessionThumb). */
.session-item.racebox.active { border-color: var(--red); background: rgba(239, 68, 68, 0.08); }
.session-item.racebox .session-badge.loaded,
.session-item.racebox .session-badge.building,
.session-item.racebox .session-badge.type { color: var(--red); border-color: var(--red); }
.session-item.racebox .session-progress-fill { background: var(--red); }

.session-actions-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.session-btn {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.session-btn:hover { color: var(--text); border-color: var(--muted); }
.session-btn:disabled { opacity: 0.5; cursor: default; }
.session-btn.save:hover:not(:disabled)   { color: var(--green); border-color: var(--green); }
.session-btn.unload:hover:not(:disabled) { color: var(--red);   border-color: var(--red); }

#session-resize-handle {
  position: absolute;
  top: 0; right: -3px;
  width: 6px; height: 100%;
  cursor: col-resize;
  z-index: 10;
}

/* ---- Welcome / Home page ---- */
#page-welcome {
  flex: 1;
  overflow-y: auto;
  padding: 40px;
}
#welcome-wrap { max-width: 920px; margin: 0 auto; }
#welcome-wrap h2 { font-size: 28px; margin-bottom: 8px; }
.welcome-lead { color: var(--muted); margin-bottom: 24px; font-size: 15px; }
#welcome-cta { display: flex; gap: 12px; margin-bottom: 32px; flex-wrap: wrap; }
#welcome-cta button {
  padding: 12px 22px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 14px;
}
#welcome-load-btn:hover   { border-color: var(--accent); color: var(--accent); }
#welcome-record-btn:hover { border-color: var(--red);    color: var(--red); }
#welcome-help {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 16px;
}
.welcome-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
}
.welcome-card h3 { font-size: 14px; margin-bottom: 8px; }
.welcome-card p { font-size: 12px; color: var(--muted); line-height: 1.6; }
.welcome-card code { font-family: var(--font-mono); color: var(--text); }

/* ---- Header ---- */
header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  height: 52px;
  flex-shrink: 0;
}

header h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text);
}

/* ---- Page tabs ---- */
#page-tabs {
  display: flex;
  gap: 2px;
  background: var(--bg);
  border-radius: 7px;
  padding: 2px;
  border: 1px solid var(--border);
  margin-right: auto;
}

.page-btn {
  padding: 4px 12px;
  border-radius: 5px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.05em;
}

.page-btn.active {
  background: var(--border);
  color: var(--text);
}

.pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
  background: var(--bg);
  border: 1px solid var(--border);
}

.pill .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}

.pill.rec .dot      { background: var(--red); animation: blink 1s step-start infinite; }
.pill.conn .dot     { background: var(--green); }
.pill.search .dot   { background: var(--yellow); animation: blink 1.5s step-start infinite; }

@keyframes blink {
  50% { opacity: 0; }
}

#help-btn {
  padding: 5px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
#help-btn:hover { background: var(--border); }

/* PS5 status group — sits with the Help button as one right-anchored cluster
   (only #page-tabs's margin-right:auto pushes right, so nothing drifts). */
#conn-status { display: flex; align-items: center; gap: 8px; }
#conn-status-label { color: var(--muted); font-size: 12px; font-weight: 600; white-space: nowrap; }

/* ---- Generic session dialog ---- */
#app-dialog {
  position: fixed;
  inset: 0;
  background: rgba(13, 15, 20, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
#app-dialog-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 300px;
  max-width: 420px;
}
#app-dialog-msg { font-size: 13px; font-weight: 600; color: var(--text); line-height: 1.5; }
#app-dialog-buttons { display: flex; gap: 8px; }
.app-dialog-btn {
  flex: 1;
  padding: 7px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.app-dialog-btn:hover { background: var(--border); }
.app-dialog-btn.primary { border-color: var(--green); color: var(--green); }
.app-dialog-btn.danger  { border-color: var(--red);   color: var(--red); }
.app-dialog-btn.muted   { color: var(--muted); }
.app-dialog-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.app-dialog-btn:disabled:hover { background: var(--surface); }
/* The Add-to picker stacks its destinations vertically so long labels/reasons fit. */
#app-dialog-buttons { flex-wrap: wrap; }

/* ---- Comparison Sessions: floating lap-selection action bar ---- */
#selection-bar {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  z-index: 900;
}
#selection-count { font-size: 12px; font-weight: 700; color: var(--accent); white-space: nowrap; }
#selection-bar-actions { display: flex; gap: 8px; }
#selection-bar-actions button {
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
#selection-bar-actions button:hover { background: var(--border); }
#selection-create { border-color: var(--green); color: var(--green); }
#selection-bar-actions button.muted { color: var(--muted); }

/* Selected lap highlight + inline checkbox (GT7/RaceBox tables + lanes). */
.lap-select-cb { cursor: pointer; accent-color: var(--accent); vertical-align: middle; }
.lap-selected { outline: 1px solid var(--accent); outline-offset: -1px; }

/* Provenance/source tag shown on composed comparison laps. */
.lap-source-tag { color: var(--muted); font-size: 10px; font-weight: 600; margin-left: 6px; }

/* ---- Page containers ---- */
#page-dash {
  flex: 0 0 55%;
  min-height: 0;
  overflow: hidden;
}

/* ---- Main layout ---- */
main {
  display: flex;
  flex-direction: row;
  gap: 10px;
  padding: 12px 16px;
  height: 100%;
  overflow: hidden;
}

#gauge-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
  overflow: hidden;
}

#lapmap-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

#lapmap-card {
  flex: 1;
  min-height: 0;
}

#lapmap-canvas {
  display: block;
  width: 100%;
  flex: 1;
  min-height: 0;
}

.row {
  display: grid;
  gap: 10px;
  flex: 1;
  min-height: 0;
}

.row-1 { grid-template-columns: 1fr 2fr; }
.row-2 { grid-template-columns: 1fr; }
.row-3 { grid-template-columns: 1fr 3fr; }

/* ---- Card ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.card-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
  flex-shrink: 0;
}

/* ---- Speed card ---- */
.speed-value {
  font-size: clamp(42px, 6vw, 72px);
  font-weight: 800;
  font-family: var(--font-mono);
  line-height: 1;
  letter-spacing: -2px;
  flex: 1;
  display: flex;
  align-items: center;
}

.speed-unit {
  font-size: 14px;
  font-weight: 400;
  color: var(--muted);
  margin-left: 6px;
  align-self: flex-end;
  margin-bottom: 4px;
}

/* ---- RPM gauge ---- */
#rpm-card {
  align-items: center;
  justify-content: center;
}

.rpm-wrapper {
  width: 100%;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

#rpm-svg {
  width: 100%;
  height: 100%;
  max-width: 160px;
  max-height: 160px;
}

.rpm-center-text {
  position: absolute;
  text-align: center;
  pointer-events: none;
}
.rpm-number {
  font-size: clamp(20px, 3vw, 32px);
  font-weight: 800;
  font-family: var(--font-mono);
  letter-spacing: -1px;
}
.rpm-label {
  font-size: 10px;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

/* ---- Tire grid ---- */
.tire-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  flex: 1;
  min-height: 0;
}

.tire-cell {
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6px;
  background: var(--bg);
  border: 2px solid var(--border);
  transition: background 0.3s, border-color 0.3s;
  min-height: 0;
}

.tire-cell-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.tire-cell-value {
  font-size: clamp(14px, 2vw, 20px);
  font-weight: 700;
  font-family: var(--font-mono);
}

/* ---- Bar charts ---- */
.bar-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
}

.bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.bar-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  width: 60px;
  color: var(--muted);
  flex-shrink: 0;
}

.bar-track {
  flex: 1;
  height: 18px;
  background: var(--bg);
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.bar-fill {
  height: 100%;
  width: 0%;
  border-radius: 4px;
  transition: width 0.05s linear;
}

.bar-fill.throttle { background: var(--green); }
.bar-fill.brake    { background: var(--red); }

.bar-pct {
  font-size: 12px;
  font-weight: 700;
  font-family: var(--font-mono);
  width: 38px;
  text-align: right;
  flex-shrink: 0;
}

/* ---- Gear / Lap info ---- */
.big-gear {
  font-size: clamp(60px, 10vw, 120px);
  font-weight: 900;
  font-family: var(--font-mono);
  line-height: 1;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: -4px;
}

.lap-info {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

.lap-stat {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
}

.lap-stat-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}

.lap-stat-value {
  font-size: clamp(14px, 2vw, 20px);
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text);
}

/* ---- Grip grid (same as tire grid, different header) ---- */
.grip-cell {
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6px;
  background: var(--bg);
  border: 2px solid var(--border);
  transition: border-color 0.3s;
}

.grip-cell-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.grip-cell-value {
  font-size: clamp(14px, 2vw, 18px);
  font-weight: 700;
  font-family: var(--font-mono);
}

/* ---- Scrollable last row ---- */
.car-name {
  font-size: 12px;
  color: var(--text);
  font-family: var(--font-mono);
  padding-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}


/* ---- Trace panel ---- */
#traces {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
  background: var(--bg);
  border-top: 1px solid var(--border);
  padding: 0 0 16px;
}

/* Sticky timeline head: distance ruler, then (Video-only) delta + analysis lanes,
   stacked at fixed offsets so only #lap-list scrolls beneath them.
   Heights: ruler 28 · delta 64 · analysis 30. */
/* z-order matches RaceBox so the one dashed #crosshair (z:10) spans the delta +
   analysis lanes (z:9, below it) and the scrolling lap lanes, while the ruler
   (z:11, above it) draws its own hover tick. */
#dist-ruler {
  display: block;
  width: calc(100% - 32px);  /* 16px margin each side, same as .lap-block */
  margin: 0 16px;
  height: 28px;
  position: sticky;
  top: 0;
  z-index: 11;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

/* Video Delta lane — reuses renderDelta; sticky directly below the ruler. */
#video-delta {
  width: calc(100% - 32px);
  margin: 0 16px;
  height: 64px;
  position: sticky;
  top: 28px;
  z-index: 9;                /* under the crosshair (10), over the scrolling lanes */
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

/* Analysis Lanes — the selected card's events for the fastest (top) and pinned
   (below) laps (Video page only). Sticky below the ruler + delta. */
.analysis-lane {
  width: calc(100% - 32px);
  margin: 0 16px;
  height: 30px;
  position: sticky;
  z-index: 9;                /* under the crosshair (10), over the scrolling lanes */
  background: var(--bg);
}
#analysis-lane   { top: 92px; }   /* 28 (ruler) + 64 (delta) */
#analysis-lane-2 { top: 122px; }  /* + 30 (first analysis lane) */

.lap-block {
  margin: 0 16px 12px;
  position: relative;
}

.lap-block-header {
  display: flex;
  align-items: center;
  font-size: 11px;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0 4px 4px 52px;  /* 52px = PAD_LEFT, matches canvas left padding */
  cursor: pointer;
  user-select: none;
}
.lap-pin {
  margin-left: auto;
  padding: 0 2px;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s;
}
.lap-pin:hover { color: var(--text); }
.lap-pin.active { color: var(--accent); }
.pin-btn {
  cursor: pointer;
  color: var(--muted);
  transition: color 0.15s;
}
.pin-btn:hover { color: var(--text); }
.pin-btn.active { color: var(--accent); }
.lap-del {
  margin-left: 6px;
  padding: 0 2px;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s;
}
.lap-del:hover { color: var(--red); }
.del-btn {
  cursor: pointer;
  color: var(--muted);
  margin-left: 4px;
  transition: color 0.15s;
}
.del-btn:hover { color: var(--red); }

/* Pill-style lap actions in the lap-lane headers — reuse the Session panel's
   .session-btn look, adding only layout + the pin-active / delete-hover accents. */
.lap-toggle-btn { margin-right: 8px; }
/* Δ-from-best chip in a lap lane header, after the lap time (colour set inline). */
.lap-header-delta { margin-left: 8px; letter-spacing: 0.04em; white-space: nowrap; }
.lap-pin-btn { margin-left: auto; }
.lap-del-btn { margin-left: 6px; }
.lap-pin-btn.active { color: var(--accent); border-color: var(--accent); }
.lap-del-btn:hover  { color: var(--red);    border-color: var(--red); }

.lap-toggle {
  display: inline-block;
  margin-right: 5px;
  transition: transform 0.15s;
}

.lap-block.collapsed .lap-toggle { transform: rotate(-90deg); }
/* Collapsed: keep only the TOP lane visible (GT7 T/B, RaceBox MPH) at one-lane
   height — the canvas is re-rendered with a single lane; the display height matches. */
.lap-block.collapsed canvas.lap-canvas          { height: 44px; }   /* 176/4 — one lane */
.lap-block.collapsed canvas.racebox-lane-canvas { height: 60px; }   /* 120/2 — one lane */
/* Collapsed lanes keep their hover readout — the updaters show only the top lane's
   value (the other lane spans are hidden in JS). */

.lap-block.trace-hover {
  background: rgba(255,255,255,0.03);
  border-radius: 6px;
}

canvas.lap-canvas {
  display: block;
  width: 100%;
  height: 176px;
}

#crosshair {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  /* dashed vertical line, matching the RaceBox crosshair. It spans the delta +
     analysis lanes (z:9, below) and the scrolling lap lanes; the ruler (z:11, above)
     draws its own hover tick. */
  background-image: repeating-linear-gradient(to bottom, rgba(255,255,255,0.45) 0 4px, transparent 4px 8px);
  pointer-events: none;
  display: none;
  z-index: 10;
}

.hover-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
}

.hover-val {
  position: absolute;
  font-size: 10px;
  font-weight: 700;
  font-family: var(--font-mono);
  background: rgba(13, 15, 20, 0.85);
  padding: 1px 4px;
  border-radius: 3px;
  white-space: nowrap;
  transform: translateY(-50%);
}

/* ---- Summary page layout ---- */
#page-summary {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  gap: 10px;
  padding: 10px 16px;
}

#delta-section {
  flex-shrink: 0;
}

#delta-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding-left: 52px;
  margin-bottom: 2px;
  cursor: pointer;
  user-select: none;
}

#delta-toggle {
  display: inline-block;
  font-size: 10px;
  color: var(--muted);
  transition: transform 0.15s;
  margin-left: -16px;  /* pull back inside the 52px left pad */
  margin-right: 6px;
}

#delta-toggle.expanded {
  transform: rotate(180deg);
}

#delta-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

#delta-ref-label {
  font-size: 10px;
  color: var(--muted);
  font-family: var(--font-mono);
}

#delta-canvas {
  display: block;
  width: 100%;
}

/* Top row: Session info (30%) | Sector Map (70%), side by side, fixed height */
#summary-top {
  display: grid;
  grid-template-columns: 30fr 70fr;
  gap: 10px;
  flex: 0 0 auto;
  height: 42vh;
  min-height: 260px;
}

#summary-map-card {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#summary-map {
  flex: 1;
  min-height: 0;
  display: block;
  width: 100%;
}

/* Session info: left column of the top row; sections flow into as many columns as fit
   (usually 1 in this narrow column), scrolls if it overflows the row height. */
#summary-meta-card {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
}
#summary-meta {
  font-size: 12px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 4px 20px;
  align-items: start;
}
.summary-meta-section { margin-bottom: 8px; break-inside: avoid; }
.summary-meta-section:last-child { margin-bottom: 0; }
.summary-meta-title {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  padding-bottom: 3px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--border);
}
.summary-meta-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 2px 0;
}
.summary-meta-key { color: var(--muted); white-space: nowrap; }
.summary-meta-val {
  color: var(--text);
  font-family: var(--font-mono);
  text-align: right;
}
.summary-meta-empty { color: var(--muted); font-style: italic; }

/* Lap Summary card — middle column of the top row; the table scrolls within it. */
/* Lap Summary — left cell of the row; fills the cell height, table scrolls internally. */
#summary-lapsum-card {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#summary-lapsum-wrap {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

/* Lap telemetry statistics */
#summary-stats-card {
  display: flex;
  flex-direction: column;
  flex: 1 0 auto;
  min-height: 0;
}
#summary-stats { display: flex; flex-direction: column; gap: 12px; }
.summary-stats-empty { color: var(--muted); font-style: italic; }

.summary-signal-bar {
  display: flex;
  align-items: center;
  gap: 10px;
}
.summary-signal-bar label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.summary-signal {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  font-family: var(--font-mono);
  font-size: 12px;
  cursor: pointer;
}
.summary-signal-note { font-size: 11px; color: var(--muted); font-style: italic; }

.summary-stats-body {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 1.4fr;
  gap: 16px;
  align-items: start;
}

.summary-stat-table table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 12px;
}
.summary-stat-table th {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  text-align: right;
  padding: 2px 6px 4px;
  border-bottom: 1px solid var(--border);
}
.summary-stat-table th:first-child { text-align: left; }
.summary-stat-table td {
  text-align: right;
  padding: 3px 6px;
  color: var(--text);
  border-bottom: 1px solid rgba(37, 40, 48, 0.5);
}
.summary-stat-table td.metric { text-align: left; color: var(--muted); }
.summary-stat-n { font-size: 10px; color: var(--muted); padding-top: 4px; }

.summary-viz { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.summary-viz-title {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.summary-hist, .summary-box { display: block; width: 100%; }
.summary-legend { display: flex; gap: 14px; font-size: 11px; color: var(--muted); }
.summary-legend-item { display: inline-flex; align-items: center; gap: 5px; }
.summary-legend-swatch { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }

/* GT7 Lap Summary — flex-row list styled like the RaceBox table (.lap-row), with the
   GT7 columns. Whole-row click pins; zebra-striped; the fastest lap row reads green. */
#lap-table { font-size: 12px; font-family: var(--font-mono); }
.lap-row {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 5px 10px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  color: var(--text);
}
.lap-row:hover    { background: rgba(255,255,255,0.03); }
.lap-row.selected { background: rgba(59,130,246,0.12); }
#lap-table-body .lap-row:nth-child(even) { background: rgba(255,255,255,0.02); }
#lap-table-body .lap-row:nth-child(even):hover    { background: rgba(255,255,255,0.045); }
#lap-table-body .lap-row.selected,
#lap-table-body .lap-row.selected:hover { background: rgba(59,130,246,0.12); }
.lap-row.ref-lap .lap-c-lap { color: var(--green); }
/* Columns: lap label flexes; numeric columns are fixed-width + right-aligned. */
.lap-c-lap   { flex: 1 1 auto; min-width: 0; display: flex; align-items: center; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lap-c-time  { flex: 0 0 64px; text-align: right; color: var(--accent); }
.lap-c-delta { flex: 0 0 68px; text-align: right; color: var(--muted); }
.lap-c-fuel  { flex: 0 0 56px; text-align: right; }
.lap-c-temp  { flex: 0 0 56px; text-align: right; }
.lap-c-tcs   { flex: 0 0 56px; text-align: right; display: flex; justify-content: flex-end; align-items: center; }
.lap-row.header {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  cursor: default;
  font-size: 9px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted);
}
.lap-row.header:hover { background: var(--surface); }

/* ---- Sector Summary ---- */
/* flex: 0 0 auto (never shrink) so the card keeps its natural height and #page-summary
   scrolls through it — matching #summary-top / #summary-lapsum-card. Without this it was
   the only shrinkable sibling next to the grow:1/shrink:0 stats card, so it absorbed all
   the overflow and collapsed instead of scrolling into view. */
#summary-sectors-card { display: flex; flex-direction: column; flex: 0 0 auto; min-height: 0; }

/* Control bar under the title: Sectors slider · Signal · (RaceBox) Real|Dynamic toggle. */
.sector-controls { display: flex; align-items: center; gap: 18px; margin-bottom: 10px; flex-wrap: wrap; }
.sector-count-control, .sector-signal-control { display: inline-flex; align-items: center; gap: 8px; }
.sector-controls label {
  font-size: 10px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted);
}
.sector-count-control input[type="range"] { width: 128px; accent-color: var(--accent); cursor: pointer; }
.sector-count-control output {
  font-family: var(--font-mono); font-size: 12px; font-weight: 700; color: var(--text);
  min-width: 16px; text-align: right;
}
.sector-signal-control select {
  background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 6px;
  padding: 4px 8px; font-family: var(--font-mono); font-size: 12px; cursor: pointer;
}
/* .seg sets display:inline-flex, which would beat the [hidden] UA rule — restore it so
   the toggle genuinely disappears for GT7 (RaceBox-only control). */
#sector-mode-control[hidden] { display: none; }

#summary-sectors { display: flex; flex-direction: column; gap: 14px; }
.summary-sectors-empty { color: var(--muted); font-style: italic; }

/* Lap × sector split table. table-layout:fixed + width:100%: every real column has a fixed
   width and a trailing empty spacer column (.sector-spacer, width:auto) absorbs the slack —
   so the data columns stay compact/contiguous (Δ Best sits right after Lap Time) while the
   row background still draws full width to the edge. S1-S3 stay put as N changes; many
   sectors overflow → wrap scrolls. */
.sector-table-wrap { overflow-x: auto; }
.sector-table { width: 100%; table-layout: fixed; border-collapse: collapse; font-family: var(--font-mono); font-size: 12px; white-space: nowrap; }
.sector-table th {
  font-size: 9px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--muted); text-align: right; padding: 2px 8px 4px; border-bottom: 1px solid var(--border);
}
.sector-table th:first-child { text-align: left; }
.sector-table td { text-align: right; padding: 3px 8px; color: var(--text); border-bottom: 1px solid rgba(37,40,48,0.5); }
.sector-table td.lap-cell { text-align: left; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.sector-table td.lap-cell svg { vertical-align: middle; }
/* Fixed column widths: lap name, uniform sectors, Lap Time, trailing stats. The empty
   .sector-spacer column is left unsized so it absorbs the slack out to the edge. */
.sector-table .sector-lap-col,  .sector-table td.lap-cell   { width: 150px; }
.sector-table .sector-col                                   { width: 74px; }
.sector-table .sector-time-col, .sector-table td.lap-time   { width: 92px; }
.sector-table .sector-trail-col                             { width: 68px; }
.sector-table .sector-spacer                                { width: auto; }
.sector-table td.lap-time { color: var(--text); font-weight: 700; }
.sector-table td.best-cell { color: var(--green); font-weight: 700; }   /* fastest in this sector column */
/* Lap rows: single click pins; zebra-striped; hover + pinned highlight. */
.sector-table tr.sector-lap-row { cursor: pointer; }
.sector-table tbody tr.sector-lap-row:nth-child(even) td { background: rgba(255,255,255,0.02); }
.sector-table tbody tr.sector-lap-row:hover td { background: rgba(255,255,255,0.045); }
.sector-table tbody tr.sector-lap-row.selected td { background: rgba(59,130,246,0.12); }
/* Theoretical-best row: all times green (the owning-lap colour lives on the map). */
.sector-table tr.theory-row td { border-top: 1px solid var(--border); border-bottom: none; padding-top: 6px; color: var(--green); }
.sector-table tr.theory-row td.lap-cell { color: var(--green); font-weight: 700; text-transform: none; }

/* Stitched theoretical-best lane (full width; the map now lives in the top row) */
.sector-viz-block { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.sector-viz-title {
  font-size: 9px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
#sector-lane { display: block; width: 100%; height: 128px; cursor: crosshair; }
.sector-lane-signal {
  background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 6px;
  padding: 3px 7px; font-family: var(--font-mono); font-size: 11px; cursor: pointer; text-transform: none; letter-spacing: 0;
}

/* ---- Drag-and-drop overlay ---- */
body.drag-active::after {
  content: 'Drop a .gt7raw or RaceBox .csv to load';
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--accent);
  background: rgba(13, 15, 20, 0.75);
  border: 2px dashed var(--accent);
  border-radius: 4px;
  pointer-events: none;
  z-index: 999;
}

/* ---- Analysis page ---- */
#page-analysis {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  padding: 10px 16px;
  gap: 8px;
}

#analysis-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-size: 11px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

#analysis-subject-label { color: var(--text); font-weight: 700; }
#analysis-ref-label      { color: var(--muted); }

/* Three-area comparative layout: cards (left ~50%, scrolls) | map (top-right) +
   coaching (bottom-right, scrolls). */
#analysis-body {
  flex: 1;
  display: flex;
  gap: 12px;
  min-height: 0;
}
#analysis-left {
  flex: 1 1 50%;
  min-width: 0;
  overflow-y: auto;
}
#analysis-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
#analysis-right {
  flex: 1 1 50%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}
#analysis-map-wrap {
  flex: 1 1 50%;
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  overflow: hidden;
  position: relative;
}
#analysis-map { display: block; width: 100%; height: 100%; }
#analysis-map-toggle {
  position: absolute;
  top: 8px; right: 8px;
  z-index: 2;
  background: rgba(13, 15, 20, 0.7);
}
#analysis-map-toggle .seg-btn:disabled { opacity: 0.35; cursor: default; }

#analysis-coaching {
  flex: 1 1 50%;
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
}
#coach-view-toggle { margin: 0 0 12px; }
#coach-narrative-headline { font-size: 12.5px; line-height: 1.5; color: var(--text); margin-bottom: 14px; font-weight: 600; }
#coach-narrative-closing { font-size: 12px; line-height: 1.6; color: var(--muted); margin-top: 12px; font-style: italic; }
/* Continuous prose: 2–3 big flowing paragraphs, each section an inline clickable span. */
#coach-narrative-body { font-size: 12.5px; line-height: 1.7; color: var(--text); }
/* Running time standing, coloured by whether the gap is getting worse (red) or better (green). */
.gap-worse { color: var(--red); font-weight: 600; }
.gap-better { color: var(--green); font-weight: 600; }
.gap-flat { color: var(--muted); }
.coach-narrative-para { margin: 0 0 1em; }
.coach-narrative-para:last-child { margin-bottom: 0; }
.coach-narrative-seg { border-radius: 3px; transition: background 0.12s ease; }
.coach-narrative-seg.selectable { cursor: pointer; }
.coach-narrative-seg.selectable:hover { background: rgba(148,163,184,0.14); }
.coach-narrative-seg.selected { background: rgba(245,158,11,0.16); color: var(--text); }
.coach-section { margin-bottom: 14px; }
.coach-heading {
  font-size: 10px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 6px;
}
#coach-summary { font-size: 13px; line-height: 1.55; color: var(--text); }
#coach-why {
  margin-top: 6px; font-size: 11px; line-height: 1.5; color: var(--muted);
  font-style: italic; border-left: 2px solid var(--border); padding-left: 8px;
}
.coach-insight { margin-bottom: 10px; }
.coach-insight-title { font-size: 12px; font-weight: 700; color: var(--text); margin-bottom: 3px; }
.coach-n { display: inline-block; margin-right: 6px; color: var(--accent); font-family: var(--font-mono); }
.coach-insight-body { font-size: 12px; line-height: 1.5; color: var(--muted); }
.coach-corner {
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px;
  transition: border-color 0.12s, background 0.12s;
}
.coach-corner.selectable { cursor: pointer; }
.coach-corner.selectable:hover { border-color: var(--accent); }
.coach-corner.selected {
  border-color: #f59e0b; background: rgba(245,158,11,0.08);
}
.coach-corner.selected .coach-corner-label { color: #f59e0b; }
.coach-corner-label { font-size: 12px; font-weight: 700; color: var(--text); margin-bottom: 5px; }
.coach-row { font-size: 12px; line-height: 1.5; color: var(--muted); margin-bottom: 2px; }
.coach-tag {
  display: inline-block; min-width: 54px; margin-right: 6px; font-size: 9px; font-weight: 700;
  letter-spacing: 0.04em; text-transform: uppercase;
}
.coach-tag.fast  { color: var(--green); }
.coach-tag.pin   { color: var(--accent); }
.coach-tag.coach { color: var(--yellow); }
.coach-empty { font-size: 12px; color: var(--muted); }

.analysis-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 0;
}

/* Diagnostic-workflow selection: one active card at a time (drives the Video-page
   Analysis Lane). Reuses the accent active-state language of tabs/sessions. */
.analysis-card.selectable { cursor: pointer; transition: border-color 0.12s, box-shadow 0.12s; }
.analysis-card.selectable:hover { border-color: var(--muted); }
.analysis-card.active { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.analysis-step {
  display: inline-flex; align-items: center; justify-content: center;
  width: 15px; height: 15px; margin-right: 7px; border-radius: 50%;
  background: var(--border); color: var(--text);
  font-size: 9px; font-weight: 700; letter-spacing: 0; vertical-align: middle;
}
.analysis-card.active .analysis-step { background: var(--accent); color: #fff; }
.analysis-video-hint { display: none; margin-left: 8px; color: var(--accent); font-size: 9px; font-weight: 700; letter-spacing: 0.04em; }
.analysis-card.active .analysis-video-hint { display: inline; }

.analysis-metric {
  font-size: 26px;
  font-weight: 800;
  font-family: var(--font-mono);
  letter-spacing: -1px;
  color: var(--text);
  line-height: 1.1;
  flex-shrink: 0;
}

.analysis-canvas {
  display: block;
  width: 100%;
  flex: 1;
  min-height: 55px;
  max-height: 80px;
}

.analysis-what {
  font-size: 12px;
  color: var(--text);
  line-height: 1.45;
  flex-shrink: 0;
  padding-bottom: 5px;
  border-bottom: 1px solid var(--border);
}

.analysis-data-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  cursor: help;
}

#analysis-tooltip {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.5;
  max-width: 280px;
  z-index: 500;
  pointer-events: none;
  display: none;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}

.analysis-advice {
  font-size: 12px;
  color: #ffffff;
  line-height: 1.5;
  flex-shrink: 0;
}

#analysis-placeholder {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-family: var(--font-mono);
  color: var(--muted);
}

/* ── Video Page ── */
#page-video {
  flex: 0 0 55%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#video-controls-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  font-size: 12px;
  font-family: var(--font-mono);
  background: var(--surface);
}

.video-ctrl-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .06em;
  color: var(--muted);
  text-transform: uppercase;
}

#video-controls-bar select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  padding: 3px 6px;
  font-size: 12px;
  font-family: var(--font-mono);
}

#video-refresh-btn,
#video-sync-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 11px;
  font-family: var(--font-mono);
  cursor: pointer;
  transition: border-color .15s, color .15s;
}
#video-refresh-btn:hover         { border-color: var(--accent); color: var(--accent); }
#video-sync-btn:not(:disabled):hover { border-color: var(--green); color: var(--green); }
#video-sync-btn:disabled         { color: var(--muted); cursor: default; }
#video-sync-btn.synced           { border-color: var(--green); color: var(--green); }

.video-sep        { color: var(--border); }
#video-sync-status { color: var(--muted); font-size: 11px; flex: 1; }

#video-panels {
  display: flex;
  gap: 8px;
  flex: 1;
  padding: 8px;
  overflow: hidden;
  min-height: 0;
}

.video-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  min-width: 0;
  position: relative;   /* positioning context for the overlaid corner-names toggle */
}

.video-panel-label {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--muted);
  padding: 5px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.video-panel video {
  flex: 1;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  min-height: 0;
}

.video-render-canvas,
.video-map-canvas {
  flex: 1;
  width: 100%;
  height: 100%;
  display: block;
  background: #000;
  min-height: 0;
}
.video-map-canvas { background: var(--bg); }

/* Corner-names toggle overlaid on every lap map (bottom-left, clear of other controls). */
.corner-toggle {
  position: absolute;
  left: 8px;
  bottom: 8px;
  z-index: 4;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(13, 15, 20, 0.72);
  color: var(--muted);
  border: 1px solid var(--border);
  font: 700 10px/1 var(--font-mono);
  letter-spacing: 0.05em;
  cursor: pointer;
  white-space: nowrap;
  transition: color .15s, border-color .15s;
}
.corner-toggle:hover { color: var(--text); }
.corner-toggle.on { color: var(--text); border-color: var(--accent); }

/* Overlay hosts need a positioning context (analysis wrap + video panel already have one). */
#lapmap-card, #summary-map-card { position: relative; }

/* map-only toggles (Video / RaceBox) appear only when their map view is active. */
.corner-toggle.map-only { display: none; }
#page-video.view-maps .corner-toggle.map-only { display: block; }

/* Segmented toggle (like the header page tabs): all options visible, active one
   highlighted. Used for View (Video/Maps) + Source (Rendered/Video) on the VIDEO
   tab and the RaceBox panel. */
.ctrl-group { display: inline-flex; align-items: center; gap: 6px; }
.seg {
  display: inline-flex;
  gap: 2px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 2px;
}
.seg-btn {
  padding: 3px 10px;
  border: none;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  font-family: var(--font-mono);
  letter-spacing: 0.05em;
  cursor: pointer;
  white-space: nowrap;
  transition: color .15s, background .15s;
}
.seg-btn:hover:not(.active) { color: var(--text); }
.seg-btn.active { background: var(--border); color: var(--text); }

/* Mode visibility: the JS sets these classes on #page-video */
#page-video.src-rendered .video-panel video,
#page-video.src-rendered #video-file-controls { display: none; }
#page-video.src-video .video-render-canvas { display: none; }

/* Lap-map view: hide the video/render panels + the (now-irrelevant) source group +
   file controls, show the maps. Video view (default): hide the map canvases. */
.video-map-canvas { display: none; }
#page-video.view-maps .video-panel video,
#page-video.view-maps .video-render-canvas,
#page-video.view-maps #video-source-group,
#page-video.view-maps #video-file-controls { display: none; }
#page-video.view-maps .video-map-canvas { display: block; }

/* Same mode visibility for the RaceBox comparison panels (#page-racebox). */
#page-racebox.src-rendered #racebox-video-left,
#page-racebox.src-rendered #racebox-video-right,
#page-racebox.src-rendered #racebox-video-file-controls { display: none; }
#page-racebox.src-video .video-render-canvas { display: none; }

#video-mode-warning {
  margin: 10px 12px;
  padding: 8px 12px;
  background: rgba(234,179,8,.07);
  border: 1px solid var(--yellow);
  border-radius: 6px;
  font-size: 12px;
  color: var(--yellow);
  flex-shrink: 0;
}

/* ── Render Page (synthetic driver's-view) ── */
#page-render {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#render-controls-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  font-size: 12px;
  font-family: var(--font-mono);
  background: var(--surface);
}

#render-controls-bar select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  padding: 3px 6px;
  font-size: 12px;
  font-family: var(--font-mono);
}

#render-play-btn,
#render-speed-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  padding: 3px 10px;
  font-size: 12px;
  font-family: var(--font-mono);
  cursor: pointer;
  transition: border-color .15s, color .15s;
}
#render-play-btn:not(:disabled):hover,
#render-speed-btn:hover { border-color: var(--accent); color: var(--accent); }
#render-play-btn:disabled { color: var(--muted); cursor: default; }
#render-play-btn.playing { border-color: var(--green); color: var(--green); }

#render-scrub {
  flex: 1;
  accent-color: var(--accent);
  cursor: pointer;
}
#render-scrub:disabled { cursor: default; opacity: .4; }

#render-rec-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  padding: 3px 10px;
  font-size: 12px;
  font-family: var(--font-mono);
  cursor: pointer;
  white-space: nowrap;
  transition: border-color .15s, color .15s;
}
#render-rec-btn:not(:disabled):hover { border-color: var(--red); color: var(--red); }
#render-rec-btn:disabled { color: var(--muted); cursor: default; }
#render-rec-btn.recording { border-color: var(--red); color: var(--red); }

#render-scrub-status {
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

#render-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #000;
}

#render-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

#render-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 13px;
  font-family: var(--font-mono);
  text-align: center;
  padding: 0 20px;
}

/* ── RaceBox Page ── */
#page-racebox {
  flex: 0 0 55%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#racebox-controls-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  font-size: 12px;
  font-family: var(--font-mono);
  background: var(--surface);
}

/* :not(.seg-btn) so the segmented Source toggle keeps its own .seg-btn styling
   (this id-level rule would otherwise override .seg-btn.active). */
#racebox-video-controls-bar button:not(.seg-btn) {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 11px;
  font-family: var(--font-mono);
  cursor: pointer;
  transition: border-color .15s, color .15s;
}

#racebox-summary { color: var(--muted); font-size: 11px; flex: 1; }

#racebox-placeholder {
  margin: auto;
  color: var(--muted);
  font-size: 13px;
}

#racebox-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

#racebox-main {
  display: flex;
  gap: 8px;
  flex: 1;
  padding: 8px;
  overflow: hidden;
  min-height: 0;
}
/* The two comparison panels split the row evenly and fill its full width. */
#racebox-left-panel, #racebox-right-panel { flex: 1; }

/* The Summary page's RaceBox lap table (the RaceBox page's own laps/GPS side
   panel was removed). */
#summary-rbx-laptable {
  flex: 1;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: 11px;
}

.racebox-lap-row {
  display: flex;
  gap: 10px;
  padding: 5px 10px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.racebox-lap-row:hover    { background: rgba(255,255,255,0.03); }
/* Zebra striping (subtle) — header is the first child, so data rows start at nth 2. */
.racebox-lap-row:not(.header):nth-child(even) { background: rgba(255,255,255,0.02); }
.racebox-lap-row:not(.header):nth-child(even):hover { background: rgba(255,255,255,0.045); }
.racebox-lap-row.selected,
.racebox-lap-row.selected:hover { background: rgba(59,130,246,0.12); }
.racebox-lap-label   { flex: 0 0 84px; color: var(--text); }
.racebox-lap-time    { flex: 0 0 64px; color: var(--accent); }
.racebox-lap-delta   { flex: 0 0 60px; color: var(--muted); }
.racebox-lap-sectors { color: var(--muted); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Sticky column header. */
.racebox-lap-row.header {
  cursor: default;
  position: sticky;
  top: 0;
  background: var(--surface);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  z-index: 1;
}
.racebox-lap-row.header:hover { background: var(--surface); }
.racebox-lap-row.header span  { color: var(--muted); }

#racebox-video-controls-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  font-size: 11px;
  font-family: var(--font-mono);
}
#racebox-video-controls-bar select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  padding: 2px 4px;
  font-size: 11px;
  font-family: var(--font-mono);
  min-width: 0;
}
#racebox-sync-btn:not(:disabled):hover { border-color: var(--green); color: var(--green); }
#racebox-sync-btn:disabled             { color: var(--muted); cursor: default; }
#racebox-sync-btn.synced               { border-color: var(--green); color: var(--green); }
#racebox-sync-status { color: var(--muted); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* The comparison panels' <video> elements are styled by the shared .video-panel video rule. */

#racebox-traces {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
  background: var(--bg);
  border-top: 1px solid var(--border);
  padding: 0 0 16px;
}

#racebox-dist-ruler {
  display: block;
  width: calc(100% - 32px);
  margin: 0 16px;
  height: 28px;
  position: sticky;
  top: 0;
  z-index: 11;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

#racebox-crosshair {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  /* dashed vertical line, matching the GT7 lap-lane crosshair */
  background-image: repeating-linear-gradient(to bottom, rgba(255,255,255,0.45) 0 4px, transparent 4px 8px);
  pointer-events: none;
  display: none;
  z-index: 10;
}

/* RaceBox stacked lap lanes (Speed + G = 2 lanes × 60px). */
canvas.racebox-lane-canvas { display: block; width: 100%; height: 120px; }
canvas#racebox-delta-canvas { display: block; width: 100%; height: 80px; }
/* Keep the delta pinned below the sticky dist-ruler while the lap lanes scroll. */
#racebox-delta-block {
  position: sticky;
  top: 28px;                 /* dist-ruler height */
  z-index: 9;                /* under the ruler (11) + crosshair (10), over the lanes */
  background: var(--bg);
  margin-bottom: 0;
  padding-bottom: 10px;      /* inside the bg so scrolling lanes don't peek under it */
}
/* RaceBox analysis lanes (selected card's events, fastest + comparison). Scrolls with
   the lap lanes below the sticky delta block — full-width canvases like the delta. */
#racebox-analysis-block { margin-bottom: 6px; }
canvas.racebox-analysis-lane { display: block; width: 100%; height: 30px; }
canvas.racebox-analysis-lane + canvas.racebox-analysis-lane { margin-top: 1px; }
.racebox-delta-ref { margin-left: auto; color: var(--muted); font-weight: 400; text-transform: none; letter-spacing: 0; }
.lap-block-header-static { cursor: default; }
#racebox-lap-list .lap-block.selected { background: rgba(59,130,246,0.06); border-radius: 6px; }
#racebox-lap-list .lap-block.selected .lap-block-header { color: var(--text); }
.lap-block-star { color: var(--yellow); margin-left: 5px; }

/* ---------------------------------------------------------------------------
   Auth — login/signup overlay + account menu (S4d browser auth)
   --------------------------------------------------------------------------- */
#auth-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}
#auth-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 30px;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#auth-title { margin: 0; font-size: 20px; color: var(--text); font-family: var(--font-ui); }
#auth-sub   { margin: 0 0 14px; font-size: 12px; color: var(--muted); }
#auth-form  { display: flex; flex-direction: column; gap: 12px; }
.auth-field { display: flex; flex-direction: column; gap: 4px; }
.auth-field > span { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.auth-optional { font-weight: 400; text-transform: none; letter-spacing: 0; opacity: 0.75; }
.auth-field input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--text);
  font-size: 13px;
  font-family: var(--font-ui);
}
.auth-field input:focus { outline: none; border-color: var(--accent); }
.auth-error { min-height: 16px; font-size: 12px; font-weight: 600; color: var(--red); }
.auth-submit {
  margin-top: 4px;
  padding: 9px 12px;
  border-radius: 6px;
  border: 1px solid var(--green);
  background: var(--surface);
  color: var(--green);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.auth-submit:hover:not(:disabled) { background: rgba(34,197,94,0.1); }
.auth-submit:disabled { opacity: 0.5; cursor: not-allowed; }
.auth-switch { margin-top: 14px; font-size: 12px; color: var(--muted); text-align: center; }
.auth-switch a { color: var(--accent); text-decoration: none; margin-left: 4px; }
.auth-switch a:hover { text-decoration: underline; }
/* In login mode the signup-only fields are hidden via this class on the form. */
#auth-form.login-mode .auth-signup-only { display: none; }

/* Account menu in the header */
#account-menu { position: relative; }
#account-btn {
  display: flex; align-items: center; gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
#account-btn:hover { background: var(--border); }
.account-caret { color: var(--muted); font-size: 10px; }
#account-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px;
  min-width: 200px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  z-index: 1500;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.account-drop-email { padding: 6px 8px; font-size: 11px; color: var(--muted); word-break: break-all; }
.account-drop-item {
  text-align: left;
  background: none;
  border: none;
  border-radius: 5px;
  padding: 8px;
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.account-drop-item:hover { background: var(--border); }
.account-drop-item.danger { color: var(--red); }

/* ---------------------------------------------------------------------------
   Social — envelope + badge in the header, and the top-right overlay drawer
   (docs/social-features-plan.md §9). The drawer sits OVER the dashboard; it
   touches no session state, so closing restores the exact prior view.
   --------------------------------------------------------------------------- */
#social-btn {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 34px; height: 30px;
  color: var(--text);
  cursor: pointer;
}
#social-btn:hover { background: var(--border); }
#social-btn.active { border-color: var(--accent); color: var(--accent); }
.social-badge {
  position: absolute; top: -6px; right: -6px;
  min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 8px;
  background: var(--red); color: #fff;
  font-family: var(--font-mono); font-size: 10px; font-weight: 700; line-height: 16px;
  text-align: center;
  box-shadow: 0 0 0 2px var(--surface);
}

/* Non-modal, push-style: the panel is pinned to the right edge and the app shrinks to make
   room (see body.social-open). No scrim; the rest of the UI stays fully interactive. It
   closes only via the ✕ or when a shared session is opened. */
:root { --social-drawer-w: 380px; }
#social-drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: var(--social-drawer-w); max-width: 92vw;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -12px 0 32px rgba(0,0,0,0.45);
  z-index: 1601;
  display: flex; flex-direction: column;
  font-family: var(--font-ui);
}
#social-drawer[hidden] { display: none; }

#social-drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; border-bottom: 1px solid var(--border);
}
#social-tabs { display: flex; gap: 4px; }
.social-tab {
  display: inline-flex; align-items: center; gap: 6px;
  background: none; border: 1px solid transparent; border-radius: 6px;
  padding: 6px 10px; color: var(--muted);
  font-size: 12px; font-weight: 700; letter-spacing: 0.02em; cursor: pointer;
}
.social-tab:hover { color: var(--text); }
.social-tab.active { color: var(--text); background: var(--bg); border-color: var(--border); }
.social-tab-count {
  min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px;
  background: var(--red); color: #fff;
  font-family: var(--font-mono); font-size: 10px; line-height: 16px; text-align: center;
}
#social-close {
  background: none; border: none; color: var(--muted);
  font-size: 15px; cursor: pointer; padding: 4px 8px; border-radius: 6px;
}
#social-close:hover { color: var(--text); background: var(--border); }

.social-pane { flex: 1; overflow-y: auto; padding: 12px; }
.social-pane[hidden] { display: none; }
.social-addbar { display: flex; gap: 6px; margin-bottom: 6px; }
.social-addbar input {
  flex: 1; background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  padding: 8px 10px; color: var(--text); font-family: var(--font-mono); font-size: 12px;
}
.social-addbar input:focus { outline: none; border-color: var(--accent); }
.social-btn-primary {
  background: rgba(59,130,246,0.12); border: 1px solid var(--accent); color: var(--accent);
  border-radius: 6px; padding: 8px 12px; font-size: 12px; font-weight: 700; cursor: pointer;
}
.social-btn-primary:hover { background: rgba(59,130,246,0.2); }
.social-btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.social-hint { min-height: 14px; font-size: 11px; color: var(--muted); margin-bottom: 8px; }
.social-hint.ok  { color: var(--green); }
.social-hint.err { color: var(--red); }
.social-subhead {
  font-size: 10px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--muted); margin: 10px 2px 6px;
}
.social-list { display: flex; flex-direction: column; gap: 6px; }
.social-empty { font-size: 12px; color: var(--muted); padding: 8px 2px; }
.social-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
}
.social-row-main { flex: 1; min-width: 0; }
.social-row-name { font-size: 13px; font-weight: 600; color: var(--text); }
.social-row-sub  { font-size: 11px; color: var(--muted); font-family: var(--font-mono); }
.social-row-actions { display: flex; gap: 6px; }
.social-act {
  background: none; border: 1px solid var(--border); border-radius: 6px;
  padding: 5px 9px; font-size: 11px; font-weight: 700; color: var(--muted); cursor: pointer;
}
.social-act:hover { color: var(--text); border-color: var(--muted); }
.social-act.accept { color: var(--green); border-color: rgba(34,197,94,0.4); }
.social-act.accept:hover { background: rgba(34,197,94,0.12); }
.social-act.danger { color: var(--red); border-color: rgba(239,68,68,0.4); }
.social-act.danger:hover { background: rgba(239,68,68,0.12); }
/* Friend/request rows still get a plain unread dot; conversation rows carry a numeric
   count badge (.social-convo-badge) instead, so suppress the dot there. */
.social-row.unread .social-row-name::after {
  content: ''; display: inline-block; width: 7px; height: 7px; margin-left: 6px;
  border-radius: 50%; background: var(--accent); vertical-align: middle;
}
#social-convo-list .social-row.unread .social-row-name { font-weight: 700; }
#social-convo-list .social-row.unread .social-row-name::after { display: none; }
.social-convo-badge {
  flex: none; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--accent); color: #fff;
  font-family: var(--font-mono); font-size: 10px; font-weight: 700; line-height: 18px;
  text-align: center;
}

/* Messages — conversation thread + composer */
/* `:not([hidden])` so this column layout never overrides `.social-pane[hidden]` (equal
   specificity) and keeps the pane hidden when its tab is inactive. `overflow: hidden` (not the
   `.social-pane` default `auto`) so the pane is NOT a scroll container — only the inner
   conversation list / message list scrolls (two competing scrollers caused the judder). */
.social-pane[data-pane="messages"]:not([hidden]) { display: flex; flex-direction: column; overflow: hidden; }
/* List mode: the conversation list is the single scroller (needs min-height:0 to shrink). */
#social-convo-list { display: flex; flex-direction: column; gap: 6px; flex: 1; min-height: 0; overflow-y: auto; }
#social-thread { flex: 1; display: flex; flex-direction: column; min-height: 0; }
/* The list/thread toggle uses the `hidden` attribute; these ID+attr rules beat the ID
   `display:flex` above so hiding actually takes effect (Back returns to the list). */
#social-convo-list[hidden], #social-thread[hidden] { display: none; }
#social-thread-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
#social-thread-back {
  background: none; border: 1px solid var(--border); border-radius: 6px;
  color: var(--muted); font-size: 14px; cursor: pointer; padding: 3px 9px;
}
#social-thread-back:hover { color: var(--text); background: var(--border); }
#social-thread-name { font-size: 13px; font-weight: 700; color: var(--text); }
#social-thread-msgs {
  flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 6px;
  padding: 4px 2px;
}
.social-msg {
  max-width: 78%; padding: 7px 10px; border-radius: 10px;
  font-size: 13px; line-height: 1.35; word-wrap: break-word; white-space: pre-wrap;
}
.social-msg.theirs { align-self: flex-start; background: var(--bg); border: 1px solid var(--border); }
.social-msg.mine   { align-self: flex-end; background: rgba(59,130,246,0.15); border: 1px solid rgba(59,130,246,0.4); }
.social-msg-time { display: block; margin-top: 3px; font-size: 9px; color: var(--muted); font-family: var(--font-mono); }
#social-composer { display: flex; gap: 6px; margin-top: 8px; }
#social-composer input {
  flex: 1; background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  padding: 8px 10px; color: var(--text); font-size: 13px;
}
#social-composer input:focus { outline: none; border-color: var(--accent); }
#social-composer.readonly { display: none; }
.social-convo-preview { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Shared-snapshot markers in the Library + the share-session modal */
.lib-shared-chip {
  display: inline-block; margin-left: 6px; padding: 1px 6px; border-radius: 4px;
  font-size: 9px; font-weight: 800; letter-spacing: 0.04em;
  background: rgba(59,130,246,0.15); color: var(--accent); border: 1px solid rgba(59,130,246,0.4);
}
.lib-shared-prov { font-size: 10px; color: var(--accent); opacity: 0.85; margin-top: 2px; }
.social-msg.share { border-style: dashed; }
.social-msg.unavailable { opacity: 0.6; font-style: italic; border-style: dashed; }
/* Explicit, reliable action button on a received share card (single click). */
.social-share-btn {
  display: inline-block; margin-top: 6px;
  background: rgba(59,130,246,0.15); border: 1px solid var(--accent); color: var(--accent);
  border-radius: 6px; padding: 4px 10px; font-size: 11px; font-weight: 700; cursor: pointer;
}
.social-share-btn:hover { background: rgba(59,130,246,0.28); }
.social-msg-share-note {
  margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--border);
  font-size: 13px; color: var(--text); font-style: normal;
  white-space: pre-wrap; word-wrap: break-word;
}

#share-scrim { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 1700; }
#share-scrim[hidden], #share-modal[hidden] { display: none; }
#share-modal {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 380px; max-width: 92vw;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 18px; z-index: 1701; box-shadow: 0 16px 48px rgba(0,0,0,0.5);
  display: flex; flex-direction: column; gap: 12px;
}
#share-modal h3 { margin: 0; font-size: 15px; color: var(--text); }
.share-session-label { font-size: 12px; color: var(--muted); font-family: var(--font-mono); }
.share-field { display: flex; flex-direction: column; gap: 4px; }
.share-field > span { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.share-field select, .share-field textarea {
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  padding: 8px 10px; color: var(--text); font-size: 13px; font-family: var(--font-ui);
  resize: vertical;
}
.share-field select:focus, .share-field textarea:focus { outline: none; border-color: var(--accent); }
.share-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ---------------------------------------------------------------------------
   Session Library ("Library") — slide-in drawer beside the Open panel (L2)
   --------------------------------------------------------------------------- */
#library-drawer {
  flex: 0 0 340px;
  width: 340px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow: hidden;
}
#library-header {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; border-bottom: 1px solid var(--border);
}
#library-title { flex: 1; font-size: 12px; font-weight: 700; letter-spacing: 0.05em; color: var(--muted); }
#library-view-toggle { display: flex; gap: 2px; }
.lib-view-btn {
  background: var(--bg); border: 1px solid var(--border); color: var(--muted);
  border-radius: 5px; padding: 3px 7px; cursor: pointer; font-size: 12px;
}
.lib-view-btn.active { color: var(--text); border-color: var(--accent); }
.lib-tool-btn {
  background: var(--bg); border: 1px solid var(--border); color: var(--muted);
  border-radius: 5px; padding: 3px 7px; cursor: pointer; font-size: 12px; margin-left: 4px;
}
.lib-tool-btn:hover { color: var(--text); }
#library-refresh, #library-close-btn {
  background: none; border: none; color: var(--muted); cursor: pointer;
}
#library-refresh { font-size: 14px; }
#library-close-btn { font-size: 18px; line-height: 1; }
#library-refresh:hover, #library-close-btn:hover { color: var(--text); }
#library-controls {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 12px; border-bottom: 1px solid var(--border);
  font-size: 11px; color: var(--muted);
}
#library-controls label { display: flex; align-items: center; gap: 5px; }
#library-controls select {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 5px; padding: 3px 5px; font-size: 11px;
}
#library-selbar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; background: rgba(59,130,246,0.08); border-bottom: 1px solid var(--border);
}
#library-selcount { flex: 1; font-size: 11px; font-weight: 600; color: var(--text); }
.lib-selbar-actions { display: flex; gap: 6px; }
.lib-selbar-actions button, .lib-tile-actions button {
  font-size: 11px; padding: 3px 7px; border-radius: 5px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text); cursor: pointer;
}
.lib-selbar-actions button:hover, .lib-tile-actions button:hover { background: var(--border); }
.lib-selbar-actions .danger, .lib-tile-actions .danger { color: var(--red); }
.lib-selbar-actions .muted { color: var(--muted); }
.lib-star {
  background: none; border: none; cursor: pointer; padding: 0 3px;
  font-size: 14px; line-height: 1; color: var(--muted);
}
.lib-star:hover { color: var(--yellow); }
.lib-star.on { color: var(--yellow); }
#library-body { flex: 1; overflow-y: auto; padding: 6px 8px; }
#library-empty { padding: 20px 12px; text-align: center; font-size: 12px; color: var(--muted); line-height: 1.6; }
.lib-group-header {
  position: sticky; top: 0; z-index: 1;
  padding: 8px 4px 4px; font-size: 11px; font-weight: 700; color: var(--muted);
  background: var(--surface); cursor: pointer; user-select: none;
  display: flex; align-items: center; gap: 5px;
}
.lib-group-header:hover { color: var(--text); }
.lib-group-caret { display: inline-block; font-size: 9px; transition: transform 0.12s; }
.lib-group-header.collapsed .lib-group-caret { transform: rotate(-90deg); }
.lib-group-count { color: var(--border); font-weight: 400; }
.lib-group.collapsed { display: none; }
.lib-group { display: flex; flex-direction: column; gap: 2px; }
#library-body.cards-view .lib-group { gap: 8px; margin-bottom: 8px; }

/* list rows */
.lib-row {
  position: relative;
  display: flex; align-items: center; gap: 8px;
  padding: 6px 4px; border-radius: 6px; cursor: pointer;
}
.lib-row:hover { background: var(--bg); }
.lib-row.selected { background: rgba(59,130,246,0.10); }
.lib-row input, .lib-card input { cursor: pointer; flex-shrink: 0; }
.lib-row-main { flex: 1; min-width: 0; }
.lib-row-title { display: flex; align-items: center; gap: 6px; min-width: 0; font-size: 12px; color: var(--text); }
.lib-title-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.lib-cmp-chip {
  flex-shrink: 0; font-size: 8px; font-weight: 700; letter-spacing: 0.03em; line-height: 1;
  color: var(--yellow); border: 1px solid var(--yellow); border-radius: 3px; padding: 2px 3px;
}
.lib-row-sub { font-size: 10px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Tile icon: a GT7/RaceBox type badge until a real lap-layout thumbnail is captured. */
.lib-thumb {
  width: 32px; height: 32px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.lib-thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.lib-type-badge {
  font-size: 8px; font-weight: 700; letter-spacing: 0.03em;
  color: var(--muted); border: 1px solid var(--border); border-radius: 4px;
  padding: 3px 4px; line-height: 1;
}
.lib-thumb.racebox .lib-type-badge { color: var(--red); border-color: var(--red); }

/* RaceBox tiles read red (matching a loaded RaceBox session), not GT7 blue. */
.lib-row.racebox.selected { background: rgba(239, 68, 68, 0.10); }
.lib-card.racebox { border-color: rgba(239, 68, 68, 0.45); }
.lib-card.racebox.selected { border-color: var(--red); background: rgba(239, 68, 68, 0.08); }

/* Row/tile actions overlay on hover — absolute so they never reserve width and crop
   the title (they used to eat ~160px even while invisible). */
.lib-tile-actions {
  position: absolute; opacity: 0;
  display: flex; gap: 4px;
  background: var(--bg); padding: 2px 4px; border-radius: 5px;
}
.lib-row .lib-tile-actions { right: 4px; top: 50%; transform: translateY(-50%); }
.lib-card .lib-tile-actions { right: 8px; top: 8px; }
.lib-row:hover .lib-tile-actions, .lib-card:hover .lib-tile-actions { opacity: 1; }

/* cards */
.lib-card { position: relative; border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; cursor: pointer; }
.lib-card:hover { background: var(--bg); }
.lib-card.selected { border-color: var(--accent); background: rgba(59,130,246,0.08); }
.lib-card-top { display: flex; align-items: center; gap: 6px; }
.lib-card-title { flex: 1; display: flex; align-items: center; gap: 6px; min-width: 0; font-size: 12px; font-weight: 600; color: var(--text); }
.lib-card-stats { display: flex; gap: 12px; font-size: 10px; color: var(--muted); margin-top: 6px; }

/* Library button caret — points ▸ (closed) and rotates to ▾ when the drawer opens. */
#library-btn .lib-caret {
  display: inline-block;
  transition: transform 0.2s ease;
  font-size: 10px;
  color: var(--muted);
}
body.library-open #library-btn .lib-caret { transform: rotate(90deg); }
body.library-open #library-btn { border-color: var(--accent); }
