/* =====================================================================
   Animated Feature Cards — index.html "One Edge AI Box Per Barn" section
   Each card has a looping CSS-only visual + hover-revealed detail panel.
   ===================================================================== */

/* ---------- Grid + Card shell ---------- */
.features-v2 {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
    align-items: start;
}
@media (min-width: 640px) {
    .features-v2 { grid-template-columns: repeat(2, 1fr); }
    /* On 2-column layout, card 5 is alone on the last row — full width */
    .features-v2 > .fcard:nth-child(5) { grid-column: span 2; }
}
@media (min-width: 1024px) {
    /* 6-column grid so 5 cards (each spanning 2) leave cards 4 and 5 centered */
    .features-v2 { grid-template-columns: repeat(6, 1fr); }
    .features-v2 > .fcard { grid-column: span 2; }
    .features-v2 > .fcard:nth-child(4) { grid-column: 2 / span 2; }
    .features-v2 > .fcard:nth-child(5) { grid-column: 4 / span 2; }
}

.fcard {
    position: relative;
    background: #fff;
    border-radius: 0.75rem;
    overflow: hidden;
    border: 1px solid rgba(27, 67, 50, 0.06);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
    display: flex;
    flex-direction: column;
    transition:
        transform 360ms cubic-bezier(0.16, 1, 0.3, 1),
        box-shadow 360ms cubic-bezier(0.16, 1, 0.3, 1),
        border-color 360ms ease;
}
.fcard:hover,
.fcard:focus-within {
    transform: translateY(-6px);
    box-shadow: 0 16px 40px -12px rgba(27, 67, 50, 0.22);
    border-color: rgba(27, 67, 50, 0.18);
}

/* ---------- Visual (top of card) ---------- */
.fvis {
    position: relative;
    height: 168px;
    overflow: hidden;
    background: linear-gradient(135deg, #faf7f2 0%, #ede9e0 100%);
    border-bottom: 1px solid rgba(27, 67, 50, 0.06);
}
.fvis-grid {
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(27, 67, 50, 0.05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(27, 67, 50, 0.05) 1px, transparent 1px);
    background-size: 20px 20px;
    pointer-events: none;
}

/* ---------- Body ---------- */
.fbody {
    padding: 1.25rem 1.5rem 1.5rem;
    flex: 1;
    display: flex;
    flex-direction: column;
}
.fhead {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}
.fhead h3 {
    font-weight: 700;
    color: #1B4332;
    font-size: 0.95rem;
    margin: 0;
}
.fnum {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #1B4332;
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    flex-shrink: 0;
}
.fdesc {
    font-size: 0.85rem;
    color: rgba(27, 67, 50, 0.7);
    line-height: 1.6;
    margin: 0;
}

/* ---------- Hover detail ---------- */
.fdetail {
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    margin-top: 0;
    transition:
        max-height 420ms cubic-bezier(0.16, 1, 0.3, 1),
        opacity 320ms ease,
        margin-top 320ms ease;
}
@media (hover: hover) {
    .fcard:hover .fdetail,
    .fcard:focus-within .fdetail {
        max-height: 260px;
        opacity: 1;
        margin-top: 0.85rem;
    }
}
@media (hover: none) {
    .fdetail {
        max-height: 260px;
        opacity: 1;
        margin-top: 0.85rem;
    }
}
.fstats {
    display: flex;
    gap: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid rgba(27, 67, 50, 0.08);
}
.fstats .stat {
    display: flex;
    flex-direction: column;
    line-height: 1.1;
}
.fstats .stat-num {
    font-weight: 700;
    color: #1B4332;
    font-size: 0.95rem;
}
.fstats .stat-lbl {
    margin-top: 0.25rem;
    font-size: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: rgba(27, 67, 50, 0.55);
}
.fdetail-text {
    margin-top: 0.75rem;
    font-size: 0.75rem;
    color: rgba(27, 67, 50, 0.65);
    line-height: 1.6;
}

/* Live indicator dot (used in a few visuals) */
.live-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #6B8F71;
    box-shadow: 0 0 0 0 rgba(107, 143, 113, 0.5);
    animation: live-pulse 2s ease-out infinite;
}
@keyframes live-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(107, 143, 113, 0.6); }
    70%  { box-shadow: 0 0 0 6px rgba(107, 143, 113, 0); }
    100% { box-shadow: 0 0 0 0 rgba(107, 143, 113, 0); }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .fcard,
    .fcard *,
    .fvis * {
        animation: none !important;
        transition: none !important;
    }
}

/* =====================================================================
   01 — Piling Detection  (JS-driven, mirrors the hero demo)
   Uniform dots positioned via --x/--y. JS moves them between a
   scattered layout and a clustered layout. When clustered, dots turn
   red and the detection box fades in.
   ===================================================================== */
.fvis-piling .fbird,
.fvis-prevention .fbird {
    position: absolute;
    left: var(--x, 50%);
    top: var(--y, 50%);
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #1B4332;
    box-shadow: 0 0 4px rgba(27, 67, 50, 0.25);
    transition:
        left 1.3s cubic-bezier(0.4, 0, 0.2, 1),
        top 1.3s cubic-bezier(0.4, 0, 0.2, 1),
        background 0.5s ease,
        box-shadow 0.5s ease;
}

/* Clustered birds get flagged red only once detection fires */
.fvis-piling.is-detected .fbird {
    background: #E85D4C;
    box-shadow: 0 0 6px rgba(232, 93, 76, 0.45);
}

/* Detection box overlays the cluster zone (upper-right) */
.fvis-piling .detection-box {
    position: absolute;
    left: 54%;
    top: 12px;
    width: 42%;
    height: 82px;
    border: 2px solid #E85D4C;
    border-radius: 4px;
    opacity: 0;
    transform: scale(0.94);
    transform-origin: center;
    transition: opacity 0.4s ease, transform 0.4s ease;
    pointer-events: none;
}
.fvis-piling .detection-box::before {
    content: "PILING";
    position: absolute;
    top: -16px;
    left: 0;
    font-size: 8px;
    font-weight: 700;
    letter-spacing: 0.15em;
    color: #E85D4C;
}
.fvis-piling.is-detected .detection-box {
    opacity: 1;
    transform: scale(1);
}

/* Status pill bottom-left */
.fvis .vis-tag {
    position: absolute;
    bottom: 10px;
    left: 12px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    background: rgba(27, 67, 50, 0.85);
    color: #fff;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    border-radius: 3px;
    backdrop-filter: blur(4px);
}

/* =====================================================================
   02 — Piling Prevention  (JS-driven, mirrors the hero demo)
   Dots start clustered. JS adds .is-dispersing: the LED strip waves,
   the speakers ring, and the dots scatter to the edges. Then it
   returns to clustered and repeats.
   ===================================================================== */

/* LED strips top + bottom (forms a rectangle around the barn) */
.fvis-prevention .led-strip {
    position: absolute;
    left: 12%;
    right: 12%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    pointer-events: none;
}
.fvis-prevention .led-strip-top    { top: 10px; }
.fvis-prevention .led-strip-bottom { bottom: 10px; }
.fvis-prevention .led-dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: rgba(212, 160, 23, 0.2);
    box-shadow: none;
    transition: background 0.3s ease, box-shadow 0.3s ease;
}
.fvis-prevention.is-dispersing .led-dot {
    animation: prv-led-light 1.6s ease-in-out infinite;
}
.fvis-prevention.is-dispersing .led-dot:nth-child(1)  { animation-delay: 0.00s; }
.fvis-prevention.is-dispersing .led-dot:nth-child(2)  { animation-delay: 0.08s; }
.fvis-prevention.is-dispersing .led-dot:nth-child(3)  { animation-delay: 0.16s; }
.fvis-prevention.is-dispersing .led-dot:nth-child(4)  { animation-delay: 0.24s; }
.fvis-prevention.is-dispersing .led-dot:nth-child(5)  { animation-delay: 0.32s; }
.fvis-prevention.is-dispersing .led-dot:nth-child(6)  { animation-delay: 0.40s; }
.fvis-prevention.is-dispersing .led-dot:nth-child(7)  { animation-delay: 0.48s; }
.fvis-prevention.is-dispersing .led-dot:nth-child(8)  { animation-delay: 0.56s; }
.fvis-prevention.is-dispersing .led-dot:nth-child(9)  { animation-delay: 0.64s; }
.fvis-prevention.is-dispersing .led-dot:nth-child(10) { animation-delay: 0.72s; }
.fvis-prevention.is-dispersing .led-dot:nth-child(11) { animation-delay: 0.80s; }
.fvis-prevention.is-dispersing .led-dot:nth-child(12) { animation-delay: 0.88s; }
@keyframes prv-led-light {
    0%, 100% { background: rgba(212, 160, 23, 0.2); box-shadow: none; }
    40%      { background: #F5C842; box-shadow: 0 0 10px #D4A017; }
}

/* Side speakers */
.fvis-prevention .speaker {
    position: absolute;
    width: 10px;
    height: 10px;
    top: 50%;
    margin-top: -5px;
    border-radius: 50%;
    background: #6B8F71;
    box-shadow: 0 0 8px rgba(107, 143, 113, 0.45);
}
.fvis-prevention .speaker.s-l { left: 10px; }
.fvis-prevention .speaker.s-r { right: 10px; }

.fvis-prevention .speaker::before,
.fvis-prevention .speaker::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 10px;
    height: 10px;
    margin: -5px 0 0 -5px;
    border-radius: 50%;
    border: 2px solid #6B8F71;
    opacity: 0;
    transform: scale(0.5);
}
.fvis-prevention.is-dispersing .speaker::before {
    animation: prv-sound-ring 1.4s ease-out infinite;
}
.fvis-prevention.is-dispersing .speaker::after {
    animation: prv-sound-ring 1.4s ease-out 0.5s infinite;
}
@keyframes prv-sound-ring {
    0%   { transform: scale(0.5); opacity: 0.8; }
    100% { transform: scale(5);   opacity: 0; }
}

/* Dots — clustered by default, JS repositions them via --x/--y */
.fvis-prevention.is-dispersing .fbird {
    background: #6B8F71;
    box-shadow: 0 0 6px rgba(107, 143, 113, 0.4);
}

/* =====================================================================
   03 — Weight Monitoring
   Growth chart: SVG line draws across the visual. The flock weight
   counter ticks through ascending values to mirror the curve.
   ===================================================================== */
.fvis-weight {
    background: linear-gradient(135deg, #f8f6f1 0%, #ede9e0 100%);
}
.fvis-weight .chart {
    position: absolute;
    inset: 16px 16px 28px 16px;
}
.fvis-weight .chart-axis {
    stroke: rgba(27, 67, 50, 0.15);
    stroke-width: 1;
    fill: none;
}
.fvis-weight .chart-line {
    stroke: #1B4332;
    stroke-width: 2;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-dasharray: 220;
    stroke-dashoffset: 220;
    animation: wt-draw 5s ease-in-out infinite;
}
.fvis-weight .chart-area {
    fill: rgba(27, 67, 50, 0.08);
    opacity: 0;
    animation: wt-area 5s ease-in-out infinite;
}
.fvis-weight .chart-dot {
    fill: #D4A017;
    r: 3.5;
    opacity: 0;
    animation: wt-dot 5s ease-in-out infinite;
}
@keyframes wt-draw {
    0%        { stroke-dashoffset: 220; opacity: 0; }
    6%        { stroke-dashoffset: 220; opacity: 1; }
    55%, 85%  { stroke-dashoffset: 0;   opacity: 1; }
    97%, 100% { stroke-dashoffset: 0;   opacity: 0; }
}
@keyframes wt-area {
    0%, 10%   { opacity: 0; }
    55%, 85%  { opacity: 1; }
    97%, 100% { opacity: 0; }
}
@keyframes wt-dot {
    0%, 50%   { opacity: 0; }
    60%, 85%  { opacity: 1; }
    97%, 100% { opacity: 0; }
}

/* Static weight value, anchored where the line ends (top-right) */
.fvis-weight .weight-counter {
    position: absolute;
    top: 12px;
    right: 14px;
    font-family: '"JetBrains Mono"', monospace;
    font-weight: 700;
    font-size: 16px;
    color: #1B4332;
    line-height: 1;
    text-align: right;
}

.fvis-weight .weight-label {
    position: absolute;
    top: 12px;
    left: 14px;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: rgba(27, 67, 50, 0.55);
}

/* =====================================================================
   04 — Early Disease Detection
   A scan line sweeps across the floor. One bird pulses red as an
   anomaly. Surrounding birds gently brighten as the scan passes.
   ===================================================================== */
.fvis-disease .fbird {
    position: absolute;
    width: 6px;
    height: 6px;
    background: #1B4332;
    border-radius: 50%;
    opacity: 0.6;
    box-shadow: 0 0 4px rgba(27, 67, 50, 0.25);
    transition: background 200ms ease, opacity 200ms ease;
}
.fvis-disease .fbird.b-1  { left: 12%; top: 24%; }
.fvis-disease .fbird.b-2  { left: 22%; top: 60%; }
.fvis-disease .fbird.b-3  { left: 26%; top: 82%; }
.fvis-disease .fbird.b-4  { left: 38%; top: 40%; }
.fvis-disease .fbird.b-5  { left: 42%; top: 72%; }
.fvis-disease .fbird.b-6  { left: 52%; top: 28%; }
.fvis-disease .fbird.b-7  { left: 56%; top: 58%; }
.fvis-disease .fbird.b-8  { left: 65%; top: 80%; }
.fvis-disease .fbird.b-9  { left: 76%; top: 36%; }
.fvis-disease .fbird.b-10 { left: 84%; top: 66%; }
.fvis-disease .fbird.b-11 { left: 16%; top: 44%; }

/* The anomalous one */
.fvis-disease .fbird.anomaly {
    left: 70%;
    top: 50%;
    width: 7px;
    height: 7px;
    background: #E85D4C;
    opacity: 1;
    box-shadow: 0 0 0 0 rgba(232, 93, 76, 0.55);
    animation: dis-anomaly 2.4s ease-out infinite;
}
@keyframes dis-anomaly {
    0%   { box-shadow: 0 0 0 0 rgba(232, 93, 76, 0.55); }
    70%  { box-shadow: 0 0 0 14px rgba(232, 93, 76, 0); }
    100% { box-shadow: 0 0 0 0 rgba(232, 93, 76, 0); }
}

/* Scan line sweeping left-to-right */
.fvis-disease .scan-line {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 2px;
    background: linear-gradient(
        to bottom,
        transparent,
        rgba(212, 160, 23, 0.85) 30%,
        rgba(212, 160, 23, 0.85) 70%,
        transparent
    );
    box-shadow: 0 0 16px rgba(212, 160, 23, 0.65);
    animation: dis-scan 4s linear infinite;
}
@keyframes dis-scan {
    0%   { left: -2%; opacity: 0; }
    10%  { opacity: 1; }
    90%  { opacity: 1; }
    100% { left: 102%; opacity: 0; }
}

/* Header label */
.fvis-disease .scan-tag {
    position: absolute;
    top: 10px;
    left: 14px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: rgba(27, 67, 50, 0.65);
}
.fvis-disease .scan-tag .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #E85D4C;
    animation: live-pulse 2s ease-out infinite;
    box-shadow: 0 0 0 0 rgba(232, 93, 76, 0.5);
}

/* =====================================================================
   05 — Environmental Monitoring
   Three live gauges: temperature wave, humidity droplets, AQI bars.
   ===================================================================== */
.fvis-env {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0;
    background: linear-gradient(135deg, #fbfaf7 0%, #efeae0 100%);
}
.fvis-env .env-cell {
    position: relative;
    padding: 14px 10px 12px;
    border-right: 1px solid rgba(27, 67, 50, 0.07);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
}
.fvis-env .env-cell:last-child { border-right: 0; }
.fvis-env .env-lbl {
    font-size: 8px;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: rgba(27, 67, 50, 0.55);
}
.fvis-env .env-val {
    font-family: '"JetBrains Mono"', monospace;
    font-weight: 700;
    font-size: 16px;
    color: #1B4332;
    line-height: 1;
    position: relative;
    height: 16px;
    width: 100%;
    text-align: center;
}
.fvis-env .env-val span {
    position: absolute;
    inset: 0;
    text-align: center;
    opacity: 0;
    animation: env-blink 6s linear infinite;
}
.fvis-env .env-val span:nth-child(1) { animation-delay: 0.0s; }
.fvis-env .env-val span:nth-child(2) { animation-delay: 1.5s; }
.fvis-env .env-val span:nth-child(3) { animation-delay: 3.0s; }
.fvis-env .env-val span:nth-child(4) { animation-delay: 4.5s; }
@keyframes env-blink {
    0%, 22%   { opacity: 1; }
    25%, 100% { opacity: 0; }
}

/* Temperature: wave */
.fvis-env .env-temp svg { width: 100%; height: 36px; }
.fvis-env .env-temp .wave {
    fill: none;
    stroke: #E85D4C;
    stroke-width: 2;
    stroke-linecap: round;
    animation: env-wave 3s linear infinite;
}
@keyframes env-wave {
    0%   { transform: translateX(0); }
    100% { transform: translateX(-40px); }
}

/* Humidity: falling droplets */
.fvis-env .env-humid .drops {
    position: relative;
    width: 100%;
    height: 36px;
}
.fvis-env .env-humid .drop {
    position: absolute;
    top: 0;
    width: 3px;
    height: 6px;
    background: #6B8F71;
    border-radius: 50% 50% 50% 50% / 70% 70% 30% 30%;
    opacity: 0;
    animation: env-drop 2.4s ease-in infinite;
}
.fvis-env .env-humid .drop:nth-child(1) { left: 20%; animation-delay: 0s; }
.fvis-env .env-humid .drop:nth-child(2) { left: 45%; animation-delay: 0.8s; }
.fvis-env .env-humid .drop:nth-child(3) { left: 70%; animation-delay: 1.6s; }
@keyframes env-drop {
    0%   { transform: translateY(0); opacity: 0; }
    10%  { opacity: 1; }
    90%  { opacity: 1; }
    100% { transform: translateY(30px); opacity: 0; }
}

/* Air quality: bars */
.fvis-env .env-aq .bars {
    display: flex;
    gap: 3px;
    align-items: flex-end;
    height: 36px;
    width: 100%;
    justify-content: center;
}
.fvis-env .env-aq .bar {
    width: 5px;
    background: #1B4332;
    border-radius: 1px;
    animation: env-bar 2s ease-in-out infinite;
}
.fvis-env .env-aq .bar:nth-child(1) { animation-delay: 0s;   }
.fvis-env .env-aq .bar:nth-child(2) { animation-delay: 0.2s; }
.fvis-env .env-aq .bar:nth-child(3) { animation-delay: 0.4s; }
.fvis-env .env-aq .bar:nth-child(4) { animation-delay: 0.6s; }
.fvis-env .env-aq .bar:nth-child(5) { animation-delay: 0.8s; }
@keyframes env-bar {
    0%, 100% { height: 30%; }
    50%      { height: 95%; }
}

/* Live dot on each cell */
.fvis-env .env-cell .live-dot {
    position: absolute;
    top: 8px;
    right: 8px;
}
