/* RaceLogger V5 — global top bar + per-tab headers */

.app {
  grid-template-rows: auto 1fr;
}

.race-topbar {
  background: var(--panel-hi);
  border: 1px solid var(--border);
  border-top: none;
  flex-shrink: 0;
}

.race-topbar-inner {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 6px 12px;
  padding: 4px 12px;
  min-height: 0;
}

.tb-left {
  position: relative;
  z-index: 2;
  grid-column: 1;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  min-width: 0;
  max-width: 100%;
}

.tb-center {
  grid-column: 2;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  width: max-content;
  max-width: min(340px, 32vw);
  min-width: 0;
  padding: 0 8px;
  pointer-events: none;
  z-index: 1;
  gap: 0;
}

.tb-series-logo {
  width: min(100%, 260px);
  max-height: 22px;
  height: auto;
  object-fit: contain;
  margin: 0 auto;
}

.tb-event {
  font-size: 11px;
  font-weight: 700;
  color: var(--text);
  margin-top: 0;
  line-height: 1.1;
  width: 100%;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tb-circuit {
  font-size: 9px;
  color: var(--cyan);
  margin-top: 0;
  letter-spacing: 0.04em;
  line-height: 1.1;
  width: 100%;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tb-right {
  position: relative;
  z-index: 2;
  grid-column: 3;
  justify-self: end;
  display: grid;
  grid-template-columns: repeat(3, minmax(124px, 1fr));
  align-items: stretch;
  gap: 8px;
  min-width: 0;
  width: 100%;
  max-width: 520px;
}

.tb-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 2px;
  background: linear-gradient(180deg, var(--panel-hi) 0%, var(--panel) 100%);
  border: 1px solid var(--border-bright);
  border-radius: 5px;
  padding: 4px 8px 5px;
  min-width: 0;
  min-height: 46px;
  height: 100%;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.03) inset, 0 3px 8px rgba(0, 0, 0, 0.35);
}

/* Global flag bar — the session flag/state, visible from every tab, not just
   Live. Mirrors _FLAG_STYLES in app/core/race_results_parser.py. The CSP
   (style-src 'self') blocks JS-set inline styles/custom properties, so
   app.js sets data-flag and these attribute-selector rules (plain CSS2,
   not the fragile attr() value function) supply the actual colors. These
   are real flag colors (motorsport convention), not brand colors, so they
   stay fixed regardless of white-label.config.json. */
.global-flag-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 14px;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  background: #1a1f28;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
  transition: background-color 0.25s ease, color 0.25s ease;
}

.global-flag-bar[data-flag="idle"] { background: #1a1f28; color: var(--text-dim); }
.global-flag-bar[data-flag="ready"] { background: #888888; color: #fff; }
.global-flag-bar[data-flag="red"] { background: #e10600; color: #fff; }
.global-flag-bar[data-flag="sc"] { background: #fdda24; color: #111111; }
.global-flag-bar[data-flag="finish"] { background: #5a9fd4; color: #fff; }
.global-flag-bar[data-flag="green"] { background: #00c853; color: #fff; }
.global-flag-bar[data-flag="fcy"] { background: #fdda24; color: #111111; }

.gfb-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.global-flag-bar[data-live="true"] .gfb-dot {
  animation: gfb-pulse 1.8s ease-in-out infinite;
}

@keyframes gfb-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.78); }
}

.global-flag-bar.gfb-flash {
  animation: gfb-flash 0.6s ease-in-out 3;
}

@keyframes gfb-flash {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.4); }
}

.tb-card.tb-alert {
  min-height: 64px;
  padding: 5px 10px 6px;
}

.tb-position {
  flex: 1 1 auto;
  min-width: 0;
}

.tb-divider {
  width: 1px;
  background: var(--border-bright);
  margin: 4px 12px;
  align-self: stretch;
}

.tb-card-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.07em;
  color: var(--cyan);
  text-transform: uppercase;
  line-height: 1.1;
}

.tb-metric-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 4px;
  width: 100%;
}

.tb-metric-cell {
  flex: 1 1 0;
  min-width: 0;
  padding: 0;
}

.tb-micro {
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.tb-metric-val {
  font-family: var(--mono);
  font-size: 16px;
  font-weight: 700;
  line-height: 1.05;
  color: var(--text);
}

.tb-metric-sub {
  font-size: 10px;
  color: var(--subtext);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tb-fuel-val {
  font-family: var(--mono);
  font-size: 16px;
  font-weight: 700;
  color: var(--cyan);
  text-align: right;
}

.tb-fuel-cell {
  flex: 1 1 0;
  min-width: 0;
  text-align: right;
  padding-left: 0;
}

.tb-fuel-cell:first-child {
  padding-left: 0;
}

.tb-left .tb-divider {
  margin: 4px 12px;
}

.tb-right .tb-divider {
  margin: 4px 12px;
}

.tb-alert-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  align-items: stretch;
  width: 100%;
}

.tb-alert-btn {
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.25;
  text-align: center;
  padding: 6px 8px;
  min-width: 0;
  min-height: 44px;
  width: 100%;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--panel-alt);
  color: var(--subtext);
  cursor: pointer;
  white-space: pre-line;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.tb-alert-btn:hover {
  border-color: var(--border-bright);
  color: var(--text);
}

.tb-alert-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.tb-header-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(2, auto);
  align-items: stretch;
  align-self: center;
  flex-shrink: 0;
  gap: 3px;
  min-width: 0;
  width: 118px;
}

.tb-header-actions-sep {
  display: none;
}

.tb-fullscreen,
.tb-signout {
  align-self: stretch;
  flex-shrink: 0;
  padding: 3px 5px;
  background: rgba(0, 0, 0, 0.15);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-dim);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  cursor: pointer;
  white-space: nowrap;
  line-height: 1.15;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tb-crew-chip {
  align-self: stretch;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 3px 5px;
  border: 1px solid var(--accent, #dc2626);
  border-radius: 4px;
  background: rgba(220, 38, 38, 0.15);
  color: var(--accent-label, #fecaca);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.08em;
  line-height: 1.15;
  text-align: center;
  min-width: 0;
}

/* Section picker — matches metric cards / pit-wall dark palette */
.race-topbar .tab-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(22px, auto));
  gap: 1px;
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
  padding: 2px;
  background: var(--panel);
  border: 1px solid var(--border-bright);
  border-radius: 4px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.race-topbar .tab-grid button.tab {
  margin: 0;
  padding: 2px 3px;
  min-height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text-dim);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.03em;
  line-height: 1.05;
  text-transform: uppercase;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  box-shadow: none;
}

.tab-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tab-kind-icon {
  flex: 0 0 9px;
  width: 9px;
  height: 9px;
  line-height: 1;
}

.tab--form .tab-kind-icon::before {
  content: "";
  display: block;
  width: 6px;
  height: 7px;
  border: 1.5px solid var(--text-dim, #9aa0a8);
  border-radius: 1px;
  margin: 0 auto;
  box-sizing: border-box;
}

.tab--data .tab-kind-icon::before {
  content: "";
  display: block;
  width: 7px;
  height: 5px;
  border: 1.5px solid var(--accent, #dc2626);
  border-bottom-width: 2px;
  margin: 1px auto 0;
  box-sizing: border-box;
}

.tab--checklist .tab-kind-icon::before {
  content: "\2713";
  display: block;
  font-size: 8px;
  font-weight: 800;
  line-height: 9px;
  text-align: center;
  color: #e8952a;
}

.race-topbar .tab-grid button.tab.active .tab-kind-icon::before {
  border-color: #ffffff;
  color: #ffffff;
}

.race-topbar .tab-grid button.tab:hover {
  background: var(--panel-hi);
  color: var(--text);
  border-color: var(--border-bright);
}

.race-topbar .tab-grid button.tab.active {
  background: linear-gradient(180deg, var(--accent-alt) 0%, var(--accent) 55%, #9a0500 100%);
  border-color: #7a0400;
  color: #ffffff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.race-topbar .tab-grid button.tab.tab--gated,
.race-topbar .tab-grid button.tab:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

.race-topbar .tab-grid button.tab:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 0;
}

.tb-fullscreen:hover,
.tb-signout:hover {
  color: var(--text);
  border-color: var(--border-bright);
  background: var(--panel);
}

.shell-rule {
  display: none;
}

/* Per-tab page header — hidden; global race topbar already shows branding */
.tab-page-header {
  display: none;
}

.tab-header-row {
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 14px;
  min-height: 88px;
  padding: 8px 2px 0;
}

.tab-header-logo {
  position: relative;
  z-index: 2;
  flex: 0 1 auto;
  max-width: 42%;
  background: transparent;
  padding: 0;
  border-radius: 0;
  line-height: 0;
}

.tab-header-logo img {
  display: block;
  max-width: 340px;
  max-height: 88px;
  width: auto;
  height: auto;
  object-fit: contain;
}

.tab-header-text {
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  text-align: center;
  width: max-content;
  max-width: min(520px, 58vw);
  pointer-events: none;
  z-index: 1;
}

.tab-header-text h2 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text);
  line-height: 1.2;
  text-align: center;
  margin: 0;
}

.tab-header-text .tagline {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
  text-align: center;
}

.tab-header-belcar {
  position: relative;
  z-index: 2;
  width: 180px;
  height: 132px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  overflow: visible;
  margin-left: auto;
}

.tab-header-belcar img {
  max-width: 108%;
  max-height: 108%;
  object-fit: contain;
  object-position: right center;
}

.be-flag-sep {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin: 6px 0;
}

.be-flag-sep span {
  display: block;
  height: 1px;
}

.be-flag-sep .be-black { background: #1a1a1a; }
.be-flag-sep .be-yellow { background: #FDDA24; }
.be-flag-sep .be-red { background: #EF3340; }

/* M2 guide — caption, text, then full-width image (stacked, no side-by-side crop) */
.guide-block {
  margin-bottom: 16px;
}

.guide-block .guide-caption {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent, #dc2626);
}

.guide-block .guide-text {
  margin-bottom: 10px;
}

.guide-image-frame {
  width: 100%;
  max-width: min(960px, 100%);
  overflow: visible;
}

.guide-image-frame img {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  border-radius: 4px;
}

/* Legacy side-by-side (unused) */
.guide-image-row {
  display: block;
}

.guide-image-side {
  text-align: left;
  overflow: visible;
  min-width: 0;
}

.guide-image-side img {
  max-width: 100%;
  width: auto;
  height: auto;
  display: block;
}

.guide-image-side .caption {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent, #dc2626);
  margin-bottom: 6px;
}

@media (max-width: 1100px) {
  .race-topbar-inner {
    display: flex !important;
    flex-direction: column;
    gap: 8px;
    padding: 6px 10px 8px;
    min-height: 0;
  }

  .tb-left {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    grid-column: auto;
    max-width: none;
  }

  .tb-header-actions {
    align-self: flex-end;
    width: 140px;
  }

  .tb-signout,
  .tb-fullscreen,
  .tb-crew-chip {
    align-self: stretch;
  }

  .race-topbar .tab-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-template-rows: repeat(3, minmax(24px, auto));
  }

  .tb-center {
    grid-column: auto;
    order: -1;
    width: 100%;
    max-width: 100%;
    pointer-events: auto;
    align-items: center;
    text-align: center;
  }

  .tb-right {
    grid-column: auto;
    justify-self: stretch;
    max-width: none;
    width: 100%;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .tb-series-logo {
    max-height: 24px;
  }

  .tb-event {
    font-size: 10px;
  }

  .tb-circuit {
    font-size: 9px;
  }

  .tab-header-row {
    flex-wrap: wrap;
    justify-content: center;
    min-height: 0;
    padding-top: 4px;
  }

  .tab-header-text {
    position: relative;
    left: auto;
    bottom: auto;
    transform: none;
    order: -1;
    flex: 1 1 100%;
    max-width: 100%;
    margin-bottom: 8px;
    pointer-events: auto;
  }

  .tab-header-logo,
  .tab-header-belcar {
    max-width: 100%;
  }

  .tab-header-belcar {
    width: auto;
    height: auto;
    justify-content: flex-start;
  }

  .guide-image-row { grid-template-columns: 1fr; }
}

/* Full screen is a toggle — show the active state here instead of swapping in
   a longer label, which used to overflow the button's ~57px grid cell. */
.tb-fullscreen[aria-pressed="true"] {
  color: var(--accent-label, #fecaca);
  border-color: var(--accent, #dc2626);
  background: rgba(220, 38, 38, 0.16);
}

/* Sign out is the one destructive control in the topbar — keep it visually
   distinct from the neighbouring toggles. */
#btn-signout {
  color: var(--accent-muted, #f87171);
  border-color: rgba(220, 38, 38, 0.42);
}

#btn-signout:hover {
  color: #fff;
  background: var(--accent, #dc2626);
  border-color: var(--accent, #dc2626);
}
