/* ══════════════════════════════════════════════════════════════
   Device stage - draggable / resizable device wrappers.
   Shared by the Simulation screen and the network room (WI 443),
   driven by js/drag-resize.js.

   Global on purpose, not .razor.css: drag-resize.js injects the
   .touch-resize-handle grip itself, and an element Blazor did not
   render never gets the CSS-isolation attribute - so scoped rules
   for it never matched.
   ══════════════════════════════════════════════════════════════ */

/* ══════════════════════════════════════════════════════════════
   Device wrapper
   ══════════════════════════════════════════════════════════════ */
.device-wrapper {
    position: absolute;
    display: flex;
    flex-direction: column;
    /* CSS resize (mouse – bottom-right corner grip) */
    resize: both;
    /* overflow:hidden is required for resize:both; we compensate for
       the canvas-crop issue in C# by subtracting the handle-bar height
       from MaxHeight, so the canvas content always fits. */
    overflow: hidden;
    min-width: 200px;
    min-height: 150px;
    border-radius: 8px;
    border: 1px solid transparent;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: transparent;
    will-change: transform;
}

    .device-wrapper:hover {
        border-color: var(--brand-primary-30);
    }

    /* Active drag */
    .device-wrapper.device-dragging {
        border-color: var(--brand-primary-50);
        box-shadow: 0 6px 24px var(--brand-primary-30);
        z-index: 100;
    }

    /* Active resize (touch) */
    .device-wrapper.device-resizing {
        border-color: var(--brand-primary-50);
        box-shadow: 0 4px 16px var(--brand-primary-15);
    }

    /* Locked – remove all interactive cursors */
    .device-wrapper.layout-locked {
        resize: none;
        cursor: default;
    }

        .device-wrapper.layout-locked .device-drag-handle {
            cursor: not-allowed;
            opacity: 0 !important; /* hide handle entirely when locked */
        }

        .device-wrapper.layout-locked .touch-resize-handle {
            display: none;
        }

/* ── Drag handle bar ── */
.device-drag-handle {
    /* Fixed height so C# can subtract it from MaxHeight reliably */
    height: 29px;
    flex-shrink: 0; /* never let flexbox squash it */

    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 10px;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border-stroke);
    border-radius: 8px 8px 0 0;
    cursor: grab;
    user-select: none;
    /* touch-action:none is required so the Pointer Events pointermove
       fires on touch without the browser intercepting it as a scroll */
    touch-action: none;
    opacity: 0;
    transition: opacity 0.2s;
}

.device-wrapper:hover .device-drag-handle,
.device-wrapper.device-dragging .device-drag-handle {
    opacity: 1;
}

.device-drag-handle:active {
    cursor: grabbing;
}

/* Six-dot grip icon (pure CSS) */
.drag-dots {
    width: 20px;
    height: 12px;
    display: grid;
    grid-template-columns: repeat(3, 4px);
    grid-template-rows: repeat(2, 4px);
    gap: 2px;
}

    .drag-dots::before {
        content: '';
        display: block;
        width: 4px;
        height: 4px;
        border-radius: 50%;
        background: var(--brand-text);
        grid-column: 1 / 4;
        grid-row: 1;
        box-shadow: 8px 0 0 var(--brand-text), 16px 0 0 var(--brand-text), 0 8px 0 var(--brand-text), 8px 8px 0 var(--brand-text), 16px 8px 0 var(--brand-text);
    }

.device-label {
    font-family: var(--font-family-body);
    font-size: 11px;
    font-weight: 500;
    color: var(--color-text-secondary);
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

/* ── Inner content area ── */
.device-inner {
    flex: 1;
    /* overflow:hidden here prevents the canvas from bleeding outside  */
    overflow: hidden;
    display: flex;
    align-items: flex-start; /* top-align so canvas is never cropped at top */
    justify-content: center;
    min-height: 0; /* allow flex child to shrink */
}

/* ── Touch resize corner grip ── */
.touch-resize-handle {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 28px;
    height: 28px;
    cursor: se-resize;
    touch-action: none;
    z-index: 10;
    /* Visual: three diagonal lines in the corner */
    background: linear-gradient( 135deg, transparent 30%, var(--brand-primary-50) 30%, var(--brand-primary-50) 40%, transparent 40%, transparent 55%, var(--brand-primary-50) 55%, var(--brand-primary-50) 65%, transparent 65%, transparent 80%, var(--brand-primary-50) 80%, var(--brand-primary-50) 90%, transparent 90% );
    opacity: 0;
    transition: opacity 0.2s;
}

.device-wrapper:hover .touch-resize-handle,
.device-wrapper.device-resizing .touch-resize-handle {
    opacity: 1;
}


/* ══════════════════════════════════════════════════════════════
   Responsive: touch pointer (tablets in landscape, iPad, etc.)
   Show touch resize handle and drag handle for pointer:coarse
   but only on reasonably large screens
   ══════════════════════════════════════════════════════════════ */
@media (pointer: coarse) and (min-width: 700px) and (min-height: 500px) {
    /* Always show drag handle on touch tablets so it's discoverable */
    .device-drag-handle {
        opacity: 1;
        background: var(--color-bg-default);
    }

    .touch-resize-handle {
        opacity: 0.6;
    }

    /* Hide the native CSS resize corner – replaced by our touch grip */
    .device-wrapper {
        resize: none;
    }
}
