:root {
    --dlg-radius:      14px;
    --dlg-header-h:    46px;
    --dlg-shadow:      0 24px 64px color-mix(in srgb, var(--text-on-surface) 16%, transparent),
                       0 8px 24px color-mix(in srgb, var(--text-on-surface) 8%, transparent),
                       0 0 0 1px color-mix(in srgb, var(--text-on-surface) 6%, transparent);
    --dlg-shadow-hover:0 32px 80px color-mix(in srgb, var(--text-on-surface) 20%, transparent),
                       0 12px 32px color-mix(in srgb, var(--text-on-surface) 10%, transparent);
    --dlg-primary:     var(--color-primary);
    --dlg-primary-dark:var(--color-primary-hover);
    --dlg-surface:     var(--surface);
    --dlg-border:      color-mix(in srgb, var(--text-on-surface) 7%, transparent);
    --dlg-min-w:       340px;
    --dlg-min-h:       180px;
    --dlg-spring:      280ms cubic-bezier(.2,.9,.4,1.1);
    --dlg-ease:        180ms cubic-bezier(.4,0,.2,1);
}

.eq-dlg {
    position: fixed;
    min-width: var(--dlg-min-w);
    min-height: var(--dlg-min-h);
    max-width: calc(100vw - 24px);
    max-height: calc(var(--eq-app-h) - 24px);
    display: flex;
    flex-direction: column;
    background: var(--dlg-surface);
    border-radius: var(--dlg-radius);
    box-shadow: var(--dlg-shadow);
    border: 1px solid var(--dlg-border);
    pointer-events: auto;
    animation: dlg-in var(--dlg-spring) both;
    overflow: hidden;
    will-change: transform, box-shadow;
    transition: box-shadow var(--dlg-ease), transform var(--dlg-ease);
}
.eq-dlg:not(.eq-dlg-maximized):not(.eq-dlg-minimized):hover {
    box-shadow: var(--dlg-shadow-hover);
}

.eq-dlg.eq-dlg-closing {
    animation: dlg-out var(--dlg-ease) both;
    pointer-events: none;
}

@keyframes dlg-in {
    from { opacity: 0; transform: var(--dlg-pos, ) translateY(16px) scale(.96); }
    to   { opacity: 1; transform: var(--dlg-pos, ); }
}
@keyframes dlg-out {
    from { opacity: 1; transform: var(--dlg-pos, ); }
    to   { opacity: 0; transform: var(--dlg-pos, ) translateY(8px) scale(.98); }
}

.eq-dlg-titlebar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 10px 0 18px;
    height: var(--dlg-header-h);
    min-height: var(--dlg-header-h);
    background: linear-gradient(135deg, var(--dlg-primary) 0%, var(--color-primary-hover) 100%);

    position: relative;
    cursor: move;
    user-select: none;
    flex-shrink: 0;
    overflow: hidden;
}

.eq-dlg-titlebar::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(to right, color-mix(in srgb, var(--surface) 6%, transparent) 0%, transparent 60%);
    pointer-events: none;
}
.eq-dlg-titlebar:active { cursor: grabbing; }

.eq-dlg-title {
    flex: 1;
    font-size: max(12px, calc(13px * var(--eq-escala)));
    font-weight: 600;
    letter-spacing: .02em;
    color: var(--surface);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.eq-dlg-controls {
    display: flex;
    gap: 3px;
    flex-shrink: 0;
    position: relative;
    z-index: 1;
}

.eq-dlg-btn {
    width: 28px; height: 28px;
    border-radius: 7px;
    border: none;
    background: transparent;
    color: color-mix(in srgb, var(--surface) 70%, transparent);
    display: grid; place-items: center;
    cursor: pointer;
    padding: 0;
    transition: background var(--dlg-ease), color var(--dlg-ease),
                transform 120ms cubic-bezier(.2,.9,.4,1.1);
}
.eq-dlg-btn:hover {
    background: color-mix(in srgb, var(--surface) 18%, transparent);
    color: var(--surface);
    transform: scale(1.08);
}
.eq-dlg-btn:active { transform: scale(.95); }
.eq-dlg-btn--close:hover { background: color-mix(in srgb, var(--error) 70%, transparent); color: var(--surface); transform: scale(1.08); }
.eq-dlg-btn svg { pointer-events: none; }

.eq-dlg-body {
    flex: 1;
    overflow: auto;
    min-height: 0;
    position: relative;
    background: var(--dlg-surface);

}

.eq-dlg canvas { will-change: transform; }

.eq-dlg-loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    min-height: 140px;
}
.eq-dlg-loader-ring {
    width: 32px; height: 32px;
    border: 2.5px solid color-mix(in srgb, var(--color-primary) 12%, transparent);
    border-top-color: var(--dlg-primary);
    border-radius: 50%;
    animation: dlg-spin 700ms linear infinite;
}
@keyframes dlg-spin { to { transform: rotate(360deg); } }

.eq-dlg.eq-dlg-minimized {
    display: none;
}

.eq-dlg.eq-dlg-maximized {
    inset: 12px !important;
    width: auto !important; height: auto !important;
    max-width: none !important; max-height: none !important;
    border-radius: var(--dlg-radius);
    animation: none;
}
.eq-dlg.eq-dlg-maximized .eq-dlg-titlebar { cursor: default; }

.eq-dlg-resize {
    position: absolute;
    right: 0; bottom: 0;
    width: 20px; height: 20px;
    cursor: se-resize;
    z-index: 1;
}
.eq-dlg-resize::before,
.eq-dlg-resize::after {
    content: '';
    position: absolute;
    background: color-mix(in srgb, var(--color-primary) 25%, transparent);
    border-radius: 2px;
    transition: background var(--dlg-ease);
}
.eq-dlg:hover .eq-dlg-resize::before,
.eq-dlg:hover .eq-dlg-resize::after { background: color-mix(in srgb, var(--color-primary) 45%, transparent); }
.eq-dlg-resize::before { right: 5px; bottom: 9px; width: 10px; height: 2px; transform: rotate(-45deg); }
.eq-dlg-resize::after  { right: 4px; bottom: 4px; width: 14px; height: 2px; transform: rotate(-45deg); }

#eq-dlg-dock {
    position: fixed;
    bottom: 0; left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 6px;
    align-items: flex-end;
    z-index: 2100;
    pointer-events: none;
}

.eq-dlg-dock-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 14px;
    background: color-mix(in srgb, var(--color-primary) 92%, transparent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid color-mix(in srgb, var(--surface) 14%, transparent);
    border-bottom: none;
    color: var(--surface);
    border-radius: 8px 8px 0 0;
    font-size: max(12px, calc(12px * var(--eq-escala)));
    font-weight: 600;
    font-family: 'Inter', system-ui, sans-serif;
    cursor: pointer;
    pointer-events: auto;
    box-shadow: 0 -4px 16px color-mix(in srgb, var(--text-on-surface) 12%, transparent);
    transition: background var(--dlg-ease), transform 120ms cubic-bezier(.2,.9,.4,1.1);
    max-width: 200px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.eq-dlg-dock-item:hover {
    background: color-mix(in srgb, var(--color-primary-hover) 95%, transparent);
    transform: translateY(-2px);
}
.eq-dlg-dock-item svg,
.eq-dlg-dock-item i { flex-shrink: 0; opacity: .85; font-size: max(12px, calc(12px * var(--eq-escala))); }

.eq-dlg-has-grid .eq-dlg-body {
    overflow: hidden !important;
    padding: 0 !important;
}

.eq-dlg-body .pagina-principal { min-height: 0; }
.eq-dlg-body .contenedor-pagina-principal { height: auto; min-height: 0; }
.eq-dlg-body .contenedor-cuerpo { overflow-y: visible; }
.eq-dlg-body .dp-measures { grid-template-columns: repeat(3, 1fr); }

@media (max-width: 600px) {
    .eq-dlg:not(.eq-dlg-minimized) {
        inset: 0 auto auto 0 !important;
        width: 100% !important;
        height: var(--eq-app-h) !important;
        max-width: none !important;
        max-height: none !important;
        min-width: 0;
        min-height: 0;
        --dlg-pos: translate(0,0) !important;
        transform: none;
        border-radius: 0;
        border: none;
    }
    .eq-dlg-btn[data-action="maximize"] { display: none; }

    .eq-dlg.eq-dlg--ajustado:not(.eq-dlg-minimized) {
        inset: auto 0 0 0 !important;
        height: auto !important;
        max-height: calc(var(--eq-app-h) - 56px) !important;
        border-radius: 16px 16px 0 0;
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }
    .eq-dlg.eq-dlg-minimized {
        inset: auto !important;
        width: auto !important;
    }
}
