/* ── Design tokens ────────────────────────────────────────────────────────
   Scoped to widget-canvas; deliberately NOT added to the global theme.scss,
   which is fragile/entangled with unrelated experiments (drawflow editor,
   claymorphism demo, etc). Radius/shadow modeled on .ff-card's existing
   clamp(16px,3.5vw,24px) radius and card-theme.css's .dsc-backdrop
   translucent-wash pattern — both already-sanctioned "premium but
   restrained" precedents elsewhere in this codebase.
   ─────────────────────────────────────────────────────────────────────── */
.wc-canvas {
    --wc-radius: clamp(16px, 2vw, 24px);
    --wc-radius-sm: clamp(12px, 1.5vw, 16px);
    --wc-shadow-soft: 0 4px 16px rgba(0,0,0,.06);
    --wc-shadow-hover: 0 8px 28px rgba(0,0,0,.12);
    --wc-tile-tint: color-mix(in srgb, var(--bs-body-color) 3%, transparent);
    --wc-tile-tint-hover: color-mix(in srgb, var(--bs-body-color) 5%, transparent);
}

body.no-select, body.no-select * {
    user-select: none;
}

/* ── Manual connection popup (widget-connections.directive.js) ──────────────
   The directive's root element is pointer-events:none so the SVG never blocks
   tile clicks/drags underneath it; pointer-events is inheritable, so the popup
   itself must explicitly opt back in or its buttons/inputs would be inert. */
.wc-conn-popup {
    position: absolute;
    pointer-events: auto;
    z-index: 5;
    width: 220px;
    padding: 10px;
    border-radius: var(--wc-radius-sm);
    border: 1px solid var(--app-border, rgba(0,0,0,.12));
    background: color-mix(in srgb, var(--bs-body-bg, #fff) 92%, transparent);
    box-shadow: var(--wc-shadow-hover);
    backdrop-filter: blur(var(--glass-blur, 12px));
}

.wc-conn-handle {
    transition: r 0.12s ease, fill 0.12s ease;
}

    .wc-conn-handle:hover {
        fill: #6366f1;
    }

/* ── Widget Canvas Grid Background ───────────────────────────────────── */
.wc-canvas {
    background-color: transparent;
    background-image: radial-gradient(circle, var(--bs-border-color) 1px, transparent 1px);
    background-size: 24px 24px;
}

.cursor-hand {
    cursor: pointer;
}

.widget-header .text-truncate {
    display: inline-block;
}

/* Only disable selection while actively dragging/resizing */
.resize-drag.is-interacting,
.resize-drag.is-interacting * {
    -webkit-user-select: none;
    -moz-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

.js-drag-handle {
    cursor: grab;
    transition: box-shadow .2s ease, background-color .2s ease, transform .15s ease;
}

    .js-drag-handle.is-dragging {
        cursor: grabbing;
        background-color: rgba(13,110,253,.12);
        box-shadow: 0 8px 24px rgba(0,0,0,.25), 0 0 0 2px rgba(13,110,253,.35);
        transform: scale(1.01);
        animation: dragPulse 0.6s ease-in-out infinite;
    }

@keyframes dragPulse {
    0% {
        box-shadow: 0 8px 24px rgba(0,0,0,.25);
    }

    50% {
        box-shadow: 0 12px 30px rgba(0,0,0,.35);
    }

    100% {
        box-shadow: 0 8px 24px rgba(0,0,0,.25);
    }
}

/*
 * Fix GridStack resize handles overlapping tile content.
 *
 * GridStack appends .ui-resizable-handle elements as direct children of
 * .grid-stack-item. They are absolutely positioned relative to that item,
 * so they sit on top of .grid-stack-item-content.
 *
 * The solution:
 *   1. Give .grid-stack-item a small inset on the edges where handles live.
 *   2. The content div fills the remaining space normally — no padding needed.
 *   3. The handles sit in the reserved gutter, never on top of content.
 *
 * Handle positions used:  se, sw, ne, nw, e, w, n, s
 * Gutter size: 8px  (matches typical ui-resizable handle size)
 */

/* ── Reserve gutter inside the grid item for handles ─────────────────── */
.grid-stack-item {
    box-sizing: border-box;
}

    /* The content wrapper must not cover the handle gutter.
   We achieve this by giving grid-stack-item a padding that equals
   the handle thickness, then letting the content fill what remains.   */
    .grid-stack-item > .grid-stack-item-content {
        /* Reset any inline padding added by accident */
        padding: 0 !important;
        position: absolute;
        top: 8px;
        left: 8px;
        right: 8px;
        bottom: 8px;
        overflow: hidden; /* content clips to the inset box     */
        display: flex;
        flex-direction: column;
    }

    /* ── Make sure handles render above content, in the gutter ───────────── */
    .grid-stack-item > .ui-resizable-handle {
        z-index: 10;
    }

    /* ── Visual affordance: subtle resize gripper on SE corner ───────────── */
    .grid-stack-item > .ui-resizable-se {
        width: 16px;
        height: 16px;
        right: 0;
        bottom: 0;
        cursor: se-resize;
        /* Diagonal lines gripper — pure CSS, no image needed */
        background-image: none;
        background: transparent;
    }

    .grid-stack-item:hover > .ui-resizable-se::after {
        border-color: rgba(0, 0, 0, 0.45);
    }

/* ── Tile card chrome ─────────────────────────────────────────────────────
   Applies to the real content wrapper of every tile shape (GridStack's
   .grid-stack-item-content and interact.js's .wc-tile), each carrying this
   class alongside its structural classes. Translucent tint (not an opaque
   fill) per CLAUDE.md's "no background-color on components" rule — same
   interpretation already used by .ff-card / .n1-goal / .dsc-backdrop
   elsewhere in this codebase.
   ─────────────────────────────────────────────────────────────────────── */
.wc-tile-inner {
    border-radius: var(--wc-radius);
    border: 1px solid var(--app-border, var(--bs-border-color));
    background: var(--wc-tile-tint);
    box-shadow: var(--wc-shadow-soft);
    transition: box-shadow 0.2s ease, border-color 0.2s ease, background 0.2s ease;
    overflow: hidden;
}

.grid-stack-item:hover .wc-tile-inner,
.wc-tile:hover.wc-tile-inner {
    box-shadow: var(--wc-shadow-hover);
    border-color: var(--bs-secondary-border-subtle);
    background: var(--wc-tile-tint-hover);
}

/* ── Drag Handle — glass strip floating above tile content ─────────────── */
.wc-drag-handle {
    height: 28px;
    padding: 0 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: grab;
    user-select: none;
    position: relative;
    background: var(--glass-bg, transparent);
    border-bottom: 1px solid var(--glass-border, transparent);
    backdrop-filter: blur(var(--glass-blur, 12px));
    -webkit-backdrop-filter: blur(var(--glass-blur, 12px));
    transition: background-color 0.18s ease, height 0.18s ease;
    /* Subtle grip lines using body color at low opacity */
    background-image: repeating-linear-gradient( 90deg, transparent, transparent 3px, color-mix(in srgb, var(--bs-body-color) 9%, transparent) 1px, color-mix(in srgb, var(--bs-body-color) 9%, transparent) 2px );
}

.grid-stack-item:hover .wc-drag-handle {
    background-image: repeating-linear-gradient( 90deg, transparent, transparent 3px, color-mix(in srgb, var(--bs-body-color) 3%, transparent) 3px, color-mix(in srgb, var(--bs-body-color) 4%, transparent) 4px );
    height: 34px;
}

.wc-drag-handle:active {
    cursor: grabbing;
}

/* ── Widget name ──────────────────────────────────────────────────────── */
.wc-drag-handle .wc-tile-name {
    font-size: var(--text-xs, 11px);
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: color-mix(in srgb, var(--bs-body-color) 35%, transparent);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 160px;
    transition: color 0.18s ease;
}

.grid-stack-item:hover .wc-drag-handle .wc-tile-name {
    color: color-mix(in srgb, var(--bs-body-color) 85%, transparent);
}

/* ── Action buttons ───────────────────────────────────────────────────── */
.wc-drag-handle .wc-tile-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    opacity: 0;
    transform: translateY(-2px);
    transition: opacity 0.18s ease, transform 0.18s ease;
    pointer-events: none;
}

.grid-stack-item:hover .wc-drag-handle .wc-tile-actions {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

/* ── Drag grip dots ───────────────────────────────────────────────────── */
.wc-drag-grip {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-right: 6px;
    flex-shrink: 0;
    opacity: 0.25;
    transition: opacity 0.18s ease;
}

.grid-stack-item:hover .wc-drag-grip {
    opacity: 0.55;
}

.wc-drag-grip span {
    display: flex;
    gap: 2px;
}

    .wc-drag-grip span i {
        width: 3px;
        height: 3px;
        border-radius: 50%;
        background: var(--bs-body-color);
        display: block;
    }

/* ── View-type-2 flat tile ──────────────────────────────────────────────
   Was Bootstrap's utility `rounded` (0.375rem) + `border`, no shadow.
   Brought in line with the GridStack/interact.js tile chrome above. */
.wc-flat-tile {
    border-radius: var(--wc-radius) !important;
    border: 1px solid var(--app-border, var(--bs-border-color)) !important;
    background: var(--wc-tile-tint);
    box-shadow: var(--wc-shadow-soft);
    transition: box-shadow 0.2s ease, background 0.2s ease;
}

    .wc-flat-tile:hover {
        box-shadow: var(--wc-shadow-hover);
        background: var(--wc-tile-tint-hover);
    }
