/* ============================================================================
   DATA-PIPELINE DIAGRAM — shared component
   ----------------------------------------------------------------------------
   The animated input → Tvyal → output diagram. Structure + skin + animation
   live here ONCE. Markup is generated at runtime by js/consultation-animation.js
   (buildDiagram()); this file is the ONLY stylesheet that styles it.

   Loaded by:
     • consultation-popup.html  (the consultation popup, in modal.js's iframe)
     • event.html               (/event, with the .diagram-deapple host skin)

   Both hosts load design-system.css FIRST, so every colour var used here
   (--card-bg-color --border-color --color-main --color-second --icon-blue
   --text-color --transition-speed --accent --radius-sm) resolves globally, and
   @keyframes fadeIn comes from design-system.css — we do NOT redefine it here
   (redefining it would silently change every .fade-in on the host page).
   @keyframes pulse and logoSuccess are diagram-specific and live here; the JS
   references `pulse` BY NAME, so keep that name.
   ============================================================================ */

.diagram-container {
  width: 100%;
  max-width: 600px;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative; /* CRITICAL: Needed for packet positioning */
  padding: 3rem 1.5rem;
}

@media (max-width: 1024px) {
  .diagram-container {
    max-width: 100%;
    padding: 1rem;
  }
}

/* Diagram Rows */
.diagram-row {
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
  justify-content: center !important;
  align-items: center;
  gap: 2rem !important;
  margin: 1rem 0;
  position: relative;
  width: 100%;
}

/* Diagram Items (Boxes) — fixed uniform size to fit 2-line HY labels */
.diagram-item {
  background: var(--card-bg-color);
  border: 2px solid var(--border-color);
  border-radius: 12px;
  padding: 0.5rem;

  width: 150px !important;
  min-width: 150px !important;
  max-width: 150px !important;
  height: 110px !important;
  min-height: 110px !important;
  max-height: 110px !important;

  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  overflow: hidden;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  transition: all var(--transition-speed) ease;
  position: relative;
  flex-shrink: 0 !important;
  flex-grow: 0 !important;

  /* Start invisible for fade-in animation */
  opacity: 0;
  transform: translateY(20px);
}

/* CRITICAL FIX: Ensure items become visible even if animation doesn't fire */
.diagram-container.animated .diagram-item {
  opacity: 1;
  transform: translateY(0);
}

.diagram-item-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.diagram-item-icon svg {
  width: 2rem;
  height: 2rem;
}

/* Theme-aware icon colors: top row (inputs) blue, bottom row (outputs) orange.
   Icons use stroke="currentColor", so setting `color` drives them.
   --icon-blue is defined globally in design-system.css. */
#input-row  .diagram-item-icon { color: var(--icon-blue); }
#output-row .diagram-item-icon { color: var(--accent); }

.diagram-item-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-color);
  text-align: center;
  line-height: 1.3;
  /* Break at spaces and at &shy; soft hyphens only; fall back to breaking a too-long
     word only if nothing else fits. The soft hyphen stays invisible until a break is needed. */
  overflow-wrap: break-word;
  word-break: normal;
  hyphens: manual;
}

/* Armenian labels run ~10% wider than the fallback; nudge them down so 3-line
   labels («ERP համակար-գեր») stay inside the fixed box height. Specificity
   (0,2,0): the smaller per-breakpoint HY sizes below MUST come later in source
   to win — a single-class .diagram-item-label rule cannot override this. */
body.lang-hy .diagram-item-label { font-size: 90%; }

/* Process Box (Middle) - FORCE BIGGER SIZE */
.diagram-process-box {
  /* Override all sizing constraints */
  min-width: 200px !important;
  max-width: 200px !important;
  width: 200px !important;
  min-height: 200px !important;
  max-height: 200px !important;
  height: 200px !important;

  background: linear-gradient(135deg, var(--color-main), var(--color-second));
  border-color: var(--color-second);
  position: relative;
}

/* Success state: Logo grows 1.5x and shifts colors */
.diagram-process-box.success-state {
  animation: logoSuccess 1s ease forwards;
}

@keyframes logoSuccess {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.5);
  }
  100% {
    transform: scale(1.5);
    background: linear-gradient(135deg, var(--color-second), var(--color-second-n2));
  }
}

/* Animated logo inside process box. The logo is injected INLINE (an <svg>, or
   an <img> fallback) into #process-logo, which sits in the flex column above the
   label — so it must stay in normal flow (NOT absolute) for the label to clear it. */
.diagram-process-box #process-logo svg,
.diagram-process-box #process-logo img {
  display: block;
  width: 120px;
  height: 120px;
}

/* Diagram Arrows */
.diagram-arrow {
  font-size: 2rem;
  color: var(--text-color);
  opacity: 0;
  margin: 0.5rem 0;
}

/* CRITICAL FIX: Ensure arrows become visible */
.diagram-container.animated .diagram-arrow {
  opacity: 1;
}

/* Data Packets (Moving dots) */
.data-packet {
  position: absolute;
  width: 12px;
  height: 12px;
  background: var(--color-second);
  border-radius: 50%;
  box-shadow: 0 0 10px var(--color-second);
  pointer-events: none;
  z-index: 10;
}

/* Pulse animation for process box (referenced by name from the JS) */
@keyframes pulse {
  0%, 100% {
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  }
  50% {
    box-shadow: 0 8px 30px rgba(255, 124, 67, 0.4);
  }
}

/* Mobile adjustments for diagram */
@media (max-width: 768px) {
  .diagram-row {
    gap: 1.5rem !important;
  }

  .diagram-item {
    width: 128px !important;
    min-width: 128px !important;
    max-width: 128px !important;
    height: 100px !important;
    min-height: 100px !important;
    max-height: 100px !important;
    padding: 0.5rem;
  }

  .diagram-process-box {
    min-width: 160px !important;
    max-width: 160px !important;
    width: 160px !important;
    min-height: 190px !important;
    max-height: 190px !important;
    height: 190px !important;
  }

  /* Shrink the inline logo (svg or img fallback) so it never crowds the label
     out of the box. */
  .diagram-process-box #process-logo svg,
  .diagram-process-box #process-logo img {
    width: 80px !important;
    height: 80px !important;
  }

  .diagram-item-icon svg {
    width: 1.75rem;
    height: 1.75rem;
  }

  .diagram-item-label {
    font-size: 0.85rem;
  }

  .diagram-arrow {
    font-size: 1.5rem;
  }
}

/* Very small screens (iPhone SE 320px → iPhone 12/13/14 390px).
   Three input boxes + two gaps + container padding must clear a 320px viewport:
   3 × 92 + 2 × 8 + 2 × 8 = 308px < 320. The old 108px/1rem-gap sizing summed to
   356px and overflowed every phone narrower than ~390px — this is the fit fix. */
@media (max-width: 400px) {
  .diagram-container {
    padding: 0.5rem;
  }

  .diagram-row {
    gap: 0.5rem !important;
  }

  .diagram-item {
    width: 92px !important;
    min-width: 92px !important;
    max-width: 92px !important;
    height: 104px !important;
    min-height: 104px !important;
    max-height: 104px !important;
    padding: 0.4rem;
  }

  .diagram-process-box {
    min-width: 150px !important;
    max-width: 150px !important;
    width: 150px !important;
    min-height: 165px !important;
    max-height: 165px !important;
    height: 165px !important;
  }

  .diagram-process-box #process-logo svg,
  .diagram-process-box #process-logo img {
    width: 70px !important;
    height: 70px !important;
  }

  .diagram-item-icon svg {
    width: 1.5rem;
    height: 1.5rem;
  }

  .diagram-item-label {
    font-size: 0.8rem;
  }

  .diagram-arrow {
    font-size: 1.5rem;
    margin: 0.25rem 0;
  }

  /* HY at ≤400: the 90% rule above resolves to 14.4px and shaves the widest
     one-line labels; 0.72rem (~11.5px) clears the 92px box. */
  body.lang-hy .diagram-item-label {
    font-size: 0.72rem;
  }
}

/* ----------------------------------------------------------------------------
   HOST SKIN: .diagram-deapple  (used by /event)
   /event ran a de-Apple pass — flat frames, 4px radius, 1px hairlines, no drop
   shadows. This override flattens the input/output FRAME only; the centre
   process box keeps its navy→orange gradient (the brand mark the white logo is
   recoloured to sit on). The consultation popup does NOT carry this class, so
   its 12px/2px/shadow skin is untouched.
   ---------------------------------------------------------------------------- */
.diagram-deapple .diagram-item {
  border-width: 1px;
  border-radius: var(--radius-sm);
  box-shadow: none;
}
