:host {
  --bc-background: var(
    --ha-card-background,
    var(--card-background-color, white)
  );
  --bc-primary-text-color: var(--primary-text-color, #000);
  --bc-secondary-text-color: var(--secondary-text-color, #555);
  --bc-icon-color: var(--secondary-text-color);
  --bc-toolbar-background: var(--bc-background);
  --bc-toolbar-text-color: var(--bc-secondary-text-color);
  --bc-toolbar-icon-color: var(--bc-secondary-text-color);
  --bc-divider-color: var(--entities-divider-color, var(--divider-color, #ccc));
  --bc-spacing: 5px;
  --ha-card-border-radius: 12px;
  --ha-icon-size: 24px;

  /* Couleurs spécifiques pour les éléments */
  --bc-bar-height: 24px;
  --bc-bar-background: #e0e0e0;
  --bc-bar-current: #007bff; /* Couleur de la barre */
  --bc-bar-target: rgba(255, 255, 255, 0.4); /* Couleur pour la cible */
  --bc-bar-remaining: rgb(
    25.5,
    140.7,
    25.5
  ); /* Couleur pour la partie restante */
  --bc-bar-marker: red;
}

ha-card {
  display: flex;
  flex-direction: column;
  height: 100%;
  border-radius: var(--ha-card-border-radius);
  overflow: hidden;
}

.background {
  background-repeat: no-repeat;
  background-position: center center;
  background-size: cover;
  height: auto;
  border-radius: var(--ha-card-border-radius);
  overflow: hidden;
}

.pointer {
  cursor: pointer;
}

.preview {
  background: var(--bc-background);
  cursor: pointer;
  position: relative;
}

.preview.not-available {
  filter: grayscale(1);
}

.not-available {
  text-align: center;
  color: var(--text-primary-color, #333);
  font-size: 16px;
}

.metadata {
  margin: var(--bc-spacing) auto;
}

.bodymiscale-name {
  font-size: 20px;
  text-align: center;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

.flex {
  display: flex;
  align-items: center;
  justify-content: space-evenly;
}

.grid {
  cursor: pointer;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
}

.grid-left,
.grid-right {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.grid-left {
  text-align: left;
  padding-left: 10px;
  border-left: 2px solid var(--primary-color);
}

.grid-right {
  text-align: right;
  padding-right: 10px;
  border-right: 2px solid var(--primary-color);
}

#items {
  transform-origin: top;
  transform: scaleY(0);
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
  max-height: 0;
}

#items[open] {
  transform: scaleY(1);
  opacity: 1;
  max-height: 500px;
}

.toolbar {
  background: var(--bc-toolbar-background);
  min-height: 30px;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0px;
  padding-inline: 8px;
}

.toolbar ha-icon-button {
  align-items: center;
  justify-content: center;
}

.fill-gap {
  flex-grow: 1;
  gap: 0px;
}

.toolbar ha-icon {
  width: var(--ha-icon-size);
  height: var(--ha-icon-size);
  fill: currentColor;
  margin: 0;
  font-size: 0px; /* Override font-size inheritance to fix icon alignment */
}

.image {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  vertical-align: middle;
  fill: currentColor;
  width: var(--ha-icon-size);
  height: var(--ha-icon-size);
}

.problem {
  color: var(--error-color, #f44336);
  animation: blinker 2s cubic-bezier(0.5, 0, 1, 1) infinite alternate;
}

@keyframes blinker {
  0% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

.state-div {
  display: grid;
  grid-template-columns: 24px 1fr;
  align-items: start;
}

.state-label {
  padding: 3px 0 0 10px;
}

#score {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  padding: 8px;
}

#score > * {
  margin-bottom: 8px;
}

#score > :last-child {
  margin-top: 0px;
  margin-bottom: 0px;
}

#score > :first-child {
  margin-top: 0px;
}

.flex-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  width: 100%;
}

.value-container {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  width: 100%;
}

.name {
  text-align: left;
}

.minmax {
  font-size: 10px;
  color: var(--secondary-text-color);
}
.minmax .min, .minmax .max {
  color: var(--primary-text-color);
}

.bar-container {
  width: 100%;
  display: flex;
  justify-content: center;
}

.bar-inner {
  display: flex;
  height: 8px;
  width: 100%;
  background: lightgray;
  position: relative;
  border-radius: 8px;
  overflow: visible;
}

.bar-marker {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--card-background-color, white);
  border: 3px solid var(--primary-color);
}

.bar-marker-wrapper {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
}

.bar-marker-tooltip {
  position: absolute;
  top: 20px; /* en dessous du cercle */
  left: 50%;
  transform: translateX(-50%);
  background-color: var(--card-background-color, #fff);
  color: var(--primary-text-color, #000);
  padding: 2px 6px;
  font-size: 10px;
  border-radius: 4px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.bar-marker-wrapper:hover .bar-marker-tooltip,
.bar-marker-wrapper:focus-within .bar-marker-tooltip,
.bar-marker-wrapper:active .bar-marker-tooltip {
  opacity: 1;
}

.colorbar-segment {
  height: 100%;
  position: relative;
}

.segment-label-above {
  font-size: 10px;
  font-weight: bold;
  position: absolute;
  text-align: center;
  white-space: nowrap;
  top: -24px;
  left: 100%;
  transform: translateX(-50%);
}

.segment-label-below {
  font-size: 10px;
  font-weight: bold;
  position: absolute;
  text-align: center;
  white-space: nowrap;
  bottom: -24px;
  left: 50%;
  transform: translateX(-50%);
}

.scroll-wrapper {
  max-height: 40vh; ; /* Par défaut pour les petits écrans */
  overflow-y: auto;
  padding-right: 0.5rem; /* espace pour la scrollbar */
  scroll-behavior: smooth;
}

/* Scrollbar style */
.scroll-wrapper::-webkit-scrollbar {
  width: 6px;
}
.scroll-wrapper::-webkit-scrollbar-thumb {
  background-color: rgba(100, 100, 100, 0.3);
  border-radius: 4px;
}

/* Pour Firefox */
.scroll-wrapper {
  scrollbar-width: thin;
  scrollbar-color: rgba(100, 100, 100, 0.3) transparent;
}

/* Styles pour les écrans jusqu'à 600px (téléphones) */
@media (max-width: 600px) {
  .scroll-wrapper {
    max-height: 50vh;
  }
}

@media (min-height: 600px) { /* Pour les écrans plus hauts que 600px */
  .scroll-wrapper {
    max-height: 300px; /* Utiliser une hauteur fixe sur les écrans plus grands */
  }
}

/* Dark mode support complémentaire */
@media (prefers-color-scheme: dark) {
  :host {
    --bc-bar-background: #444;
    --bc-divider-color: #555;
  }
}

/* Mobile optimisation */
@media (max-width: 400px) {
  .bodymiscale-name {
    font-size: 16px;
  }

  .segment-label {
    font-size: 8px;
  }
}