/* ==========================================================================
   Prima Pompa — css/simulator-pipa.css
   Simulator sistem perpipaan (kalkulator head loss + visualisasi aliran).

   ✏️ EDIT warna/kecepatan:
      - warna fluida  : variabel --fluid diatur dari js/simulator-pipa.js
      - kecepatan air : variabel --flow-duration diatur dari js/simulator-pipa.js
   ========================================================================== */

.pf {
  --fluid: #2f7bc4;
  --flow-duration: 1s;
  display: grid;
  gap: 1.5rem;
}

/* Visualisasi tampil lebih dulu di mobile, panel kontrol di bawah */
.pf-stage {
  order: -1;
}

@media (min-width: 64rem) {
  .pf {
    grid-template-columns: 388px minmax(0, 1fr);
    gap: 1.75rem;
    align-items: start;
  }

  .pf-stage {
    order: 0;
    position: sticky;
    top: calc(var(--header-h) + 1rem);
  }

  .pf-report {
    grid-column: 1 / -1;
  }
}

/* ==========================================================================
   PANEL KONTROL
   ========================================================================== */
.pf-panel {
  padding: clamp(1.1rem, 3vw, 1.6rem);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.pf-panel__head h2 {
  margin-bottom: 0.2rem;
  font-size: 1.15rem;
}

.pf-panel__head p {
  margin: 0 0 1.1rem;
  color: var(--muted);
  font-size: 0.85rem;
}

/* Preset */
.pf-presets {
  margin-bottom: 1.1rem;
  padding: 0.85rem 0.95rem;
  background: var(--blue-50);
  border: 1px dashed #cfe0ee;
  border-radius: var(--radius);
}

.pf-presets__label {
  display: block;
  margin-bottom: 0.5rem;
  color: var(--blue-600);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.pf-presets__row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.pf-preset {
  padding: 0.35rem 0.72rem;
  background: #fff;
  border: 1px solid #cfe0ee;
  border-radius: 999px;
  color: var(--blue-800);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.pf-preset:hover {
  border-color: var(--blue-500);
  background: var(--blue-50);
}

.pf-preset[aria-pressed="true"] {
  background: var(--blue-700);
  border-color: var(--blue-700);
  color: #fff;
}

/* Grup input */
.pf-group {
  margin: 0;
  padding: 1rem 0 0;
  border: 0;
  border-top: 1px solid var(--line);
}

.pf-group legend {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0;
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.pf-group__no {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 6px;
  background: var(--blue-100);
  color: var(--blue-700);
  font-size: 0.68rem;
  font-weight: 700;
}

.pf-field {
  margin-top: 0.85rem;
}

.pf-field label {
  display: block;
  margin-bottom: 0.3rem;
  color: var(--slate);
  font-size: 0.79rem;
  font-weight: 600;
}

.pf-field input,
.pf-field select,
.pf-qty__input {
  width: 100%;
  padding: 0.58rem 0.7rem;
  background: #fbfdff;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

.pf-field input:focus,
.pf-field select:focus,
.pf-qty__input:focus {
  outline: none;
  background: #fff;
  border-color: var(--blue-500);
  box-shadow: 0 0 0 3px rgba(47, 123, 196, 0.16);
}

.pf-field.is-invalid input,
.pf-field.is-invalid select {
  border-color: var(--danger);
  background: #fff7f7;
}

.pf-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.7rem;
}

.pf-hint {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.74rem;
  line-height: 1.5;
}

/* Aksesoris */
.pf-acc-list {
  display: grid;
  gap: 0.5rem;
  margin-top: 0.7rem;
}

.pf-acc {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.5rem 0.65rem;
  background: #fbfdff;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.pf-acc__name {
  display: block;
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 600;
}

.pf-acc__kv {
  display: block;
  color: var(--muted);
  font-size: 0.7rem;
}

.pf-qty {
  display: flex;
  flex: none;
  align-items: center;
  gap: 0.25rem;
}

.pf-qty__btn {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--blue-700);
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.pf-qty__btn:hover {
  background: var(--blue-50);
  border-color: var(--blue-500);
}

.pf-qty__btn:active {
  transform: translateY(1px);
}

.pf-qty__input {
  width: 46px;
  padding: 0.32rem 0.2rem;
  text-align: center;
  font-size: 0.86rem;
  font-weight: 600;
  border-radius: 8px;
  -moz-appearance: textfield;
}

.pf-qty__input::-webkit-outer-spin-button,
.pf-qty__input::-webkit-inner-spin-button {
  margin: 0;
  -webkit-appearance: none;
}

.pf-total {
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
  margin: 0.85rem 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.pf-total strong {
  margin-left: auto;
  color: var(--blue-800);
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
}

.pf-mono {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.76rem;
  background: var(--blue-50);
  padding: 0.05rem 0.28rem;
  border-radius: 4px;
}

/* Pesan error & aksi */
.pf-error {
  display: none;
  margin: 0.9rem 0 0;
  padding: 0.6rem 0.8rem;
  background: #fdecec;
  border: 1px solid #f3c2c2;
  border-radius: 10px;
  color: #9b2c2c;
  font-size: 0.82rem;
}

.pf-error.is-visible {
  display: block;
}

.pf-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 1.15rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

.pf-actions .btn {
  flex: 0 1 auto;
  white-space: nowrap;
}

/* ==========================================================================
   PANGGUNG VISUALISASI
   ========================================================================== */
.pf-stage {
  padding: clamp(0.9rem, 2.5vw, 1.25rem);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.pf-stage__bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 0.9rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--line);
}

.pf-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.28rem 0.7rem;
  background: #eef3f8;
  border-radius: 999px;
  color: var(--slate);
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
}

.pf-badge::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9fb0c0;
}

.pf-stage[data-running="true"] .pf-badge {
  background: #e7f7ee;
  color: #146c3c;
}

.pf-stage[data-running="true"] .pf-badge::before {
  background: var(--success);
  animation: pfPulse 1.8s infinite;
}

@keyframes pfPulse {
  0% {
    box-shadow: 0 0 0 0 rgba(31, 157, 85, 0.45);
  }
  70% {
    box-shadow: 0 0 0 8px rgba(31, 157, 85, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(31, 157, 85, 0);
  }
}

.pf-stage__mode {
  color: var(--muted);
  font-size: 0.76rem;
}

/* Kanvas + grid teknik */
.pf-canvas {
  position: relative;
  margin: 0.75rem 0 0.25rem;
  padding: 0.25rem 0 1.5rem;
  background-image: linear-gradient(rgba(10, 77, 140, 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(10, 77, 140, 0.055) 1px, transparent 1px);
  background-size: 26px 26px;
  border-radius: var(--radius);
}

.pf-draw {
  display: block;
  width: 100%;
  height: auto;
}

/* ---------- Elemen SVG ---------- */
.pf-ground {
  stroke: #dbe7f1;
  stroke-width: 2;
  stroke-dasharray: 6 8;
}

.pf-tank {
  fill: #eef5fb;
  stroke: #a9c3d8;
  stroke-width: 2.5;
}

.pf-tank-rim {
  fill: #a9c3d8;
}

.pf-tank-water {
  fill: var(--fluid);
  opacity: 0.5;
  transition: fill 0.4s ease;
}

.pf-pipe {
  stroke: #cfdde9;
  stroke-width: 16;
  stroke-linecap: round;
  fill: none;
}

.pf-fluid {
  stroke: var(--fluid);
  stroke-width: 11;
  stroke-linecap: round;
  fill: none;
  opacity: 0.35;
  transition: fill 0.4s ease, stroke 0.4s ease, opacity 0.3s ease;
}

.pf-flow {
  stroke: rgba(255, 255, 255, 0.9);
  stroke-width: 6;
  stroke-linecap: round;
  stroke-dasharray: 2 18;
  fill: none;
  opacity: 0;
  transition: opacity 0.3s ease;
  animation: pfFlow var(--flow-duration, 1s) linear infinite;
  animation-play-state: paused;
}

@keyframes pfFlow {
  to {
    stroke-dashoffset: -40;
  }
}

.pf-stage[data-running="true"] .pf-fluid {
  opacity: 0.75;
}

.pf-stage[data-running="true"] .pf-flow {
  opacity: 0.95;
  animation-play-state: running;
}

.pf-base {
  fill: #9bb0c2;
}

.pf-pump {
  fill: #0a4d8c;
  stroke: #083a6b;
  stroke-width: 2;
}

.pf-impeller line {
  stroke: #7fb3e0;
  stroke-width: 4;
  stroke-linecap: round;
}

.pf-impeller {
  transform-origin: 234px 222px;
  animation: pfSpin 1.6s linear infinite;
  animation-play-state: paused;
}

.pf-stage[data-running="true"] .pf-impeller {
  animation-play-state: running;
}

@keyframes pfSpin {
  to {
    transform: rotate(360deg);
  }
}

.pf-pump-hub {
  fill: var(--orange-500);
}

.pf-motor {
  fill: #9bb0c2;
  stroke: #7e93a6;
  stroke-width: 2;
}

.pf-motor-fin {
  stroke: #7e93a6;
  stroke-width: 2.5;
}

.pf-valve-body {
  fill: #dfeaf3;
  stroke: #7e93a6;
  stroke-width: 2;
}

.pf-valve-stem {
  stroke: #7e93a6;
  stroke-width: 3;
  stroke-linecap: round;
}

.pf-valve-wheel {
  fill: #fff;
  stroke: var(--blue-700);
  stroke-width: 3;
}

.pf-tap {
  fill: #dfeaf3;
  stroke: #7e93a6;
  stroke-width: 2;
}

.pf-drop {
  fill: var(--fluid);
  opacity: 0;
}

.pf-stage[data-running="true"] .pf-drop {
  animation: pfDrip 1.6s ease-in infinite;
}

@keyframes pfDrip {
  0% {
    opacity: 0;
    transform: translateY(0);
  }
  20% {
    opacity: 1;
  }
  75% {
    opacity: 1;
    transform: translateY(14px);
  }
  100% {
    opacity: 0;
    transform: translateY(18px);
  }
}

/* ---------- Label komponen (HTML overlay) ---------- */
.pf-tag {
  position: absolute;
  transform: translateX(-50%);
  color: #8199ad;
  font-size: 0.64rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  pointer-events: none;
}

.pf-tag--tank {
  left: 12.7%;
  top: 92%;
}

.pf-tag--pump {
  left: 36.6%;
  top: 92%;
}

.pf-tag--valve {
  left: 62.5%;
  top: 92%;
}

.pf-tag--tap {
  right: 0;
  top: 92%;
  transform: none;
}

/* ---------- Indikator angka melayang ---------- */
.pf-chip {
  position: absolute;
  display: inline-flex;
  align-items: baseline;
  gap: 0.28rem;
  padding: 0.22rem 0.5rem;
  background: #fff;
  border: 1px solid #d7e5f1;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(6, 42, 74, 0.1);
  color: var(--ink);
  font-size: 0.72rem;
  white-space: nowrap;
  transform: translate(-50%, -100%);
  transition: border-color 0.3s ease;
}

.pf-chip b {
  font-size: 0.86rem;
  font-variant-numeric: tabular-nums;
}

.pf-chip__key {
  color: var(--blue-600);
  font-weight: 700;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.72rem;
}

.pf-chip__unit {
  color: var(--muted);
  font-size: 0.68rem;
}

/* Kecepatan di bawah pipa, pressure drop di atas pipa — agar tidak menutupi komponen */
.pf-chip--v {
  left: 56%;
  top: 69%;
  transform: translate(-50%, 0);
}

.pf-chip--dp {
  left: 76%;
  top: 61.5%;
}

.pf-stage[data-running="true"] .pf-chip {
  border-color: #bcd6ea;
}

.pf-noscript {
  position: absolute;
  inset: auto 0 0;
  margin: 0;
  padding: 0.5rem;
  background: #fff6e5;
  color: #7a4c05;
  font-size: 0.78rem;
  text-align: center;
}

/* ---------- Komponen terpasang ---------- */
.pf-parts {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  min-height: 1.7rem;
  margin: 0.35rem 0 0.9rem;
}

.pf-part {
  padding: 0.22rem 0.55rem;
  background: var(--blue-50);
  border: 1px solid #d8e6f2;
  border-radius: 999px;
  color: var(--blue-800);
  font-size: 0.7rem;
  font-weight: 600;
}

.pf-part--empty {
  background: transparent;
  border-style: dashed;
  border-color: var(--line);
  color: var(--muted);
  font-weight: 500;
}

/* ---------- Gauge ---------- */
.pf-gauge {
  display: grid;
  grid-template-columns: minmax(0, 190px) minmax(0, 1fr);
  gap: 0.9rem;
  align-items: center;
  padding: 0.75rem 0.9rem;
  background: var(--blue-50);
  border-radius: var(--radius);
}

.pf-gauge__svg {
  display: block;
  width: 100%;
  height: auto;
}

.pf-gauge__track {
  fill: none;
  stroke: #d3e2ee;
  stroke-width: 11;
  stroke-linecap: round;
}

.pf-gauge__fill {
  fill: none;
  stroke: var(--orange-500);
  stroke-width: 11;
  stroke-linecap: round;
  stroke-dasharray: 0 100;
  transition: stroke-dasharray 0.6s var(--ease);
}

.pf-gauge__ticks line {
  stroke: #a9c0d2;
  stroke-width: 2;
  stroke-linecap: round;
}

.pf-gauge__needle {
  transform-origin: 110px 110px;
  transform: rotate(-90deg);
  transition: transform 0.55s var(--ease);
}

.pf-gauge__needle line {
  stroke: var(--blue-800);
  stroke-width: 3.5;
  stroke-linecap: round;
}

.pf-gauge__hub {
  fill: var(--blue-800);
}

.pf-gauge__scale {
  fill: #8299ad;
  font-size: 10px;
  font-weight: 600;
}

.pf-gauge__info {
  display: grid;
  gap: 0.1rem;
}

.pf-gauge__label {
  color: var(--blue-600);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.pf-gauge__info strong {
  color: var(--ink);
  font-size: 1.25rem;
  font-variant-numeric: tabular-nums;
}

.pf-gauge__info small {
  color: var(--muted);
  font-size: 0.74rem;
}

/* ==========================================================================
   LAPORAN
   ========================================================================== */
.pf-report {
  padding: clamp(1.1rem, 3vw, 1.75rem);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.pf-report[hidden] {
  display: none;
}

.pf-report.is-revealed {
  animation: pfReveal 0.5s var(--ease) both;
}

@keyframes pfReveal {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.pf-report__status {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  padding: 0.85rem 1rem;
  background: #eaf7ef;
  border: 1px solid #cfe6d8;
  border-radius: var(--radius);
  color: #14603a;
}

.pf-report__status strong {
  display: block;
  font-size: 0.95rem;
}

.pf-report__status p {
  margin: 0.15rem 0 0;
  font-size: 0.85rem;
  line-height: 1.5;
}

.pf-report__icon {
  display: grid;
  flex: none;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.7);
}

.pf-report__icon svg {
  width: 20px;
  height: 20px;
}

.pf-report__status--warn {
  background: #fff6e5;
  border-color: #f2d8a4;
  color: #7a4c05;
}

.pf-report__status--danger {
  background: #fdecec;
  border-color: #f3c2c2;
  color: #9b2c2c;
}

.pf-report__status--idle {
  background: #eef3f8;
  border-color: #d7e5f1;
  color: var(--slate);
}

.pf-report__head {
  margin: 1.35rem 0 1rem;
}

.pf-report__title {
  margin-bottom: 0.25rem;
  font-size: clamp(1.25rem, 3vw, 1.55rem);
  scroll-margin-top: calc(var(--header-h) + 16px);
}

.pf-report__title:focus {
  outline: none;
}

.pf-report__lead {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.pf-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(155px, 1fr));
  gap: 0.7rem;
}

.pf-metric {
  padding: 0.8rem 0.9rem;
  background: var(--blue-50);
  border-radius: var(--radius);
}

.pf-metric__label {
  display: block;
  margin-bottom: 0.15rem;
  color: var(--blue-600);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.pf-metric strong {
  display: block;
  color: var(--ink);
  font-size: 1.08rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.3;
}

.pf-metric small {
  display: block;
  margin-top: 0.15rem;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.45;
}

.pf-details {
  margin-top: 1.15rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.pf-details summary {
  padding: 0.8rem 1rem;
  background: var(--blue-50);
  color: var(--blue-800);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.pf-details summary:hover {
  background: #e8f1f9;
}

.pf-steps {
  display: grid;
  gap: 0.55rem;
  margin: 0;
  padding: 0.9rem 1rem 0.9rem 2.2rem;
  color: var(--slate);
  font-size: 0.82rem;
  line-height: 1.55;
}

.pf-steps code {
  padding: 0.05rem 0.3rem;
  background: #f3f8fc;
  border-radius: 4px;
  color: var(--blue-800);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.76rem;
}

.pf-report__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  margin-top: 1.25rem;
  padding-top: 1.1rem;
  border-top: 1px solid var(--line);
}

/* ==========================================================================
   Reduced motion & penyesuaian kecil
   ========================================================================== */
@media (max-width: 30rem) {
  .pf-gauge {
    grid-template-columns: minmax(0, 150px) minmax(0, 1fr);
  }

  .pf-chip {
    font-size: 0.66rem;
  }

  .pf-chip b {
    font-size: 0.78rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .pf-flow,
  .pf-impeller,
  .pf-drop,
  .pf-badge::before {
    animation: none;
  }

  .pf-stage[data-running="true"] .pf-flow {
    opacity: 0.9;
  }

  .pf-chip,
  .pf-fluid,
  .pf-gauge__needle,
  .pf-gauge__fill,
  .pf-tank-water,
  .pf-report.is-revealed {
    transition: none;
    animation: none;
  }
}
