/* ==========================================================================
   METRIC CARDS — static/assets/css/metric-cards.css
   Shared KPI card design for the device transaction pages (pump, well head,
   EFM, generic device_transaction_page). Adapted from pinewave_intelligence's
   metric-cards.css; same class names so the two stay easy to compare.
   Loaded globally from includes/head.html.

   Layout: one line, at most --mc-visible cards (4 on desktop, fewer on
   narrow screens). With that many or fewer, cards stretch evenly to fill the
   row; with more, each keeps exactly one slot's width and the rest sit in a
   carousel — prev/next arrows on desktop (metric-cards.js wraps every
   .mc-row in .mc-carousel and adds them), swipe on touch.

   Values/labels are <div>s on purpose — dark.css recolours every
   `body.dark span/p/h5`, which would override the card's own colours.
   ========================================================================== */
.mc-row {
  --mc-gap: 12px;
  --mc-visible: 4;
  --mc-surface: linear-gradient(145deg, rgba(26, 31, 53, .85), rgba(20, 24, 39, .75));
  --mc-border: rgba(255, 255, 255, .07);
  --mc-txt: #e8eaed;
  --mc-muted: #8b93a7;
  --mc-radius: 16px;

  display: flex;
  flex-wrap: nowrap;
  gap: var(--mc-gap);
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  padding: 2px 2px 4px;            /* room for the hover lift */
  scroll-padding-inline: 2px;      /* snap to the padding edge so rows line up */
  scrollbar-width: none;           /* arrows (desktop) / swipe (touch) instead */
}
.mc-row::-webkit-scrollbar { display: none; }

/* ── Carousel shell + arrows (added by metric-cards.js) ── */
.mc-carousel { position: relative; }
.mc-carousel-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 3;
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: rgba(26, 31, 53, .7);
  backdrop-filter: blur(14px) saturate(180%);
  -webkit-backdrop-filter: blur(14px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, .14);
  color: #c4cad8;
  font-size: 12px;
  cursor: pointer;
  box-shadow: 0 8px 22px -8px rgba(0, 0, 0, .5);
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s ease, transform .2s ease, border-color .2s, color .2s;
}
.mc-carousel-prev { left: -14px; }
.mc-carousel-next { right: -14px; }
.mc-carousel--scrollable .mc-carousel-nav:not(:disabled) { opacity: 1; pointer-events: auto; }
.mc-carousel-nav:hover { border-color: #4facfe; color: #fff; transform: translateY(-50%) scale(1.08); }
.mc-carousel-nav:active { transform: translateY(-50%) scale(.94); }

.mc-card {
  --card-accent: #4facfe;
  position: relative;
  box-sizing: border-box;
  /* grow to fill when there are --mc-visible cards or fewer; never shrink
     below one slot, so extra cards overflow into the carousel */
  flex: 1 0 calc((100% - (var(--mc-visible) - 1) * var(--mc-gap)) / var(--mc-visible));
  min-width: 0;
  scroll-snap-align: start;
  background: var(--mc-surface);
  backdrop-filter: blur(30px) saturate(160%);
  -webkit-backdrop-filter: blur(30px) saturate(160%);
  border: 1px solid var(--mc-border);
  border-radius: var(--mc-radius);
  padding: 13px 12px 12px;
  overflow: hidden;
  /* lets .mc-value scale with THIS card's width (cqw), not the viewport */
  container-type: inline-size;
  display: flex;
  flex-direction: column;
  transition: border-color .2s ease, box-shadow .2s ease, transform .2s cubic-bezier(.22, 1, .36, 1);
}
.mc-card.hidden { display: none; }
.mc-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--card-accent);
  opacity: .5;
  transition: opacity .2s ease;
}
.mc-card:hover {
  border-color: color-mix(in srgb, var(--card-accent) 40%, var(--mc-border));
  box-shadow: 0 10px 26px -14px rgba(0, 0, 0, .5);
  transform: translateY(-1px);
}
.mc-card:hover::before { opacity: 1; }

.mc-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}
.mc-icon-wrap {
  width: 28px; height: 28px;
  flex-shrink: 0;
  border-radius: 8px;
  background: color-mix(in srgb, var(--card-accent) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--card-accent) 28%, transparent);
  color: var(--card-accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px;
}
.mc-card .mc-icon-wrap i { color: inherit; }

.mc-label {
  font-size: 10px; font-weight: 600;
  color: var(--mc-muted);
  text-transform: uppercase; letter-spacing: .06em;
  line-height: 1.3;
  margin-bottom: 8px;
  overflow-wrap: anywhere;
}
.mc-value-row {
  display: flex; align-items: baseline; flex-wrap: wrap;
  gap: 2px 5px;
  min-width: 0;
  margin-top: auto;               /* values line up across cards with 1- vs 2-line labels */
}
.mc-value {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  /* 24px on roomy cards; shrinks with narrow cards so long values fit */
  font-size: clamp(13px, 13cqw, 24px);
  font-weight: 700;
  color: var(--mc-txt);
  line-height: 1.1;
  min-height: 1.1em;
  min-width: 0; max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mc-value--text {                 /* words (status, mode, health) rather than numbers */
  font-family: inherit;
  font-size: clamp(12px, 11cqw, 18px);
  line-height: 1.45;              /* same box height as numeric values so baselines line up */
}
/* Toned cards (setMetricTone): the value takes the status colour too */
.mc-card--toned .mc-value { color: var(--card-accent); }
.mc-card--toned::before { opacity: .9; }
.mc-unit { font-size: 10.5px; color: var(--mc-muted); font-weight: 600; }

@media (max-width: 900px) {
  .mc-row { --mc-visible: 3; }
}
@media (max-width: 640px) {
  .mc-row { --mc-visible: 2; --mc-gap: 10px; }
  /* ~2⅓ cards across: the cut-off card at the edge says "swipe for more".
     Rows that fit anyway still stretch to fill (flex-grow 1). */
  .mc-card {
    padding: 12px 12px 11px;
    flex: 1 0 calc((100% - 2 * var(--mc-gap)) / 2.3);
  }
  .mc-carousel-nav { display: none; }   /* touch: swipe instead */
  .mc-carousel--scrollable .mc-dots { display: flex; }
}

/* ── Position dots (phones; added by metric-cards.js) ── */
.mc-dots {
  display: none;
  justify-content: center;
  gap: 6px;
  margin-top: 8px;
}
.mc-dot {
  width: 6px; height: 6px;
  padding: 0;
  border: 0;
  border-radius: 3px;
  background: rgba(255, 255, 255, .22);
  transition: width .25s ease, background .25s ease;
}
.mc-dot--active { width: 16px; background: #4facfe; }
