/* ─────────────────────────────────────────────────────────────────────
   Virtual IoT — instrument-style sensor modules
   Used by Live Device Viewer (sessions_live.rs)

   Layout (per card)
   ┌─────────────────────────────┐
   │  TOPLINE  (bold name + IO)  │  ← always visible
   │  ┌──────── BODY ─────────┐  │  ← shape + hard metallic edge
   │  │  dial / lcd / vu      │  │
   │  └───────────────────────┘  │
   │  readout (small, subtle)    │
   │  tools (hover only)         │
   └─────────────────────────────┘
   ───────────────────────────────────────────────────────────────────── */

/* ── Card outer (transparent, just a flex container) ────────────────── */
.virtual-iot-module-card {
    --module-accent: #7dd3fc;
    position: relative;
    display: flex;
    align-items: stretch;
    justify-content: stretch;
    padding: 0;
    background: transparent;
    border: none;
    overflow: visible;
    transition: transform 0.18s ease;
}

/* ── Shell: pure column container, no chrome of its own ─────────────── */
.virtual-iot-module-shell {
    flex: 1 1 auto;
    min-width: 168px;
    min-height: 168px;
    padding: 0;
    background: transparent;
    border: none;
    box-shadow: none;
    color: #dbeafe;
    display: grid;
    grid-template-rows: auto 1fr auto auto;
    gap: 0.3rem;
    overflow: visible;
    position: relative;
}

/* ── Topline = bold instrument name above the body ──────────────────── */
.virtual-iot-module-topline {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.4rem;
    min-width: 0;
    padding: 0 0.1rem;
}
.virtual-iot-module-title {
    font-size: 0.74rem;
    font-weight: 700;
    color: #f1f9ff;
    line-height: 1.1;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1 1 auto;
    min-width: 0;
    text-shadow: 0 1px 0 rgba(0,0,0,0.5);
}
.virtual-iot-module-io {
    font-size: 0.55rem;
    color: color-mix(in srgb, var(--module-accent) 75%, #cfe6ff);
    background: rgba(8, 15, 24, 0.55);
    padding: 0.05rem 0.4rem;
    border-radius: 999px;
    border: 1px solid color-mix(in srgb, var(--module-accent) 30%, rgba(148, 163, 184, 0.18));
    flex: 0 0 auto;
    letter-spacing: 0.06em;
    font-weight: 600;
}

/* ── Visual stage = the actual instrument body (shaped + metallic) ──── */
.virtual-iot-module-visual-stage {
    all: unset;
    --bezel-1: #2a3344;
    --bezel-2: #0e1626;
    --edge:    #050a13;
    cursor: pointer;
    width: 100%;
    height: 100%;
    min-height: 0;
    display: grid;
    place-items: center;
    position: relative;
    background:
        linear-gradient(145deg, var(--bezel-1) 0%, var(--bezel-2) 100%);
    border: 1.5px solid var(--edge);
    box-shadow:
        /* outer hard edge */
        0 0 0 1px rgba(0, 0, 0, 0.7),
        /* top inner highlight (light coming from top-left) */
        inset 0 1px 0 rgba(255, 255, 255, 0.16),
        inset 1px 0 0 rgba(255, 255, 255, 0.06),
        /* bottom inner shadow */
        inset 0 -1px 1px rgba(0, 0, 0, 0.6),
        inset 0 -2px 6px rgba(0, 0, 0, 0.55),
        /* drop shadow */
        0 4px 8px rgba(0, 0, 0, 0.4),
        0 8px 16px rgba(0, 0, 0, 0.25);
    transition: filter 0.18s ease, transform 0.15s ease, box-shadow 0.18s ease;
}
.virtual-iot-module-visual-stage:hover { filter: brightness(1.08) saturate(1.05); }
.virtual-iot-module-visual-stage:active { transform: scale(0.985); }

/* per-kind accent on the metallic edge */
.virtual-iot-module-card.is-active .virtual-iot-module-visual-stage {
    box-shadow:
        0 0 0 1px color-mix(in srgb, var(--module-accent) 60%, #050a13),
        0 0 0 3px color-mix(in srgb, var(--module-accent) 22%, transparent),
        inset 0 1px 0 rgba(255, 255, 255, 0.2),
        inset 0 -2px 6px rgba(0, 0, 0, 0.55),
        0 4px 8px rgba(0, 0, 0, 0.4),
        0 0 18px color-mix(in srgb, var(--module-accent) 50%, transparent);
    animation: viot-module-pulse 1.6s ease-in-out infinite;
}
@keyframes viot-module-pulse {
    0%, 100% { filter: brightness(1) saturate(1); }
    50%      { filter: brightness(1.1) saturate(1.15); }
}

/* ── Shape variants (live on the stage, not the shell) ──────────────── */
.virtual-iot-module-shell.shape-round  .virtual-iot-module-visual-stage {
    border-radius: 999px;
    aspect-ratio: 1 / 1;
    width: min(180px, 100%);
    justify-self: center;
}
.virtual-iot-module-shell.shape-square .virtual-iot-module-visual-stage {
    border-radius: 14px;
    aspect-ratio: 1 / 1;
    width: min(180px, 100%);
    justify-self: center;
}
.virtual-iot-module-shell.shape-rect   .virtual-iot-module-visual-stage {
    border-radius: 12px;
    aspect-ratio: 5 / 4;
    width: 100%;
    min-width: 200px;
}
.virtual-iot-module-shell.shape-hex    .virtual-iot-module-visual-stage {
    border-radius: 10px;
    aspect-ratio: 1 / 1;
    width: min(180px, 100%);
    justify-self: center;
    clip-path: polygon(50% 0%, 95% 25%, 95% 75%, 50% 100%, 5% 75%, 5% 25%);
}

/* ── Meter / Dial instrument ──────────────────────────────────────────
   The dial fills the metallic stage; the stage bezel acts as the chrome rim.
   Coordinate system: 0,0 at top-left of the dial; center at 50%,50%.
   Tick & needle pivot at the dial center via transform-origin: 50% 100%.
*/
.virtual-iot-meter-dial {
    --needle-deg: -120deg;
    position: absolute;
    inset: 5%;
    border-radius: 999px;
    background:
        /* lit conic arc -120°..+120° (240° sweep) */
        conic-gradient(from -120deg at 50% 50%,
            color-mix(in srgb, var(--module-accent) 70%, transparent) 0deg,
            color-mix(in srgb, var(--module-accent) 30%, transparent) 240deg,
            transparent 240deg 360deg),
        /* dark face */
        radial-gradient(circle at 50% 32%, rgba(255,255,255,0.06) 0%, transparent 38%),
        radial-gradient(circle at 50% 50%, rgba(8, 14, 22, 0.96) 50%, rgba(4, 8, 14, 0.98) 100%);
    box-shadow:
        inset 0 0 0 1px rgba(0,0,0,0.55),
        inset 0 0 14px rgba(0,0,0,0.55);
    overflow: hidden;
}
/* On non-round shells the dial is a circle inside a square/hex box */
.virtual-iot-module-shell.shape-square .virtual-iot-meter-dial,
.virtual-iot-module-shell.shape-hex   .virtual-iot-meter-dial {
    position: relative;
    inset: auto;
    width: 86%;
    aspect-ratio: 1 / 1;
    box-shadow:
        inset 0 0 0 1.5px rgba(0,0,0,0.7),
        inset 0 0 0 3px rgba(255,255,255,0.04),
        inset 0 0 16px rgba(0,0,0,0.55),
        0 2px 4px rgba(0,0,0,0.4);
}
/* meter-ring is no longer needed; hide if present */
.virtual-iot-meter-ring { display: none; }
/* Ticks: 5 thin marks on a virtual circle at radius ~42% from center.
   Each tick is rendered as a span anchored at the dial center with
   transform-origin 50% 100%, then rotated. The colored portion sits at the top of the span. */
.virtual-iot-meter-ticks {
    position: absolute;
    inset: 0;
    pointer-events: none;
}
.virtual-iot-meter-ticks span {
    position: absolute;
    left: 50%;
    bottom: 50%;
    width: 2px;
    height: 42%;
    transform-origin: 50% 100%;
    transform: translateX(-50%) rotate(0deg);
    background:
        linear-gradient(180deg,
            color-mix(in srgb, var(--module-accent) 90%, #eaf3ff) 0%,
            color-mix(in srgb, var(--module-accent) 90%, #eaf3ff) 18%,
            transparent 19%);
    border-radius: 1px;
    opacity: 0.9;
}
.virtual-iot-meter-ticks span:nth-child(1) { transform: translateX(-50%) rotate(-120deg); }
.virtual-iot-meter-ticks span:nth-child(2) { transform: translateX(-50%) rotate( -60deg); }
.virtual-iot-meter-ticks span:nth-child(3) { transform: translateX(-50%) rotate(   0deg); }
.virtual-iot-meter-ticks span:nth-child(4) { transform: translateX(-50%) rotate(  60deg); }
.virtual-iot-meter-ticks span:nth-child(5) { transform: translateX(-50%) rotate( 120deg); }
/* Needle: anchored at dial center, rotates about its bottom. */
.virtual-iot-meter-needle {
    position: absolute;
    left: 50%;
    bottom: 50%;
    width: 3px;
    height: 36%;
    transform-origin: 50% 100%;
    transform: translateX(-50%) rotate(var(--needle-deg));
    transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
    background: linear-gradient(180deg, #fff7d6 0%, #f97316 55%, #b91c1c 100%);
    border-radius: 2px 2px 1px 1px;
    box-shadow: 0 0 6px rgba(249, 115, 22, 0.55);
    z-index: 2;
}
.virtual-iot-meter-core {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 14%;
    aspect-ratio: 1 / 1;
    border-radius: 999px;
    background: radial-gradient(circle at 30% 30%, #d8e1ec, #5b6776 60%, #1c2330);
    transform: translate(-50%, -50%);
    box-shadow: 0 0 0 1px rgba(0,0,0,0.6), 0 1px 2px rgba(0,0,0,0.55);
    z-index: 3;
}
.virtual-iot-meter-icon { display: none; }

/* Motion wave overlay above center */
.virtual-iot-wave-overlay {
    position: absolute;
    top: 24%;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 3px;
    align-items: flex-end;
    height: 12px;
    z-index: 2;
    pointer-events: none;
}
.virtual-iot-wave-overlay span {
    width: 3px;
    background: color-mix(in srgb, var(--module-accent) 80%, #eaf3ff);
    border-radius: 1px;
    animation: viot-wave 1.1s ease-in-out infinite;
}
.virtual-iot-wave-overlay span:nth-child(1) { height: 60%;  animation-delay: 0s; }
.virtual-iot-wave-overlay span:nth-child(2) { height: 100%; animation-delay: 0.18s; }
.virtual-iot-wave-overlay span:nth-child(3) { height: 70%;  animation-delay: 0.36s; }
@keyframes viot-wave {
    0%, 100% { transform: scaleY(0.5); }
    50%      { transform: scaleY(1); }
}

/* ── Digital LCD (digital, location) ────────────────────────────────── */
.virtual-iot-digital-screen {
    position: absolute;
    inset: 6%;
    border-radius: 6px;
    background:
        repeating-linear-gradient(0deg,
            rgba(0,0,0,0.0) 0px, rgba(0,0,0,0.0) 2px,
            rgba(0,0,0,0.20) 3px, rgba(0,0,0,0.0) 4px),
        linear-gradient(180deg, #0d2418, #061a10);
    border: 1px solid #1a3a26;
    box-shadow:
        inset 0 0 0 1px rgba(0,0,0,0.7),
        inset 0 0 14px rgba(0, 255, 120, 0.06),
        0 1px 2px rgba(0,0,0,0.5);
    color: #6ee7a8;
    font-family: var(--font-mono);
    text-shadow: 0 0 5px rgba(110, 231, 168, 0.55);
    padding: 0.4rem 0.5rem;
    display: grid;
    grid-template-rows: auto 1fr auto;
    gap: 0.15rem;
    overflow: hidden;
}
.virtual-iot-module-card[data-kind="location"] .virtual-iot-digital-screen {
    background:
        repeating-linear-gradient(0deg,
            rgba(0,0,0,0.0) 0px, rgba(0,0,0,0.0) 2px,
            rgba(0,0,0,0.20) 3px, rgba(0,0,0,0.0) 4px),
        linear-gradient(180deg, #2a0d10, #1a0608);
    border-color: #5a1f24;
    color: #fca5a5;
    text-shadow: 0 0 5px rgba(252, 165, 165, 0.5);
}
.virtual-iot-digital-chip {
    font-size: 0.5rem;
    letter-spacing: 0.18em;
    opacity: 0.65;
    text-transform: uppercase;
}
.virtual-iot-digital-reading {
    font-size: 0.95rem;
    font-weight: 700;
    line-height: 1.05;
    letter-spacing: 0.04em;
    align-self: center;
    word-break: break-word;
}
.virtual-iot-digital-bus {
    font-size: 0.5rem;
    letter-spacing: 0.12em;
    opacity: 0.55;
    text-transform: uppercase;
}

/* ── Bar / VU meter (audio, network) ────────────────────────────────── */
.virtual-iot-bar-screen {
    position: absolute;
    inset: 6%;
    display: grid;
    grid-template-columns: 14px 1fr;
    grid-template-rows: 1fr auto;
    gap: 0.4rem;
    padding: 0.4rem 0.5rem;
    border-radius: 8px;
    background: linear-gradient(180deg, rgba(8, 15, 24, 0.95), rgba(4, 10, 18, 0.98));
    border: 1px solid rgba(148, 163, 184, 0.18);
    box-shadow: inset 0 0 0 1px rgba(0,0,0,0.55), inset 0 1px 0 rgba(255,255,255,0.04);
}
.virtual-iot-bar-rail {
    position: relative;
    grid-row: 1 / 2;
    grid-column: 1 / 2;
    background: rgba(0,0,0,0.55);
    border-radius: 3px;
    overflow: hidden;
    border: 1px solid rgba(0,0,0,0.55);
}
.virtual-iot-bar-fill {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(180deg,
        #f87171 0%,
        #facc15 35%,
        color-mix(in srgb, var(--module-accent) 80%, #34d399) 60%,
        color-mix(in srgb, var(--module-accent) 100%, transparent) 100%);
    transition: height 0.35s ease-out;
    box-shadow: 0 0 8px color-mix(in srgb, var(--module-accent) 60%, transparent);
}
.virtual-iot-bar-peaks {
    grid-row: 1 / 2;
    grid-column: 2 / 3;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 4px;
    height: 100%;
}
.virtual-iot-bar-peaks span {
    flex: 1 1 0;
    background: linear-gradient(180deg,
        color-mix(in srgb, var(--module-accent) 100%, transparent),
        color-mix(in srgb, var(--module-accent) 30%, transparent));
    border-radius: 2px 2px 0 0;
    min-height: 6px;
    transition: height 0.35s ease-out;
    box-shadow: inset 0 -1px 0 rgba(0,0,0,0.4);
}
.virtual-iot-bar-reading {
    grid-row: 2 / 3;
    grid-column: 1 / 3;
    text-align: right;
    font-family: var(--font-mono);
    font-size: 0.65rem;
    color: color-mix(in srgb, var(--module-accent) 80%, #eaf3ff);
    letter-spacing: 0.02em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Readout under the body (compact, subtle) ───────────────────────── */
.virtual-iot-module-readout {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.04rem;
    text-align: center;
    min-width: 0;
    padding: 0 0.1rem;
}
.virtual-iot-module-subtitle {
    font-size: 0.46rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: rgba(141, 170, 196, 0.6);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}
.virtual-iot-module-reading {
    font-size: 0.7rem;
    font-weight: 600;
    color: color-mix(in srgb, var(--module-accent) 85%, #eaf3ff);
    line-height: 1.15;
    letter-spacing: 0.02em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
    font-family: var(--font-mono);
}
.virtual-iot-module-range {
    font-size: 0.44rem;
    letter-spacing: 0.08em;
    color: rgba(141, 170, 196, 0.45);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

/* ── Tools row (hover-only) ─────────────────────────────────────────── */
.virtual-iot-module-tools {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.3rem;
    padding: 0 0.1rem;
    opacity: 0;
    transition: opacity 0.18s ease;
}
.virtual-iot-module-card:hover .virtual-iot-module-tools,
.virtual-iot-module-card:focus-within .virtual-iot-module-tools,
.virtual-iot-module-card.is-expanded .virtual-iot-module-tools {
    opacity: 1;
}
.virtual-iot-module-tools .btn {
    font-size: 0.52rem;
    padding: 0.08rem 0.4rem;
    line-height: 1.2;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}
.virtual-iot-module-drag-tip {
    font-size: 0.42rem;
    color: rgba(141, 170, 196, 0.5);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Expand panel (radial overlay when expanded) ────────────────────── */
.virtual-iot-module-expand-panel {
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translate(-50%, 6px);
    z-index: 20;
    width: max(220px, 100%);
    background: rgba(10, 18, 28, 0.97);
    border: 1px solid color-mix(in srgb, var(--module-accent) 38%, rgba(148, 163, 184, 0.3));
    border-radius: 12px;
    padding: 0.55rem 0.6rem;
    box-shadow: 0 18px 32px rgba(0,0,0,0.55);
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}
.virtual-iot-module-control-row {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    width: 100%;
}
.virtual-iot-module-slider {
    width: 100%;
    accent-color: var(--module-accent);
}
.virtual-iot-module-control-meta {
    font-size: 0.6rem;
    color: rgba(141, 170, 196, 0.85);
    letter-spacing: 0.04em;
}
.virtual-iot-module-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    align-items: center;
}
.virtual-iot-module-actions .btn {
    font-size: 0.6rem;
    padding: 0.12rem 0.4rem;
    line-height: 1.2;
}
.virtual-iot-module-busy {
    margin-left: auto;
    font-size: 0.58rem;
    color: rgba(141, 170, 196, 0.7);
    opacity: 0;
    transition: opacity 0.15s ease;
    letter-spacing: 0.04em;
}
.virtual-iot-module-busy.is-visible {
    opacity: 1;
    color: #67e8f9;
}

/* expanded state — slight scale */
.virtual-iot-module-card.is-expanded .virtual-iot-module-visual-stage {
    transform: scale(0.98);
}
