/* =========================================================
  ChemEquilibrium Lab - assets/css/graph.css
  ---------------------------------------------------------
  Style khusus Mode Grafik:
  - panel grafik konsentrasi dan laju reaksi
  - canvas chart
  - legend grafik
  - tooltip / snapshot / marker setimbang
  - state gangguan sistem
  - responsive polish
========================================================= */

/* =========================================================
  Graph Panel Decorative Layers
========================================================= */

.graph-panel {
  position: relative;
  overflow: hidden;
}

.graph-panel::before,
.graph-panel::after {
  content: "";
  position: absolute;
  pointer-events: none;
  border-radius: var(--radius-full);
  z-index: 0;
}

.graph-panel::before {
  width: 520px;
  height: 520px;
  right: -180px;
  top: -150px;
  background: radial-gradient(circle, rgba(34, 211, 238, 0.16), transparent 70%);
}

.graph-panel::after {
  width: 430px;
  height: 430px;
  left: -150px;
  bottom: -160px;
  background: radial-gradient(circle, rgba(37, 99, 235, 0.12), transparent 70%);
}

.graph-panel > * {
  position: relative;
  z-index: 1;
}

/* =========================================================
  Graph Header
========================================================= */

.graph-panel .panel-header {
  align-items: center;
}

.graph-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.graph-actions .btn {
  min-height: 44px;
}

#clearGraphButton {
  background: rgba(255, 255, 255, 0.82);
}

#snapshotGraphButton {
  box-shadow: var(--shadow-sm), var(--shadow-glow-blue);
}

/* =========================================================
  Graph Cards
========================================================= */

.graph-card {
  position: relative;
  overflow: hidden;
  isolation: isolate;
}

.graph-card::before {
  content: "";
  position: absolute;
  width: 170px;
  height: 170px;
  right: -82px;
  top: -82px;
  z-index: -1;
  border-radius: var(--radius-full);
  background: rgba(34, 211, 238, 0.1);
  pointer-events: none;
}

.graph-card:nth-child(2)::before {
  background: rgba(249, 115, 22, 0.1);
}

.graph-card .card-header h3 {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.graph-card .card-header h3::before {
  content: "";
  width: 12px;
  height: 12px;
  border-radius: var(--radius-full);
  background: var(--gradient-primary);
  box-shadow: 0 0 0 6px rgba(37, 99, 235, 0.12);
}

.graph-card:nth-child(2) .card-header h3::before {
  background: var(--gradient-warning);
  box-shadow: 0 0 0 6px rgba(249, 115, 22, 0.12);
}

.graph-canvas {
  position: relative;
  display: block;
  width: 100%;
  height: 420px;
  border-radius: var(--radius-xl);
  border: 1px solid var(--border-soft);
  background-image:
    linear-gradient(rgba(15, 23, 42, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(15, 23, 42, 0.045) 1px, transparent 1px),
    linear-gradient(180deg, rgba(255, 255, 255, 0.86), rgba(255, 255, 255, 0.7));
  background-size: 42px 42px, 42px 42px, 100% 100%;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.58),
    var(--shadow-sm);
  transition:
    box-shadow var(--duration-fast) var(--ease-out),
    border-color var(--duration-fast) var(--ease-out),
    transform var(--duration-fast) var(--ease-out);
}

.graph-card:hover .graph-canvas {
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.58),
    var(--shadow-md);
}

#concentrationGraphCanvas {
  border-color: rgba(37, 99, 235, 0.14);
}

#rateGraphCanvas {
  border-color: rgba(249, 115, 22, 0.16);
}

/* =========================================================
  Optional Graph Legend
========================================================= */

.graph-legend {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-top: var(--space-4);
  padding: var(--space-3);
  border-radius: var(--radius-xl);
  background: rgba(255, 255, 255, 0.68);
  border: 1px solid var(--border-soft);
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: 850;
}

.graph-legend-item {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.graph-legend-line {
  width: 28px;
  height: 5px;
  display: inline-block;
  border-radius: var(--radius-full);
  background: var(--primary);
}

.graph-legend-line.reactant {
  background: var(--reactant);
}

.graph-legend-line.product {
  background: var(--product);
}

.graph-legend-line.forward-rate {
  background: var(--primary);
}

.graph-legend-line.reverse-rate {
  background: var(--product);
}

.graph-legend-line.equilibrium {
  background: var(--equilibrium);
}

/* =========================================================
  Graph Tooltip
========================================================= */

.graph-tooltip {
  position: fixed;
  z-index: var(--z-modal);
  min-width: 170px;
  max-width: 260px;
  display: grid;
  gap: var(--space-1);
  padding: var(--space-3);
  border-radius: var(--radius-lg);
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--border-soft);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(14px);
  pointer-events: none;
  font-size: var(--text-sm);
  opacity: 0;
  transform: translateY(4px) scale(0.98);
  transition:
    opacity var(--duration-fast) var(--ease-out),
    transform var(--duration-fast) var(--ease-out);
}

.graph-tooltip.is-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.graph-tooltip strong {
  color: var(--primary);
  font-weight: 950;
}

.graph-tooltip span {
  color: var(--text-muted);
  font-weight: 750;
}

/* =========================================================
  Graph Stats Strip
========================================================= */

.graph-stats-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-3);
  margin: 0 var(--space-5) var(--space-5);
}

.graph-stat-card {
  display: grid;
  gap: var(--space-1);
  padding: var(--space-4);
  border-radius: var(--radius-xl);
  background: rgba(255, 255, 255, 0.74);
  border: 1px solid var(--border-soft);
  box-shadow: var(--shadow-sm);
}

.graph-stat-card span {
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: 850;
}

.graph-stat-card strong {
  color: var(--text-main);
  font-size: var(--text-2xl);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.graph-stat-card.is-reactant strong {
  color: var(--reactant);
}

.graph-stat-card.is-product strong {
  color: var(--product);
}

.graph-stat-card.is-equilibrium strong {
  color: var(--equilibrium);
}

.graph-stat-card.is-success strong {
  color: var(--success);
}

/* =========================================================
  Snapshot Gallery
========================================================= */

.graph-snapshot-panel {
  margin: 0 var(--space-5) var(--space-5);
  padding: var(--space-4);
  border-radius: var(--radius-2xl);
  background: rgba(255, 255, 255, 0.76);
  border: 1px solid var(--border-soft);
  box-shadow: var(--shadow-md);
}

.graph-snapshot-panel h3 {
  margin-bottom: var(--space-4);
}

.snapshot-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-3);
}

.snapshot-card {
  display: grid;
  gap: var(--space-2);
  padding: var(--space-3);
  border-radius: var(--radius-xl);
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--border-soft);
  box-shadow: var(--shadow-xs);
  transition:
    transform var(--duration-fast) var(--ease-out),
    box-shadow var(--duration-fast) var(--ease-out),
    border-color var(--duration-fast) var(--ease-out);
}

.snapshot-card:hover {
  transform: translateY(-2px);
  border-color: rgba(37, 99, 235, 0.22);
  box-shadow: var(--shadow-sm);
}

.snapshot-thumb {
  min-height: 90px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-lg);
  background:
    linear-gradient(135deg, rgba(219, 234, 254, 0.82), rgba(255, 237, 213, 0.72));
  border: 1px solid var(--border-soft);
  overflow: hidden;
}

.snapshot-card small {
  color: var(--text-muted);
  font-weight: 800;
  line-height: var(--leading-normal);
}

/* =========================================================
  Equilibrium Marker Overlay
========================================================= */

.graph-canvas-wrap {
  position: relative;
  border-radius: var(--radius-xl);
}

.equilibrium-marker-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  left: 70%;
  border-radius: var(--radius-full);
  background: linear-gradient(180deg, transparent, var(--equilibrium), transparent);
  opacity: 0.72;
  pointer-events: none;
}

.equilibrium-marker-label {
  position: absolute;
  top: var(--space-3);
  left: 70%;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-full);
  color: var(--color-white);
  background: var(--equilibrium);
  box-shadow: var(--shadow-sm);
  font-size: var(--text-xs);
  font-weight: 900;
  white-space: nowrap;
  pointer-events: none;
}

/* =========================================================
  Graph State Effects
========================================================= */

.graph-panel.is-live .graph-card {
  animation: graphLivePulse 3s ease-in-out infinite;
}

@keyframes graphLivePulse {
  0%,
  100% {
    box-shadow: var(--shadow-lg);
  }

  50% {
    box-shadow: var(--shadow-lg), 0 0 0 4px rgba(34, 211, 238, 0.08);
  }
}

.graph-panel.is-disturbed .graph-card {
  animation: graphDisturbancePulse 760ms ease-out;
}

@keyframes graphDisturbancePulse {
  0%,
  100% {
    transform: translateY(0);
  }

  30% {
    transform: translateY(-3px);
  }

  60% {
    transform: translateY(2px);
  }
}

.graph-card.is-updating .graph-canvas {
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.58),
    var(--shadow-md),
    0 0 0 5px rgba(37, 99, 235, 0.1);
}

.graph-card.is-balanced .graph-canvas {
  border-color: rgba(22, 163, 74, 0.26);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.58),
    var(--shadow-md),
    0 0 28px rgba(22, 163, 74, 0.16);
}

/* =========================================================
  Empty / Loading States
========================================================= */

.graph-empty-state,
.graph-loading-state {
  min-height: 260px;
  display: grid;
  place-items: center;
  padding: var(--space-6);
  border-radius: var(--radius-xl);
  background: rgba(255, 255, 255, 0.72);
  border: 1px dashed rgba(15, 23, 42, 0.16);
  text-align: center;
}

.graph-empty-state p,
.graph-loading-state p {
  max-width: 40ch;
  line-height: var(--leading-relaxed);
}

.graph-loading-dots {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.graph-loading-dots span {
  width: 10px;
  height: 10px;
  border-radius: var(--radius-full);
  background: var(--primary);
  animation: graphDotLoading 1s ease-in-out infinite;
}

.graph-loading-dots span:nth-child(2) {
  animation-delay: 140ms;
}

.graph-loading-dots span:nth-child(3) {
  animation-delay: 280ms;
}

@keyframes graphDotLoading {
  0%,
  100% {
    transform: translateY(0);
    opacity: 0.5;
  }

  50% {
    transform: translateY(-7px);
    opacity: 1;
  }
}

/* =========================================================
  Responsive Graph Mode
========================================================= */

@media (max-width: 1360px) {
  .graph-canvas {
    height: 380px;
  }

  .snapshot-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 1180px) {
  .graph-panel .panel-header {
    display: grid;
    align-items: start;
  }

  .graph-actions {
    justify-content: flex-start;
  }

  .graph-stats-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 980px) {
  .graph-canvas {
    height: 340px;
  }

  .snapshot-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .graph-panel::before,
  .graph-panel::after {
    opacity: 0.55;
  }

  .graph-card {
    padding: var(--space-3);
  }

  .graph-card .card-header {
    display: grid;
    gap: var(--space-2);
  }

  .graph-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr;
  }

  .graph-canvas {
    height: 300px;
    border-radius: var(--radius-lg);
    background-size: 36px 36px, 36px 36px, 100% 100%;
  }

  .graph-legend {
    justify-content: flex-start;
  }

  .graph-stats-strip,
  .graph-snapshot-panel {
    margin-inline: var(--space-3);
  }

  .graph-stats-strip {
    grid-template-columns: 1fr;
  }

  .snapshot-grid {
    grid-template-columns: 1fr;
  }

  .equilibrium-marker-label {
    top: var(--space-2);
    font-size: 0.68rem;
  }
}

@media (max-width: 520px) {
  .graph-canvas {
    height: 260px;
    background-size: 32px 32px, 32px 32px, 100% 100%;
  }

  .graph-legend {
    display: grid;
    grid-template-columns: 1fr;
    justify-items: start;
  }

  .graph-stat-card {
    padding: var(--space-3);
  }

  .graph-stat-card strong {
    font-size: var(--text-xl);
  }

  .graph-tooltip {
    max-width: calc(100vw - 2rem);
  }
}

/* =========================================================
  Reduced Motion
========================================================= */

@media (prefers-reduced-motion: reduce) {
  .graph-panel.is-live .graph-card,
  .graph-panel.is-disturbed .graph-card,
  .graph-loading-dots span {
    animation: none !important;
  }
}