/*
 * Components of the PerfExpert web design system (issue #308).
 *
 * Every class is prefixed `pe-` and every value comes from tokens.css. The components are
 * written to work both on a `pe-page` body and inside the Bootstrap SPA shell, so each one
 * sets the few element properties Bootstrap would otherwise impose (font, margins, line-height).
 * Add a new component here and show it on /design.
 */

/* ---- Buttons: 56px, bold, ALL CAPS, radius 10 (apps' Button.Primary/Secondary/Tertiary) ---- */
.pe-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--pe-space-1);
  min-height: var(--pe-btn-height);
  padding: 0 var(--pe-space-3);
  border: 1px solid transparent;
  border-radius: var(--pe-radius-btn);
  font-family: var(--pe-font);
  font-size: var(--pe-font-size);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  text-decoration: none;
  text-align: center;
  color: var(--pe-text);
  background: transparent;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.15s, border-color 0.15s, opacity 0.15s;
}
.pe-btn:hover,
.pe-btn:focus-visible {
  text-decoration: none;
  color: var(--pe-text);
}
.pe-btn:active {
  opacity: 0.85;
}
.pe-btn:disabled,
.pe-btn[aria-disabled="true"] {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}
.pe-btn--primary {
  background: var(--pe-accent);
  border-color: var(--pe-accent);
}
.pe-btn--primary:hover,
.pe-btn--primary:focus-visible {
  background: #3b95ff;
}
.pe-btn--secondary {
  border-color: var(--pe-text);
}
.pe-btn--secondary:hover,
.pe-btn--secondary:focus-visible {
  background: rgba(255, 255, 255, 0.08);
}
.pe-btn--tertiary {
  background: var(--pe-card);
  border-color: var(--pe-card);
  justify-content: flex-start;
  text-transform: none;
  letter-spacing: 0;
}
.pe-btn--tertiary:hover,
.pe-btn--tertiary:focus-visible {
  background: #45457a;
}
.pe-btn--destructive {
  background: var(--pe-red);
  border-color: var(--pe-red);
}
.pe-btn--destructive:hover,
.pe-btn--destructive:focus-visible {
  background: #ff554c;
}
.pe-btn--sm {
  min-height: var(--pe-btn-height-sm);
  padding: 0 var(--pe-space-2);
  font-size: var(--pe-font-size-sm);
}
.pe-btn--block {
  display: flex;
  width: 100%;
}
.pe-btn__icon {
  width: 24px;
  height: 24px;
  flex: none;
}
/* Light-surface variants (inside .pe-form / .pe-dialog) */
.pe-form .pe-btn--secondary,
.pe-dialog .pe-btn--secondary {
  color: var(--pe-dialog-text);
  border-color: var(--pe-dialog-text);
}
.pe-form .pe-btn--secondary:hover,
.pe-dialog .pe-btn--secondary:hover {
  background: rgba(8, 8, 46, 0.06);
}
/* Text button: the dialogs' blue text actions */
.pe-btn--text {
  min-height: var(--pe-btn-height-sm);
  padding: 0 var(--pe-space-1);
  color: var(--pe-accent);
  text-transform: none;
  letter-spacing: 0;
}
/* Same specificity as .pe-btn:hover / :focus-visible, declared later, so the accent label stays
   on the white surfaces instead of turning white. */
.pe-btn--text:hover,
.pe-btn--text:focus-visible {
  color: var(--pe-accent);
  text-decoration: underline;
}

/* ---- Card: #37375D, radius 10 ---- */
.pe-card {
  display: block;
  background: var(--pe-card);
  color: var(--pe-text);
  border-radius: var(--pe-radius-card);
  padding: var(--pe-space-2);
  text-decoration: none;
}
a.pe-card:hover,
a.pe-card:focus-visible {
  text-decoration: none;
  color: var(--pe-text);
  outline: 2px solid var(--pe-accent);
  outline-offset: 0;
}
.pe-card__title {
  margin: 0 0 var(--pe-space-1);
  color: var(--pe-text);
  font-size: var(--pe-font-size);
  font-weight: 700;
  line-height: 1.3;
}
.pe-card__body {
  margin: 0;
  color: var(--pe-muted-on-card);
  font-size: var(--pe-font-size-sm);
  line-height: var(--pe-line-height);
}
.pe-card__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--pe-space-1);
  margin-top: var(--pe-space-2);
}
.pe-card--accent {
  border: 2px solid var(--pe-accent);
}

/* ---- Pill: fully rounded label ---- */
.pe-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 2px 12px;
  border-radius: var(--pe-radius-pill);
  background: var(--pe-card);
  color: var(--pe-text);
  font-family: var(--pe-font);
  font-size: var(--pe-font-size-sm);
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
}
.pe-pill--accent { background: var(--pe-accent); color: var(--pe-navy); }
.pe-pill--green { background: var(--pe-green); color: var(--pe-navy); }
.pe-pill--orange { background: var(--pe-orange); color: var(--pe-navy); }
.pe-pill--red { background: var(--pe-red); color: var(--pe-navy); }
/* The two tinted pills can sit on a card (result card): their text is the AA variant there */
.pe-pill--outline {
  background: transparent;
  border: 1px solid var(--pe-muted);
  color: var(--pe-muted-on-card);
}
.pe-pill--soft {
  background: rgba(31, 134, 255, 0.18);
  color: var(--pe-accent-text-on-dark);
}

/* ---- Metric: a big value with its label (vehicle stats, counters) ---- */
.pe-metric {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.pe-metric__value {
  font-size: var(--pe-font-size-title);
  font-weight: 700;
  line-height: 1.1;
  color: var(--pe-text);
}
.pe-metric__label {
  font-size: var(--pe-font-size-sm);
  color: var(--pe-muted);
}
.pe-metric--power .pe-metric__value { color: var(--pe-chart-power); }
.pe-metric--torque .pe-metric__value { color: var(--pe-chart-torque); }
.pe-metric--distance .pe-metric__value { color: var(--pe-chart-distance); }

/* ---- Forms: the apps' light surface (white, radius 24) ---- */
.pe-form,
.pe-dialog {
  background: var(--pe-dialog-bg);
  color: var(--pe-dialog-text);
  border-radius: var(--pe-radius-dialog);
  padding: var(--pe-space-3);
  font-family: var(--pe-font);
}
.pe-form__title,
.pe-dialog__title {
  margin: 0 0 var(--pe-space-1);
  color: var(--pe-dialog-text);
  font-size: var(--pe-font-size-lg);
  font-weight: 700;
  line-height: 1.3;
}
.pe-form__intro,
.pe-dialog__body {
  margin: 0 0 var(--pe-space-2);
  color: var(--pe-dialog-muted);
  font-size: var(--pe-font-size-sm);
}
.pe-form__divider,
.pe-dialog__divider {
  height: 1px;
  margin: var(--pe-space-2) 0;
  border: 0;
  background: var(--pe-dialog-divider);
}
.pe-field {
  display: block;
  margin: 0 0 var(--pe-space-2);
}
.pe-field__label {
  display: block;
  margin: 0 0 6px;
  color: var(--pe-dialog-text);
  font-size: var(--pe-font-size-sm);
  font-weight: 600;
}
.pe-input,
.pe-select,
.pe-textarea {
  display: block;
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  border: 1px solid var(--pe-input-border);
  border-radius: var(--pe-radius-btn);
  background: var(--pe-dialog-bg);
  color: var(--pe-dialog-text);
  font-family: var(--pe-font);
  font-size: var(--pe-font-size);
  line-height: 1.4;
  box-shadow: none;
  appearance: none;
  -webkit-appearance: none;
}
.pe-textarea {
  min-height: 120px;
  resize: vertical;
}
.pe-select {
  padding-right: 40px;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='%2363638A' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 20px;
}
.pe-input::placeholder,
.pe-textarea::placeholder {
  color: var(--pe-dialog-muted); /* AA on white; the apps' hint grey is 3.84:1 */
  opacity: 1;
}
.pe-input:focus,
.pe-select:focus,
.pe-textarea:focus {
  outline: none;
  border-color: var(--pe-accent);
  box-shadow: 0 0 0 3px var(--pe-accent-10);
}
.pe-field--error .pe-input,
.pe-field--error .pe-select,
.pe-field--error .pe-textarea {
  border-color: var(--pe-red);
}
.pe-field__hint {
  display: block;
  margin: 6px 0 0;
  color: var(--pe-dialog-muted);
  font-size: var(--pe-font-size-xs);
}
.pe-field--error .pe-field__hint {
  color: var(--pe-red-on-light);
}
.pe-check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 0 0 var(--pe-space-2);
  color: var(--pe-dialog-text);
  font-size: var(--pe-font-size-sm);
  font-weight: 400;
  cursor: pointer;
}
.pe-check input {
  flex: none;
  width: 20px;
  height: 20px;
  margin: 1px 0 0;
  accent-color: var(--pe-accent);
}
.pe-form__actions,
.pe-dialog__actions {
  display: flex;
  flex-direction: column;
  gap: var(--pe-space-1);
  margin-top: var(--pe-space-3);
}
.pe-form__actions .pe-btn,
.pe-dialog__actions .pe-btn {
  width: 100%;
}
/* Dark-surface input (search field on a navy page) */
.pe-input--dark {
  background: var(--pe-card);
  border-color: var(--pe-card);
  color: var(--pe-text);
}
.pe-input--dark::placeholder {
  color: var(--pe-muted-on-card); /* --pe-muted on the card colour is 4.45:1, short of AA */
}

/* ---- Result card: a shared test result in a list (explore, vehicle page) ---- */
.pe-result-card {
  display: flex;
  gap: var(--pe-space-2);
  align-items: flex-start;
  background: var(--pe-card);
  color: var(--pe-text);
  border-radius: var(--pe-radius-card);
  padding: var(--pe-space-2);
  text-decoration: none;
}
a.pe-result-card:hover,
a.pe-result-card:focus-visible {
  text-decoration: none;
  color: var(--pe-text);
  outline: 2px solid var(--pe-accent);
  outline-offset: 0;
}
.pe-result-card__icon {
  flex: none;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--pe-radius-btn);
  background: var(--pe-navy);
}
.pe-result-card__icon img {
  width: 28px;
  height: 28px;
}
.pe-result-card__content {
  display: block;
  flex: 1;
  min-width: 0;
}
/* The card is often an <a>, so its parts are <span>s: make them blocks. */
.pe-result-card__vehicle,
.pe-result-card__summary,
.pe-result-card__meta {
  display: block;
}
.pe-result-card__vehicle {
  margin: 0;
  font-size: var(--pe-font-size);
  font-weight: 700;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pe-result-card__summary {
  margin: 2px 0 0;
  color: var(--pe-text);
  font-size: var(--pe-font-size-sm);
}
.pe-result-card__meta {
  margin: 6px 0 0;
  color: var(--pe-muted-on-card);
  font-size: var(--pe-font-size-xs);
}
.pe-result-card__pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: var(--pe-space-1);
}
.pe-result-card__pills .pe-pill {
  min-height: 24px;
  font-size: var(--pe-font-size-xs);
}

/* ---- Store badge ---- */
.pe-badge {
  display: inline-block;
  line-height: 0;
}
.pe-badge img {
  height: 40px;
  width: auto;
}

/* ---- Banner: install the app (#309 uses it) ---- */
.pe-banner {
  display: flex;
  align-items: center;
  gap: var(--pe-space-2);
  padding: 12px var(--pe-space-2);
  background: var(--pe-navy);
  color: var(--pe-text);
  font-family: var(--pe-font);
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.35);
}
.pe-banner__icon {
  flex: none;
  width: 48px;
  height: 48px;
  border-radius: 11px;
}
.pe-banner__text {
  flex: 1;
  min-width: 0;
}
.pe-banner__title {
  margin: 0;
  font-size: var(--pe-font-size-sm);
  font-weight: 700;
  line-height: 1.3;
}
.pe-banner__subtitle {
  margin: 2px 0 0;
  color: var(--pe-muted);
  font-size: var(--pe-font-size-xs);
  line-height: 1.3;
}
.pe-banner__close {
  flex: none;
  width: var(--pe-touch-target);
  height: var(--pe-touch-target);
  margin: -8px -8px -8px 0;
  padding: 12px;
  border: 0;
  background: transparent;
  cursor: pointer;
}
.pe-banner__close img {
  width: 24px;
  height: 24px;
  display: block;
}
.pe-banner__stores {
  display: flex;
  gap: var(--pe-space-1);
  flex-wrap: wrap;
}
.pe-banner__qr {
  flex: none;
  width: 72px;
  height: 72px;
  border-radius: 6px;
  background: var(--pe-text);
}
/* Mobile: fixed bar at the bottom of the viewport */
.pe-banner--bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
}
/* Desktop: ribbon under the header, badges and QR code */
.pe-banner--ribbon {
  border-bottom: 1px solid var(--pe-card);
  box-shadow: none;
}
/* Shown in the page flow (the /design page) */
.pe-banner--static {
  position: static;
  border-radius: var(--pe-radius-card);
  border: 1px solid var(--pe-card);
}

/* ---- Account menu (header, SPA) ---- */
.pe-menu {
  position: relative;
}
.pe-menu__summary {
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: var(--pe-btn-height-sm);
  padding: 0 var(--pe-space-2);
  border-radius: var(--pe-radius-btn);
  background: var(--pe-card);
  color: var(--pe-text);
  font-weight: 600;
  cursor: pointer;
}
.pe-menu__summary::-webkit-details-marker {
  display: none;
}
.pe-menu__summary::after {
  content: "";
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--pe-muted);
  border-bottom: 2px solid var(--pe-muted);
  transform: translateY(-2px) rotate(45deg);
  transition: transform 0.15s;
}
.pe-menu[open] > .pe-menu__summary::after {
  transform: translateY(2px) rotate(-135deg);
}
/* Browsers draw a focus ring on a clicked <summary>: keep it for the keyboard only */
.pe-menu__summary:focus:not(:focus-visible) {
  outline: none;
}
.pe-menu__list {
  list-style: none;
  margin: var(--pe-space-1) 0 0;
  padding: var(--pe-space-1) 0;
  min-width: 220px;
  background: var(--pe-card);
  border-radius: var(--pe-radius-btn);
  box-shadow: var(--pe-shadow);
}
.pe-menu__list a {
  display: block;
  padding: 10px var(--pe-space-2);
  color: var(--pe-text);
  text-decoration: none;
}
.pe-menu__list a:hover,
.pe-menu__list a:focus-visible {
  background: rgba(255, 255, 255, 0.08);
  text-decoration: none;
  color: var(--pe-text);
}

/* ---- Icon sizes ---- */
.pe-icon {
  width: 24px;
  height: 24px;
  vertical-align: middle;
}
.pe-icon--lg {
  width: 40px;
  height: 40px;
}
